您的位置:首页 > 编程语言 > PHP开发

thinkphp微信上传永久素材报41005错误解决办法

2017-01-03 21:12 429 查看
thinkphp微信上传永久素材报41005错误说明传参值有误,正确的传参方式如下:

例如:

$filepath= "themes/simplebootx/Public/assets/images/banner-inner-fail.jpg";
if(class_exists('\CURLFile')){
$data['media'] = new \CURLFile(realpath($filepath));
}else{
$data['media'] = '@'.realpath($filepath);
}
if (!$filepath) throw new \Exception('资源路径错误!');


WechatAuth.class.php类库中更改materialAddMaterial方法如下:

public function materialAddMaterial($filename, $type, $description = '')
{
//将$filename = realpath($filename);更改为:

if(class_exists('\CURLFile')){
$filename = new \CURLFile(realpath($filename));
}else{
$filename = '@'.realpath($filename);
}

if (!$filename) throw new \Exception('资源路径错误!');

$data = array(
'type' => $type,
'media' => $filename,//将'media' => "@{$filename}"改为'media' => $filename
);

if ($type == 'video') {
if (is_array($description)) {
//保护中文,微信api不支持中文转义的json结构
array_walk_recursive($description, function (&$value) {
$value = urlencode($value);
});
$description = urldecode(json_encode($description));
}
$data['description'] = $description;
}
return $this->api('material/add_material', $data, 'POST', '', false);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息