wx 小程式獲取手機號
阿新 • • 發佈:2020-12-15
//onLoad 裡
wx.login({ success(res) { console.log(res); var code = res.code var appid = '自己的appid'; var appSecret = '自己的appSecret' wx.request({ url: 'https://api.weixin.qq.com/sns/jscode2session?appid='+appid+'&secret='+appSecret+'&js_code='+code+'&grant_type=authorization_code', method:"post", // data: { // code // }, success: function (res) { console.log(res.data); console.log(res.data.openid); console.log(res.data.session_key); } }) } })
//Page 裡
getPhoneNumber: function (e) {var that = this; console.log(e.detail.errMsg == "getPhoneNumber:ok"); if (e.detail.errMsg == "getPhoneNumber:ok") {
//回撥函式 wx.request({ url: 'http://www.baidu.com', data: { }, method: "post", success: function (res) { console.log(res); } }) } },
//html 裡
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">獲取手機號</button>