Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wechat login - do not receive token

Tags:

android

wechat

I just followed all the stuff which are mentioned in this example from Aaron Bruckner. Tried out with and without the boolean flag for enabling the 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 trying to login i get the confirmation screen from wechat. When hitting "Confirm Login" i get redirected to my app but nothing happens.

enter image description here

The WXEntryActivity.class is not called - so i dont receive any token to proceed with my authentification.

the 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) }

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

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

I have the correct Application-Signature MD5 without : added to the Wechat-Dev-Console as well as the packageName com.my.packaname.debug as i am using 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. Also i added a rule to proguard-rules.pro to be safe:

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

Just can not figure out why the onCreate and onResp of the WxEntryActivity is not getting called to get the token.

like image 949
Maxi Avatar asked Feb 02 '18 10:02

Maxi


People also ask

Why can't I log into WeChat?

Another reason you are unable to log in to your WeChat account is that your account could be blocked. Step 1: You should uninstall the WeChat application on your phone and reinstall it again. Then you can try logging in again after. Step 2: Another reason is you could be using unofficial plugins to access WeChat.

How do I log into WeChat using my email?

(4) To log in to WeChat, tap More Options at the bottom of login page > Log in to Another Account > Other Login Options > Log in via WeChat ID/Email/QQ ID > enter your email address and new WeChat password > Log In.


1 Answers

Solution found:

Problem was caused by the package-name.

As am using two build variants release & debug, I expected the packagename to be com.my.packagename.debug for my debug-build (which is setup in build.gradle) So in the Admin-Center of Wechat i used com.my.packagename.debug. Problem is that the WxEntryActivity is called via reflection and my WxEntryActivity is located in my com.my.packagename.wxapi.

Therefore the class couldnt be found and needs to be put into a "manual" package .debug.wxapi.

So you need two Activities located in two different packages when using release and debug.

like image 70
Maxi Avatar answered Oct 02 '22 10:10

Maxi