Commit e8d30c2c authored by Nature's avatar Nature

hmapLogin

parent bbc23a33
...@@ -45,18 +45,13 @@ For a detailed explanation on how things work, check out the [guide](http://vuej ...@@ -45,18 +45,13 @@ For a detailed explanation on how things work, check out the [guide](http://vuej
{path: '/tab/userInfo', component: UserInfo, name: 'UserInfo', meta: {keepAlive: true}}, {path: '/tab/userInfo', component: UserInfo, name: 'UserInfo', meta: {keepAlive: true}},
``` ```
# keyStore签名信息 ### 组件的使用
keystore文件 hlscar.keystore 参考home页面
详细的用法参考插件的源码
别名 HLSkey ### 开发说明
密码 com.hls.easy.car 1.项目开发中中入口页面必须为home页面
2.在home页面的created函数中调用登录接口用于根据海马汇的个人信息获取业务系统的个人信息
# 签名
jarsigner -verbose -keystore hls.keystore -signedjar 车租易.apk hls.apk HLSkey
# 打包冲突解决
各项目如果安装了 com.hls.plugins.barcode 扫码插件与cordova-plugin-open-camera 媒体插件
两个插件之间存在一些冲突 请注释掉媒体插件 plugin.xml 第83行 <uses-feature android:name="android.hardware.camera" />
...@@ -265,6 +265,7 @@ ...@@ -265,6 +265,7 @@
<script> <script>
import svg from '@/assets/image/loading/rolling.svg' import svg from '@/assets/image/loading/rolling.svg'
import hmapLogin from '@/scripts/login'
export default { export default {
data () { data () {
...@@ -358,6 +359,8 @@ export default { ...@@ -358,6 +359,8 @@ export default {
// this.bottom = 20; // this.bottom = 20;
}, },
created: function () { created: function () {
hmapLogin('local').then(res => {
})
this.bgColor = ['#5D98F6', '#1aad19', '#eebe41'] this.bgColor = ['#5D98F6', '#1aad19', '#eebe41']
}, },
mounted () { mounted () {
......
...@@ -7,34 +7,40 @@ import axios from 'axios' ...@@ -7,34 +7,40 @@ import axios from 'axios'
import { getUrlParam } from './utils' import { getUrlParam } from './utils'
// 模拟登录 // 模拟登录
export async function analogLogin () { export function analogLogin () {
const url = `${$config.baseURL}/oauth/token?client_id=a765ff3f-8d33-49b4-a9c9-48e991544242&client_secret=ec2a9a5d-8b21-40fb-b20b-fa846b944e7b&grant_type=password&authType=TEL&username=17700002674&password=123456` return new Promise((resolve, reject) => {
const url = `${$config.hmapUrl}/oauth/token?client_id=18f58010-2831-11e8-b467-0ed5f89f718b&client_secret=2fe58f36-2831-11e8-b467-0ed5f89f718b&grant_type=password&username=%2B8618325379820&password=jingchaowu520&authType=TEL`
const res = await axios.post(url) axios.post(url).then(res => {
return { window.localStorage.setItem('token', res.access_token)
token: res.data.access_token, resolve({
tokenType: res.data.token_type, token: res.access_token,
expires: res.data.expires_in, tokenType: res.token_type,
userId: res.data.userId, expires: res.expires_in,
organizationId: res.data.organizationId, userId: res.userId,
} organizationId: res.organizationId,
})
})
})
} }
// 授权码登录 // 授权码登录
export async function authorizedLogin () { export async function authorizedLogin () {
const code = getUrlParam('code') return new Promise((resolve, reject) => {
const code = getUrlParam('code')
const url = `${$config.baseURL}/oauth/token?client_id=a765ff3f-8d33-49b4-a9c9-48e991544242&client_secret=ec2a9a5d-8b21-40fb-b20b-fa846b944e7b&grant_type=authorization_code&code=${encodeURIComponent(code)}` const url = `${$config.hmapUrl}/oauth/token?client_id=18f58010-2831-11e8-b467-0ed5f89f718b&client_secret=2fe58f36-2831-11e8-b467-0ed5f89f718b&grant_type=authorization_code&code=${encodeURIComponent(code)}`
axios.post(url).then(res => {
const res = await axios.post(url) window.localStorage.setItem('token', res.access_token)
resolve({
return { token: res.access_token,
token: res.data.access_token, tokenType: res.token_type,
tokenType: res.data.token_type, expires: res.expires_in,
expires: res.data.expires_in, userId: res.userId,
userId: res.data.userId, organizationId: res.organizationId,
organizationId: res.data.organizationId, account: res.account,
} mobile: res.phoneNumber,
})
})
})
} }
// 桥登录 // 桥登录
...@@ -43,15 +49,16 @@ export function bridgeLogin () { ...@@ -43,15 +49,16 @@ export function bridgeLogin () {
// 登录成功回调 // 登录成功回调
window.bridgeLoginSuccess = function (str) { window.bridgeLoginSuccess = function (str) {
const res = JSON.parse(str) const res = JSON.parse(str)
window.localStorage.setItem('token', res.token)
const data = { const data = {
token: res.token, token: res.token,
tokenType: res.tokenType, tokenType: res.tokenType,
expires: res.expiresIn, expires: res.expiresIn,
userId: res.userId, userId: res.userId,
organizationId: res.organizationId, organizationId: res.organizationId,
account: res.account,
mobile: res.phoneNumber,
} }
resolve(data) resolve(data)
} }
// 登录失败回调 // 登录失败回调
...@@ -59,21 +66,19 @@ export function bridgeLogin () { ...@@ -59,21 +66,19 @@ export function bridgeLogin () {
console.error(res) console.error(res)
reject(res) reject(res)
} }
const dict = { const dict = {
'className': 'BaseBridge', 'className': 'BaseBridge',
'function': 'getBaseInfo', 'function': 'getBaseInfo',
'successCallBack': 'bridgeLoginSuccess', 'successCallBack': 'bridgeLoginSuccess',
'failureCallBack': 'bridgeLoginFailure', 'failureCallBack': 'bridgeLoginFailure',
} }
HandBridge.postMessage(JSON.stringify(dict)) HandBridge.postMessage(JSON.stringify(dict))
}) })
} }
// 获取用户详细信息 // 获取用户详细信息
export async function getUserInfo (userId) { export function getUserInfo (userId) {
const url = `${$config.baseURL}/i/api/staff/customDetail` const url = `${$config.hmapUrl}/i/api/staff/customDetail`
const data = { const data = {
userId, userId,
} }
...@@ -82,9 +87,53 @@ export async function getUserInfo (userId) { ...@@ -82,9 +87,53 @@ export async function getUserInfo (userId) {
Authorization: `Bearer ${window.localStorage.token}`, Authorization: `Bearer ${window.localStorage.token}`,
}, },
} }
const res = await axios.post(url, data, options) return new Promise((resolve, reject) => {
axios.post(url, data, options).then(res => {
resolve({
account: res.accountNumber,
mobile: res.mobile,
userId: res.userId,
organizationId: res.organizationId,
email: res.email,
})
})
})
}
return res.data /**
* 获取中台的token
* @returns {Promise<*>}
*/
export async function getSupportToken () {
const url = `${$config.loginPath}appadmin`
const res = await axios.post(url)
return res
}
/**
* 获取业务系统个人信息
* @returns {Promise<*>}
*/
export async function getLeasingUserInfo (account, mobile) {
window.localStorage.setItem('account', account)
const url = `${$config.basePath}hmap_app_login`
const data = {
'user_name': account,
'mobile': mobile,
}
const options = {
headers: {
Authorization: `Bearer ${window.localStorage.access_token}`,
},
}
return new Promise((resolve, reject) => {
axios.post(url, data, options).then(res => {
// console.log('leasingInfo:' + JSON.stringify(res))
if (res.result === 'S') {
resolve(res.user_info[0])
}
})
})
} }
/** /**
...@@ -93,26 +142,85 @@ export async function getUserInfo (userId) { ...@@ -93,26 +142,85 @@ export async function getUserInfo (userId) {
* @param {Boolean} [needInfo] 是否需要获取用户详细信息 * @param {Boolean} [needInfo] 是否需要获取用户详细信息
* @return {Object.Promise} 若登录成功PromiseValue为数据对象/登录失败PromiseValue 为 false * @return {Object.Promise} 若登录成功PromiseValue为数据对象/登录失败PromiseValue 为 false
*/ */
export default async function login (type = 'online', needInfo = true) { // 登录 export async function login (type = 'online', needInfo = true) { // 登录
const env = process.env.CONFIG_ENV // 环境 const env = process.env.CONFIG_ENV // 环境
try { try {
let result = {} let result = {}
let tokenInfo = {}
tokenInfo = await getSupportToken()
window.localStorage.setItem('access_token', tokenInfo.access_token)
if (env === 'prod' || env === 'uat') { // 真机 if (env === 'prod' || env === 'uat') { // 真机
if (type === 'online') result = await authorizedLogin() // 在线子应用 if (type === 'online') result = await authorizedLogin() // 在线子应用
if (type === 'local') result = await bridgeLogin() // 本地子应用 if (type === 'local') result = await bridgeLogin() // 本地子应用
window.localStorage.setItem('mobile', result.mobile)
result.userInfo = await getLeasingUserInfo(result.account, result.mobile)
} else { } else {
result = await analogLogin() result = await analogLogin()
result.hmapUserInfo = await getUserInfo(result.userId)
window.localStorage.setItem('mobile', result.hmapUserInfo.mobile)
result.userInfo = await getLeasingUserInfo(result.hmapUserInfo.account, result.hmapUserInfo.mobile)
} }
window.localStorage.token = result.token window.localStorage.setItem('user_id', result.userInfo.user_id)
if (needInfo) result.userInfo = await getUserInfo(result.userId)
return result return result
} catch (e) { } catch (e) {
console.error(e) // console.error(e)
return false return false
} }
} }
/**
* 海马汇业务系统集成登录
* @param type
* @param needInfo
* @returns {Promise<any>}
*/
export default function hmapLogin (type = 'local', needInfo = true) {
const env = process.env.CONFIG_ENV // 环境
return new Promise((resolve, reject) => {
try {
let result = {}
if (env === 'prod' || env === 'uat') { // 真机
if (type === 'online') {
authorizedLogin().then(res => {
result = res
window.localStorage.setItem('mobile', res.mobile)
})
}// 在线子应用
if (type === 'local') {
result = bridgeLogin().then(res => {
result = res
window.localStorage.setItem('mobile', res.mobile)
})
}
getSupportToken().then(res => {
window.localStorage.setItem('access_token', res.access_token)
getLeasingUserInfo(result.account, result.mobile).then(res => {
result.userInfo = res
window.localStorage.setItem('user_id', res.user_id)
resolve(result)
})
})
} else {
analogLogin().then(res => {
result = res
getUserInfo(res.userId).then(info => {
result.hmapUserInfo = info
window.localStorage.setItem('mobile', info.mobile)
getSupportToken().then(support => {
window.localStorage.setItem('access_token', support.access_token)
getLeasingUserInfo(info.account, info.mobile).then(res => {
result.userInfo = res
window.localStorage.setItem('user_id', res.user_id)
resolve(result)
})
})
})
})
}
} catch (e) {
reject(e)
}
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment