From ac44b970dd456b124e81b05f7d1c2b7d9f4a8231 Mon Sep 17 00:00:00 2001 From: admin <592225189@qq.com> Date: Thu, 31 Oct 2024 11:45:22 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E7=99=BB=E5=BD=95=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=BD=AFkey=E7=99=BB=E5=BD=95=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/trxLogin.js | 16 +++++++++ src/store/modules/skey.js | 68 +++++++++++++++++++++++++++++++++++++++ src/views/login/login.vue | 54 +++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 src/store/modules/skey.js diff --git a/src/services/trxLogin.js b/src/services/trxLogin.js index 5f0520c..8f6d388 100644 --- a/src/services/trxLogin.js +++ b/src/services/trxLogin.js @@ -4,6 +4,14 @@ export function getLoginRandom(ngxCookie) { return request.get('/sms/v1/trx/randomstr', { params: { ngxCookie } }) } +export function getSoftLoginRandom(ngxCookie,account) { //多传一个账号,这个接口返回的结果,作为randoms + return request.get('/sms/v1/trx/soft/randomstr', { params: { ngxCookie,account } }) +} + +export function trxSoftLogin(params) { + return request.post('/sms/v1/trx/softlogin', params) +} + export function trxLogin(params) { return request.post('/sms/v1/trx/login', params) } @@ -12,6 +20,14 @@ export function offlineToken(trxToken) { return request.post('/sms/v1/trx/logout', { trxToken }) } +export function getSoftLoginRandom(ngxCookie,account) { //多传一个账号,这个接口返回的结果,作为randoms + return request.get('/sms/v1/trx/soft/randomstr', { params: { ngxCookie,account } }) +} + +export function trxSoftLogin(params) { + return request.post('/sms/v1/trx/softlogin', params) +} + // 理想那边给的代码调用 getAuthToken 时需要传 ip,云管目前不传 export function getIp() { return request({ diff --git a/src/store/modules/skey.js b/src/store/modules/skey.js new file mode 100644 index 0000000..ed766a5 --- /dev/null +++ b/src/store/modules/skey.js @@ -0,0 +1,68 @@ +import { getClientHello } from 'services/ukeyAuth.js' +import { getSoftLoginRandom, trxSoftLogin } from 'services/trxLogin.js' +import Cookies from 'js-cookie' +import { ElMessage } from 'element-plus' +const state = {} +const mutations = {} +const actions = { + // 登录 + Login({ commit }, loginParam) { + return new Promise((resolve, reject) => { + // 调用 skey 获取 clientHello + console.log('执行 store.dispatch(skey/Login)开始,传参为password:', loginParam.password) + getClientHello(loginParam.password).then(checkRes => { + console.log('调用 skey getClientHello 方法,接口返回结果为:', checkRes) + if (checkRes.result !== 0) { + console.log('调用 skey getClientHello 方法失败,接口返回结果为:', checkRes) + Cookies.remove('ngx_cookie') + ElMessage({ message: checkRes.message, type: 'error' }) + resolve({ + success: false + }) + } + const clientHello = checkRes.clientHello + console.log('clientHello:', clientHello) + Cookies.set('ngx_cookie', clientHello) + // 调用天融信单点登录获取 serverHello + getSoftLoginRandom(clientHello, loginParam.account) + .then(randomRes => { + console.log('调用 getSoftLoginRandom 方法,接口返回结果为:', randomRes) + if (!randomRes.success) { + console.log('调用 getSoftLoginRandom 方法失败,接口返回结果为:', randomRes) + resolve({ + success: false + }) + return + } + const randoms = randomRes.result + console.log('loginRandom:', randoms) + trxSoftLogin({clientHello, randoms, password: loginParam.password}).then(loginRes=>{ + console.log('调用 trxSoftLogin 方法,接口返回结果为:', loginRes) + if (!loginRes.success) { + console.log('调用 trxSoftLogin 方法失败,接口返回结果为:', loginRes) + resolve({ + success: false + }) + return + } + resolve(loginRes) + return + }).catch(err => { + console.log('调用 trxSoftLogin 方法 [catch] ,接口返回结果为:', err) + reject(err) + }) + }) + .catch(err => { + console.log('调用 getSoftLoginRandom 方法 [catch] ,接口返回结果为:', err) + reject(err) + }) + }) + }) + } +} +export default { + namespaced: true, + state, + mutations, + actions +} diff --git a/src/views/login/login.vue b/src/views/login/login.vue index 1bfbaa5..9e03f45 100644 --- a/src/views/login/login.vue +++ b/src/views/login/login.vue @@ -62,6 +62,39 @@ 登录 + +
+ + + + + + + +
+
@@ -144,6 +177,27 @@ function handleLogin() { } }) } +// 软key 登录 +function handleLogin4sKey() { + if (!loginFormRef.value) return + loginFormRef.value.validate(async valid => { + if (valid) { + loading.value = true + const { saccount, spassword } = loginForm + const res = await store + .dispatch('skey/Login', {account: saccount, password: spassword}) + .finally(() => (loading.value = false)) + .catch(() => (loading.value = false)) + if (res && res.success) { + console.log('SKEY: 登录成功,云管融合登录接口返回', res) + goLogin(res.data) + } else { + console.log('SKEY: 登录失败,云管融合登录接口返回', res) + } + } + }) + + // ukey 登录 async function handleUkeyLogin() { if (!loginFormRef.value) return