Skip to content

用户账号 API ​

接口地址: /user

请求方式: POST Content-Type: application/json;charset=UTF-8

请求头需带 waf: off,详见 通用约定

API 列表 ​

序号接口type 值需要 CSRF
1登录login否
2二维码登录 - 获取设备 Tokenqrlogin否
3二维码登录 - 检查扫码状态qrlogin(带 devtoken)否
4验证 Tokencsrf传 csrf
5发送注册验证码sendregcode否
6注册register否
7获取用户信息info是
8签到sign是
9重置 FRP Tokenretoken是
10发送重置密码验证码findpassem否
11重置密码findpassct否(用邮箱临时 Token)
12修改用户名cuname是
13兑换码兑换redemption是

1. 登录 ​

type: login

参数必填说明
user是用户名或邮箱
passwd是密码
keepcsrf否是否保留当前有效 CSRF,默认 true;为 false 时会使同账号其他设备的旧 Token 失效
json
{
  "type": "login",
  "user": "demo@example.com",
  "passwd": "123456",
  "keepcsrf": true
}

成功:

json
{
  "status": 200,
  "message": "登录成功,欢迎使用HayFrp!",
  "token": "xxxxxxxxxxx"
}

失败:

json
{ "status": 403, "message": "登录失败,您的密码有误", "token": null }
json
{ "status": 404, "message": "用户不存在", "token": null }

TIP

token 即 CSRF,有效期 7 天。前端存为 localStorage.csrf = { token, expiry }。

2. 二维码登录 - 获取设备 Token ​

type: qrlogin

json
{ "type": "qrlogin" }
json
{ "status": 200, "devtoken": "设备标识符用于生成二维码" }

前端用 qrcode 库把 devtoken 渲染成二维码供 HayFrp App 扫描。

3. 二维码登录 - 检查扫码状态 ​

type: qrlogin(带 devtoken)

json
{ "type": "qrlogin", "devtoken": "设备标识符" }

等待扫码:

json
{ "status": 202, "message": "等待扫码" }

扫码成功:

json
{ "status": 200, "message": "登录成功", "token": "csrf_token" }

前端轮询该接口,202 继续等待,200 取 token 完成登录;超时后提示「二维码已失效,请重新获取」。

4. 验证 Token ​

type: csrf

json
{ "type": "csrf", "csrf": "Token值" }
json
{ "status": 200, "message": "登录成功,欢迎使用HayFrp!", "token": "1145141919810" }
json
{ "status": 403, "message": "Token无效或已过期", "token": null }

5. 发送注册验证码 ​

type: sendregcode

json
{
  "type": "sendregcode",
  "user": "newuser",
  "device": "newuser",
  "email": "user@example.com"
}
json
{ "status": 200, "message": "系统已将验证码发送到您的账户,请查收." }
json
{ "status": 403, "message": "发送过于频繁,请稍后再试" }

6. 注册 ​

type: register

json
{
  "type": "register",
  "user": "newuser",
  "device": "newuser",
  "email": "user@example.com",
  "passwd": "123456",
  "regcode": "123456"
}
返回含义
{ "status": 200, "message": "注册成功,欢迎使用HayFrp." }成功
{ "status": 403, "message": "用户名已被使用" }用户名占用
{ "status": 404, "message": "验证码错误" }验证码错误

7. 获取用户信息 ​

type: info

json
{ "type": "info", "csrf": "Token值" }
json
{
  "status": true,
  "id": "114514",
  "username": "demo",
  "token": "frp_link_token",
  "email": "demo@example.com",
  "traffic": "1024",
  "realname": "true",
  "proxies": "5",
  "useproxies": "2",
  "regtime": "1700000000",
  "signdate": "1700000000",
  "totalsign": "30",
  "totaltraffic": "10.5",
  "todaytraffic": "1048576",
  "qid": "12345678",
  "sprovider": "false",
  "uuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
  "group": "user"
}
字段类型说明
idstring用户 ID
usernamestring用户名
tokenstringFRP 连接 Token(也是服务商接口凭证)
emailstring邮箱
trafficstring剩余流量(MB)
realnamestring→bool是否已实名(前端归一化为布尔)
proxiesstring隧道数量上限
useproxiesstring已用隧道数
regtimestring注册时间戳
signdatestring上次签到时间
totalsignstring累计签到天数
totaltrafficstring累计签到获得流量(GB)
todaytrafficstring今日流量(Bytes)
qidstringQQ 号(用于头像)
sproviderstring→bool是否为服务商
uuidstring用户 UUID
groupstring用户组:user / admin / sprovider 等

WARNING

成功标识是 status: true(不是 200),且 realname / sprovider 是字符串 "true"/"false",直接当布尔用会把 "false" 判成真。

8. 签到 ​

type: sign

json
{ "type": "sign", "csrf": "Token值" }
json
{
  "status": 200,
  "message": "签到成功,您今天获得了114514GB的流量",
  "signflow": 114514,
  "flow": 1145141919810
}
json
{ "status": 404, "message": "今日已签到" }

9. 重置 FRP Token ​

type: retoken

json
{ "type": "retoken", "csrf": "Token值" }
json
{
  "status": 200,
  "message": "重置成功,您的Token为已被重置为xxxxxxxxxx.",
  "token": "新Token"
}

重置后旧的 FRP 客户端配置立即失效,需要更新 frpc 配置中的 token。

10. 发送重置密码验证码 ​

type: findpassem

json
{ "type": "findpassem", "user": "demo@example.com" }

11. 重置密码 ​

type: findpassct

json
{
  "type": "findpassct",
  "token": "邮箱收到的临时Token",
  "newpass": "new_password"
}

12. 修改用户名 ​

type: cuname

json
{ "type": "cuname", "csrf": "Token值", "newname": "new_username" }

13. 兑换码兑换 ​

type: redemption

参数必填说明
active是固定为 exchange
csrf是CSRF Token
code是兑换码
json
{
  "type": "redemption",
  "active": "exchange",
  "csrf": "Token值",
  "code": "XXXX-XXXX-XXXX-XXXX"
}

前端入口在 AppLayout 顶栏用户菜单的「兑换码」弹窗(不在控制台页面内)。

前端封装 ​

typescript
await api.login(user, passwd, keepcsrf)
const devToken = await api.qrLoginGetDevToken()
await api.qrLoginCheck(devToken.devtoken)
await api.validateCsrf(csrf)
await api.sendRegCode(user, email, device)
await api.register(user, email, passwd, regcode, device)
await api.getUserInfo(csrf)
await api.sign(csrf)
await api.retoken(csrf)
await api.sendResetCode(user)
await api.resetPassword(token, newpass)
await api.changeUsername(csrf, newname)
await api.redeemCode(csrf, code)

相关页面 ​

基于 MIT 许可证发布