// grant_type:'client_credential',
// appid:'wx2248cee66fc1c47c',
// secret:'05b55e20fe28f8eeb1e02c2dd1659185',
$url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx2248cee66fc1c47c&secret=05b55e20fe28f8eeb1e02c2dd1659185";
// $Http=new Http;
$get= geturl($url);
// var_dump();die;
$url='https://api.weixin.qq.com/wxa/msg_sec_check?access_token='.$get["access_token"];
$params = [
"content"=>$content
];
// var_dump($content);die;
$post= posturl($url,$params) ;
// var_dump($post,1);die;
// $url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token='. $res["access_token"];
if($post['errcode'] == 87014){
// console.log('有敏感词');
return json(["code"=>87014,"msg"=>'有敏感词。']);
}
function geturl($url){
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL,$url); // url
$res = curl_exec($ch); // 返回值
curl_close($ch);
$result = json_decode($res,true); //关闭当前curl
return $result;
}
function posturl($url,$data){
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL,$url); // url
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // json数据
$res = curl_exec($ch); // 返回值
curl_close($ch);
$result = json_decode($res,true); //关闭当前curl
return $result;
}
转载:https://blog.csdn.net/wangzhae/article/details/109748985
查看评论