tp5使用腾讯安全接口security.mediaCheckAsync校验图片及音频的合法性
// +----------------------------------------------------------------------
// | 对媒体信息校验path媒体本地地址,media_type媒体类型1是视频,2是图片
// +----------------------------------------------------------------------
function media_check($path,$type) {
$url = "https://api.weixin.qq.com/wxa/media_check_async?access_token=" . AccessTokenCl();//AccessTokenCl()是common的方法
$file_data = array("media_url" => $path,"media_type"=>$type);
$file_data = json_encode($file_data);
// $file_data = "{media_url:".new \CURLFile($path).",media_type:".$type."}";
Log::write($file_data);
// return $file_data;
$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); //关闭会话
return $output;
}
//使用
$check = media_check($checkName,"2");
$result = json_decode($check, true);
Log::write($result);
if ($result['errmsg'] == 'ok') {
return getjson('1', '上传成功', $imgname);
} else {
return getjson('0', '图片违规,请重新选择后上传', 'ERROR');
}