之前用的创蓝 也就是253发送短信接口老提示json格式不对
检查了一下发现缺少个HTTP头 放在这里随便记录一下~
function post_curl($url, $post_data = [])
{
if (empty($post_data) || empty($url)) {
return false;
}
$ch = curl_init();
$data_string = json_encode($post_data);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// post数据
curl_setopt($ch, CURLOPT_POST, 1);
// post的变量
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
// 下面这样就是单独设置的HTTP头
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string)));
$output = curl_exec($ch);
curl_close($ch);
//打印获得的数据
return json_decode($output,True);
}