本文档描述小程序登录模块的API接口,包括登录、用户管理、token管理等功能。
http://your-domain/applet/login
{
"success": true,
"message": "操作成功",
"code": 200,
"result": {}
}
接口地址: POST /wxLogin
请求参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
code | String | 是 | 微信登录code |
请求示例:
curl -X POST "http://your-domain/applet/login/wxLogin" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "code=wx_login_code_here"
响应示例:
{
"success": true,
"message": "登录成功",
"code": 200,
"result": {
"token": "eyJhbGciOiJIUzI1NiJ9...",
"userInfo": {
"id": "applet_user_123",
"name": "微信用户12345678",
"openid": "wx_openid_123",
"phone": "13800138000",
"avatar": "https://example.com/avatar.jpg",
"bmi": 22.5,
"fat": 15.2
},
"openid": "wx_openid_123",
"sessionKey": "session_key_123"
}
}
接口地址: POST /getPhoneNumber
请求参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
code | String | 是 | 手机号获取code |
请求示例:
curl -X POST "http://your-domain/applet/login/getPhoneNumber" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "code=phone_code_here"
响应示例:
{
"success": true,
"message": "获取成功",
"code": 200,
"result": "13800138000"
}
接口地址: POST /bindPhoneNumber
请求参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
token | String | 是 | 用户token |
phoneCode | String | 是 | 手机号获取code |
请求示例:
curl -X POST "http://your-domain/applet/login/bindPhoneNumber" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "token=user_token_here&phoneCode=phone_code_here"
响应示例:
{
"success": true,
"message": "绑定成功",
"code": 200,
"result": "绑定成功"
}
接口地址: POST /refreshToken
请求参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
token | String | 是 | 原token |
请求示例:
curl -X POST "http://your-domain/applet/login/refreshToken" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "token=old_token_here"
响应示例:
{
"success": true,
"message": "刷新成功",
"code": 200,
"result": "eyJhbGciOiJIUzI1NiJ9..."
}
接口地址: POST /logout
请求参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
token | String | 是 | 用户token |
请求示例:
curl -X POST "http://your-domain/applet/login/logout" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "token=user_token_here"
响应示例:
{
"success": true,
"message": "退出成功",
"code": 200,
"result": "退出成功"
}
接口地址: GET /checkLogin
请求参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
token | String | 是 | 用户token |
请求示例:
curl -X GET "http://your-domain/applet/login/checkLogin?token=user_token_here"
响应示例:
{
"success": true,
"message": "登录有效",
"code": 200,
"result": {
"id": "applet_user_123",
"name": "微信用户12345678",
"openid": "wx_openid_123",
"phone": "13800138000",
"avatar": "https://example.com/avatar.jpg",
"bmi": 22.5,
"fat": 15.2
}
}
接口地址: GET /getUserInfo
请求参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
token | String | 是 | 用户token |
请求示例:
curl -X GET "http://your-domain/applet/login/getUserInfo?token=user_token_here"
响应示例:
{
"success": true,
"message": "获取成功",
"code": 200,
"result": {
"id": "applet_user_123",
"name": "微信用户12345678",
"openid": "wx_openid_123",
"phone": "13800138000",
"avatar": "https://example.com/avatar.jpg",
"bmi": 22.5,
"fat": 15.2
}
}
接口地址: POST /updateUserInfo
请求参数:
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
token | String | 是 | 用户token |
userInfo | Object | 是 | 用户信息对象 |
请求示例:
curl -X POST "http://your-domain/applet/login/updateUserInfo" \
-H "Content-Type: application/json" \
-d '{
"token": "user_token_here",
"userInfo": {
"name": "新昵称",
"avatar": "https://example.com/new_avatar.jpg",
"bmi": 23.0,
"fat": 16.0
}
}'
响应示例:
{
"success": true,
"message": "更新成功",
"code": 200,
"result": "更新成功"
}
错误码 | 说明 |
---|---|
200 | 成功 |
400 | 请求参数错误 |
401 | 未授权/token无效 |
403 | 禁止访问 |
404 | 资源不存在 |
500 | 服务器内部错误 |
{
"success": false,
"message": "token无效",
"code": 401,
"result": null
}
{
"success": false,
"message": "用户不存在",
"code": 404,
"result": null
}
{
"success": false,
"message": "微信登录失败: code无效",
"code": 400,
"result": null
}
{
"success": false,
"message": "该手机号已被其他用户绑定",
"code": 400,
"result": null
}
wx.login()
获取code/wxLogin
接口进行登录wx.getPhoneNumber()
获取手机号code/getPhoneNumber
接口获取手机号/bindPhoneNumber
接口绑定手机号到用户/refreshToken
刷新token/logout
接口/checkLogin
检查登录状态