记录一下微信微信小程序内容安全接口踩坑
在微信文档上可以看出
HTTPS 调用
请求地址
POST https://api.weixin.qq.com/wxa/msg_sec_check?access_token=ACCESS_TOKEN
请求参数
| 属性 | 类型 | 默认值 | 必填 | 说明 |
|---|---|---|---|---|
| access_token | string | 是 | 接口调用凭证 | |
| content | string | 是 | 要检测的文本内容,长度不超过 500KB |
返回值
Object
返回的 JSON 数据包
| 属性 | 类型 | 说明 |
|---|---|---|
| errcode | number | 错误码 |
| errMsg | string | 错误信息 |
errcode 的合法值
| 值 | 说明 | 最低版本 |
|---|---|---|
| 0 | 内容正常 | |
| 87014 | 内容含有违法违规内容 |
errMsg 的合法值
| 值 | 说明 | 最低版本 |
|---|---|---|
| "ok" | 内容正常 | |
| "risky | content" 内容含有违法违规内容 |
调用示例
curl -d '{ "content":"hello world!" }' 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=ACCESS_TOKEN'
测试用例
特3456书yuuo莞6543李zxcz蒜7782法fgnv级
完2347全dfji试3726测asad感3847知qwez到
开发者可使用以上两段文本进行测试,若接口errcode返回87014(内容含有违法违规内容),则对接成功。
看出要发送一个json格式的content过去
起初使用的代码如下
//公共封装post方法
function curl_post($url,$data){
$data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$file_contents = curl_exec($ch);
if (curl_errno($ch)) {
return curl_error($ch);
}
curl_close($ch);
return $file_contents;
}public function msgSecCheck($content){//检查一段文本是否含有违法违规内容
$data = [
'content' => $content,
];
$msgSecCheckUrl = sprintf($this->msgSecCheckUrl, $token);
$result = curl_post($msgSecCheckUrl, $data);
$result = json_decode($result, true);
return [
'errorCode' => 0,
'result' =>$result,
];
}写到这里 并没有看出什么异样,请求就会发现无论什么违规词汇都会返回OK
WFT
经过几个小时的测试 content需要以json字符串的形式发送............
好吧修改发送数据
public function msgSecCheck($content){//检查一段文本是否含有违法违规内容
$post_data = '{ "content":"'.$content.'" }';
$msgSecCheckUrl = sprintf($this->msgSecCheckUrl, $token);
$result = curl_post($msgSecCheckUrl, $post_data,true);
$result = json_decode($result, true);
return [
'errorCode' => 0,
'result' =>$result,
];
}修改公共方法curl_post
//公共封装post方法function curl_post($url,$data,$type=false){
if(!$type){ //默认为false,在内容安全校验你时不进行格式化
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $file_contents = curl_exec($ch); if (curl_errno($ch)) { return curl_error($ch); } curl_close($ch); return $file_contents; }$data = json_encode($data);}
文档有些坑呀...............
然后发现终于打开里新世界的大门!!!!!!!!!

