开发
async PKILogin() {
try {
if (!this.loginForm.agreement) {
this.noticePrivacyPolicy()
return
}
this.loading = true
let original = await this.getOriginal()
if (original) {
let signResult = detachSignStr(INIT_PARAM, original.original, '')
if (signResult) {
this.certAuth.original = original.original
this.certAuth.originalData = original.original_data
this.certAuth.signedData = signResult
this.certAuth.authMode = AUTH_MODE.cert
this.certAuth.remoteAddr = window.location.hostname
await this.getPKIAuth(this.certAuth)
let { CN } = this.getPKIUserInfo
let [name, IDNumber] = CN.split(' ')
let params = {
yhId: IDNumber
}
await this.thirdPartyLogin(params)
getUserInfo('from-login', this.$route)
}
}
} catch (e) {
console.log(e)
} finally {
this.loading = false
}
}
1、获取随机数
async getOriginal({ commit }){
try {
let data = await getOriginal({})
return data
} catch (e) {
console.log(e,"获取随机数失败")
}
},
2、调用 detachSignStr 签名
3、获取认证信息
async getPKIAuth({ commit }, params){
try {
let {data} = await getPKIAuth(params)
if (Object.values(data.certAttributeNodeMap).length === 0) return
let userInfoList = Object.values(data.certAttributeNodeMap)[0].split(",")
let userInfo = {}
userInfoList.forEach(item=>{
let [key, value] = item.split("=")
userInfo[key] = value
})
commit("setPKIUserInfo", userInfo)
} catch (e) {
console.log(e,"获取认证信息失败")
}
},
4、登录
async thirdPartyLogin({commit}, params) {
try {
let {data} = await thirdPartyLogin(params)
commit('setToken', data.access_token)
commit('setTokenDetail', data)
}catch (e) {
console.log(e)
}
},