initHeader
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
import createAxios from '@/utils/http'
|
||||
import { useUserInfoStore } from '@/stores/modules/user'
|
||||
import { sm3Digest } from '@/assets/commjs/sm3.js'
|
||||
import { sm2, encrypt } from '@/assets/commjs/sm2.js'
|
||||
|
||||
// 获取公钥
|
||||
export const publicKey = (params?: any) => {
|
||||
if (!params) {
|
||||
const userInfo = useUserInfoStore()
|
||||
params = {
|
||||
loginName: encrypt(userInfo.loginName),
|
||||
}
|
||||
}
|
||||
return createAxios({
|
||||
url: '/user/generateSm2Key',
|
||||
method: 'get',
|
||||
params,
|
||||
})
|
||||
}
|
||||
|
||||
export const pwdSm3 = async (pwd: any, loginName?: string) => {
|
||||
let publicKeyStr = await publicKey(
|
||||
loginName ? { loginName: encrypt(loginName) } : false,
|
||||
)
|
||||
let sm3Pwd = sm3Digest(pwd) //SM3加密
|
||||
return sm2(sm3Pwd + '|' + pwd, publicKeyStr.data, 0)
|
||||
}
|
||||
|
||||
//登录获取token
|
||||
export const login = async (params: any) => {
|
||||
params.password = await pwdSm3(params.password, params.username)
|
||||
params.username = encrypt(params.username)
|
||||
return createAxios({
|
||||
url: '/pqs-auth/oauth/token',
|
||||
method: 'post',
|
||||
params,
|
||||
})
|
||||
}
|
||||
|
||||
//获取用户信息
|
||||
export const getUserById = () => {
|
||||
const userInfo = useUserInfoStore()
|
||||
return createAxios({
|
||||
url: '/user-boot/user/getUserById?id=' + userInfo.userIndex,
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
||||
// 刷新token
|
||||
export function refreshToken(): Promise<any> {
|
||||
const userInfo = useUserInfoStore()
|
||||
return login({
|
||||
grant_type: 'refresh_token',
|
||||
refresh_token: userInfo.refresh_token,
|
||||
username: userInfo.loginName,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user