对接 https://gateway.gztbyc.com:二维码与「扫码确认」由网关提供,本服务只负责 申请临时码 → 验签收通知 → 落地自己的业务。 - 新增 service/wx_gateway.js + controller/gateway/notify.js(POST /api/wechat-gateway/notify,验签 401 / 会话过期 200 ignored) - 新增 controller/web/wx_gateway.js(登录二维码 / 长轮询 / SVG+GIF / 个人中心绑定与解绑) - 新表 wechat_gateway_bindings(uk(app_key, openid)):一个微信只绑一个账号,解绑是软删, 再绑定走 restore 复用(否则会撞唯一键报 Validation error) - 「这个微信已绑别的账号」策略:原账号正常 → 拒绝并提示对方账号名;原账号禁用/已删 → 直接改绑; 拿不到原账号 → 运维接口 GET/DELETE /api/internal/wechat-bindings 强制解绑 - 主体成员改为「扫码绑定」:管理员出二维码 → 成员微信扫码 → 已有账号直接继承(自动建的临时账号删掉), 没有账号则由服务端建号并绑成其登录方式;subject_members.temp_user_id 记录临时账号 - 废弃自建登录码:删除 GET /api/wechat/login(6 位串码)与 workstations.login_code(迁移 20261028121000), 工作台改扫码登入,成员绑定码与 /wechat?bind= 手机确认页下线 - 前端:登录页/个人中心/主体成员/工作台全部切到网关;桌面端登录窗改网关二维码 + 长轮询 - 测试:wx-gateway.test.js 覆盖登录/绑定/解绑-再绑/禁用账号改绑/运维强制解绑/成员绑定/工作台登入 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
'use strict';
|
||
|
||
const { Controller } = require('egg');
|
||
|
||
/**
|
||
* 微信登录网关回调(**公开接口**,靠签名鉴权)
|
||
*
|
||
* 网关在用户微信里确认后 `POST` 到这里(地址在网关管理台配成「服务端通知地址」,
|
||
* 对应 `config.wxGateway.notifyPath`)。请求体带 `sign` / `timestamp` / `nonce`,
|
||
* 用 `sha256(appSecret)` 当密钥做 HMAC-SHA256,见 `service/wx_gateway.js#verifyNotify`。
|
||
*
|
||
* ⚠️ 网关只看 HTTP 状态码:**2xx 视为成功**,失败会重试 1 次。
|
||
* 真正给浏览器/设备看的结果,通过本地会话(Redis)交给正在长轮询的那个请求。
|
||
*/
|
||
class GatewayNotifyController extends Controller {
|
||
/** POST /api/wechat-gateway/notify */
|
||
async index() {
|
||
const { ctx } = this;
|
||
const svc = ctx.service.wxGateway;
|
||
|
||
if (!svc.enabled) {
|
||
ctx.status = 503;
|
||
ctx.body = { ok: false, message: '未配置微信登录网关' };
|
||
return;
|
||
}
|
||
|
||
const body = ctx.request.body || {};
|
||
const checked = svc.verifyNotify(body);
|
||
if (!checked.ok) {
|
||
ctx.logger.warn('[wx-gateway] 通知验签失败:%s(event=%s state=%s)', checked.message, body.event, body.state);
|
||
ctx.status = 401;
|
||
ctx.body = { ok: false, message: checked.message };
|
||
return;
|
||
}
|
||
|
||
const data = await svc.handleNotify(body);
|
||
ctx.logger.info('[wx-gateway] 通知已处理:event=%s state=%s → %j', body.event, body.state, data);
|
||
ctx.body = { ok: true, data };
|
||
}
|
||
}
|
||
|
||
module.exports = GatewayNotifyController;
|