php 模拟https post传输数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hai7425/article/details/84918395
	

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

猜你喜欢

转载自blog.csdn.net/hai7425/article/details/84918395