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:
Please confirm that the selected application supports mini-program-side building. For specific operations, refer to Create Application Guide.
Add the Get Phone Number component in the editor.
- Create a string variable for the application to store the retrieved phone number.
- 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.
- 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.
- 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
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 Certification. Go to Certification
Properties
组件接收的外部传入的属性
属性名 | 属性标识 | 类型 | 说明 |
---|
按钮标题(小程序) | text | string | 按钮组件的标题 示例:"获取用户手机号" |
按钮风格(小程序) | type | string | 按钮组件的风格,相对于普通按钮组件,新增“微信”按钮风格 示例:"wechat" |
按钮大小(小程序) | size | string | 按钮的大小 示例:"default" |
Events
组件暴露的事件,可以监听组件的事件来触发一些外部的动作
事件名 | 事件code | 事件出参 event.detail | 适用情况 | 说明 |
---|
手机号授权成功 | phonesuccess | object
| 小程序 | 弹窗中点击了允许按钮后触发的事件 |
手机号授权失败 | phonefail | 小程序 | 弹窗中点击了拒绝按钮后触发的事件 |