经我多次尝试,终于搞定了这个返回都是ok的问题,下面把重要代码放下面,供大家参考,
第一步,获取access_token:
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->app_id}&secret={$this->app_secret}";
$res = json_decode(file_get_contents($url));
$access_token = $res->access_token;
第二步:转发请求post
function curl_post_weixin($url, $data)
{
if ($url && count($data)) {
$headers = ['Content-Type:application/json'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // 关键点
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data,JSON_UNESCAPED_UNICODE));//注意这里的JSON_UNESCAPED_UNICODE一定要写,不然都是ok
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
}
第三步:调用转发函数:
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->app_id}&secret={$this->app_secret}";
$res = json_decode(file_get_contents($url));
$access_token = $res->access_token;
$url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=' . $access_token;
// 请求参数
$request = [];
$request['content'] = $content;
$result = curl_post_weixin($url, $request);
return $result;
注意替换自己的appId和token,如果遇到问题不明白的,可以加我微信:xingguangbi
$this_header =['Content-Type:application/json']; $curl = curl_init(); curl_setopt($curl,CURLOPT_HTTPHEADER,$this_header); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); if (!empty($data)) { curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data,JSON_UNESCAPED_UNICODE)); } curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($curl); curl_close($curl); return $output; 我这样设置,不管发送什么内容,返回都是OK,这个怎么解决