轻量级服务器的开发方法——lean cloud
二、非云开发环境登录流程登录授权流程图,结合流程图和下面的伪代码,对比理解登录逻辑。
button . on tap((info)= & gt;{ let userinfo = info . userinfo;//[0]登录前提前触发授权获取用户的基本信息 console . log(userinfo) if(userinfo){ wx.login({//[1])调用wx . log in获取登录凭证(代码)。用户的登录状态信息,包括用户的唯一标识符(OpenID) success:(RES)= >:{ if(RES . code){ let code = RES . code; userinfo . jscode = code; console . log(userinfo); wx . request({ URL:window。BASE _ URL+& # 39;/user/users & # 39;, 方法:& # 39;邮政& # 39;, header:{ & # 39;内容类型& # 39;: 'application/x-www-form-urlencoded;charset = utf-8 & # 39; }, data: userinfo,//[2]发送代码等用户信息(昵称、头像)到服务器验证 成功:(log in data)= >;{//[3]开发者服务器经过微信服务器验证后,获取openid等信息并发送到前端 console . log(log indata) wx . set storage({//调用云函数获取用户openid(参考my.js)]前端根据需要在本地缓存opendid等信息,下次请求其他敏感数据接口时,会取openid进行访问[/OpenID & # 34;, data:log in data . data . msg }) wx . set storage({ key:& # 34;userinfo & # 34, data:userinfo }) console . log(& # 34;登录成功,获取代码& # 34;) }, fail:(err)= & gt;{ console . log(err) console . log(& # 39;登录失败& # 39;) } }] } } }] [/]