uniapp获取手机号
微信文档
获取手机号
获取微信用户绑定的手机号,需先调用wx.login接口。
因为需要用户主动触发才能发起获取手机号接口,所以该功能不由 API 来调用,需用 button 组件的点击来触发。
注意:目前该接口针对非个人开发者,且完成了认证的小程序开放(不包含海外主体)。需谨慎使用,若用户举报较多或被发现在不必要场景下使用,微信有权永久回收该小程序的该接口权限。
个人小程序不能使用这个功能,必须是企业小程序,如果没权限那就是没有完成微信的认证,必须先去认证
必须用button 设置为 open-type=“getPhoneNumber”
<button type="default" size="mini" hover-class='none' open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">获取手机号</button>
button样式 跟背景浑然一体 (支付宝小程序不行)
button {
/* width: calc(100% - 100rpx); */
position: relative;
left: -168rpx;
font-size: 34rpx;
font-weight: 400;
display: block;
box-sizing: border-box;
text-align: center;
text-decoration: none;
line-height: 1;
-webkit-tap-highlight-color: transparent;
overflow: hidden;
color: #999999;
background-color: #fff;
/* #ifdef MP-ALIPAY */
background-color: #f7f7f7;
/* #endif */
}
微信文档
注意
在回调中调用