AppShelf
设备与订阅管理
一个 License 能绑定的设备数量有上限(激活响应里的 maxDevices:购买的 License 是 3,试用是 1)。
用户换电脑或达到上限时,需要解绑旧设备。
这一页的三个接口都用“激活码 + 邮箱”作为凭证,不需要其他令牌。 邮箱必须是会员登录返回的邮箱。接口从桌面客户端、移动客户端或你的后端调用。
不想自己做界面时,可以把用户带到 AppShelf 的自助页面 https://appshelf.gridscale.com/{语言}/portal,用户在那里输入激活码和邮箱就能查看和解绑设备。
查看已绑定的设备
Section titled “查看已绑定的设备”curl -X POST https://appshelf.gridscale.com/api/license/my \ -H "content-type: application/json" \ -d '{ "licenseKey": "K7QM-2XHD-9RTV-B4NC", "productId": "<内置的 productId>", "email": "buyer@example.com" }'注意字段名是 licenseKey,激活接口用的是 license。productId 可以不传,建议传。
{ "license": { "id": "3b1f6c0e-8a52-4d0b-9f43-2c7e5a1d9b60", "email": "buyer@example.com", "status": "ACTIVE", "expiresAt": null, "maxDevices": 3, "createdAt": "2026-05-01T00:00:00.000Z", "product": { "name": "Desktop AI Tool", "iconUrl": "https://..." }, "devices": [ { "id": "5d2a9e14-7c3b-4f18-a6d0-91b8e4c27f35", "machineId": "device-fingerprint-123", "deviceName": "Verified Device", "lastActive": "2026-05-07T00:00:00.000Z", "createdAt": "2026-05-01T00:00:00.000Z" } ] }}devices按最近使用时间从新到旧排列。deviceName目前固定是Verified Device。要让用户认出哪台是哪台,用machineId和本机的比较(“这台设备”),并显示lastActive。expiresAt对买断的 License 是null。
curl -X POST https://appshelf.gridscale.com/api/license/deactivate \ -H "content-type: application/json" \ -d '{ "licenseKey": "K7QM-2XHD-9RTV-B4NC", "productId": "<内置的 productId>", "machineId": "<要解绑的设备的 machineId>", "email": "buyer@example.com" }'成功时返回:
{ "ok": true, "message": "Device unbound successfully" }解绑的是当前这台设备时,客户端要同时删除本地的离线 License 令牌和 AI 令牌,并回到未激活状态。
返回 404 device_not_found 表示这台设备本来就没有绑定,当作已经解绑处理。
订阅制的商品,用户可以在 Stripe 的页面里取消订阅、更换支付方式和查看账单。客户端取一个链接,用系统浏览器打开:
curl -X POST https://appshelf.gridscale.com/api/subscription/portal-link \ -H "content-type: application/json" \ -d '{ "license": "K7QM-2XHD-9RTV-B4NC", "email": "buyer@example.com", "returnUrl": "https://appshelf.gridscale.com/zh/portal" }'这里的字段名是 license。productId 可以不传。
{ "ok": true, "url": "https://billing.stripe.com/p/session/...", "expiresAt": "2026-05-07T01:00:00.000Z" }- 链接有时效,约 1 小时(
expiresAt,可能是null)。每次用户点击时取新的,不要保存。 - 买断和试用的 License 没有订阅,返回 400
not_a_subscription。对这两种 License 不要显示这个入口。
订阅状态变化后,客户端在下次联网校验时得到最新的结果,处理方式见 License 激活。
这三个接口的错误格式和激活接口不同,彼此也不完全相同。
查看设备 /api/license/my
Section titled “查看设备 /api/license/my”| HTTP | 响应体 | 含义 | 处理 |
|---|---|---|---|
| 404 | { "error": "License not found" } |
激活码、邮箱和 productId 对不上。不区分是哪一项 |
提示检查激活码和登录邮箱 |
| 429 | { "error": "Too many requests" } |
请求过于频繁 | 稍后重试 |
| 500 | { "error": "..." } |
服务端出错 | 稍后重试 |
| 400 | 带 code: "invalid_request" 的对象 |
请求参数不合格 | 修正请求 |
前三种没有错误码,按 HTTP 状态判断。
解绑设备和订阅管理
Section titled “解绑设备和订阅管理”错误响应的形状是:
{ "ok": false, "error": "License not found", "code": "not_found", "errorDetail": { "message": "License not found", "code": "not_found" }}error 是一段文字,错误码在顶层的 code 里。按 code 判断:
code |
HTTP | 出现在 | 含义 | 处理 |
|---|---|---|---|---|
not_found |
404 | 两个接口 | 激活码、邮箱和 productId 对不上 |
提示检查激活码和登录邮箱 |
device_not_found |
404 | 解绑 | 这台设备没有绑定在这个 License 上 | 当作已经解绑 |
revoked |
401 | 订阅管理 | License 已撤销 | 不显示订阅管理入口 |
not_a_subscription |
400 | 订阅管理 | License 不是订阅 | 不显示订阅管理入口 |
invalid_request、invalid_json |
400 | 两个接口 | 请求参数不合格,包括 returnUrl 不被接受 |
修正请求 |
rate_limited |
429 | 两个接口 | 请求过于频繁 | 按响应头 Retry-After 等待后重试 |
portal_unavailable |
503 | 订阅管理 | 暂时无法打开订阅管理页面 | 稍后重试;持续出现时联系 AppShelf 团队 |
stripe_not_configured、subscription_misconfigured |
503 / 500 | 订阅管理 | AppShelf 一侧的配置问题 | 应用无法自行解决,联系 AppShelf 团队 |
server_error、internal_error |
500 | 解绑 / 订阅管理 | 服务端出错 | 稍后重试 |
| 接口 | 上限 | 按什么计 |
|---|---|---|
| 查看设备 | 10 分钟 10 次 | 每个 IP |
| 解绑设备 | 10 分钟 10 次 | 每个 IP + 激活码 |
| 订阅管理 | 10 分钟 10 次 | 每个 IP + 激活码 |
解绑和订阅管理的响应带 X-RateLimit-Limit、X-RateLimit-Remaining、X-RateLimit-Reset,429 时另有 Retry-After。查看设备的响应不带这些响应头。
查看设备的上限按 IP 计,而且不高:解绑后不要重新拉取列表,在本地把那一项去掉即可。
全部字段见 AppShelf API。