feat: add web oauth login adapters

This commit is contained in:
Codex
2026-06-29 10:20:20 +08:00
parent 64d58d895e
commit d89f77e9af
15 changed files with 766 additions and 41 deletions

View File

@@ -146,7 +146,7 @@ tenant:<tenantId>:theme
| 页面 | 主要接口 |
| --- | --- |
| 启动页 | `GET /api/tenant/resolve` |
| 登录页 | `POST /api/auth/sms/send``POST /api/auth/sms/verify``POST /api/auth/oauth/wechat-miniapp`后续微信网页/QQ provider |
| 登录页 | `POST /api/auth/sms/send``POST /api/auth/sms/verify``POST /api/auth/oauth/wechat-miniapp``POST /api/auth/oauth/wechat``POST /api/auth/oauth/qq` |
| 首页 | `/api/catalog/content-entries``/api/catalog/banners``/api/catalog/announcements``/api/catalog/exam-dates``/api/profile/me` |
| 选地区 | `/api/catalog/regions``/api/commerce/entitlements/check` |
| 题库入口 | `/api/catalog/content-entries` |
@@ -1110,6 +1110,46 @@ identity.unionId
- 如果登录前已经解析到推广码,登录成功后再调用 `/api/referral/bind` 完成首绑保护。
- 如果用户没有手机号,跳转到上面的“绑定或更换手机号”流程。
### 微信网页登录
H5 端在微信开放平台授权回调页拿到 `code` 后,交给后端:
```text
POST /api/auth/oauth/wechat
body: {
"code": "<wechat oauth code>",
"lang": "zh_CN"
}
```
成功响应与小程序登录一致,包含 `provider=user/identity/session`。后端会使用租户 `wechat-web/wechat_web/wechat` provider 配置换取 `access_token``openid`,再拉取用户资料;如果返回 `unionid`,会和同一开放平台下的小程序身份合并。
前端注意:
- H5 回调页只短暂读取 `code/state`,不要持久化微信 `access_token`
- `state` 应在前端本地或服务端中转页校验,避免跨站授权回调混淆。
- 多租户自定义域名下,授权回调域名必须与租户微信开放平台配置一致;如果未来使用统一授权中转域名,需要在回调后再解析目标租户。
### QQ 登录
H5 端在 QQ 互联授权回调页拿到 `code` 后,交给后端:
```text
POST /api/auth/oauth/qq
body: {
"code": "<qq oauth code>",
"redirectUri": "https://h5.example.com/auth/qq/callback"
}
```
后端会完成 `code -> access_token -> openid -> userinfo`,并签发本项目 session。
前端注意:
- `redirectUri` 必须与 QQ 互联后台登记地址一致;也可以由租户后台 provider 配置固定,前端不传。
- 前端不要接触 QQ `clientSecret/AppKey``access_token`
- 登录后如果没有手机号,同样进入“绑定或更换手机号”流程。
## 支付对接
支付流程必须以后端订单金额和后端回调为准,前端只负责拉起支付。