微信一次性訂閱訊息接入問題解析

小云云
發布: 2023-03-20 19:14:01
原創
1894 人瀏覽過

本文主要和大家分享微信一次性訂閱訊息接入問題解析,環境都已經接入,發送一次性訂閱訊息授權:

 final IWXAPI api = WXAPIFactory.createWXAPI(SettingActivity.this, response.getAppId());
                // 将该app注册到微信
                api.registerApp(ServerUrls.WEIXIN_APP_ID);
                Log.i("20180228", "come to send request with subscribeMessage....");
                SubscribeMessage.Req req = new SubscribeMessage.Req();
                req.templateID = response.getTemplateId();
                req.scene = 889;
//                req.reserved = response.getReserved();
                Log.i("20180228", "req.appId: "+response.getAppId());
                Log.i("20180228", "req.templateId: "+req.templateID);
//                Log.i("20180228", "req.scene: "+req.scene);
//                Log.i("20180228", "req.reserved: "+req.reserved);
                Log.i("20180228", "before send request: "+req.toString());
                boolean sendResult = api.sendReq(req);
                Log.i("20180228", "after send request: "+sendResult);
                ToastUtils.show(SettingActivity.this, "发送请求结束");
登入後複製

在授權頁面的回調中做簡單的處理:

@Override
    public void onResp(BaseResp resp) {
        Log.i("20180228", "here come to the resp with wechat request: "+resp.toString());
        Log.i("20180228", "here come to the resp with wechat errCode: "+resp.errCode);
        Log.i("20180228", "here come to the resp with wechat errStr: "+resp.errStr);
        Log.i("20180228", "here come to the resp with wechat openId: "+resp.openId);
        Log.i("20180228", "here come to the resp with wechat type: "+resp.getType());
        ToastUtils.show(this, "openId: "+resp.openId);
        if(resp.getType() == ConstantsAPI.COMMAND_SUBSCRIBE_MESSAGE){
            Log.i("20180305", "here come to resp method successful....");
        }
//        if (resp.getType() == ConstantsAPI.COMMAND_SENDAUTH && resp.errCode == BaseResp.ErrCode.ERR_OK){
//            ToastUtils.show(this, "request auth here ....");
//            String openId = resp.openId;
//            int errCode = resp.errCode;
//            String errString = resp.errStr;
//
//            new UserManager(this).bidnWXRSS(openId, new SimpleCallback<ApiResponse>() {
//                @Override
//                public void onSuccess(ApiResponse response) {
//                    ToastUtils.show(WXEntryActivity.this, "绑定成功!");
//                    finish();
//                }
//            });
//        }


        finish();
    }
登入後複製

在開啟的偵錯列印中顯示:

03-05 17:46:00.967 10706-10706/com.xxx I/MicroMsg.SDK.WXApiImplV10: handleIntent, cmd = 4
03-05 17:46:00.967 10706-10706/com.xxx I/MicroMsg.SDK.WXMediaMessage: pathOldToNew, oldPath = com.tencent.mm.sdk.openapi.WXAppExtendObject
03-05 17:46:00.967 10706-10706/com.xxx I/MicroMsg.SDK.WXApiImplV10: handleWxInternalRespType, extInfo = wx_internal_resptype=subscribemessage&openid=oerX_woJRjvv8NzuUJHcKJe5PzwU&template_id=H0tXdBxs_ea5bVofycFBUPZl3hRgLWHxJIVBEYhSnxQ&action=confirm&reserved=null&scene=889
03-05 17:46:00.967 10706-10706/com.xxx I/MicroMsg.SDK.WXApiImplV10: handleWxInternalRespType, respType = null
03-05 17:46:00.967 10706-10706/com.xxx E/MicroMsg.SDK.WXApiImplV10: handleWxInternalRespType fail, respType is null
登入後複製

handleIntent()的時候,回傳的是false,也沒辦法呼叫onResp方法,其中的原因是因為上面的respType = null,但上面發現extInfo是有資料的,並且可以看出wx_internal_resptype=subscribemessage。

這邊查看WXApiImplV10.class,部分程式碼如下: 


也就是說,這邊的respType=subscribemessage,但上面解析出來變成了null, 其中關鍵的程式碼是:


然後才明白,這邊的extInfo字串的起始處少了一個“?”,所以把extInfo解析成Uri後,就找不到指定的「wx_internal_resptype」屬性了。所以頁面會卡在WXEntryActivity頁面沒有進行下一步的操作,這邊希望微信開發團隊可以儘早處理!

以上是微信一次性訂閱訊息接入問題解析的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!