首页 新闻 赞助 找找看

微信开放平台,全网发布时,API文本消息调用失败

0
悬赏园豆:15 [已关闭问题] 关闭于 2016-06-30 08:53

我看了微信的文档 实在是绕啊!

文档:

模拟粉丝发送文本消息给专用测试公众号,第三方平台方需在5秒内返回空串表明暂时不回复,然后再立即使用客服消息接口发送消息回复粉丝

  1. 1)微信模推送给第三方平台方:文本消息,其中Content字段的内容固定为: QUERY_AUTH_CODE:$query_auth_code$(query_auth_code会在专用测试公众号自动授权给第三方平台方时,由微信后台推送给开发者)

  2. 2)第三方平台方拿到$query_auth_code$的值后,通过接口文档页中的“使用授权码换取公众号的授权信息”API,将$query_auth_code$的值赋值给API所需的参数authorization_code。然后,调用发送客服消息api回复文本消息给粉丝,其中文本消息的content字段设为:$query_auth_code$_from_api(其中$query_auth_code$需要替换成推送过来的query_auth_code) 

 

1.已经返回空串了

2.手动不断刷新此接口,调用客服消息接口

复制代码
// 调用客服接口,发送消息
    public function get_kefu_service($openid, $key,$id) {
        $access_token = $this->get_authorizer_access_token ( $key );
        if (is_array ( $access_token )) {
            $key = $access_token ['msg'];
        }
        $data = [ 
                "touser" => $openid,
                "msgtype" => 'text',
                "text" => [ 
                        "content" => $key . '_from_api' 
                ] 
        ];
        $url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' . $access_token;
        $rt = $this->curl->post ( $url, json_encode ( $data ) );
        $this->db->where('id',$id)->update('yy_aa',['status'=>1]);
        echo $rt;
    }

//使用授权码换取公众号的授权信息,获取access_token
public function get_authorizer_access_token($auth_code) {
        $component_access_token = $this->cache->get ( 'component_access_token' );
        $url = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=" . $component_access_token;
        $postdata = [ 
                "component_appid" => APPID,
                "authorization_code" => $auth_code 
        ];
        $postdata = json_encode ( $postdata );
        $json = $this->curl->post ( $url, $postdata );
     $data = json_decode ( $json, true );
        
        if (isset ( $data ['errcode'] )) {
            return [ 
                    'msg' => $data ['errmsg'] 
            ];
        }
        
        return $data ['authorization_info'] ['authorizer_access_token'];
    }
    

 

 
复制代码

这个调用客服接口的方法,我是手动执行,不断刷新的,可是可是,还是不行,

求指教

y_php的主页 y_php | 初学一级 | 园豆:2
提问于:2016-06-23 15:32
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册