小程序图片内容安全检测

官方文档地址
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/sec-check/security.imgSecCheck.html
/**

点击查看代码
		/**
     * 图片内容安全校验
     * @param $file_path
     * @return array
     */
    public static function imgSecCheck($file_path){
        $result = WechatToken::getAppletAccessToken();
        if ($result['code']) {
            $access_token = $result['data'];
        } else {
            return ['code' => 0, 'msg' => $result['msg']];
        }
        $url = 'https://api.weixin.qq.com/wxa/img_sec_check?access_token=' . $access_token;
        $file_data =  array("media"  => new \CURLFile($file_path['temp_name'],$file_path['type'],$file_path['name']));

        $res = Helper::httpRequest($url, $file_data);
        $result = json_decode($res, true); // 格式化为数组
        if($result['errcode'] == 0){
            return ['code' => 1, 'msg' => 'Ok'];
        } else {
            return ['code' => 0, 'msg' => '图片含有违规信息'];
        }
    }
 * 图片内容安全校验
 * @param $file_path
 * @return array
 */
public static function imgSecCheck($file_path){
    $result = WechatToken::getAppletAccessToken();
    if ($result['code']) {
        $access_token = $result['data'];
    } else {
        return ['code' => 0, 'msg' => $result['msg']];
    }
    $url = 'https://api.weixin.qq.com/wxa/img_sec_check?access_token=' . $access_token;
    $file_data =  array("media"  => new \CURLFile($file_path['temp_name'],$file_path['type'],$file_path['name']));

    $res = Helper::httpRequest($url, $file_data);
    $result = json_decode($res, true); // 格式化为数组
    if($result['errcode'] == 0){
        return ['code' => 1, 'msg' => 'Ok'];
    } else {
        return ['code' => 0, 'msg' => '图片含有违规信息'];
    }
}

参数示例
//前端表单提交图片
$file = UploadedFile::getInstanceByName('image');
$file_path = [
'temp_name' => $file->tempName,//文件的临时文件名
'type' => $file->type,
'name' => $file->name,
];
//校验服务器本地图片
$image = "0.jpg";//可以解析出绝对路径的真实图片
$file_path = [
'temp_name' => realpath($image), //服务器本地的绝对路径,
'type' => 'image/jpeg',
'name' => 'test_name',
];

posted @   风落叶微  阅读(224)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· NetPad:一个.NET开源、跨平台的C#编辑器
· PowerShell开发游戏 · 打蜜蜂
· 凌晨三点救火实录:Java内存泄漏的七个神坑,你至少踩过三个!
点击右上角即可分享
微信分享提示