内容检测接口文档
class Check{
public function curlImg($path, $AccessToken){
/*$token=M('config')->field('access_token')->where('1=1')->find();
$ACCESS_TOKEN=$token['access_token'];//自己获取access_token*/
//$ACCESS_TOKEN = $this->getAccessToken();
$ACCESS_TOKEN = $AccessToken;
$url = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=".$ACCESS_TOKEN;
// $file_path =realpath("24.jpg");
$file_path = $_SERVER['DOCUMENT_ROOT']."/".$path;//接受表单文件保存本地的文件地址
//$file_path = $path;//接受表单文件保存本地的文件地址
//$file_path = DOC_ROOT . "/Public/Uploads/paimai_goods/2018-06-14/tmp_71012dc7fc3e63ad1f3e9950ffb43bca394d88ecae3798d6.png";
$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);
//return $output['errmsg'];//返回结果
return $output;//返回结果
}
//检测文本是否含有违禁内容(频率限制:单个 appId 调用上限为 1000 次/分钟,100,000 次/天)
public function curlText($content){
$ACCESS_TOKEN = $this->getAccessToken();
$url = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=".$ACCESS_TOKEN;
$file_data = '{ "content":"'.$content.'" }';//$content(需要检测的文本内容,最大520KB)
$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);//发送请求获取结果
$output=json_decode($output,false);
curl_close($ch);//关闭会话
return $output;//返回结果
}
/*获取access_token,不能用于获取用户信息的token*/
public function getAccessToken(){
$token_file = json_decode(file_get_contents('token.json'));
//有效期外才重新获取
if($token_file->expires_time
$appid = '';
$appsecret = '';
$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $appid . '&secret=' . $appsecret;
$token_json = file_get_contents($url);
//return $token_json;
$token_json = json_decode($token_json);
$token_file->access_token = $token_json->access_token;
$token_file->expires_time = time()+7200;
$access_token = $token_json->access_token;
file_put_contents('token.json', json_encode($token_file));
return $access_token;
}else{
$access_token = $token_file->access_token;
}
return $access_token;
}
}
网友评论