WeChat applet obtains the mobile phone number authorized user login function, Applet User Login

Source: Internet
Author: User
Tags call back

The applet obtains the mobile phone number Authorization User Login function, and the applet User Login

There are many areas in the applet that use the registered user information. You need to enter the mobile phone number and so on. With this component, you can quickly obtain the bound mobile phone number without entering it.

1. The getPhoneNumber component is implemented through the button (other labels are invalid ). Call back open-type = "getPhoneNumber" in the button and bindgetphonenumber to obtain the event.

<span style="font-size:14px;"><button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber"></button></span>

2. You must call the login interface before using this component. If you do not call login, you will be prompted to call login first when you click the button.

App ({onLaunch: function () {wx. login ({success: function (res) {if (res. code) {// initiate a network request console. log (res. code)} else {console. log ('failed to get the user logon status! '+ Res. errMsg )}}});}})

3. Get the callback through the bindgetphonenumber Bound event. There are three callback parameters,

ErrMsg: Call back the information you click to cancel or authorize.

Iv: the initial vector of the encryption algorithm (undefined if the user does not agree to the authorization ).

EncryptedData: Encrypted data of user information (undefined is returned if the user does not agree to the authorization)

GetPhoneNumber: function (e) {console. log (e. detail. errMsg) console. log (e. detail. iv) console. log (e. detail. encryptedData) if (e. detail. errMsg = 'getphonenumber: fail user deny') {wx. showModal ({title: 'hprompt ', showCancel: false, content: 'unauthorized', success: function (res) {}})} else {wx. showModal ({title: 'hprompt ', showCancel: false, content: 'agree to authorization', success: function (res ){}})}}

4. finally, we need to process it according to our own business logic. If the user does not agree to the authorization, we may have an interface for manual input, if you do not need to obtain the mobile phone number forcibly, you can directly jump to the page and proceed to the next step. (The user does not agree to authorize errMsg to return 'getphonenumber: fail user deny ')

5. the User agrees to authorize. We can get session_key through the background and Processing Based on the code obtained during login, and finally get session_key, iv, encryptedData through app_id, session_key (the user agrees to authorize errMsg to return 'getphonenumber: OK ')

Summary

The above is a small program introduced to everyone to get the mobile phone number authorized user login function, I hope to help you, if you have any questions, please leave a message, xiaobian will reply to you in a timely manner. Thank you very much for your support for the help House website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.