From 54c6e483a41f138c928be66846dee1bd630b1f28 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 10 Sep 2023 18:01:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E5=BD=95=EF=BC=9A=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=EF=BC=8C=E9=9D=99=E9=BB=98=E7=99=BB?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 18 +++++------ api/member/auth.js | 11 +++++++ config/cache.js | 4 ++- libs/routine.js | 58 ++++++++++++++++++++++-------------- manifest.json | 2 +- pages/users/login/index.vue | 2 -- static/images/support.png | Bin 12019 -> 2387 bytes store/modules/app.js | 15 ++++++---- 8 files changed, 67 insertions(+), 43 deletions(-) diff --git a/App.vue b/App.vue index 5f6e0dab..039f60eb 100644 --- a/App.vue +++ b/App.vue @@ -122,19 +122,15 @@ // #endif // #ifdef MP - // 小程序静默授权 TODO 芋艿: + // 小程序静默授权 if (!this.$store.getters.isLogin) { let spread = that.globalData.spid ? that.globalData.spid : 0; - Routine.getCode() - .then(code => { - Routine.authUserInfo(code, { - 'spread_spid': spread - }).then(res => { - // that.$store.commit('AuthorizeType', res.data.type); - }) - }).catch(res => { - uni.hideLoading(); - }); + Routine.getCode().then(code => { + Routine.authUserInfo(code, spread) + .then(res => {}) + }).catch(res => { + uni.hideLoading(); + }); } // #endif }, diff --git a/api/member/auth.js b/api/member/auth.js index 7a3e6c5f..ac30def2 100644 --- a/api/member/auth.js +++ b/api/member/auth.js @@ -37,3 +37,14 @@ export function smsLogin(data) { noAuth: true // TODO 芋艿:后续要做调整 }); } + +// 社交快捷登录 +export function socialLogin(type, code, state) { + return request.post('app-api/member/auth/social-login', { + type, + code, + state + }, { + noAuth: true // TODO 芋艿:后续要做调整 + }); +} diff --git a/config/cache.js b/config/cache.js index 35fa4183..73560ba5 100644 --- a/config/cache.js +++ b/config/cache.js @@ -3,6 +3,8 @@ module.exports = { LOGIN_STATUS: 'LOGIN_STATUS_TOKEN', // uid UID:'UID', + // openid + OPENID: 'OPENID', //用户信息 USER_INFO: 'USER_INFO', //token 过期时间 @@ -31,4 +33,4 @@ module.exports = { CACHE_LATITUDE: 'LATITUDE', //app手机信息 PLATFORM: 'systemPlatform' -} \ No newline at end of file +} diff --git a/libs/routine.js b/libs/routine.js index 1db96ed6..baa8fb4e 100644 --- a/libs/routine.js +++ b/libs/routine.js @@ -1,23 +1,25 @@ import store from '../store'; import { checkLogin } from './login'; -import { login } from '../api/public'; import Cache from '../utils/cache'; -import { STATE_R_KEY, USER_INFO, EXPIRES_TIME, LOGIN_STATUS} from './../config/cache'; -class Routine +import { STATE_R_KEY, USER_INFO, OPENID} from './../config/cache'; +import * as AuthApi from "@/api/member/auth"; +import * as BrokerageAPI from '@/api/trade/brokerage.js' + +class Routine { - - constructor() + + constructor() { this.scopeUserInfo = 'scope.userInfo'; } - + async getUserCode(){ let isAuth = await this.isAuth(), code = '' ; if(isAuth) code = await this.getCode(); return code; } - + /** * 获取用户信息 */ @@ -37,7 +39,7 @@ class Routine }) }) } - + /** * 获取用户信息 */ @@ -61,14 +63,16 @@ class Routine }) }) } - + async getCode(){ let provider = await this.getProvider(); return new Promise((resolve,reject)=>{ uni.login({ provider:provider, success(res) { - if (res.code) Cache.set(STATE_R_KEY, res.code ,10800); + if (res.code) { + Cache.set(STATE_R_KEY, res.code ,10800); + } return resolve(res.code); }, fail(){ @@ -77,7 +81,7 @@ class Routine }) }) } - + /** * 获取服务供应商 */ @@ -95,7 +99,7 @@ class Routine }); }); } - + /** * 是否授权 */ @@ -118,17 +122,27 @@ class Routine } /** * 小程序登录 + * + * @param code 授权码 + * @param spread 推广员编号 */ - authUserInfo(code,data) - { + authUserInfo(code, spread) { return new Promise((resolve, reject)=>{ - login(code,data).then(res=>{ - if(res.data.type==='login'){ - store.commit('LOGIN', { - token: res.data.token - }); - store.commit("SETUID", res.data.uid); - } + // 34 的原因,它是小程序登录的社交类型 + AuthApi.socialLogin(34, code, 'default').then(res => { + if (res.code !== 0) { + return; + } + // 设置访问令牌 + store.commit('LOGIN', { + token: res.data.accessToken + }); + store.commit("SETUID", res.data.userId); + store.commit("OPENID", res.data.openid); + // 绑定推广员 + if (spread > 0) { + BrokerageAPI.bindBrokerageUser(spread) + } return resolve(res); }).catch(res=>{ return reject(res); @@ -137,4 +151,4 @@ class Routine } } -export default new Routine(); \ No newline at end of file +export default new Routine(); diff --git a/manifest.json b/manifest.json index e45eafa1..d3571b9c 100644 --- a/manifest.json +++ b/manifest.json @@ -59,7 +59,7 @@ "quickapp" : {}, /* 小程序特有相关 */ "mp-weixin" : { - "appid" : "wx62056c0d5e8db250", + "appid" : "wx63c280fe3248a3e7", "setting" : { "urlCheck" : true, "minified" : true, diff --git a/pages/users/login/index.vue b/pages/users/login/index.vue index 6f00c33a..18940f71 100644 --- a/pages/users/login/index.vue +++ b/pages/users/login/index.vue @@ -57,13 +57,11 @@