This commit is contained in:
lcj
2026-09-11 17:31:59 +08:00
parent dac4260d73
commit b4360ada34
5 changed files with 77 additions and 43 deletions
+34 -16
View File
@@ -1,8 +1,20 @@
import { Encrypt, Decrypt } from '@/js_sdk/cainiao-crypto/cainiao-crypto.js' import { Encrypt, Decrypt } from '@/js_sdk/cainiao-crypto/cainiao-crypto.js'
const install = (Vue, vm) => { const install = (Vue, vm) => {
let redirecting99 = false
const lylawPost = (url, params = {}) => { const lylawPost = (url, params = {}) => {
console.log('[接口请求]', url, JSON.stringify(params)) console.log('[接口请求]', url, JSON.stringify(params))
const handleInvalidAuth = (body) => {
if (body && (body.code === -99 || body.code === '-99')) {
uni.setStorageSync('authorizationGift', '')
uni.$emit('authorizationExpired')
if (!redirecting99) {
redirecting99 = true
setTimeout(() => { redirecting99 = false }, 1500)
uni.switchTab({ url: '/pages/index/index' })
}
}
}
return Vue.prototype.$u.post(url, { request: Encrypt(JSON.stringify(params)) }).then(res => { return Vue.prototype.$u.post(url, { request: Encrypt(JSON.stringify(params)) }).then(res => {
if (res && res.Data) { if (res && res.Data) {
if (res.Data === 'VFXeGhPbmE9mfQeg2iiwdA==') { if (res.Data === 'VFXeGhPbmE9mfQeg2iiwdA==') {
@@ -11,26 +23,32 @@ const install = (Vue, vm) => {
try { res.Data = JSON.parse(Decrypt(res.Data)) } catch (e) {} try { res.Data = JSON.parse(Decrypt(res.Data)) } catch (e) {}
} }
} }
if (res && res.Data && res.Data.authorization) {
uni.setStorageSync('authorizationGift', res.Data.authorization)
}
handleInvalidAuth(res)
return res return res
}).catch(err => {
handleInvalidAuth(err && err.data ? err.data : err)
return Promise.reject(err)
}) })
} }
Vue.prototype.$u.api = { Vue.prototype.$u.api = {
getWxOpenId: (code) => lylawPost('/lylaw/api/lylaw/getWxOpenId', { code }), getWxOpenId: (code) => lylawPost('/lylaw/api/hnlylaw/getWxOpenId', { code }),
wxOpenidLogin: (data) => lylawPost('/lylaw/api/lylaw/wxOpenidLogin', data), wxOpenidLogin: (data) => lylawPost('/lylaw/api/hnlylaw/wxOpenidLogin', data),
sendSms: (phone) => lylawPost('/lylaw/api/lylaw/sendAliSms', { phone }), sendSms: (phone) => lylawPost('/lylaw/api/hnlylaw/sendAliSms', { phone }),
userRegist: (data) => lylawPost('/lylaw/api/lylaw/userRegist', data), userRegist: (data) => lylawPost('/lylaw/api/hnlylaw/userRegist', data),
queryWenjuanQA: (data) => lylawPost('/lylaw/api/lylaw/queryWenjuanQA', data), queryWenjuanQA: (data) => lylawPost('/lylaw/api/hnlylaw/queryWenjuanQA', data),
submitQA: (data) => lylawPost('/lylaw/api/lylaw/submitQA', data), submitQA: (data) => lylawPost('/lylaw/api/hnlylaw/submitQA', data),
getWenjuanPhb: (data) => lylawPost('/lylaw/api/lylaw/getWenjuanPhb', data), getWenjuanPhb: (data) => lylawPost('/lylaw/api/hnlylaw/getWenjuanPhb', data),
getChouJiangResult: (data) => lylawPost('/lylaw/api/lylaw/getChouJiangResult', data), getChouJiangResult: (data) => lylawPost('/lylaw/api/hnlylaw/getChouJiangResult', data),
addScore: (data) => lylawPost('/lylaw/api/lylaw/addScore', data), addScore: (data) => lylawPost('/lylaw/api/hnlylaw/addScore', data),
getUserHisResultList: (data) => lylawPost('/lylaw/api/lylaw/getUserHisResultList', data), getUserHisResultList: (data) => lylawPost('/lylaw/api/hnlylaw/getUserHisResultList', data),
getUserHisResultDetail: (data) => lylawPost('/lylaw/api/lylaw/getUserHisResultDetail', data), getUserHistResultDetail: (data) => lylawPost('/lylaw/api/hnlylaw/getUserHistResultDetail', data),
getWenjuanWinDetailList: (data) => lylawPost('/lylaw/api/lylaw/getWenjuanWinDetailList', data), getWenjuanWinDetailList: (data) => lylawPost('/lylaw/api/hnlylaw/getWenjuanWinDetailList', data),
getExchangePrize: (data) => lylawPost('/lylaw/api/lylaw/getExchangePrize', data), getExchangePrize: (data) => lylawPost('/lylaw/api/hnlylaw/getExchangePrize', data),
exchangePrize: (data) => lylawPost('/lylaw/api/lylaw/exchangePrize', data), exchangePrize: (data) => lylawPost('/lylaw/api/hnlylaw/exchangePrize', data),
getUserResult: (data) => lylawPost('/lylaw/api/lylaw/getUserResult', data) getUserResult: (data) => lylawPost('/lylaw/api/hnlylaw/getUserResult', data)
}; };
} }
+2 -6
View File
@@ -27,8 +27,8 @@ const install = (Vue, vm) => {
// config.header.token = getApp().globalData.username; // config.header.token = getApp().globalData.username;
// 方式四,如果token放在了Storage本地存储中,拦截是每次请求都执行的,所以哪怕您重新登录修改了Storage,下一次的请求将会是最新值 // 方式四,如果token放在了Storage本地存储中,拦截是每次请求都执行的,所以哪怕您重新登录修改了Storage,下一次的请求将会是最新值
const token = uni.getStorageSync('tokenGift'); const auth = uni.getStorageSync('authorizationGift');
config.header.Authorization = 'Bearer '+token; if (auth) config.header.Authorization = auth;
return config; return config;
} }
@@ -41,10 +41,6 @@ const install = (Vue, vm) => {
// 如果把originalData设置为了true,这里return回什么,this.$u.post的then回调中就会得到什么 // 如果把originalData设置为了true,这里return回什么,this.$u.post的then回调中就会得到什么
return res; return res;
}else if(res.errcode==-99){
uni.navigateTo({
url:'/pages/index/login'
})
}else { }else {
// uni.showToast({ // uni.showToast({
+17 -15
View File
@@ -1,31 +1,33 @@
import CryptoJS from '../crypto-js/crypto-js.js' //引用AES源码js import CryptoJS from '../crypto-js/crypto-js.js' //引用AES源码js
// const keyCode = '1234567891234567' //十六位十六进制数作为密钥 // 密钥以 XOR(0x5A) 混淆存储,运行时还原;真实 key 不以明文出现在源码中
// const ivCode = '1234567891234567' //十六位十六进制数作为密钥偏移量 var _k = "6b68696e6f6c6d62636b68696e6f6c6d";
var _m = 0x5A;
function getKey() {
var s = "";
for (var i = 0; i < _k.length; i += 2) {
s += String.fromCharCode(parseInt(_k.substr(i, 2), 16) ^ _m);
}
return CryptoJS.enc.Utf8.parse(s);
}
// const key = CryptoJS.enc.Utf8.parse(keyCode); //十六位十六进制数作为密钥
// const iv = CryptoJS.enc.Utf8.parse(ivCode); //十六位十六进制数作为密钥偏移量
var a = "k3RA2bS97JlV5XPEueiqUA==";
//加密方法 //加密方法
export function Encrypt(word) { export function Encrypt(word) {
var key = CryptoJS.enc.Utf8.parse("1234567891234567"); var key = getKey();
var InDkn4 = CryptoJS.enc.Utf8.parse(word); var data = CryptoJS.enc.Utf8.parse(word);
var b = CryptoJS.AES.encrypt(InDkn4, key, { var b = CryptoJS.AES.encrypt(data, key, {
mode: CryptoJS.mode.ECB, mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7 padding: CryptoJS.pad.Pkcs7
}); });
return b["toString"]() return b["toString"]()
} }
//解密方法 //解密方法
export function Decrypt(word) { export function Decrypt(word) {
var key = CryptoJS.enc.Utf8.parse("1234567891234567"); var key = getKey();
var kIlnQ10 = CryptoJS.AES.decrypt(word, key, { var d = CryptoJS.AES.decrypt(word, key, {
mode: CryptoJS.mode.ECB, mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7 padding: CryptoJS.pad.Pkcs7
}); });
var t = CryptoJS.enc.Utf8.stringify(kIlnQ10); return CryptoJS.enc.Utf8.stringify(d);
return t }
}
+16 -4
View File
@@ -80,17 +80,21 @@
}) })
} }
this.initLogin() this.initLogin()
uni.$on('authorizationExpired', this.onAuthExpired)
},
onUnload() {
uni.$off('authorizationExpired', this.onAuthExpired)
}, },
onShow() { onShow() {
if (this.blocked) return if (this.blocked) return
const openId = uni.getStorageSync('openIdGift') const openId = uni.getStorageSync('openIdGift')
const isRegisteredGift = uni.getStorageSync('isRegisteredGift') const isRegisteredGift = uni.getStorageSync('isRegisteredGift')
const userId = uni.getStorageSync('userIdGift') const userId = uni.getStorageSync('userIdGift')
const auth = uni.getStorageSync('authorizationGift')
this.registered = !!isRegisteredGift this.registered = !!isRegisteredGift
if (openId && (!isRegisteredGift || !userId)) { if (openId && (!auth || !isRegisteredGift || !userId)) {
this.loginWithOpenId(openId) this.loginWithOpenId(openId)
} } else if (isRegisteredGift && userId) {
if (isRegisteredGift && userId) {
this.fetchUserResult() this.fetchUserResult()
} }
}, },
@@ -174,8 +178,13 @@
console.error('请求失败', err) console.error('请求失败', err)
}) })
}, },
onAuthExpired() {
const openId = uni.getStorageSync('openIdGift')
if (openId) this.loginWithOpenId(openId)
},
loginWithOpenId(openId) { loginWithOpenId(openId) {
return this.$u.api.wxOpenidLogin({ wenjuan_id: 1003, open_id: openId }).then(loginRes => { if (this._loginPromise) return this._loginPromise
this._loginPromise = this.$u.api.wxOpenidLogin({ wenjuan_id: 1003, open_id: openId }).then(loginRes => {
if (!loginRes.Data) { if (!loginRes.Data) {
uni.setStorageSync('isRegisteredGift', false) uni.setStorageSync('isRegisteredGift', false)
this.registered = false this.registered = false
@@ -191,7 +200,10 @@
} }
}).catch(err => { }).catch(err => {
console.error('登录请求失败', err) console.error('登录请求失败', err)
}).finally(() => {
this._loginPromise = null
}) })
return this._loginPromise
}, },
toPrize() { toPrize() {
uni.navigateTo({ uni.navigateTo({
+8 -2
View File
@@ -51,9 +51,15 @@
}, },
methods: { methods: {
fetchDetail() { fetchDetail() {
if (!this.resultId) {
this.loadError = '缺少记录ID'
return
}
this.loadError = '' this.loadError = ''
this.$u.api.getUserHisResultDetail({ this.$u.api.getUserHistResultDetail({
resultId: this.resultId resultId: this.resultId,
userId: uni.getStorageSync('userIdGift'),
wenjuanId: 1003
}).then(res => { }).then(res => {
if (res.code === 0 && Array.isArray(res.Data) && res.Data.length) { if (res.code === 0 && Array.isArray(res.Data) && res.Data.length) {
this.detailList = res.Data this.detailList = res.Data