想用到微信公众平台的图片识别系统,结果报错{"errcode":41005,"errmsg":"media data missing hint: [xScHza03164711]"}"
代码如下:
<?php
class getImgSecCheck{
function get_data(){
$url = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=ACCESSTOKEN";
$post_data = array("media"=>"@D:phpstudyPHPTutorialWWWaddAll.png");
//初始化
$curl = curl_init();
//设置抓取的url
curl_setopt ( $curl, CURLOPT_URL, $url );
curl_setopt ( $curl, CURLOPT_POST, 1 );
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $curl, CURLOPT_CONNECTTIMEOUT, 5 );
curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt ( $curl, CURLOPT_POSTFIELDS, $post_data );
//执行命令
$data = curl_exec($curl);
//关闭URL请求
var_dump($data);
curl_close($curl);
//显示获得的数据
}
}
$getImgSecCheck = new getImgSecCheck();
echo $getImgSecCheck->get_data();
这是因为php版本的不同,所导致的,在php5.5版本之前是可以用
$post_data = array("media"=>"@D:phpstudyPHPTutorialWWWaddAll.png");
来规定文件路径的,但是在php5.5之后就必须用到CURLFile 类;具体实现代码如下:
<?php
class getImgSecCheck{
function get_data(){
$url = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=ACCESSTOKEN";
$cfile = new CURLFile('D:phpstudyPHPTutorialWWWaddAll.png','image/jpeg','test_name');
$post_data = array('name' => 'Foo',"file"=>$cfile);
//初始化
$curl = curl_init();
//设置抓取的url
curl_setopt ( $curl, CURLOPT_URL, $url );
curl_setopt ( $curl, CURLOPT_POST, 1 );
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $curl, CURLOPT_CONNECTTIMEOUT, 5 );
curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt ( $curl, CURLOPT_POSTFIELDS, $post_data );
//执行命令
$data = curl_exec($curl);
//关闭URL请求
var_dump($data);
curl_close($curl);
//显示获得的数据
}
}
$getImgSecCheck = new getImgSecCheck();
echo $getImgSecCheck->get_data();
————————————————
版权声明:本文为CSDN博主「灰熊哦」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_39376608/article/details/88851810