Skip to main content

Get User Phone Number

Phone

Usage Instructions

Using the Get Phone Number component allows you to 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 building. For specific operations, refer to Create Application Guide.

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

  1. Create a string variable for the application to store the retrieved phone number.

  1. Configure a variable assignment event for the Get Phone Number component to assign the returned phone number information to the ordinary variable in Step 3 when user authorization is successful.

  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 the ordinary variable. When the user clicks the "Get Phone Number" button in the mini program and successfully grants authorization, the text component will display the corresponding phone number information.

  1. Publish the application to the mini program. You can see that when clicking the "Get Phone Number" button and granting authorization, the text component will display the obtained phone number information.

Component Usage Limitations

  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 Certification. Go to Certification

Properties

External properties received by the component

Property Name
Property Identifier
Type
Description
按钮标题(Mini Program)textstring

按钮组件的标题

Example: "获取用户手机号"

按钮风格(Mini Program)typestring

按钮组件的风格,相对于普通按钮组件,新增“微信”按钮风格

Example: "wechat"

按钮大小(Mini Program)sizestring

按钮的大小

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
手机号授权成功phonesuccessobject
  • phoneNumber: string区号+手机号
  • purePhoneNumber: string无区号手机号
  • countryCode: string区号
  • timestamp: string授权时间
Mini Program

弹窗中点击了允许按钮后触发的事件

手机号授权失败phonefailMini Program

弹窗中点击了拒绝按钮后触发的事件