/*
* 调用微信接口验证图片是否合法
* $data 数组
/
public function Is_img()
{
$img_url = “通过网址访问的图片地址”;
$tokenArr = json_decode($this->send_post_token(“GET”));
$access_token = $tokenArr->access_token;
$info = $this->imgSecCheck($access_token,$img_url);
if($info[‘errcode’]){
return false;
}else{
return true;
}
}
/
* 检测图片
* $img 是可以通过网址访问的图片地址
* $access_token
/
public function imgSecCheck($access_token,$img)
{
$img = file_get_contents($img);
$filePath = ‘/dev/shm/tmp1.png’;
file_put_contents($filePath, $img);
$obj = new \CURLFile(realpath($filePath));
$obj->setMimeType(“image/jpeg”);
$file[‘media’] = $obj;
$url = “https://api.weixin.qq.com/wxa/img_sec_check?acces s_token=$access_token”;
$info = $this->http_request($url,$file);
return json_decode($info,true);
}
/
* 获取access_token
*/
function send_post_token($method=‘POST’)
{
//获取ACCESS_TOKEN
$this->appid = ‘小程序appid’;
$this->secret = ‘小程序的secret’;
$url = “https://api.weixin.qq.com/cgi-bin/token?grant_type= client_credential&appid=”.$this->appid."&secret=".$t his->secret;
$post_data = array();
$postdata = http_build_query($post_data);
$options = array(
‘http’ => array(
‘method’ => $method, //or GET
‘header’ => ‘Content-type:application/x-www-form-urle ncoded’,
‘content’ => $postdata,
‘timeout’ => 15 * 60 // 超时时间(单位:s)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
return $result;
}
你好,这个按照你这个方法,请求接口后返回了个false