检测一段文字是否安全
$accessToken = $this->gettoken();
$url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=".$accessToken;
$examdata = json_encode(['content'=>$data['content']],JSON_UNESCAPED_UNICODE);
$respon = $this->curlRequest($url,'post',$examdata);
$respon = json_decode($respon,true);
if($respon['errcode'] == 87014){
return json(array('code'=>'','msg'=>'效验失败,内容含有违法违规内容'));
}
检测一张图片是否安全
$accessToken = $this->gettoken();
$url = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=".$accessToken;
$file_path = $_SERVER['DOCUMENT_ROOT'].($fileurl);
$file_data = array("media" => new \CURLFile($file_path));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch , CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch , CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $file_data);
$output = curl_exec($ch);
curl_close($ch);
$output=json_decode($output,true);
if($output['errcode'] == 87014){
return json(array('code'=>'','msg'=>'效验失败,内容含有违法违规内容'));
}
获取token
public function gettoken(){
$APPID = "替换成你的APPID";
$APPSECRET = "替换成你的APPSECRET";
$access_token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$APPID&secret=$APPSECRET";
if (!session_id()) session_start();
$_SESSION['access_token'] = "";
$_SESSION['expires_in'] = 0;
if(!isset($_SESSION['access_token']) || (isset($_SESSION['expires_in']) && time() > $_SESSION['expires_in'])){
$json = $this->httpRequest( $access_token );
$json = json_decode($json,true);
$_SESSION['access_token'] = $json['access_token'];
$_SESSION['expires_in'] = time()+7200;
$ACCESS_TOKEN = $json["access_token"];
}else{
$ACCESS_TOKEN = $_SESSION["access_token"];
}
return $ACCESS_TOKEN;
}