- 新增网关客户端与通知验签(sha256(appSecret) 派生 HMAC-SHA256,5 分钟防重放), 扫码会话与一次性结果存 Redis,openid 仅服务端保存 - 新增 user_wechat_binds 表与迁移:openid 唯一(一个微信只绑一个账号)、 user_id 唯一(重新绑定覆盖旧微信) - 新增 /api/auth/wechat/* 接口与 /api/wx/notify 网关回调;登录二维码按 IP 限流, 未配置网关时相关接口返回 400 提示,不影响账号密码 / 邮箱验证码登录 - 前端:「微信登录」tab(二维码 + 倒计时 + 轮询)与「我的」页微信绑定 / 解绑 - 开发与生产各出一份 WX_GATEWAY_* 配置样板,生产权威副本走 shared-config 覆盖 - 同步补充 swagger 契约与请求日志脱敏字段(bind_code / sign) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
32 lines
1.6 KiB
JavaScript
32 lines
1.6 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 微信绑定模型,对应 user_wechat_binds 表。
|
||
* 一个微信身份(openid)只绑定一个系统账号;一个系统账号只保留最近一次绑定的微信。
|
||
* 网关侧的 openid 只在服务端保存,前端只展示脱敏值。
|
||
* @param {Egg.Application} app egg application
|
||
* @return {object} user_wechat_bind model
|
||
*/
|
||
module.exports = app => {
|
||
const { BIGINT, STRING, DATE } = app.Sequelize;
|
||
|
||
const UserWechatBind = app.model.define('user_wechat_bind', {
|
||
id: { type: BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true, comment: '主键' },
|
||
user_id: { type: BIGINT.UNSIGNED, allowNull: false, comment: '系统用户ID' },
|
||
app_key: { type: STRING(64), comment: '所属网关应用 appKey(区分开发/生产环境)' },
|
||
gateway_uid: { type: BIGINT.UNSIGNED, comment: '网关用户ID(通知里的 userId)' },
|
||
openid: { type: STRING(64), allowNull: false, comment: '公众号 openid,全局唯一' },
|
||
unionid: { type: STRING(64), comment: '开放平台 unionid(公众号已绑定开放平台时才有)' },
|
||
bind_scene: { type: STRING(16), allowNull: false, defaultValue: 'bind', comment: '绑定来源:bind 主动绑定 / login 扫码登录自动绑定' },
|
||
last_login_at: { type: DATE, comment: '最近一次微信登录时间' },
|
||
created_at: { type: DATE, comment: '创建时间' },
|
||
updated_at: { type: DATE, comment: '更新时间' },
|
||
});
|
||
|
||
UserWechatBind.associate = () => {
|
||
app.model.UserWechatBind.belongsTo(app.model.User, { foreignKey: 'user_id', as: 'user' });
|
||
};
|
||
|
||
return UserWechatBind;
|
||
};
|