wz-uniapp/docs/user_profile.md

77 lines
1.9 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.

# 登录后获取用户信息接口文档
## 概述
登录成功后,前端携带 `token` 调用该接口获取用户基础信息与平台扩展信息(头像、昵称、性别、地区等)。
## 基础信息
- 方法: `GET`
- 路径: `/api/user/profile`
- Content-Type: `application/json`
## 请求头
- `Authorization: Bearer <token>`
## 请求参数Query
| 字段 | 类型 | 必填 | 说明 |
| --- | --- | --- | --- |
| platformType | int | 否 | 平台类型,默认 `1`(微信小程序) |
### 请求示例
```
GET /api/user/profile?platformType=1
Authorization: Bearer <token>
```
## 响应参数
| 字段 | 类型 | 说明 |
| --- | --- | --- |
| userId | int64 | 用户IDt_user.id |
| username | string | 用户名 |
| nickname | string | 昵称 |
| avatarUrl | string | 头像URL |
| phone | string | 手机号 |
| gender | int | 性别0-未知1-男2-女 |
| region | string | 地区(优先 `platform_extra.region`,否则拼接国家/省/市) |
| platformType | int | 平台类型 |
| platformOpenid | string | 平台 openid |
| platformUnionid | string | 平台 unionid |
| platformExtra | object | 平台扩展字段(原样返回) |
### 成功响应示例
```json
{
"code": 200,
"message": "success",
"data": {
"userId": 10001,
"username": "wx_20260315121500_ab12cd34",
"nickname": "张三",
"avatarUrl": "https://oss-xxx/avatar.png",
"phone": "13800000000",
"gender": 1,
"region": "中国 广东 深圳",
"platformType": 1,
"platformOpenid": "oL1oU5gS6Q...",
"platformUnionid": "o6_bmasdasds...",
"platformExtra": {
"country": "中国",
"province": "广东",
"city": "深圳"
}
}
}
```
## 错误响应示例
```json
{
"code": 401,
"message": "未登录",
"data": null
}
```
## 备注
- 需要先登录并获取 `token`
- `platformExtra` 为空时,`region` 可能为空。