Home WeChat Applet Mini Program Development An example to explain the WeChat applet's function of obtaining authorized user login by mobile phone number

An example to explain the WeChat applet's function of obtaining authorized user login by mobile phone number

May 15, 2018 am 11:10 AM
Applets Phone number Obtain

There are many places in the mini program where registered user information is used. Users need to fill in their mobile phone number, etc. With this component, you can quickly obtain the mobile phone number bound to WeChat without the user filling it in. This article mainly shares with you the WeChat applet function of obtaining authorized user login with mobile phone number. Friends who need it can refer to it. I hope it can help everyone.

1. The getPhoneNumber component is implemented through button (other tags are invalid). Set open-type="getPhoneNumber" in the button and bind the bindgetphonenumber event to get the callback.

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

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

App({  
  onLaunch: function () {  
    wx.login({  
      success: function (res) {  
        if (res.code) {  
          //发起网络请求  
          console.log(res.code)  
        } else {  
          console.log(&#39;获取用户登录态失败!&#39; + res.errMsg)  
        }  
      }  
    });  
  }  
})
Copy after login

3. Get the callback through the event bound to bindgetphonenumber. There are three parameters of the callback,

errMsg: the information callback when the user clicks 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 (if the user does not agree to authorize, it will also return undefined)

getPhoneNumber: function(e) {   
  console.log(e.detail.errMsg)   
  console.log(e.detail.iv)   
  console.log(e.detail.encryptedData)   
  if (e.detail.errMsg == &#39;getPhoneNumber:fail user deny&#39;){  
   wx.showModal({  
     title: &#39;提示&#39;,  
     showCancel: false,  
     content: &#39;未授权&#39;,  
     success: function (res) { }  
   })  
  } else {  
   wx.showModal({  
     title: &#39;提示&#39;,  
     showCancel: false,  
     content: &#39;同意授权&#39;,  
     success: function (res) { }  
   })  
  }  
 }
Copy after login

4. Finally, we need to do it according to our own business logic Processing, if the user does not agree to the authorization, we may have an interface for him to enter manually. If it is not mandatory to obtain the mobile phone number, he can jump directly to the page and proceed to the next step. (The user does not agree to authorize errMsg and returns 'getPhoneNumber:fail user deny')

5. The user agrees to authorize. We can get the session_key through the background and WeChat processing based on the code obtained when logging in. Finally Through app_id, session_key, iv, encryptedData (the user agrees to authorize errMsg to return 'getPhoneNumber:ok')

I also learned a small program function, I hope it can help everyone.

Related recommendations:

Regular expression writing method for obtaining mobile phone number in PHP

Instance analysis of WeChat applet implementing synchronous request authorization

Summary of points to note about authentication and authorization

The above is the detailed content of An example to explain the WeChat applet's function of obtaining authorized user login by mobile phone number. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use Xiaohongshu account to find users? Can I find my mobile phone number? How to use Xiaohongshu account to find users? Can I find my mobile phone number? Mar 22, 2024 am 08:40 AM

With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the &quot;Discover&quot; button in the lower right corner, and then select the &quot;Notes&quot; option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the &quot;Follow&quot; button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select &quot;Personal Information&quot;

How to set up if WeChat does not allow adding by mobile phone number How to set up if WeChat does not allow adding by mobile phone number Mar 12, 2024 pm 05:04 PM

How to set up WeChat to disallow adding via mobile phone number? In WeChat APP, you can disallow adding WeChat via mobile phone number, but most users don’t know how to set it up to not allow WeChat to be added via mobile phone number. Next is WeChat brought by the editor to users It is not allowed to add setting method tutorials through mobile phone numbers. Interested users can come and take a look! Tutorial on how to use WeChat. How to set up WeChat when adding a mobile phone number is not allowed. 1. First open the WeChat APP, enter the main page, click [Me] in the lower right corner to enter, and select the [Settings] function; 2. Then enter the setting function page and find [Friend Permissions] ] Service function; 3. Then on the friend permissions interface, slide the button behind [Verification is required when adding me as a friend]; 4. Finally, on the page shown below, slide [Mobile Phone Number]

How to change the mobile phone number of Xiaohongshu account? Will there be any impact if I change my mobile phone number? How to change the mobile phone number of Xiaohongshu account? Will there be any impact if I change my mobile phone number? Mar 22, 2024 am 08:11 AM

In the digital age, Xiaohongshu has become a platform for many people to share their lives and discover good things. Over time, we may need to change the mobile phone number on the account. So, how to change Xiaohongshu’s mobile phone number? 1. How to change the mobile phone number of Xiaohongshu account? 1. Log in to your Xiaohongshu account and enter the “My” page. 2. Click &quot;...&quot; in the upper right corner and select &quot;Settings&quot;. 3. On the settings page, find the &quot;Account and Security&quot; option and click to enter. 4. On the Account and Security page, find the &quot;Mobile Phone Number&quot; option and click to enter. 5. At this time, the page will display the current mobile phone number, click &quot;Change Mobile Number&quot;. 6. Enter the new mobile phone number, receive the verification code, and fill it out. 7. Set a new password to ensure account security. 8. After completing the above steps,

How to get file extension in Python? How to get file extension in Python? Sep 08, 2023 pm 01:53 PM

A file extension in Python is a suffix appended to the end of a file name to indicate the format or type of the file. It usually consists of three or four characters, a file name followed by a period, such as ".txt" or ".py". Operating systems and programs use file extensions to determine what type of file it is and how it should be processed. Recognized as a plain text file. File extensions in Python are crucial when reading or writing files because it establishes the file format and the best way to read and write data. For example, the ".csv" file extension is the extension used when reading CSV files, and the csv module is used to process the files. Algorithm for obtaining file extension in Python. Manipulate file name string in Python.

Where to get Google security code Where to get Google security code Mar 30, 2024 am 11:11 AM

Google Authenticator is a tool used to protect the security of user accounts, and its key is important information used to generate dynamic verification codes. If you forget the key of Google Authenticator and can only verify it through the security code, then the editor of this website will bring you a detailed introduction on where to get the Google security code. I hope it can help you. If you want to know more Users please continue reading below! First open the phone settings and enter the settings page. Scroll down the page and find Google. Go to the Google page and click on Google Account. Enter the account page and click View under the verification code. Enter your password or use your fingerprint to verify your identity. Obtain a Google security code and use the security code to verify your Google identity.

What should I do if my railway 12306 mobile phone number has been changed and cannot be verified? What should I do if my railway 12306 mobile phone number has been changed and cannot be verified? Feb 28, 2024 am 09:00 AM

In recent years, the various certification rules of Railway 12306 have been revised to make them more standardized. In the past, when you could buy tickets through other people's mobile phone numbers or old mobile phone numbers, now when buying tickets, you will be prompted for unauthenticated operations, which affects users' travel. So how to change the mobile phone number in 12306? This tutorial guide will bring you a detailed guide introduction, hoping to help everyone in need. Then the first choice is to click on the modify mobile phone number function when you have logged in to 12306app, then enter the modification page, click to bind a new mobile phone number, use the new mobile phone number to send a text message, then enter the text message editing page, follow the prompts to send the edit Please fill in the verification code received and enter it into 12306app to complete the modification.

How to register two B-site numbers with one mobile phone number? How does Station B unbind its mobile phone? How to register two B-site numbers with one mobile phone number? How does Station B unbind its mobile phone? Mar 21, 2024 pm 10:10 PM

Bilibili (Bilibili), as a video sharing website very popular among Chinese young people, has attracted a large number of users. Some users hope to have two Bilibili accounts so that they can be managed and used separately. So, how to register two B-site numbers with one mobile phone number? This article will focus on this issue and how to unbind the mobile phone. 1. How to register two B-site numbers with one mobile phone number? 1. Register a new account: First, open the Bilibili App on your mobile phone or log in to the official website, click the &quot;Register&quot; button, and select the registration method. You can use your mobile phone number, email or third-party account (such as WeChat, QQ, etc.) to register. 2. When registering an account, please fill in the necessary information according to the system prompts, including mobile phone number, verification code, and set password. Be sure to use different accounts

Implement card flipping effects in WeChat mini programs Implement card flipping effects in WeChat mini programs Nov 21, 2023 am 10:55 AM

Implementing card flipping effects in WeChat mini programs In WeChat mini programs, implementing card flipping effects is a common animation effect that can improve user experience and the attractiveness of interface interactions. The following will introduce in detail how to implement the special effect of card flipping in the WeChat applet and provide relevant code examples. First, you need to define two card elements in the page layout file of the mini program, one for displaying the front content and one for displaying the back content. The specific sample code is as follows: &lt;!--index.wxml--&gt;&l

See all articles