Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

微信授权登录解密手机号失败 #27

Open
mamba-1024 opened this issue Oct 7, 2020 · 0 comments
Open

微信授权登录解密手机号失败 #27

mamba-1024 opened this issue Oct 7, 2020 · 0 comments

Comments

@mamba-1024
Copy link
Owner

微信小程序开发时候,使用手机号授权登录,会遇到手机解密失败的情况。

后端抛出错误如下:

javax.crypto.BadPaddingException: pad block corrupted

问题收集:

  1. javax.crypto.BadPaddingException: pad block corrupted
  2. 解密用户信息报错pad block corrupted
  3. 微信登录授权偶尔出现第一次解密失败,第二次解密成功,报错为pad block
  4. 小程序登录第一次总是会失败,第二次肯定成功pad block corrupted

总结原因:

问题还是处在微信的 sessionKey

当我在getPhoneNumber中使用wx.login的时候,第一次总是手机号机密失败,第二次可以成功。

解决方案:

在页面 onShow 中先调用一次 wx.login 将临时 code 暂存,然后在 getPhoneNumber先使用code,这样就能保证每次sessionKey是最新的。

微信小程序的消息订阅功能,不能放在异步函数中

参考

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant