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 obtain user Information in WeChat Mini Programs's Development

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you how to obtain user information in WeChat Mini Programs's development. The content is simple and clear. I hope it can help you solve your doubts. Next, let the editor take you to study and learn the article "how to obtain user information in WeChat Mini Programs's development".

Wx.getUserInfo (OBJECT)

Get user information. If withCredentials is true, you need to call the wx.login API first.

OBJECT parameter description:

The parameter name type is required to indicate whether the minimum version of withCredentialsBoolean contains login status information 1.1.0langString No specify the language in which user information is returned, zh_CN simplified Chinese, zh_TW traditional Chinese, en English 1.4.0successFunction No API call successful callback function failFunction No API call failed callback function completeFunction No API call end callback function (call will be executed if successful or failed)

Note: when withCredentials is true, it is required that wx.login has been called before and the login status has not expired, and the returned data will contain sensitive information such as encryptedData and iv; when withCredentials is false, login status is not required, and the returned data does not contain sensitive information such as encryptedData and iv.

Success return parameter description:

The parameter type describes the userInfoOBJECT user information object, which does not contain sensitive information such as openid. RawDataString does not include the original data string of sensitive information, which is used to calculate the signature. SignatureString uses sha1 (rawData + sessionkey) to get the string, which is used to verify the user information, refer to the documentation signature. For the encrypted data of encryptedDataString complete user information, including sensitive data, see the initial vector of the encrypted data decryption algorithm ivString encryption algorithm for details, and see the encrypted data decryption algorithm for details.

Sample code:

Wx.getUserInfo ({success: function (res) {var userInfo = res.userInfovar nickName = userInfo.nickNamevar avatarUrl = userInfo.avatarUrlvar gender = userInfo.gender / / gender 0: unknown, 1: male, 2: female var province = userInfo.provincevar city = userInfo.cityvar country = userInfo.country}})

The decrypted encryptedData has the following json structure. For more information, please see the encrypted data decryption algorithm.

{"openId": "OPENID", "nickName": "NICKNAME", "gender": GENDER, "city": "CITY", "province": "PROVINCE", "country": "COUNTRY", "avatarUrl": "AVATARURL", "unionId": "UNIONID", "watermark": {"appid": "APPID", "timestamp": TIMESTAMP}} Bug & Tip

The tip:wx.getUserInfo API requires user authorization. Please be compatible with the scenario in which the user refuses authorization.

UnionID mechanism description:

If developers have multiple mobile applications, web apps, and public accounts (including Mini Program), they can distinguish the uniqueness of users through unionid, because as long as they are mobile apps, web apps and public accounts (including Mini Program) under the same Wechat open platform account, the user's unionid is unique. In other words, the same user, different applications under the same Wechat open platform, unionid is the same.

For App, official account and Mini Program of the same principal under the same Wechat open platform, if the user has followed the official account or has logged in to App or official account, when the user opens Mini Program, the developer can obtain the user UnionID directly through wx.login without the need for user authorization again.

Wechat Open platform binds Mini Program process

Prerequisite: Wechat open platform account must have completed developer qualification verification

Developer qualification certification process:

Login to Wechat Open platform (open.weixin.qq.com) account Center developer qualification Verification

Binding process:

Log in to Wechat Open platform (open.weixin.qq.com)-console-Public account-bind Public account

What is the advantage of Mini Program Mini Program compared with developers, Mini Program is less difficult to develop, can save development and operating costs, so that developers can quickly develop a Mini Program. And Mini Program can be easily obtained and spread in Wechat, which can meet the basic life applications, in line with life services offline stores and non-rigid needs of low-frequency applications. For users, it can save time cost and mobile phone memory space, and have excellent use experience at the same time.

The above is about "how to obtain user information in WeChat Mini Programs's development". If this article is helpful to you and thinks it is well written, please share it with your friends to learn new knowledge. If you want to know more about it, please pay more attention to the industry information channel.

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