$query = "select distinct(content) from sms2 where send_flag = 0 and SEND_TIME<='$CUR_DATE' LIMIT 0,1000";
$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,200";//每次最多送出的短信條數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);
/**************************************/
$SpCode="55656"; //企業編碼
$LoginName="bs86676y";
$Password="baise787878";
$MessageContent=$content;//"你有一項編号為12345679的事務需要處理.";
$UserNumber=$phone_str;
$url = "https://api.ums86.com:9600/sms/Api/Send.do";
$post_data['SpCode'] = $SpCode;
$post_data['LoginName'] = $LoginName;
$post_data['Password'] =$Password;
$post_data['MessageContent'] =$MessageContent;
$post_data['UserNumber']=$UserNumber;
$post_data['SerialNumber']='';
$post_data['ScheduleTime']='';
$post_data['ExtendAccessNum']='';
$post_data['f']='1';
$o1="";
foreach ( $post_data as $k => $v )
{
$o1.= "$k=" . urlencode( $v ). "&" ;
}
$post_data1 = substr($o1,0,-1);
$res1 =request_post($url, $post_data1);
//echo $res1;
$res1_arr=explode("&",$res1);
if($res1_arr[0]=="result=0"){
// echo "ssssuccess";
$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 {
//送出失敗
//邏輯代碼
}
/**************************************/
}
function request_post($url = '', $param = '') {
if (empty($url) || empty($param)) {
return false;
}
$postUrl = $url;
$curlPost = $param;
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定網頁
curl_setopt($ch, CURLOPT_HEADER, 0);//設定header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求結果為字元串且輸出到螢幕上
curl_setopt($ch, CURLOPT_POST, 1);//post送出方式
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https請求 不驗證證書和hosts
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);//運作curl
curl_close($ch);
return $data;
}