$url="http://mas.ecloud.10086.cn/app/http/authorize";
$post_data=array();
$post_data["ec_name"]=iconv("gb2312","utf-8","464674"); //单位名称
$post_data["user_name"]=iconv("gb2312","utf-8","57767sms"); //用户名
$post_data["user_passwd"]=iconv("gb2312","utf-8","oa_018");//密码
//$arr["sign"]=iconv("gb2312","utf-8","58586587"); //签名编码
$o = "";
foreach ( $post_data as $k => $v )
{
$o.= "$k=" . urlencode( $v ). "&" ;
}
$post_data = substr($o,0,-1);
$res =request_post($url, $post_data);
// print_r($res);
$re=json_decode($res,true);
// print_r($re); //{"status":"Success","access_token_expire_seconds":"7200","mas_user_id":"416c3892-79c2-465d-80a8-40ddd1df3cb4","access_token":"YHOsg8JlsMfoS90N6rQR44e2OYOvxm"}
$status=$re["status"];
$mas_user_id=$re["mas_user_id"];
$access_token=$re["access_token"];
// echo $status;
if($status=="Success"){
$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);
/**************************************/
//$arr["ecName"]=iconv("gb2312","utf-8","眉山市投资促进局"); //单位名称
$url1="http://mas.ecloud.10086.cn/app/http/sendSms";
$post_data1=array();
$post_data1["mas_user_id"]=$mas_user_id;
$post_data1["sign"]=iconv("gb2312","utf-8","232323");
$post_data1["serial"]="";
$post_data1["mobiles"]=iconv("gb2312","utf-8",$phone_str);
$post_data1["content"]=iconv("gb2312","utf-8",$content);
$post_data1["mac"]=strtoupper(md5($mas_user_id.$post_data1["mobiles"].$post_data1["content"].$post_data1["sign"]. $post_data1["serial"].$access_token));
// echo $post_data1["mac"];
$o1 = "";
foreach ( $post_data1 as $k => $v )
{
$o1.= "$k=" . urlencode( $v ). "&" ;
}
$post_data1 = substr($o1,0,-1);
$res1 =request_post($url1, $post_data1);
// print_r($res1);
$re1=json_decode($res1,true);
$sc=$re1["RET-CODE"];
if($sc=="SC:0000"){
// 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 {
//提交失败
//逻辑代码
}
/**************************************/
}
}//if status
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_POSTFIELDS, $curlPost);
$data = curl_exec($ch);//运行curl
curl_close($ch);
return $data;
}
function object_array($array){
if(is_object($array)){
$array = (array)$array;
}
if(is_array($array)){
foreach($array as $key=>$value){
$array[$key] = object_array($value);
}
}
return $array;
}