// 獲取用戶手機號 getPhoneNumber(e){ // getPhoneNumber:fail no permission 說明沒有開通權限,需要企業賬號。 console.log(e.detail.errMsg) // 判斷用戶是否允許獲取手機號 console.log(e.detail.iv) // 參數 iv console.log(e.detail.encryptedData) // 參數encryptedData if(e.detail.errMsg == "getPhoneNumber:ok"){ // 用戶允許或去手機號 console.log('來了,老弟') } }, // 獲取 openid unionid getuserNew(){ uni.login({ provider: 'weixin', success:res=>{ // console.log(res.code); uni.request({ url: 'https://api.weixin.qq.com/sns/jscode2session', method:'GET', data: { appid: 'wxb7f97dd94793cb5e', //你的小程序的APPID secret: '31cbb0f3cc0af4ac4aeb515bd3e856f0', //你的小程序的secret, js_code:res.code, //wx.login 登錄成功後的code grant_type: 'authorization_code', }, success: (cts) => { // 換取成功後 暫存這些數據 留作後續操作 this.openId=cts.data.openid //openid 用戶唯一標識 this.unionid=cts.data.unionid //unionid 開放平臺唯一標識 當公衆號和小程序同時登錄過纔會有 this.session_key=cts.data.session_key //session_key 會話密鑰 console.log(cts) console.log(this.openId,this.session_key) } }); } }); }, // 彈出授權並獲取 經緯度 async GetAddressCoordinate(e) { let that = this // 獲取用戶是否開啓 授權獲取當前的地理位置、速度的權限。 uni.getSetting({ success (res) { console.log(res) // 如果沒有授權 if (!res.authSetting['scope.userLocation']) { // 則拉起授權窗口 uni.authorize({ scope: 'scope.userLocation', success () { console.info('成功') //點擊允許後--就一直會進入成功授權的回調 就可以使用獲取的方法了 uni.getLocation({ type: 'wgs84', success: function (res) { that.x = res.longitude that.y = res.latitude console.log(res) console.log('當前位置的經度:' + res.longitude) console.log('當前位置的緯度:' + res.latitude) uni.showToast({ title: '當前位置的經緯度:' + res.longitude + ',' + res.latitude, icon: 'success', mask: true }) }, fail (error) { console.log('失敗', error) } }) }, fail (error) { //點擊了拒絕授權後--就一直會進入失敗回調函數--此時就可以在這裏重新拉起授權窗口 console.log('拒絕授權', error) uni.showModal({ title: '提示', content: '若點擊不授權,將無法使用位置功能', cancelText: '不授權', cancelColor: '#999', confirmText: '授權', confirmColor: '#f94218', success (res) { console.log(res) if (res.confirm) { // 選擇彈框內授權 uni.openSetting({ success (res) { console.log(res.authSetting) } }) } else if (res.cancel) { // 選擇彈框內 不授權 console.log('用戶點擊不授權') } } }) } }) } else { // 有權限則直接獲取 uni.getLocation({ type: 'wgs84', success: function (res) { that.x = res.longitude that.y = res.latitude console.log(res) console.log('當前位置的經度:' + res.longitude) console.log('當前位置的緯度:' + res.latitude) uni.showToast({ title: '當前位置的經緯度:' + res.longitude + ',' + res.latitude, icon: 'success', mask: true }) }, fail (error) { uni.showToast({ title: '請勿頻繁調用!', icon: 'none', }) console.log('失敗', error) } }) } } }) }, //獲取 當前位置的經度 經度 getLocation () { let that = this // 獲取用戶是否開啓 授權獲取當前的地理位置、速度的權限。 uni.getSetting({ success (res) { console.log(res) // 如果沒有授權 if (!res.authSetting['scope.userLocation']) { // 則拉起授權窗口 uni.authorize({ scope: 'scope.userLocation', success () { //點擊允許後--就一直會進入成功授權的回調 就可以使用獲取的方法了 uni.getLocation({ type: 'wgs84', success: function (res) { that.x = res.longitude that.y = res.latitude console.log(res) console.log('當前位置的經度:' + res.longitude) console.log('當前位置的緯度:' + res.latitude) uni.showToast({ title: '當前位置的經緯度:' + res.longitude + ',' + res.latitude, icon: 'success', mask: true }) }, fail (error) { console.log('失敗', error) } }) }, fail (error) { //點擊了拒絕授權後--就一直會進入失敗回調函數--此時就可以在這裏重新拉起授權窗口 console.log('拒絕授權', error) uni.showModal({ title: '提示', content: '若點擊不授權,將無法使用位置功能', cancelText: '不授權', cancelColor: '#999', confirmText: '授權', confirmColor: '#f94218', success (res) { console.log(res) if (res.confirm) { // 選擇彈框內授權 uni.openSetting({ success (res) { console.log(res.authSetting) } }) } else if (res.cancel) { // 選擇彈框內 不授權 console.log('用戶點擊不授權') } } }) } }) } else { // 有權限則直接獲取 uni.getLocation({ type: 'wgs84', success: function (res) { that.x = res.longitude that.y = res.latitude console.log(res) console.log('當前位置的經度:' + res.longitude) console.log('當前位置的緯度:' + res.latitude) uni.showToast({ title: '當前位置的經緯度:' + res.longitude + ',' + res.latitude, icon: 'success', mask: true }) }, fail (error) { uni.showToast({ title: '請勿頻繁調用!', icon: 'none', }) console.log('失敗', error) } }) } } }) // const univerifyManager = uni.getLocation() // console.info(univerifyManager) }
uniapp 收貸地址
<button type="primary" size="mini" class="btnChooseAddress" @click="chooseAddress" >請選擇收貨地址+</button> async chooseAddress(){ const res = await uni.chooseAddress() // 2. 用戶成功的選擇了收貨地址 if(res.errMsg === 'chooseAddress:ok') { // console.log(res) // 3.2 把下面這行代碼註釋掉,使用 3.3 中的代碼替代之 // this.address=res // 3.3 調用 Store 中提供的 updateAddress 方法,將 address 保存到 Store 裏面 this.updateAddress(res) }
}