该问题已被锁定!
6
关注
3784
浏览

微信群发,media data missing 终极解决方案!

AI智能回复搜索中,请稍后...

查看全部 2 个回答

final 高级会员 用户来自于: 日本
2016-12-12 17:35
打开/models/openid/weixin/weixin.php 新增方法:
public function curl_post($url, $data, $header = array()){
            if(function_exists('curl_init')) {
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, $url);
                if(is_array($header) && !empty($header)){
                    $set_head = array();
                    foreach ($header as $k=>$v){
                        $set_head = "$k:$v";
                    }
                    curl_setopt($ch, CURLOPT_HTTPHEADER, $set_head);
                }
                curl_setopt($ch, CURLOPT_HEADER, 0);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_TIMEOUT, 0);// 1s to timeout.
                $response = curl_exec($ch);
                if(curl_errno($ch)){
                    //error
                    return curl_error($ch);
                }
                $reslut = curl_getinfo($ch);
                print_r($reslut);
                curl_close($ch);
                $info = array();
                if($response){
                    $info = json_decode($response, true);
                }
                return $info;
            } else {
                throw new Exception('Do not support CURL function.');
            }
    }
更改upload_file 方法
public function upload_file($file, $type)
    {
        $app_id = get_setting('weixin_app_id');

        $app_secret = get_setting('weixin_app_secret');

        $file = realpath($file);

        if (!is_readable($file))
        {
            return false;
        }

        $file_md5 = md5_file($file);

        $cached_result = AWS_APP::cache()->get('weixin_upload_file_' . $file_md5);

        if ($cached_result)
        {
            return $cached_result;
        }
		
		$data = array(
			'media'=> new CURLFile($file)
		);
		$result = $this->curl_post(self::WEIXIN_API . 'media/upload?access_token=' . $this->get_access_token($app_id, $app_secret) . '&type=' . $type ,$data);
		
        if (!$result)
        {
            return false;
        }

        $result = json_decode($result, true);

        if ($result['errcode'])
        {
            if ($result['errcode'] == 40001)
            {
                $this->refresh_access_token($app_id, $app_secret);

                return $this->upload_file($file, $type);
            }
        }
        else
        {
            AWS_APP::cache()->set('weixin_upload_file_' . $file_md5, $result, 259200);
        }

        return $result;
    }

关于作者

问题动态

发布时间
2016-12-10 13:18
更新时间
2016-12-12 21:39
关注人数
6 人关注

推荐内容

最新版本后台微信群发功能上传图片,出现以下代码?
招募令 英雄请留步
微信群发不能群发所有用户
用网站后台群发的微信内容图片不显示
微信消息群发,media data missing 用的3.13
在后台,微信群发功能中,填好封面文章标题后,上传封面图片出现错误问题?
建议增加微信群发功能,微信分享分享积分功能
后台微信群发只能群发一条消息吗?
微信群发信息提示远程服务器忙,如何解决?