Purpose: to get the token that I need to send to the application server
Problem: registered returns true, executed queries return true, but onReq and onResp not called. Here is the code:
public class WeChatActivity extends Activity implements IWXAPIEventHandler { private static final String APP_ID = ; private IWXAPI api; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_signin); api = WXAPIFactory.createWXAPI(this, APP_ID, true); api.handleIntent(getIntent(), this); regToWx(); getAuthToken(); } private void regToWx() { api.handleIntent(getIntent(), this); boolean registered = api.registerApp(APP_ID); Le(this, "registered: " + registered); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); setIntent(intent); api.handleIntent(intent, this); } public void getAuthToken() { SendAuth.Req req = new SendAuth.Req(); req.scope = "post_timeline"; req.state = "none"; boolean requestDone = api.sendReq(req); Le(this, "request done: " + requestDone); SendAuth.Resp resp = new SendAuth.Resp(); requestDone = api.sendResp(resp); Le(this, "request done: " + requestDone); } @Override public void onReq(BaseReq baseReq) { Le(this, "scope: " + ((SendAuth.Req) baseReq).scope); } @Override public void onResp(BaseResp baseResp) { Le(this, "token: " + ((SendAuth.Resp) baseResp).token); } }
Log output:
D/MicroMsg.SDK.WXApiImplV10﹕ check signature:308202eb30820254a003020... D/MicroMsg.SDK.WXApiImplV10﹕ pass D/MicroMsg.SDK.WXApiImplV10﹕ register app cn.wegazine.wegazine D/MicroMsg.SDK.MMessage﹕ send mm message, intent=Intent { act=com.tencent.mm.plugin.openapi.Intent.ACTION_HANDLE_APP_REGISTER (has extras) }, perm=com.tencent.mm.permission.MM_MESSAGE E/WeChatActivity﹕ registered: true D/MicroMsg.SDK.WXApiImplV10﹕ check signature:308202eb30820... D/MicroMsg.SDK.WXApiImplV10﹕ pass D/MicroMsg.SDK.MMessageAct﹕ send mm message, intent=Intent { flg=0x18000000 cmp=com.tencent.mm/.plugin.base.stub.WXEntryActivity (has extras) } E/WeChatActivity﹕ request done: true D/MicroMsg.SDK.WXApiImplV10﹕ check signature:308202eb30820... D/MicroMsg.SDK.WXApiImplV10﹕ pass D/MicroMsg.SDK.MMessageAct﹕ send mm message, intent=Intent { flg=0x18000000 cmp=com.tencent.mm/.plugin.base.stub.WXEntryActivity (has extras) } E/WeChatActivity﹕ request done: true
source share