Target: get token which I need to send to the app server
Problem: registered returns true, requests done returns true, but onReq
and onResp
did not get 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);
L.e(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);
L.e(this, "request done: " + requestDone);
SendAuth.Resp resp = new SendAuth.Resp();
requestDone = api.sendResp(resp);
L.e(this, "request done: " + requestDone);
}
@Override
public void onReq(BaseReq baseReq) {
L.e(this, "scope: " + ((SendAuth.Req) baseReq).scope);
}
@Override
public void onResp(BaseResp baseResp) {
L.e(this, "token: " + ((SendAuth.Resp) baseResp).token);
}
}
Log cat 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