登录:微信一键登录

pull/1/MERGE
YunaiV 2023-09-10 19:57:10 +08:00
parent 0bd831fe35
commit e8573f42bb
3 changed files with 48 additions and 3 deletions

View File

@ -48,3 +48,13 @@ export function socialLogin(type, code, state) {
noAuth: true // TODO 芋艿:后续要做调整
});
}
// 微信小程序的一键登录登录
export function weixinMiniAppLogin(phoneCode, loginCode) {
return request.post('app-api/member/auth/weixin-mini-app-login', {
phoneCode,
loginCode
}, {
noAuth: true // TODO 芋艿:后续要做调整
});
}

View File

@ -121,7 +121,7 @@ class Routine
});
}
/**
* 小程序登录
* 微信小程序静默登录
*
* @param code 授权码
* @param spread 推广员编号

View File

@ -50,7 +50,10 @@
<div class="tips">
<div v-if="current === 0" @click="current = 1"></div>
<div v-if="current === 1" @click="current = 0"></div>
</div>
<!-- #ifdef MP-WEIXIN -->
<button open-type="getPhoneNumber" type="primary" @getphonenumber="getPhoneNumber"></button>
<!-- #endif -->
</div>
</div>
<div class="bottom"></div>
</div>
@ -63,6 +66,7 @@
const BACK_URL = "login_back_url";
import * as BrokerageAPI from '@/api/trade/brokerage.js'
import Routine from '@/libs/routine.js';
import {weixinMiniAppLogin} from "../../../api/member/auth";
export default {
name: "Login",
mixins: [sendVerifyCode],
@ -350,7 +354,38 @@
});
});
},
getUserInfo(data) {
/**
* 微信一键登录
*/
async getPhoneNumber(e) {
//
const phoneCode = e.detail.code
if (!e.detail.code) {
uni.showModal({
title: '授权失败',
content: '您已拒绝获取绑定手机号登录授权,可以使用其他手机号验证登录',
confirmText: '知道了',
confirmColor: '#3C9CFFFF'
})
return;
}
//
const loginCode = await Routine.getCode()
AuthApi.weixinMiniAppLogin(phoneCode, loginCode).then(res => {
const data = res.data;
// TODO refreshToken
this.$store.commit("LOGIN", {
'token': data.accessToken
});
this.getUserInfo(data);
this.bindBrokerUser();
}).catch(e => {
this.$util.Tips({
title: e
});
});
},
getUserInfo(data) {
this.$store.commit("SETUID", data.userId);
this.$store.commit("OPENID", data.openid);
UserApi.getUserInfo().then(res => {