feat: security hardening, wechat pay v3 platform cert integration, companion certification revocation, and audit closed-loop

这个提交包含在:
xcbyy
2026-10-16 17:38:17 +08:00
父节点 3bf38db8b6
当前提交 78117bb4e1
共有 58 个文件被更改,包括 12971 次插入 和 952 次删除

查看文件

@@ -122,6 +122,79 @@ export function toggleRole() {
}
}
export function isUserLoggedIn() {
try {
if (typeof uni === 'undefined') return false;
const uid = uni.getStorageSync('userId');
const hasLoggedOut = uni.getStorageSync('user_has_logged_out');
if (hasLoggedOut === '1') return false;
return Boolean(uid && String(uid).trim() !== '' && String(uid) !== '0');
} catch (e) {
return false;
}
}
export function isUserBanned() {
try {
if (typeof uni === 'undefined') return false;
const uInfo = uni.getStorageSync('userInfo') || uni.getStorageSync('PW_USER_INFO') || uni.getStorageSync('USER_INFO');
return Boolean(uInfo && (uInfo.status === '已封禁' || uInfo.status === '封禁'));
} catch (e) {
return false;
}
}
// 必须登录才能访问的受保护业务页面清单 (未登录游客访问自动拦截并跳登录)
export const AUTH_GUARD_PAGES = [
'/pages/activity/create', // 发单/发起组队
'/pages/order/create', // 确认下单/预约
'/pages/order/list', // 我的订单中心
'/pages/activity/my-ticket', // 我的活动门票 (4位核销码)
'/pages/user/recharge', // 钱包充值
'/pages/user/withdraw', // 收益提现
'/pages/user/withdraw-records', // 提现审批明细
'/pages/user/bill-records', // 账单明细
'/pages/user/promote', // 推广赚钱
'/pages/user/favorites', // 我的收藏
'/pages/user/reports', // 我的举报与维权
'/pages/user/settings', // 系统与隐私设置
'/pages/expert/apply', // 大神入驻认证
'/pages/expert/workspace', // 大神接单工作台
'/pages/expert/radar', // 我要接单 (附近5km雷达)
'/pages/expert/hall' // 接单大厅
];
export function ensureLoginOrRedirect(redirectUrl = '') {
if (!isUserLoggedIn()) {
uni.showToast({
title: '请先登录账号',
icon: 'none',
duration: 1500
});
setTimeout(() => {
const target = redirectUrl ? `/pages/auth/login?redirect=${encodeURIComponent(redirectUrl)}` : '/pages/auth/login';
uni.navigateTo({
url: target,
fail: () => {
uni.switchTab({ url: '/pages/user/index' });
}
});
}, 350);
return false;
}
if (isUserBanned()) {
uni.showToast({
title: '账号已被封禁',
icon: 'none',
duration: 2000
});
return false;
}
return true;
}
// 非大神禁止访问的受保护页面清单
export const EXPERT_GUARD_PAGES = [
'/pages/expert/workspace',
@@ -132,6 +205,20 @@ export const EXPERT_GUARD_PAGES = [
export function checkRoleGuard(pageUrl) {
if (!pageUrl) return { allowed: true };
const pureUrl = pageUrl.split('?')[0];
// 1. 登录守卫拦截 (针对未登录游客)
if (AUTH_GUARD_PAGES.includes(pureUrl)) {
if (!isUserLoggedIn()) {
return {
allowed: false,
code: 'UNAUTHORIZED',
redirectUrl: `/pages/auth/login?redirect=${encodeURIComponent(pageUrl)}`,
message: '该功能需要登录账号,正在为您跳转登录...',
};
}
}
// 2. 大神身份守卫拦截 (针对已登录但非认证大神的普通玩家)
if (EXPERT_GUARD_PAGES.includes(pureUrl)) {
if (!isExpertCertified()) {
return {
@@ -159,10 +246,20 @@ export function installRoleGuard() {
const check = checkRoleGuard(args.url);
if (!check.allowed) {
uni.showToast({
title: check.message || '非大神禁止访问接单页面',
title: check.message || '请先登录账号',
icon: 'none',
duration: 2000,
});
if (check.redirectUrl) {
setTimeout(() => {
uni.navigateTo({
url: check.redirectUrl,
fail: () => {
uni.switchTab({ url: '/pages/user/index' });
}
});
}, 350);
}
return false;
}
return true;
@@ -173,3 +270,23 @@ export function installRoleGuard() {
});
}
let isRedirectingToExpert = false;
export function safeRedirectToExpertHall(target = '/pages/expert/hall') {
if (isRedirectingToExpert) {
return true;
}
if (getCurrentRole() === ROLE_TYPES.EXPERT && isExpertCertified()) {
isRedirectingToExpert = true;
uni.reLaunch({
url: target || '/pages/expert/hall',
complete: () => {
setTimeout(() => {
isRedirectingToExpert = false;
}, 500);
}
});
return true;
}
return false;
}