Wechat login - do not receive tokens

I just followed everything that is mentioned in this example from Aaron Bruckner. I tried with a boolean flag and without it to enable checkSignature .

init API:

 api = WXAPIFactory.createWXAPI(getContext(), WXEntryActivity.APP_ID, true); 

send register:

 api.registerApp(WXEntryActivity.APP_ID); 

send login:

 SendAuth.Req req = new SendAuth.Req(); req.scope = "snsapi_userinfo"; req.state = "none"; api.sendReq(req); 

When I try to log in, I get a confirmation screen from wechat. When I click "Confirm Login", I am redirected to my application, but nothing happens.

enter image description here

WXEntryActivity.class not called - so I do not get any token to continue authentication.

Logs when signature is set to false :

 D/MicroMsg.PaySdk.WXFactory: createWXAPI, appId = wx41XXXXXXXXX41, checkSignature = false D/MicroMsg.SDK.WXApiImplV10: <init>, appId = wx41XXXXXXXXX41, checkSignature = false D/MicroMsg.SDK.WXMsgImplComm: ignore wechat app signature validation D/MicroMsg.SDK.WXApiImplV10: registerApp, appId = wx41XXXXXXXXX41 D/MicroMsg.SDK.WXApiImplV10: registerApp, appId = wx41XXXXXXXXX41 D/MicroMsg.SDK.WXApiImplV10: register app com.my.packagename.debug D/MicroMsg.SDK.MMessage: send mm message, intent=Intent { act=com.tencent.mm.plugin.openapi.Intent.ACTION_HANDLE_APP_REGISTER (has extras) }, perm=co D/MicroMsg.SDK.WXMsgImplComm: ignore wechat app signature validation I/MicroMsg.SDK.WXApiImplV10: sendReq, req type = 1 D/MicroMsg.SDK.MMessageAct: send, targetPkgName = com.tencent.mm, targetClassName = com.tencent.mm.plugin.base.stub.WXEntryActivity D/MicroMsg.SDK.MMessageAct: send mm message, intent=Intent { flg=0x18000000 cmp=com.tencent.mm/.plugin.base.stub.WXEntryActivity (has extras) } 

Logs when the signature is true are basically the same except:

 D/MicroMsg.SDK.WXMsgImplComm: check signature:3XXXXXXXXX02eb30820254a00302010202XXXXXXXXXXXXXXXXXXXXXXXXX D/MicroMsg.SDK.WXMsgImplComm: pass 

I have the correct MD5 application signature without : added in Wechat-Dev-Console, as well as packageName com.my.packaname.debug , as I use my debug.keystore to sign my debug version. WXEntryActivity is inside my com.my.packagename.wxapi and is registered in my AndroidManifest.xml with the exported flag. In addition, I added the proguard-rules.pro rule for security:

  -keep class com.tencent.mm.sdk.** { *; } 

I just can’t understand why onCreate and onResp WXEntryActivity do not receive a call to get a token.

+4
source share
1 answer

solution found:

The problem is caused by the package name.

How I use the two release and debug build options I expected packagename to be com.my.packagename.debug for my debug-build (which is configured in build.gradle ). Therefore, in the Admin-Center Wechat, I used com.my.packagename.debug . The problem is that WxEntryActivity is called through reflection, and my WxEntryActivity is in my com.my.packagename.wxapi .

Therefore, the class cannot be found and must be placed in the "manual" package .debug.wxapi .

So, when using release and debugging, you need two activities located in two different packages.

+1
source

Source: https://habr.com/ru/post/981041/


All Articles