bindbox-game/.trae/documents/运营生成小程序二维码与登录绑定抖音账号的实现计划.md
邹方成 6ee627139c
Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 40s
feat: 新增支付测试小程序与微信支付集成
feat(pay): 添加支付API基础结构
feat(miniapp): 创建支付测试小程序页面与配置
feat(wechatpay): 配置微信支付参数与证书
fix(guild): 修复成员列表查询条件
docs: 更新代码规范文档与需求文档
style: 统一前后端枚举显示与注释格式
refactor(admin): 重构用户奖励发放接口参数处理
test(title): 添加称号效果参数验证测试
2025-11-17 00:42:08 +08:00

45 lines
2.4 KiB
Markdown
Raw 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.

## 目标
- 在运营管理新增“小程序二维码生成”,输入:`invite_code``douyin_id`,生成跳转到小程序登录页的二维码。
- 在小程序登录 API 支持绑定抖音账号,仅绑定 `douyin_id`
## 后端改造
- 数据模型
-`users` 表新增字段:`douyin_id`string唯一可空
- 迁移脚本添加唯一索引 `idx_users_douyin_id``gorm/gen` 重新生成模型。
- 生成二维码接口
- 新增管理端接口:`POST /api/admin/miniapp/qrcode`
- 请求:`{ invite_code: string, douyin_id: string, width?: number }`
- 响应:`{ image_base64: string }`
- 实现:使用 `internal/pkg/wechat/qrcode.go` 构造 `path`(示例:`/pages/login?invite_code=xxx&douyin_id=yyy`),校验长度 ≤1024。
- 小程序登录绑定
- 修改 `internal/api/user/login_app.go``weixinLoginRequest`:新增可选 `douyin_id`
- service 层 `LoginWeixin`
- 当请求含 `douyin_id` 且当前用户未绑定时,写入 `douyin_id`
-`douyin_id` 已被其他用户绑定,返回冲突错误码;不覆盖已有绑定。
## 前端改造(运营管理)
- 新增页面:`views/operations/miniapp-qrcode/index.vue`
- 表单:`invite_code``douyin_id``width`(默认 430
- 调用 `admin/miniapp/qrcode`,预览与下载二维码。
- 小程序前端:登录页读取 query`invite_code``douyin_id``code` 一并调用 `POST /api/app/users/weixin/login`
## 路由与校验
- 路由:新增 admin 路由于 `internal/router/router.go` 管理端认证组。
- 输入校验:
- `invite_code`:非空、长度/字符集校验
- `douyin_id`:长度 150字符集限制字母数字下划线
- 唯一绑定策略:`douyin_id` 全局唯一;冲突返回明确错误码与提示。
## 配置
- 使用现有 `configs.Wechat.AppID/AppSecret`;复用 `internal/pkg/wechat/qrcode.go`
## 验收
- 运营页生成二维码成功;扫码进入并完成登录绑定,用户记录含 `douyin_id`
- 登录接口兼容无 `douyin_id` 场景;携带时正确绑定并处理冲突。
## 变更清单
- 后端:新增 `miniapp_qrcode` 管理端接口;修改登录请求体与 service数据库迁移与模型生成。
- 前端:新增运营二维码页面与 API路由注册。
## 风险与回滚
- 字段新增不影响旧流程;二维码功能为增量,回滚可移除新路由与页面。