php post json數據傳輸 OA與短信平臺對接

<?

include_once 'auth.php';
include_once 'inc/utility_all.php';
include_once 'inc/utility_org.php';
include_once 'inc/utility_msg.php';


$CUR_YEAR = date('Y');
$CUR_MONTH = date('m');
$CUR_WEEK = date('w');
$CUR_DAY = date('j');
$CUR_DATE = date('Y-m-d H:i:s');
$CUR_TIME = date('H:i:s');
$query = "select * from OFFICE_TASK where USE_FLAG='1' and TASK_CODE='sms_jiaoyu' limit 0,1";
$cursor = exequery(TD::conn(), $query);

if (!$cursor) {
	echo '-ERR ' . get_err_msg($query, $TASK_ID);
	exit();
}

	

	$query = "select distinct(content) from sms2 where send_flag = 0 and SEND_TIME<='$CUR_DATE' LIMIT 0,100";
	$cursor= exequery(TD::conn(),$query); 
	while($ROW=mysql_fetch_array($cursor))
	{
		
		$content= $ROW["content"];
		//echo $content."<br>";
		$sms_id_str="";//id字符串
		$phone_str="";//手機號字符串
		$query1="select sms_id,phone from sms2 where send_flag = 0 and content='".$content."' limit 0,50";//每次最多提交的短信條數50*n
		$cursor1=mysql_query($query1);
		while($row1=mysql_fetch_array($cursor1)){
			$sms_id_str.=$row1["sms_id"].",";
			$phone_str.=$row1["phone"].",";
			}
		$sms_id_str=substr($sms_id_str,0,-1);
		$phone_str=substr($phone_str,0,-1);	
	
	
	$tels="18249035876,15665781570";
	$message="請張總明天上午九點到二樓會議室開會!";
	
 	$tels=$phone_str;
	$message=$content;
    $url = "http://xxzx22.xzlsedu.com:7033/ums/a/rest/sms-in";//tels,message
 
$arr=array();

$arr["tels"]=iconv("gb2312","utf-8",$tels); 
$arr["message"]=iconv("gb2312","utf-8",$message); 


$data = json_encode($arr);    
//$post_string = "tels=".$arr["tels"]."&message=".$arr["message"]; 
//list($return_code, $return_content) = http_post_data($url, $data);  
$aaa = http_post_data($url, $data);    
//print_r($aaa);  
//echo $aaa;  

$ccc=json_decode($aaa);  
//print_r($ccc);  
$result=$ccc->success;  //==1   或  true

	  /**************************************/	
	  if($result) {
		  //提交成功
		  //邏輯代碼
		 // echo "成功!";
		  $query2 = "update  sms2 set send_flag = 1 where find_in_set(sms_id,'".$sms_id_str."')";
			  //echo "<br>".$query2."<br><br>";
			  exequery(TD::conn(),$query2);  
		 
	  } else {
		  //提交失敗
		  //邏輯代碼
		   //echo "失敗!";
	  }
	  /**************************************/
}	



update_office_task($TASK_ID, '1', date('Y-m-d H:i:s', time()));
echo '+OK';






function http_post_data($url, $data_string) {    
    
        $ch = curl_init();    
        curl_setopt($ch, CURLOPT_POST, 1);    
        curl_setopt($ch, CURLOPT_URL, $url);    
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);    
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(    
            'Content-Type: application/json; charset=utf-8',    
           'Content-Length: ' . strlen($data_string))    
        );    //post  json
        ob_start();    
        curl_exec($ch);    
        $return_content = ob_get_contents();    
      //  echo $return_content."<br>";  
        ob_end_clean();    
    
        $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);    
      //  return array($return_code, $return_content);    
      return  $return_content;  
    }    
    


?>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章