diff --git a/Utils/Api.js b/Utils/Api.js index 7cd973d..87c9c63 100644 --- a/Utils/Api.js +++ b/Utils/Api.js @@ -30,7 +30,11 @@ export const updateUserPayPwd = params => { //获取用户信息 export const findUser = params => { return POST('GET', `${base}/highUser/findUser`, params).then(res => res.data); -} +} +//绑定用户电话 +export const loginByPhone = params => { + return POST('GET', `${base}/wechat/loginByPhone`, params).then(res => res.data); +}; //微信登录 export const WXlogin = params => { return POST('GET', `${base}/wechat/login`, params).then(res => res.data); diff --git a/pages/goods/externalCoupon/externalCoupon.vue b/pages/goods/externalCoupon/externalCoupon.vue index ca2caaa..01b1913 100644 --- a/pages/goods/externalCoupon/externalCoupon.vue +++ b/pages/goods/externalCoupon/externalCoupon.vue @@ -14,7 +14,7 @@ - 去使用 @@ -62,7 +62,8 @@ getDiscountByQrCode, receiveDiscount, HandleCode, - getUserInfo + getUserInfo, + loginByPhone } from '../../../Utils/Api.js'; // import authorize from '../../../components/Authorize'; let app = getApp(); @@ -249,6 +250,47 @@ // }) }, + // 微信获取手机号 + loginByPhone(PhoneNumber) { + if(PhoneNumber.detail.iv == undefined){ + uni.showToast({ + title: "用户取消授权", + icon: "none" + }); + return; + } + let params = { + openId: app.globalData.openId, + iv: PhoneNumber.detail.iv, + encryptedData: PhoneNumber.detail.encryptedData + } + loginByPhone(params).then(res => { + if (res.return_code == '000000') { + uni.showToast({ + title: '手机号授权成功', + icon: 'none', + duration: 2000 + }) + this.user = res.return_data.object.highUser; + app.globalData.token = res.return_data.uniqueCode; + app.globalData.userInfo = res.return_data + .object + .highUser; + uni.setStorage({ + key: "user", + data: res.return_data + .object + .highUser + }) + uni.setStorage({ + key: "token", + data: res.return_data.uniqueCode + }) + this.receiveDiscount(); + this.userInfo = 2; + } + }); + }, //商品跳转 toGoods(e) { if (app.globalData.userInfo) { diff --git a/pages/goods/goods.vue b/pages/goods/goods.vue index d8c4afa..e45aed8 100644 --- a/pages/goods/goods.vue +++ b/pages/goods/goods.vue @@ -119,7 +119,6 @@ - -