关于php:小程序接入内容内容审查接口图片文字

44次阅读

共计 2952 个字符,预计需要花费 8 分钟才能阅读完成。

明天不知咋回事应用 easywechat 的内容平安 api, 不知咋回事. 之前还能够应用的这些天忽然报这个错, 也不晓得是不是因为降级还是与其余的抵触,

那怎么办呢, 还是用下原生的接口, 在这里我获取的 token 办法还是 easywechat 的形式

$miniProgram = ZFac::miniProgram($this->config);
$token = $miniProgram->access_token->getToken()['access_token'];

具体的代码如下

use EasyWeChat\Factory as ZFac;

public function __construct (Request $request = null){
        $this->config = [
            'app_id' => 'wx412****d45a65',
            'secret' => '082dec1*****985b93d286c093e01',
            // 上面为可选项
            // 指定 API 调用返回后果的类型:array(default)/collection/object/raw/ 自定义类名
            'response_type' => 'array',
            'log' => [
                'level' => 'debug',
                'file' => __DIR__.'/log/wechat.log',
            ],
        ];
}
 
  // 文字验证
  $miniProgram = ZFac::miniProgram($this->config);
  $token = $miniProgram->access_token->getToken()['access_token'];
  // $result = $miniProgram->content_security->checkText($data['content']);
  $result = $this->z_msgSecCheck($token,$data['content']);
  if($result['errcode']!='0'){return jserror('内容含有非法关键词');die;
  }
  
            
// 图片验证
 public function upload_pic(){$file = request()->file('file');
        $info = $file->validate(['ext'=>config()['web']['file_ext']])->move('./public/upload/admin/file');
        $getSaveName = str_replace('\\', '/', $info->getSaveName());//win 下反斜杠替换成斜杠
        $msg = 'http://'.$_SERVER['SERVER_NAME'].'/public/upload/admin/file/'.$getSaveName;
         if(is_file('./public/upload/admin/file/'.$getSaveName)){
          // 验证图片
            $miniProgram = ZFac::miniProgram($this->config);
            $token = $miniProgram->access_token->getToken()['access_token'];
            $result = $this->z_imgSecCheck($token,'./public/upload/admin/file/'.$getSaveName);
            // $miniProgram = ZFac::miniProgram($this->config);
            // $result = $miniProgram->content_security->checkImage('./public/upload/admin/file/'.$getSaveName);
            if($result['errcode']!='0'){return '非法图片';}else{return $msg;}
        }else{return '0';}
    }


外围

/* 微信文字敏感内容检测 */
    public function z_msgSecCheck($token,$msg)
    {
        $checkContent = $msg;
        $url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token='. $token;
        $data = json_encode(array('content'=>$checkContent),JSON_UNESCAPED_UNICODE);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_URL,$url); // url
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // json 数据
        $res = curl_exec($ch); // 返回值
        curl_close($ch);
        $result = json_decode($res,true);
        return $result;
    }
  /* 微信图片敏感内容检测 */
    public function z_imgSecCheck($token,$path)
    {
        // $path = './public/upload/admin/file/'.$getSaveName;
        $url = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=$token";
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
        $data = array('media' => new \CURLFile(realpath($path)));
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_USERAGENT,"TEST");
        $result = curl_exec($curl);
        $error = curl_error($curl);
        return json_decode($result,true);
    }

高颜值后盾管理系统收费应用 ### 子枫后盾管理系统 ###,可在宝塔面板间接装置

欢送关注我的公众号:子枫的微妙世界,取得独家整顿的学习资源和日常干货推送。
如果您对我的其余专题内容感兴趣,中转我的集体博客:www.wangmingchang.com。

正文完
 0