zoukankan      html  css  js  c++  java
  • PHP img_sec_check url

    网络图片,直接丢给img_sec_check

    直接上源码

        public function img_sec_check($media){
            $media = file_get_contents($media);
            if (empty($media)) {
                return true;
            }
            $farce = 0;//强制更新token
            $retry = 0;
            $num = 0;
            $url = 'https://api.weixin.qq.com/wxa/img_sec_check?access_token=';  
            $boundary="----".md5(date);
            $formdata = "--" . $boundary ."
    ";
            $formdata .= "Content-Disposition: form-data; name="upload"; filename="upload.jpg"
    ";
            $formdata .= "Content-type: application/octet-stream
    
    ";
            $formdata .= $media."
    ";
            $formdata .= "--" . $boundary . "
    "."--
    
    ";
            do {
                $token = $this->getToken($farce);
                $curl = curl_init();
                curl_setopt($curl, CURLOPT_URL, $url . $token);
                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
                curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
                curl_setopt($curl, CURLOPT_POST, 1);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $formdata);
                curl_setopt($curl, CURLOPT_HTTPHEADER, [
                            "Content-Type: multipart/form-data; boundary=".$boundary,
                            "Content-Length: " . strlen($formdata)
                        ]);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                $result = curl_exec($curl);
                curl_close($curl);
                $resultObj = json_decode($result);
                var_dump($url . $token);
                var_dump($resultObj);
                $num++;
                //token过期
                if ($resultObj->errcode == 40001) {
                    $farce = 1;
                    $retry = 1;
                }else if ($resultObj->errcode == -1) {//服务器返回忙
                    $retry = 1;
                } else if($resultObj->errcode == 0){
                    $farce = 0;
                    $retry = 0;
                }
            } while ($retry && $num < 5);
            if ($resultObj->errcode != 0) {
                return false;
            }
            return true;
        }
  • 相关阅读:
    对文本抽取词袋模型特征
    jieba分词
    家用电器用户行为分析与事件识别
    Linux系统调用:创建和终止进程
    Linux系统调用:获取进程PID
    使用函数指针解决函数重载二义性调用问题
    C++ string基本操作
    有界深度优先搜索-八数码问题
    数据传送指令
    x86-64数据格式、通用寄存器与操作数格式
  • 原文地址:https://www.cnblogs.com/wangjiayuan/p/12631909.html
Copyright © 2011-2022 走看看