<?
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;
}
?>