用户授权登录换成了wx.getUserProfile怎么缓存用户的登录状态?

小程序 文章 2021-04-04 16:02 538 0 全屏看文

AI助手支持GPT4.0

用户授权登录换成了wx.getUserProfile怎么缓存用户的登录状态?User authorized login is replaced by wx.getUserProfile. How can the user's login status be cached?

用户授权登录换成了wx.getUserProfile怎么缓存用户的登录状态?

像这种写法,我要怎么修改,未登录之前,不允许点击点单页面,登录之后才能点击订单页面???

In this way, how can I modify it? Before I log in, I am not allowed to click the order page. After I log in, I can click the order page???

回答:

官方提示::
获取成功的时候,保存啊 try {  wx.setStorageSync('userInfo', res.userInfo)} catch (e) { }


清:可以了,谢谢
|G.XIAO|:

用户有没有登录,通过 openId (或者基于openId生成userId)比较合理

如果用 getUserProfile 返回的用户信息作为判断有点不恰当

如果是用openId的话,是通过 wx.login 拿到 code 去服务器换 openId

getUserProfile 是获取用户昵称和头像的,如果需要,引导用户点击进行获取


老张:

谢邀。

登录状态不等于授权微信信息。

-EOF-

AI助手支持GPT4.0