网络图片,直接丢给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; }