代码如下,不过题主给的数据包视乎不对。。自己看下api需要发送什么参数
<?php
/**
* PHP发送Json对象数据
*
* @param $url 请求url
* @param $jsonStr 发送的json字符串
* @return array
*/
function http_post_json($url, $jsonStr)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($jsonStr),
"username: 3B19HY00230",
"password: 82bnn1",
"token: 31d351d1d34d0a0f"
)
);
//不验证证书
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return array($httpCode, $response);
}
$url = "https://api.baidu.com/json/sms/service/LeadsNoticeService/getNoticeList";
$jsonStr = json_encode(array(
"solutionType"=>"form",
"startDate"=> "2021-12-01",
"endDate"=> "2021-12-31",
"pageNo"=> 1,
"pageSize"=> 2
));
list($returnCode, $returnContent) = http_post_json($url, $jsonStr);
echo $returnContent;
?>
有其他问题可以继续交流~