小程序内容安全API
- 检查一段文本是否含有违法违规内容。
POST https://api.weixin.qq.com/wxa/msg_sec_check?access_token=ACCESS_TOKEN
//微信内容安全接口public function wxmsgSecCheck($text){$accessToken = '小程序token';$url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=".$accessToken;$data = json_encode(['content'=>$text]);$respon = $this->curlRequest($url,'post',$data);$respon = json_decode($respon,true);if($respon['errcode'] == 87014){return 1;//效验失败,内容含有违法违规内容}else{return 0;}}/*请求外部地址*/public function curlRequest($url,$mothed = "GET" , $data = array()){$ch = curl_init();$header = "Accept-Charset: utf-8";curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $mothed);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);$temp = curl_exec($ch);curl_close($ch);return $temp;}
校验一张图片是否含有违法违规内容。
POST https://api.weixin.qq.com/wxa/img_sec_check?access_token=ACCESS_TOKEN
public function wximgSecCheck(){$url = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=".$accessToken;$imgpath = "/data/default/attachment/images/test.jpg";//这里是图片路径,不能使用远程资源$imgurl = parse_url($value);//解析url返回组成部分$imgarr = pathinfo($imgurl['path']);//返回文件路径信息$data = ['media' => new CURLFile(realpath($imgpath), $imgarr['extension'], $imgarr['filename']),];$respon = $this->curlRequest($url,'post',$data);$respon = json_decode($respon,true);if($respon['errcode'] == 87014){return 1;//效验失败,内容含有违法违规内容}else{return 0;}}
