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 = {}) => { console.log('[原始参数]', url, JSON.stringify(params)); return Vue.prototype.$u.post(url, { request: Encrypt(JSON.stringify(params)) }).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 auth = pickAuth(res.Data) || pickAuth(res) if (auth) { uni.setStorageSync('authorizationSft', auth) console.log('[authorization已缓存]', auth) } } 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 }