msgSecCheck 接口一直返回ok的解决方案,测试可行的msgSecCheck 接口PHP版demo
今天突然说小程序版本审核要我们处理评论中的敏感词内容,踩了一些坑终于搞好了,贴下代码出来吧,文档说的不是很详细,估计有不少小伙伴踩坑了。
public function keyCheck(){
$wxToken=wxTokenCheck(); //获取微信token
$key = input(‘key’);
$url = ‘https://api.weixin.qq.com/wxa/msg_sec_check?access_token=’.$wxToken['token’];
$data = json_encode([‘content’=>$key],JSON_UNESCAPED_UNICODE); //一定要把中文转成utf8!!!
$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);
[代码] echo "<pre>";
var_dump($result);
var_dump($data);
echo "</pre>";
}[代码]