我接手了一个项目,处理uniapp的隐私检测问题,描述说违规收集个人信息。我看了一下项目,也问了一下写项目的同事,他并没有做额外的权限动作,也没有引入sdk,修改过好几次了,就是过不了检测。


isLogin(token) {
const bar_url = uni.getStorageSync('bar_url')
if (!token) {
uni.reLaunch({
url: '/pages/login/index',
success: () => {
plus.navigator.closeSplashscreen()
uni.hideTabBar()
},
})
} else {
// 不要删 -- 影响大局
uni.switchTab({
url: '/pages/index/index',
// url: '/pages/ai/ai',
success() {
uni.hideTabBar()
},
})
plus.navigator.closeSplashscreen()
}
},
//拦截sdk
setupSDKInterceptor() {
// 方法1:使用 globalData 存储SDK队列(最安全)
if (!this.globalData._sdkQueue) {
this.globalData._sdkQueue = [];
}
let globalObject;
try {
// 尝试不同的全局对象访问方式
globalObject = typeof global !== 'undefined' ? global :
typeof window !== 'undefined' ? window :
this.$scope || this;
} catch (e) {
globalObject = this;
}
// 要拦截的SDK列表
const sdks = ['UMAnalytics', 'Mta', 'Beacon', 'JAnalytics', 'TalkingData', 'TData', 'Aegis', 'Rangers','SensorsData', 'tencentBeacon'];
sdks.forEach(sdkName => {
try {
// 安全地检查SDK是否存在
let sdkInstance;
// 尝试多种方式访问SDK对象
if (typeof global !== 'undefined' && global[sdkName]) {
sdkInstance = global[sdkName];
} else if (typeof window !== 'undefined' && window[sdkName]) {
sdkInstance = window[sdkName];
} else {
console.log(`SDK ${sdkName} 未找到,可能不存在`);
return; // 跳过不存在的SDK
}
if (sdkInstance && sdkInstance.init) {
const originalInit = sdkInstance.init;
sdkInstance.init = (...args) => {
const hasAgreed = uni.getStorageSync('agreePrivacy');
if (hasAgreed) {
console.log(`允许 ${sdkName} 初始化`);
return originalInit.apply(sdkInstance, args);
} else {
console.log(`拦截 ${sdkName} 初始化`);
// 存储到 globalData
this.globalData._sdkQueue.push({
sdk: sdkInstance,
method: 'init',
args: args,
sdkName: sdkName
});
}
};
console.log(`成功设置 ${sdkName} 拦截`);
}
} catch (error) {
console.warn(`设置 ${sdkName} 拦截器时出错:`, error);
}
});
},
enableSDKs() {
if (!this.globalData._sdkQueue || this.globalData._sdkQueue.length === 0) {
console.log('没有需要启用的SDK');
return;
}
console.log(`发现 ${this.globalData._sdkQueue.length} 个被拦截的SDK`);
this.globalData._sdkQueue.forEach(item => {
try {
if (item.sdk && item.sdk[item.method]) {
item.sdk[item.method].apply(item.sdk, item.args);
console.log(`SDK ${item.sdkName} 初始化完成`);
}
} catch (error) {
console.warn(`SDK ${item.sdkName} 初始化失败:`, error);
}
});
// 清空队列
this.globalData._sdkQueue = [];
},
interceptNetworkRequests() {
// 保存原始uni.request
const originalRequest = uni.request;
// 重写uni.request方法
uni.request = (options) => {
// 检查是否为隐私敏感请求
if (this.isPrivacySensitiveRequest(options.url)) {
const hasAgreed = uni.getStorageSync('agreePrivacy');
if (!hasAgreed) {
console.warn('隐私请求被拦截:', options.url);
// 返回模拟失败,避免真实请求
return Promise.reject({
errMsg: 'request:fail 隐私未同意',
statusCode: 403
});
}
}
return originalRequest(options);
};
},
isPrivacySensitiveRequest(url) {
const sensitiveDomains = [
'oaid.wocloud.cn', // OAID服务
'beacon.qq.com', // 腾讯信标
'umeng.com', // 友盟统计
'gtapi.cn', // 个推
'jpush.cn' // 极光
];
return sensitiveDomains.some(domain => url.includes(domain));
}
},
handleCancel() {
// if (uni.getSystemInfoSync().platform === 'android' || uni.getSystemInfoSync().platform === 'ios') {
// plus.runtime.quit() // 退出App
// #ifdef APP-PLUS
// 使用条件编译判断APP环境,避免在用户同意前获取设备信息
plus.runtime.quit() // 退出App
// #endif
},
handlePrivacyConfirm() {
this.isAgreePrivacy = true
this.showPrivacyModal = false
// 持久化存储:下次启动不再弹框
uni.setStorageSync('agreePrivacy', true)
// #ifdef APP-PLUS
// 用户同意隐私政策后,启用之前被拦截的SDK
const app = getApp()
if (app && app.enableSDKs) {
app.enableSDKs()
}
// #endif
},
wxLogin() {
if (!this.isAgreePrivacy) {
// 未同意:提示+重新弹框
uni.showToast({
title: '请先同意隐私政策再登录',
icon: 'none',
duration: 1500
})
this.showPrivacyModal = true
return
}
let that = this
uni.login({
provider: 'weixin',
success(res) {
if (res.authResult.openid && res.authResult.unionid) {
that.openCode(res.authResult)
} else {
that.$u.toast('获取微信信息失败~')
}
},
fail: function(err) {
console.log(err)
that.$u.toast('获取微信信息失败~')
}
})
},
async getOpenId(code) {
const res = await api.getOpenId({
code: code,
})
if (res.data) {
this.openCode(res.data)
}
},
async openCode(e) {
const res = await api.openCode({
openId: e.openid,
unionId: e.unionid
})
if (res.data) {
if (res.code === 200) {
uni.setStorageSync('token', res.data)
const success = await this.getUserInfo()
uni.switchTab({
url: '/pages/index/index',
success: () => {
uni.hideTabBar()
},
})
}
} else {
uni.navigateTo({
url: `/pages/login/wxLogin?openid=${e.openid}`
})
}
},
toLoginCode() {
uni.navigateTo({
url: '/pages/login/account?type=' + 3
})
},
login() {
if (this.isCheck[0] === 1) {
} else {
uni.showToast({
title: '请先阅读并勾选同意隐私协议!',
icon: 'none'
})
}
},
checkboxChange(n) {
this.isCheck = n
},
toAccount() {
uni.navigateTo({
url: '/pages/login/account'
})
},
async getUserInfo() {
let res = await api.UserInfo()
if (res.code === 200) {
uni.setStorageSync('userInfo', JSON.stringify(res.user))
let userInfoList = uni.getStorageSync('userInfoList') ? JSON.parse(uni.getStorageSync(
'userInfoList')) : []
const index = userInfoList.findIndex((e) => e.userId === res.user.userId)
index > -1 ? userInfoList[index] = res.user : userInfoList.push(res.user)
uni.setStorageSync('userInfoList', JSON.stringify(userInfoList))
}
},
async addLogin() {
if (this.isCheck[0] === 1) {
let res = await api.oneClickLogin(this.userInfo)
if (res.code === 200) {
if (res.type == 1) {
uni.setStorageSync('token', res.data)
await this.getUserInfo()
setTimeout(() => {
uni.switchTab({
url: '/pages/index/index',
success: () => {
uni.hideTabBar()
}
})
}, 1000)
} else if (res.type == 0) {
uni.showToast({
title: res.data,
icon: 'none'
})
}
}
} else {
uni.showToast({
title: '请先阅读并勾选同意隐私协议!',
icon: 'none'
})
}
},
async getUserAuthority() { // 获取权限
try {
const {
code,
data
} = await api.userAuthority()
if (code !== 200) return
let [permissions] = data.filter(e => e.id == 119)
if (permissions) {
permissions = permissions.children?.map(e => {
return e.name
})
} else {
permissions = []
}
uni.setStorageSync('powers', JSON.stringify(permissions))
uni.switchTab({
url: '/pages/index/index',
success() {
uni.hideTabBar()
},
})
} catch (e) {
uni.showToast({
title: e && e
})
}
},
// 用户1 / 隐私2 协议
navUserAgreement(e) {
uni.navigateTo({
url: '/user/agreement/agreement?type=' + e
})
}
}
这是应用宝给的行为数据报告


真是解决不了了啊,以前也遇见过这种问题