Files
llpreheat/common/http.api.js
T

63 lines
2.5 KiB
JavaScript

import { Encrypt, Decrypt } from '@/js_sdk/cainiao-crypto/cainiao-crypto.js'
const install = (Vue, vm) => {
const LYLAW_BASE = '/lylaw/api/hnlylaw'
const lylawPost = (url, params = {}) => {
const payload = Object.assign({}, params)
const forceSw = payload.__sw === true
const forceHj = payload.__hj === true
delete payload.__sw
delete payload.__hj
let authKey = 'authorizationSft'
if (forceSw || payload.wenjuan_id == 1006 || payload.wenjuanId == 1006) {
authKey = 'authorizationSw'
} else if (forceHj || payload.wenjuan_id == 1007 || payload.wenjuanId == 1007) {
authKey = 'authorizationHj'
}
const auth = uni.getStorageSync(authKey)
const header = auth ? { authorization: auth } : {}
console.log('[原始参数]', url, JSON.stringify(payload));
return Vue.prototype.$u.post(url, { request: Encrypt(JSON.stringify(payload)) }, header).then(res => {
if (res && res.Data) {
if (res.Data === 'VFXeGhPbmE9mfQeg2iiwdA==') {
res.Data = null
} else {
try { res.Data = JSON.parse(Decrypt(res.Data)) } catch (e) {}
}
}
if (url.indexOf('wxOpenidLogin') > -1 && res) {
const pickAuth = obj => {
if (!obj || typeof obj !== 'object') return ''
const k = Object.keys(obj).find(x => x.toLowerCase() === 'authorization')
return k ? obj[k] : ''
}
const a = pickAuth(res.Data) || pickAuth(res)
if (a) {
uni.setStorageSync(authKey, a)
console.log('[authorization已缓存]', authKey, a)
}
}
console.log('[解密返回]', url, JSON.stringify(res));
return res
})
}
Vue.prototype.$u.api = {
getWxOpenId: (code) => lylawPost(`${LYLAW_BASE}/getWxOpenId`, { code }),
wxOpenidLogin: (data) => lylawPost(`${LYLAW_BASE}/wxOpenidLogin`, data),
sendSms: (phone) => lylawPost(`${LYLAW_BASE}/sendAliSms`, { phone }),
userRegist: (data) => lylawPost(`${LYLAW_BASE}/userRegist`, data),
queryWenjuanQA: (data) => lylawPost(`${LYLAW_BASE}/queryWenjuanQA`, data),
submitQA: (data) => lylawPost(`${LYLAW_BASE}/submitQA`, data),
getWenjuanPhb: (data) => lylawPost(`${LYLAW_BASE}/getWenjuanPhb`, data),
getChouJiangResult: (data) => lylawPost(`${LYLAW_BASE}/getChouJiangResult`, data),
addScore: (data) => lylawPost(`${LYLAW_BASE}/addScore`, data),
getUserHisResultList: (data) => lylawPost(`${LYLAW_BASE}/getUserHisResultList`, data),
getUserHisResultDetail: (data) => lylawPost(`${LYLAW_BASE}/getUserHisResultDetail`, data),
getWenjuanWinDetailList: (data) => lylawPost(`${LYLAW_BASE}/getWenjuanWinDetailList`, data)
};
}
export default {
install
}