Skip to main content

Obtain User Phone Number

Phone

Usage Instructions

The Obtain Phone Number component can obtain the user's phone number during the mini-program runtime. The usage is as follows:

  1. Please confirm that the selected application supports mini-program-side builds. For specific operations, refer to the Create Application Guide.

  2. Add the Obtain Phone Number component in the editor.

Image 2ac36626f8e9f3033dd1192313a4bcf5
  1. Create a string-type common variable for the application to receive the obtained phone number information.
Image 12662b8e0bc7852310d415f765a652d7
  1. Configure the variable assignment event for the Obtain Phone Number component to achieve assigning the returned phone number information to the common variable in step 3 after successful user authorization.
Image 0766232a74f40caac7dbeaadc18a7b44
  1. This component only takes effect during the actual runtime of the mini-program. Therefore, we add a text component in the editor and bind it to a common variable. When the user clicks the Obtain Phone Number button in the mini-program and successfully authorizes, the text component will display the corresponding phone number information.
Image 311728e8eb0d03e991581a198abb61bc
  1. Publish the application to the mini-program. You can see that when clicking the Obtain Phone Number button and authorizing, the text component will display the obtained phone number information.
Image 1b4c8a656ae0298534e9f5c2749c9b04

Component Usage Limits

  1. This component is only supported on the Mini Program side, and the Mini Program must be an enterprise entity.

  2. This component must be used in a real mini-program environment to see the actual effect.

  3. Ensure the mini-program has completed WeChat authentication. Go to authentication

Properties

External properties received by the component

Property Name
Property Identifier
Type
Description
Button title(Mini Program)textstring

Button title

Example: "获取用户手机号"

Button style(Mini Program)typestring

The style of the button component, compared to the ordinary button component, adds the "WeChat" button style.

Example: "wechat"

Button size(Mini Program)sizestring

Button size

Example: "default"

Events

Events exposed by the component. You can listen to component events to trigger external actions

Event Name
Event Code
Event Output Parameters event.detail
Applicable Scenarios
Description
Mobile phone authorization successfulphonesuccessobject
  • phoneNumber: string区号+手机号
  • purePhoneNumber: string无区号手机号
  • countryCode: string区号
  • timestamp: string授权时间
Mini Program

Event triggered after clicking the Allow button in the pop-up window

Mobile phone authorization failedphonefailMini Program

Event triggered after clicking the Reject button in the pop-up window