msg_sec_check接口无法识别黄图,返回始终是pass?
// 获取access_token
public function getAccessToken($appId, $appSecret) {
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$appSecret}";
$response = file_get_contents($url);
$result = json_decode($response, true);
if (isset($result['access_token'])) {
return $result['access_token'];
} else {
throw new Exception("Failed to get access_token: " . $result['errmsg']);
}
}
// 调用mediaCheckAsync接口进行色情检测
public function checkMedia($accessToken, $filePath) {
$url = "https://api.weixin.qq.com/wxa/media_check_async?access_token={$accessToken}";
$data =[
"scene"=> 1,
"version"=>2,
"media_url"=>$filePath,
"media_type"=>2,
"openid"=>"ouEKM6_HtQl0kt5E2_5swUdDhpp0"
];
$options = [
'http' => [
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data),
],
];
$context = stream_context_create($options);
$response = file_get_contents($url, false, $context);
$result = json_decode($response, true);
return $result;
}
public function check_img(){
// 配置
$appId = '*********';
$appSecret = '*********';
$filePath = 'https:www.ycmy1.cn/Data/UploadFiles/product/1733456355/aa.jpeg'; // 图片文件的路径
//print_r($filePath);
try {
$accessToken =$this->getAccessToken($appId, $appSecret);
$checkResult =$this->checkMedia($accessToken, $filePath);
var_dump($checkResult);
} catch (Exception $e) {
echo "Exception: " . $e->getMessage() . "\n";
}
}
无法检测出黄图,无论输入什么图片反回结果总是pass