In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to modify the login mode of WeChat Mini Programs". In the daily operation, I believe that many people have doubts about how to modify the login mode of WeChat Mini Programs. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to modify WeChat Mini Programs login mode"! Next, please follow the editor to study!
The original login logic is to register a global login method. In the login method, first call wx.login to silently log in, obtain temporary login credentials code, call api in the developer server background, and use code in exchange for openid and session_key. Then call wx.getUserInfo to get the user information.
Now the implementation logic is to write a button transfer page, enter Mini Program wx.getUserInfo and jump to button transfer page after failing to obtain, click button to call the bindgetuserinfo method, the detail data returned by this method is consistent with the information returned by the wx.getUserInfo method, and user information can also be obtained at this time. After the callback is successful, wx.navigateBack ({}) returns to the original page.
Paste some code snippets below:
Async bindGetUserInfo (event) {const {detail} = event; const isSuccess = detail.errMsg = = 'getUserInfo:ok'; if (isSuccess) {this.authSuccess (detail); return;} / / user refuses authorization / / wx.navigateBack ({});} async authSuccess (detail) {await this.getToken (detail); wx.navigateBack ({}); / / this.nextHander () } Save user information async getToken (detail) {console.log ('getToken', detail); const session_key = wx.getStorageSync (' session_key'); const {encryptedData: encrypted_data, iv} = detail; const that = this / / Save user information to the server const {data: {user, up_token, token, is_created}} = await this.fetch ({url:'/ api/artisan/wechat/login', data: {session_key, encrypted_data, iv,}, method: 'POST',}); wx.setStorageSync (' user', user) This.$root.$parent.store.set ('up_token', up_token, 30); / store the user identifier to the local this.$root.$parent.store.set (' token', token, 30); this.$root.$parent.store.set ('is_created', is_created, 30) / / redux / / store.dispatch ({/ / type: 'SET_IS_CREATED', / / payload: is_created, / /});} at this point, the study on "how to modify WeChat Mini Programs's login method" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.