WEB/temp/wechat-bind/TODO.md
2026-03-24 18:26:53 +08:00

78 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.

# 微信绑定功能 TODO
## 任务目标
实现微信公众号扫码绑定/解绑账号功能,前后端联调。
---
## 后端接口设计(参考)
### 一、`user.getBindWechatCode` — 获取微信绑定二维码及轮询状态
**请求:** POST `/system`,params: `{ method: 'user.getBindWechatCode', v, timestamp }`
**逻辑:**
1. 查询 ye4s 数据库,判断当前账号是否已绑定微信。
2. 若已绑定,直接返回绑定信息(status: 'bound',nickname 等)。
3. 若未绑定:
- 优先从缓存中读取该账号对应的随机码 `code`,避免重复查数据库。
- 若缓存无随机码,则生成新随机码写入缓存(key: `wechat:bind:{accountId}`,TTL 可设 5 分钟)。
- 返回随机码 + 公众号二维码 URL(将 `code` 作为 state 参数带入)。
4. 微信用户扫码关注后,公众号后台回调将 openid 与 code 关联,更新缓存状态为 `scanned` / `bound`。
5. 前端通过轮询本接口,命中缓存即可感知状态变化,无需重复查数据库。
**返回结构(建议):**
```json
{
"code": 0,
"data": {
"status": "waiting | scanned | bound | expired",
"bindCode": "随机码(未绑定时返回)",
"qrUrl": "微信公众号带参二维码地址",
"nickname": "(已绑定时返回微信昵称)",
"openid": "(已绑定时返回openid)"
}
}
```
---
### 二、`user.unbindWechat` — 解除微信绑定
**请求:** POST `/system`,params: `{ method: 'user.unbindWechat', v, timestamp }`
**逻辑:**
1. 根据当前登录账号,删除 ye4s 数据库中对应的微信绑定关联记录。
2. 同步清除缓存中的绑定随机码。
3. 返回操作结果。
**返回结构(建议):**
```json
{
"code": 0,
"data": { "success": true }
}
```
---
## 前端任务
- [x] 更新 `src/api/profile.ts`:新增 `getBindWechatCode` / `unbindWechat` 接口
- [x] 重构 `src/views/profile/components/Bind.vue`:
- 打开弹窗时调用 `getBindWechatCode` 获取二维码 URL 及 bindCode
- 轮询(3s interval)`getBindWechatCode` 检测 status 变化
- status 变为 `bound` 时关闭弹窗,刷新绑定状态
- 调用 `unbindWechat` 实现解绑
---
## 临时文件列表(任务完成后删除)
- `temp/wechat-bind/TODO.md`(本文件)
---
## 回归清理
任务完成、联调通过后:
- 删除 `temp/wechat-bind/` 目录及其所有文件