php post请求,参数数据格式为json

发布于 2021-05-02 13:04:40
    	$url = "http://api.kmicloud.com/sms/send/v1/marketing";
    	
    	$params = array(
    	    'accessKey'   => 'xxx',
    	    'to'    => '0091'.$mobile, //接受短信的用户手机号码
    	    'secretKey'    => 'yyy', //您申请的短信模板ID,根据实际情况修改
    	    //senderId
    	    'from'=>'abc',
    	    'callbackUrl'=>'',
    	   'message' =>'#code#='.$qycode //您设置的模板变量,根据实际情况修改
    	   
    	);

$paramstring = json_encode($params);
$content = curlPost($url,$paramstring,1);
        
        
function curlPost($url, $post_data, $json){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT,10);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    if ($json) {
        curl_setopt($ch, CURLOPT_HTTPHEADER,array('Content-Type: application/json; charset=utf-8'));
    }
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    $output = curl_exec($ch);
    curl_close($ch);
    $output_array = json_decode($output, true);
    return $output_array;
}



关注公众号,了解更多it技术(it问答网

0 条评论

发布
问题