Update documentation structure and enhance API descriptions

- Revised README.md to provide a clearer documentation structure for multiple mini programs, including a new table of contents.
- Added references to common authentication documentation in both the remove watermark API and README files.
- Improved clarity of the login interface description and error handling messages in the remove watermark API documentation.
This commit is contained in:
nepiedg
2025-12-31 03:02:00 +00:00
parent bbc2f5f1d5
commit 2884f54666
9 changed files with 320 additions and 57 deletions
+21 -51
View File
@@ -1,6 +1,22 @@
# 微信小程序登录服务
# 文档目录
记录小程序端 `wx.login` 换取 `openid` 并写入数据库的后端服务说明
本仓库支持多个小程序共用一套后端。文档按“公共约定 + 每个小程序一个目录”的方式组织
## 公共文档(所有小程序通用)
- `docs/common/README.md`
- `docs/common/auth.md`
- `docs/common/response.md`
## 去水印小程序
- `docs/remove_watermark/README.md`
- `docs/remove_watermark/API.md`
## 戒烟/抽烟记录小程序
- `docs/smoke/README.md`
- `docs/smoke/API.md`
## 配置
@@ -20,7 +36,7 @@ go run ./cmd/api
启动流程:
1. 加载 `.env`
2. 初始化数据库连接(参见 `internal/database/database.go`)。
3. 自动迁移 `internal/model/user.go` 中的 `users`
3. 自动迁移相关数据表(用户表、去水印日志表、戒烟记录表等)
4. 注册路由并启动 Gin HTTP 服务。
## 数据表
@@ -51,55 +67,9 @@ go run ./cmd/api
| `session_key` | varchar(100) | 微信会话密钥 |
| `created_at/updated_at/deleted_at` | timestamp | GORM 默认时间戳 |
## 接口
## 登录接口
### `POST /api/v1/auth/login`
- **说明**:接收小程序端 `wx.login` 返回的 `code`,向微信 `jscode2session` 请求 `openid` / `session_key`。若 `open_id` 不存在则创建用户,存在则更新资料并返回用户信息。
- **请求体**
```json
{
"mini_program_id": 1,
"code": "wx.login返回的code",
"nickname": "可选",
"avatar_url": "可选",
"gender": 1,
"phone": "110"
}
```
- **响应体**
```json
{
"code": 200,
"message": "success",
"data": {
"user": {
"id": 1,
"mini_program_id": 1,
"open_id": "oXXX",
"union_id": "可选",
"nickname": "昵称",
"avatar_url": "链接",
"gender": 1,
"phone": "110"
},
"session_key": "wx-session-key",
"mini_program": {
"id": 1,
"name": "商城小程序",
"app_id": "wx67444119b166caa0"
}
}
}
```
- **错误**
- `400``code``mini_program_id` 缺失、请求体非法、小程序不存在。
- `502`:微信 API 返回错误。
- `500`:数据库或其他内部异常。
登录接口属于公共能力,请查看:`docs/common/auth.md`
## 健康检查