Some problems of WeChat Mini Programs's button Authorization

what I want to ask is. Now the background is to exchange three parameters for the user"s encrypted token.
one is code obtained through wx.login
and the other two are iv and encryptedData obtained through wx.getUserInfo. Here comes the problem of
three parameters in exchange for token
.
suppose I get this token now and get it. And save it locally, users can just use this token every time they come in. There is no need to drop the api.
when will token expire? I don"t believe it can be used forever.
Wechat"s authorization must also expire. Wx . Will the code that login gets will not change?
one of these three parameters is invalid, so the token returned to me by the background cannot be used without saying it.

what I"m doing now is to get whether the user is authorized or not through Wechat api,. Didn"t go through the whole process.
or, the background api field returns me the error code, and I get the user token again. I don"t know if this is feasible

how do you deal with it? tell me about your practices and opinions. It"s best to say before and after that that you don"t know much about the background of business processing, so you can probably say what you"ve done.

Apr.09,2021

is it certain that the code obtained by login will not change?

is not "it will not change", but "it will change"!
the code acquired each time will change, and only through the algorithm and backend interface given by Wechat can you get openid and unionid, that will not change.

what are these two things for?
is used to "log in automatically". After judging that it is from a user of Wechat, return the self-defined token, and use this token, to set the validity period every time you authenticate the user information. After expiration, use this token, to exchange openid/unionid, for token again through code.


first floor correct solution.
to add a little bit, the code string changes every time and can only be used once at a time. Send the code to the backend to code and the API Wechat for openid and sessionkey, to generate the self-defined token, and return the cache to Mini Program for checking.

Menu