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

微信群发,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 人关注

相关问题

如何通过微信自定义菜单发送一张图片(通过命令而不是链接)
请问wecenter有没有做针对微信平台新推出的企业号做调整?
微信消息群发,media data missing 用的3.13
微信公众平台对接后,如何修改自动给关注用户的信息?
wecenter邮件群发
悬赏3000微信活动开发
微信API,'msgType'== 'subscribe' ,判断不出新关注的用户
【紧急漏洞】微信登录跳转链接未过滤导致被恶意使用【已修复】
微信公共平台说api没反应
调整了微信公共平台的内容显示模式

推荐内容

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