本文主要和大家分享微信一次性订阅消息接入问题解析,环境都已经接入,发送 一次性订阅消息 授权:
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页面没有进行下一步的操作,这边希望微信开发团队可以尽早处理!
以上就是微信一次性订阅消息接入问题解析的详细内容。