WeChat获取手机号

 

1.微信官方文档(获取手机号):https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html
2.wx.login https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html

微信前端:
<button open-type="getPhoneNumber" bindgetphonenumber="onGetWeChatMobile"></button>


js:

 onGetWeChatMobile(e){
    console.log('获取手机号:')
    console.log(e.detail.errMsg)
    console.log(e.detail.iv)
    console.log(e.detail.encryptedData)
  },
 
wx.login({
  success (res) {
    if (res.code) {
      //发起网络请求
      wx.request({
        url: 'https://test.com/onLogin',
        data: {
          code: res.code
        }
      })
    } else {
      console.log('登录失败!' + res.errMsg)
    }
  }
})
 

 

posted @ 2020-03-28 15:20  林间有风-邓  阅读(626)  评论(0编辑  收藏  举报