feat: 用户多应用成员关系与微信扫码登录

- 新增 user_app / user_identity 模型、应用注册表与成员关系服务,启动时校验配置覆盖

- 新增微信开放平台扫码登录:二维码地址、回调与 ticket 换取 token

- 管理端接口改为路由层声明 appIds + 角色鉴权,新增批量用户信息、锁定、授权与个人配置

- 删除账号同步清理成员关系与外部身份,避免关系被新账号复用

- 补充多应用、应用配置、注册表测试与迁移/建号脚本
This commit is contained in:
lik
2026-11-06 19:47:51 +08:00
parent a429079cd9
commit 946160f3f4
23 changed files with 2638 additions and 99 deletions
+53
View File
@@ -0,0 +1,53 @@
"use strict";
import mongoose from "mongoose";
/**
* 外部登录身份
*
* 一行代表「某个外部账号(openid)对应哪个平台账号」:
* - appId + provider + openid:应用内身份唯一
* - provider + unionid :同一微信开放平台主体的跨应用身份
*
* openid / unionid 为空时必须写 undefined,不能写空字符串:
* partialFilterExpression 只按类型过滤,空字符串仍会被索引,
* 多个 openid: "" 会互相触发唯一冲突。
*/
const UserIdentitySchema = new mongoose.Schema(
{
userId: { type: mongoose.Schema.Types.ObjectId, required: true, comment: "平台账号ID" },
appId: { type: String, required: true, comment: "应用ID" },
platform: {
type: String,
enum: ["weixin", "douyin", "alipay", "web"],
required: true,
comment: "平台",
},
provider: {
type: String,
enum: ["weixin-mini", "weixin-web", "douyin-mini", "password"],
required: true,
comment: "登录方式",
},
openid: { type: String, comment: "应用内唯一身份" },
unionid: { type: String, comment: "跨应用身份" },
},
{
collection: "user_identity",
timestamps: true,
}
);
UserIdentitySchema.index(
{ appId: 1, provider: 1, openid: 1 },
{ unique: true, partialFilterExpression: { openid: { $type: "string" } } }
);
UserIdentitySchema.index(
{ provider: 1, unionid: 1 },
{ unique: true, partialFilterExpression: { unionid: { $type: "string" } } }
);
UserIdentitySchema.index({ userId: 1 });
export { UserIdentitySchema };