WeChat Mini Programs encryptedData decryption occasionally reported an error-41003, what is the cause of this problem?

I use the thinkphp3.2.3 framework, and decryption also uses Wechat php to decrypt demo,. This error does not happen every time, but a few more attempts will lead to the error of-41003. I would like to ask you what is the reason for this situation?
clipboard.png

Php
Mar.18,2021

when I use Node to decrypt, I occasionally fail to decrypt. It's not stable at all.


this is the flow chart I saw on the Internet. Just look at this and write
clipboard.png


.

occasional failures are most likely due to the wrong order of wx.getUserInfo and wx.login.

normal flow: wx.login gets code = "wx.getUserInfo gets iv and encryptedData =" sends it to the server to decrypt

can easily be mistakenly written as calling wx.login to get code in the callback of wx.getUserInfo and then sending it to the server. In this way, the session_key used for data encryption in getUserInfo may be inconsistent with the session_key at the time of decryption, because wx.login may refresh session_key

.

Resolution: make sure that userinfo always initiates after the last login

Menu