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:
Please confirm that the selected application supports mini-program-side builds. For specific operations, refer to the Create Application Guide.
Add the Obtain Phone Number component in the editor.

- Create a string-type common variable for the application to receive the obtained phone number information.

- 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.

- 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.

- 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.

Component Usage Limits
This component is only supported on the Mini Program side, and the Mini Program must be an enterprise entity.
This component must be used in a real mini-program environment to see the actual effect.
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) | text | string | Button title Example: "获取用户手机号" |
| Button style(Mini Program) | type | string | The style of the button component, compared to the ordinary button component, adds the "WeChat" button style. Example: "wechat" |
| Button size(Mini Program) | size | string | 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 successful | phonesuccess | object
| Mini Program | Event triggered after clicking the Allow button in the pop-up window |
| Mobile phone authorization failed | phonefail | Mini Program | Event triggered after clicking the Reject button in the pop-up window |