开发环境: PHP7.1 + Nginx + 宝塔面板 (尝试了百度的各种办法,都是出现一样的问题 47001错误)
以下是百度找的代码 不知道哪里有问题 就是不可以
$token = (new Dynamic)->getAccessToken();
$url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token='.$token;
$path = '/www/wwwroot/Forum/public/uploads/20200503/61b05148d3d8b83ea47602056cb44c85.png';
$data = new \CURLFile(realpath($path));
$data->setMimeType("image/png");
$postdata['media'] = $data;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($curl);
curl_close($curl);
dump($output);
请求返回的错误: "{"errcode":47001,"errmsg":"data format error hint: [ZGkDJlnre-eQn1.a] rid: 5f3f6f27-1779411b-5cdb3907"}"
请问这个问题如何解决呢? 是哪里没写对吗?
如果方便,希望能把代码贴出来,非常感谢
代码应该没问题,但是为何检测图片 你要用检测内容的接口呢?
一直返回空呀
$url = "https://api.weixin.qq.com/wxa/img_sec_check?access_token={$accessToken}";
$curl = curl_init();
if (class_exists('\CURLFile')) {
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
$data = array('media' => new \CURLFile($imgUrl));//
} else {
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
$data = array('media' => '@' . $imgUrl);
}
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);
if ($result === false) {
echo "error:" . curl_errno($curl);
exit;
}
dd($result);
我按照这么写。直接没有返回。你可以用正常返回吗?