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

组件接收的外部传入的属性

属性名
属性标识
类型
说明
按钮标题(小程序)textstring

按钮组件的标题

示例:"获取用户手机号"

按钮风格(小程序)typestring

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

示例:"wechat"

按钮大小(小程序)sizestring

按钮的大小

示例:"default"

Events

组件暴露的事件,可以监听组件的事件来触发一些外部的动作

事件名
事件code
事件出参 event.detail
适用情况
说明
手机号授权成功phonesuccessobject
  • phoneNumber: string区号+手机号
  • purePhoneNumber: string无区号手机号
  • countryCode: string区号
  • timestamp: string授权时间
小程序

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

手机号授权失败phonefail小程序

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