Files
WorkBuddy 8dee67040c fix(miniapp): 幂等键改为按操作稳定;删除指向 404 的互选死代码
1) 幂等键(配合后端机制)

原写法把 Date.now() 拼进幂等键,每次调用都生成新键,即使后端实现了幂等
也永远不会命中 —— 声明端与实现端各自都坏。

api.idempotencyKey(scope, subject):键缓存在 _pendingIdempotency(TTL 10min),
同一逻辑操作在成功之前复用同一把键,收到 200+success 才释放;失败(含网络错误)
不释放,下次重试沿用同一把键。25 处调用点(8 个 service + 2 个 TS 页面)全部替换,
Date.now 幂等键写法残留经 grep 为 0。

2) 删除死代码 submitInterests

它请求 POST /activities/{id}/interests —— 后端从未实现该端点
(Phase 16 已把表达意向合并进 /activities/{id}/feedback 的
interestTargetUserIds)。全仓确认无任何页面/组件调用方。
两个文件各留注释说明删除原因与恢复条件:若产品确认需要独立的
「提交互选」端点,应先定义语义并补后端实现,再恢复前端方法。

store 头部关于 AGENTS 第 6 条(单向意向保密)的注释同步改为引用
submitFeedback 返回的 newMutuals。
2026-09-18 16:37:33 +08:00

34 lines
1.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 实名认证服务(API_INVENTORY 行 30-31)
*
* 封装提交与查询两个端点。
* 提交走 POST + 幂等键(同一身份证不可重复提交)。
* 身份证号等敏感字段由 stores/userStore 在收集阶段加密传输,本层不缓存明文。
*/
const api = require('../utils/api');
/**
* 提交实名认证(API_INVENTORY 行 30)
* @param {{ realName: string, idCardNumber: string, faceImageUrl?: string }} payload
* @returns {Promise<{ submitted: true, status: 'pending' }>}
*/
function submit(payload) {
// 幂等键:身份证号后4位 + 当前秒,避免用户多次点击
const tail = (payload.idCardNumber || '').slice(-4).toUpperCase();
const idempotencyKey = api.idempotencyKey('verification-submit', tail);
return api.post('/verification/submit', payload, undefined, idempotencyKey);
}
/**
* 查询认证状态(API_INVENTORY 行 31)
* @returns {Promise<{ status: 'not_submitted'|'pending'|'approved'|'rejected', rejectReason?: string, submittedAt?: number, reviewedAt?: number }>}
*/
function getStatus() {
return api.get('/verification/status');
}
module.exports = {
submit,
getStatus,
};