Commit 851add20 by jianan

fix(cffp): 拦截脏userId污染obtainToken与首页区域信息接口

- interceptor 抽 readStorage 通用读取函数,过滤历史脏字符串 'null'/'undefined',
  readToken/readUserId 走同一实现,避免脏 loginId 进入 obtainToken 签发链路
- queryAreaCenterInfo 不再传 userId(后端 VO 已移除该字段,改从 ThreadLocal 取)
parent 63d48d0b
...@@ -725,7 +725,6 @@ ...@@ -725,7 +725,6 @@
// 获取轮播图 // 获取轮播图
queryAreaCenterInfo() { queryAreaCenterInfo() {
api.queryAreaCenterInfo({ api.queryAreaCenterInfo({
userId: uni.getStorageSync('cffp_userId'),
companyType: `${companyInfo.companyType}` companyType: `${companyInfo.companyType}`
}).then((res) => { }).then((res) => {
if (res['success']) { if (res['success']) {
......
...@@ -135,12 +135,15 @@ let t001Locked = false ...@@ -135,12 +135,15 @@ let t001Locked = false
const hasWindow = typeof window !== 'undefined' const hasWindow = typeof window !== 'undefined'
const canUseSession = hasWindow && !!window.sessionStorage const canUseSession = hasWindow && !!window.sessionStorage
// 读取有效 token(兼容历史脏数据 'undefined' / 'null') // 从 localStorage 读值,过滤历史脏字符串 'undefined' / 'null'
const readToken = () => { const readStorage = (key) => {
const token = uni.getStorageSync(TOKEN_KEY) const value = uni.getStorageSync(key)
if (!token || token === 'undefined' || token === 'null') return '' if (!value || value === 'undefined' || value === 'null') return ''
return token return value
} }
const readToken = () => readStorage(TOKEN_KEY)
// 避免脏 loginId 污染 obtainToken 签发的 JWT
const readUserId = () => readStorage('cffp_userId')
const isWhiteApi = (url = '') => whiteApiList.some(item => url === item || url.indexOf(item) === 0) const isWhiteApi = (url = '') => whiteApiList.some(item => url === item || url.indexOf(item) === 0)
...@@ -199,7 +202,7 @@ const obtainTokenOnce = () => { ...@@ -199,7 +202,7 @@ const obtainTokenOnce = () => {
ticket: 'uni-app', ticket: 'uni-app',
loginId: null loginId: null
} }
const h5userId = uni.getStorageSync('cffp_userId') const h5userId = readUserId()
if (h5userId) params.loginId = h5userId if (h5userId) params.loginId = h5userId
uni.request({ uni.request({
......
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