对接注册,获取用户信息接口
This commit is contained in:
parent
a0e1ab5614
commit
767b05e9fa
|
|
@ -6,9 +6,9 @@ export default {
|
|||
uni.addInterceptor('request', {
|
||||
invoke(args) {
|
||||
// request 触发前拼接 url
|
||||
args.url = 'https://www.opsoul.com' + args.url;
|
||||
// args.url = 'https://www.opsoul.com' + args.url;
|
||||
// args.url = 'http://192.168.2.3:80' + args.url;
|
||||
// args.url = 'http://127.0.0.1:80' + args.url;
|
||||
args.url = 'http://127.0.0.1:80' + args.url;
|
||||
// console.log("停止触发");
|
||||
// return false;
|
||||
},
|
||||
|
|
@ -68,29 +68,14 @@ export default {
|
|||
return true;
|
||||
}
|
||||
|
||||
// TODO:调用小程序服务端确认是否是授权登录过的用户
|
||||
let loginRes = {
|
||||
logined: false,
|
||||
userInfo: {}
|
||||
};
|
||||
// 未登录过的获取微信用户信息
|
||||
if (!loginRes.logined) {
|
||||
userInfo = await wx.getUserProfile({
|
||||
desc: '用于小程序登录'
|
||||
});
|
||||
console.log("从微信获取基本用户信息:" + userInfo);
|
||||
// 获取微信登录凭证
|
||||
const wxLoginRes = await wx.login();
|
||||
console.log(wxLoginRes)
|
||||
// 再次请求小程序服务端存储用户,服务端添加附加用户信息后返回
|
||||
loginRes = {
|
||||
logined: true,
|
||||
userInfo: {
|
||||
...userInfo,
|
||||
userId: 1,
|
||||
wxLoginCode: wxLoginRes.code
|
||||
}
|
||||
};
|
||||
|
||||
// 获取openid
|
||||
const wxAuthRes = await uni.request({
|
||||
url: '/wx/auth',
|
||||
header: {
|
||||
|
|
@ -98,12 +83,32 @@ export default {
|
|||
}
|
||||
})
|
||||
console.log(wxAuthRes)
|
||||
loginRes.userInfo.openId = wxAuthRes[1].data.data.openid;
|
||||
loginRes.userInfo.customerId = 2;
|
||||
const openId = wxAuthRes[1].data.data.openid;
|
||||
// 第一次从服务端获取用户信息
|
||||
let wxGetUserRes = await this.qryUserInfo(openId);
|
||||
// 获取失败则获取微信信息再调用注册接口
|
||||
if (!wxGetUserRes.data) {
|
||||
// 注册完成后再次从服务端获取用户信息
|
||||
let registerRes = await this.registerUser({
|
||||
openId: openId,
|
||||
name: userInfo.userInfo.nickName,
|
||||
customerLogoUrl: userInfo.userInfo.avatarUrl,
|
||||
status: 0
|
||||
});
|
||||
if (registerRes.code === 0) {
|
||||
wxGetUserRes = await this.qryUserInfo(openId);
|
||||
}
|
||||
userInfo = loginRes.userInfo;
|
||||
|
||||
if (!userInfo) {
|
||||
}
|
||||
if (!wxGetUserRes.data) {
|
||||
userInfo = null;
|
||||
} else {
|
||||
userInfo = {
|
||||
...wxGetUserRes.data,
|
||||
wxLoginCode: wxLoginRes.code
|
||||
}
|
||||
}
|
||||
console.log("通过后台服务获取用户信息:" + userInfo);
|
||||
if (!userInfo || userInfo.customerId == null || userInfo.customerId == undefined) {
|
||||
uni.showToast({
|
||||
icon: 'error',
|
||||
title: '微信用户信息获取失败,请退出小程序重试'
|
||||
|
|
@ -114,6 +119,24 @@ export default {
|
|||
uni.setStorageSync('userProfile', userInfo);
|
||||
return true;
|
||||
},
|
||||
async registerUser(params = {}) {
|
||||
let res = await uni.request({
|
||||
url: '/wx/addUser',
|
||||
method: 'POST',
|
||||
data: params
|
||||
})
|
||||
return res[1].data;
|
||||
},
|
||||
async qryUserInfo(openId) {
|
||||
let res = await uni.request({
|
||||
url: '/wx/getUserInfo',
|
||||
method: 'POST',
|
||||
data: {
|
||||
openId: openId
|
||||
}
|
||||
})
|
||||
return res[1].data;
|
||||
},
|
||||
wxLogin() {
|
||||
return wx.login();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@
|
|||
},
|
||||
methods: {
|
||||
async loadData() {
|
||||
let curUserInfo = uni.getStorageSync('userProfile');
|
||||
let curUserInfo = this.$request.getCurUserInfo();
|
||||
this.isAuthWxLoginModal = curUserInfo ? false : true;
|
||||
if (this.isAuthWxLoginModal) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
<view class="padding bg-main-color" :style="'padding-top: ' + pageContentTop + 'px; padding-bottom: 100rpx;'">
|
||||
<view class="flex justify-start padding-bottom-xl solid-bottom">
|
||||
<view class="cu-avatar round"
|
||||
:style="'width: 120rpx; height: 120rpx; background-image:url(' + curUserInfo.userInfo.avatarUrl + ');'"></view>
|
||||
:style="'width: 120rpx; height: 120rpx; background-image:url(' + curUserInfo.customerLogoUrl + ');'"></view>
|
||||
<view class="margin-lr-sm">
|
||||
<view class="text-xl margin-bottom-xs">{{curUserInfo.userInfo.nickName}}</view>
|
||||
<view class="text-xl margin-bottom-xs">{{curUserInfo.name}}</view>
|
||||
<view class="padding-xs text-sm">
|
||||
<view v-if="myInfo.vipInfo.isVip" class='cu-tag bg-yellow radius'>{{myInfo.vipInfo.level}}会员
|
||||
</view>
|
||||
|
|
|
|||
|
|
@ -240,21 +240,13 @@
|
|||
}
|
||||
let curUserInfo = this.$request.getCurUserInfo();
|
||||
let params = {
|
||||
// customerId: curUserInfo.userId,
|
||||
customerId: 2,
|
||||
customerId: curUserInfo.customerId,
|
||||
serverTime: this.formInfo.doorTime,
|
||||
addressId: this.formInfo.defaultAddress.customerAddressId,
|
||||
payType: this.formInfo.payWay,
|
||||
remark: this.formInfo.comments,
|
||||
isNeedBill: this.formInfo.isNeedBill,
|
||||
// goodsList: this.parseGoodsList()
|
||||
goodsList: [{
|
||||
goodsId: 2,
|
||||
num: 1
|
||||
}, {
|
||||
goodsId: 3,
|
||||
num: 1
|
||||
}]
|
||||
goodsList: this.parseGoodsList()
|
||||
}
|
||||
// 调用下单接口
|
||||
let res = await this.$request.placeOrder(params);
|
||||
|
|
|
|||
Loading…
Reference in New Issue