关闭

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

标签: thinkphp微信41005-永久素材
377人阅读 评论(0) 收藏 举报
分类:

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);
    }
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1758次
    • 积分:45
    • 等级:
    • 排名:千里之外
    • 原创:2篇
    • 转载:6篇
    • 译文:0篇
    • 评论:0条