Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve WeChat Mini Programs's getUserInfo Authorization problem

2025-03-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to solve the problem of WeChat Mini Programs getUserInfo authorization". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to solve the WeChat Mini Programs getUserInfo authorization problem"!

Set up a transition page where the user is authorized to log in. When the user enters Mini Program for the first time, please upgrade the Wechat version by agreeing to the authorized login and let the user click the authorized login button themselves, and then carry on the follow-up business logic.

Extend

If the user happens to fail in the login status of a page, let it jump to the login interface, click authorization to log in successfully, and return to the previous page.

Here is the specific code

1 App.js 2 App ({3 onLaunch: function () {}, 4 onShow: function () {}, 5., 6 toLogin: function () {7 / / to the authorization login interface 8 wx.navigateTo ({9 url:'/ pages/toLogin/toLogin',10}) 11}, 12 ready: function () {13 return Promise ((resolve) Reject) = > {14 const userkey = wx.getStorageSync ('userkey') 15 const userId = wx.getStorageSync (' userId') 16 const sessionData = wx.getStorageSync ('sessionData') 17 / / check whether the user has a login status 18 if (! userkey | |! userId | |! sessionData) {19 / / if you are not logged in, go to the login interface 20 this.toLogin () 21} else {22 / / if so, just change the Promise. To continue with the subsequent operations 23 resolve () 24} 25}) 26} 27}) 1 somePage.js 2 var app = getApp () 3 const someServces = require ('unified interface processing file') 4 Page ({5 data: {}, 6 onLoad: function () {}, 7 onShow: function () {}, 8. 9 getSomeData () {10 / / here every time we call the interface You must first call the ready method 11 in app.js / / in app, ready will return a promise object, and only when it returns the state will it trigger the resolved state. Then () method 12 app.ready (). Then (() = > {13 / / get server data 14}) 15} 16}) so far, I believe you have a better understanding of "how to solve WeChat Mini Programs getUserInfo authorization problem" You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report