API 参考
AppShelf API
Base URL:https://appshelf.gridscale.com
这里列出第三方应用可以调用的接口。购买和试用在 AppShelf 的商品页完成,没有给第三方调用的接口,见购买与交付。 流程说明见 AppShelf 概览。
商品标识的来源
Section titled “商品标识的来源”productId:AppShelf 商品的 UUID。客户端把它内置,用于/api/license/verify、/api/license/my、/api/license/deactivate和离线令牌pid的校验。productSlug:商品的短名,用在商品页地址https://appshelf.gridscale.com/{语言}/{productSlug}和下面的商品接口里。- 不要混用:
productId不是 Stripe 的prod_xxx,不是productSlug,也不是客户端生成的值。
取得方式:用 AppShelf 上架 MCP 上架的商品,productSlug 是上架时定的 slug,productId 在发布任务的结果里;已公开的商品可以用下面的“查询商品”接口读取。
GET /api/products/{productSlug} — 读取一个商品的公开信息。鉴权:无。
200:{ "product": { ... } }。常用字段:
| 字段 | 类型 | 说明 |
|---|---|---|
id |
string(UUID) | 即 productId |
slug |
string | 即 productSlug |
name |
string | 商品名 |
type |
string | DESKTOP、WEB、IOS、ANDROID |
status |
string | ACTIVE 表示在售 |
publicationStage |
string | PUBLIC(正式版)、BETA(测试版)、PROTOTYPE(原型) |
pricingModel |
string | free、one_time、recurring_monthly、recurring_yearly |
displayPriceCents / currency |
number / string | 价格。日元是整数日元,美元是美分 |
trialDays |
number | 试用天数,0 表示没有试用 |
currentReleaseId |
string | 当前版本的 ID |
releases[] |
array | { id, version, releaseNotes, publishedAt, assets[] } |
releases[].assets[] |
array | { id, platform, arch, fileExt, sizeBytes }。id 用于公开下载接口的 asset 参数 |
{ "product": { "id": "8f7f2f71-3d2c-4a2b-b2a1-fd2d6e9c2f70", "slug": "desktop-ai-tool", "name": "Desktop AI Tool", "type": "DESKTOP", "status": "ACTIVE", "publicationStage": "PUBLIC", "pricingModel": "one_time", "displayPriceCents": 9800, "currency": "jpy", "trialDays": 14, "currentReleaseId": "0b6f1d2e-5a47-4c39-8e1f-7d3c9a2b4e60", "releases": [ { "id": "0b6f1d2e-5a47-4c39-8e1f-7d3c9a2b4e60", "version": "1.0.0", "assets": [ { "id": "2c9d4e7a-1f36-4b58-a0c2-6e8f3b5d7a91", "platform": "mac", "arch": "arm64", "fileExt": "dmg", "sizeBytes": 104857600 } ] } ] } }错误:404 { "error": "Product not found" }。商品不存在,或是当前访问者看不到的测试版。
下载(交付链接)
Section titled “下载(交付链接)”GET /api/download/{downloadToken} — 用交付的下载链接下载安装包。鉴权:无(链接本身就是凭证)。
下载链接由 AppShelf 在交付时生成,出现在付款后的商品页和交付邮件里。downloadToken 是一个 UUID,签发后约 20 小时内有效。第三方客户端不能自己申请新的链接。
307:重定向到有时效的文件地址(1 小时内有效)。
200(请求带 Accept: application/json 时):{ "url": "...", "productId": "...", "downloadCount": 123 },不重定向。
错误(响应体都是 { "error": "<文字>" },没有错误码):
| HTTP | 含义 |
|---|---|
| 404 | 链接无效;或商品当前没有已发布的版本,或没有这个平台的安装包 |
| 410 | 链接已过期 |
| 403 | 订单已退款,或 License 已撤销、已过期 |
| 400 | 订单没有 License |
| 429 | 请求过于频繁。每个 IP 每分钟 30 次 |
下载(免费商品和原型)
Section titled “下载(免费商品和原型)”GET /api/products/{productSlug}/download?asset={assetId} — 下载免费商品或原型的当前版本。鉴权:无。
只对满足全部条件的商品有效:在售(status 为 ACTIVE)、type 为 DESKTOP,并且是原型或正式版的免费商品(pricingModel 为 free 且价格为 0)。
| 查询参数 | 必需 | 说明 |
|---|---|---|
asset |
当前版本有多个安装包时必需 | 安装包的 ID,见“查询商品”的 releases[].assets[].id |
302:重定向到有时效的文件地址(5 分钟内有效)。
200(请求带 Accept: application/json 时):{ "url": "...", "productId": "...", "downloadCount": 123 }。
错误(响应体都是 { "error": "<文字>" }):
| HTTP | 含义 |
|---|---|
| 404 | 商品不符合上面的条件;没有已发布的版本;有多个安装包而没有带 asset,或 asset 不存在 |
| 429 | 请求过于频繁。每个 IP 每分钟 30 次 |
| 503 / 500 | 服务暂时不可用 |
测试版不走这个接口:测试版只能由登录的会员在商品页下载。收费商品也不走这个接口。
激活 License
Section titled “激活 License”POST /api/license/verify — 激活 License、绑定设备、返回离线 License 令牌,并为带 AI 的商品返回 AI 令牌。鉴权:无(激活码 + 邮箱)。
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
license |
string | 是 | 激活码,1 到 1024 个字符。按原样比对,区分大小写 |
productId |
string(UUID) | 是 | 客户端内置的 productId |
machineId |
string | 是 | 稳定的设备指纹,8 到 256 个字符(去掉首尾空白后)。重启和升级后不变 |
email |
string | 是 | 会员登录返回的邮箱,最多 320 个字符。不区分大小写 |
{ "license": "K7QM-2XHD-9RTV-B4NC", "productId": "8f7f2f71-3d2c-4a2b-b2a1-fd2d6e9c2f70", "machineId": "device-fingerprint-123", "email": "buyer@example.com" }200
| 字段 | 类型 | 说明 |
|---|---|---|
valid |
boolean | true |
token |
string | 离线 License 令牌(JWT)。保存到安全存储 |
productName / productSlug / email |
string | |
memberId |
string(UUID) | 会员 ID |
tier |
string | 目前固定是 standard |
maxDevices |
integer | 设备上限。购买的 License 是 3,试用是 1 |
activatedDevices |
integer | 已绑定的设备数 |
deviceHash |
string | sha256Hex(machineId.trim()),客户端必须校验 |
serverTime |
number | 服务端时间(Unix 秒) |
nextCheckBefore |
datetime | 建议的下次联网校验时间,这次成功后 5 天 |
ai |
object | 只在带 AI 的商品上出现,见下 |
{ "valid": true, "token": "<offline_jwt>", "productName": "Desktop AI Tool", "productSlug": "desktop-ai-tool", "email": "buyer@example.com", "memberId": "1f0c7a52-9b3e-4d61-8a27-5e4c0b9d3f18", "tier": "standard", "maxDevices": 3, "deviceHash": "<sha256>", "activatedDevices": 1, "serverTime": 1778131200, "nextCheckBefore": "2026-05-12T00:00:00.000Z", "ai": { "enabled": true, "tokenSource": "members", "memberId": "1f0c7a52-9b3e-4d61-8a27-5e4c0b9d3f18", "entitlementId": "ent_123", "accountId": "acct_123", "accountAiToken": "ai_acct_tok_...", "tokenPreview": "ai_acct_tok_..." } }ai 的三种形态
| 形态 | 字段 | 含义 |
|---|---|---|
| 已就绪 | enabled: true、tokenSource: "members"、memberId、accountId(可为 null)、entitlementId(可为 null)、accountAiToken、tokenPreview |
用 accountAiToken 调用 AI Commerce |
| 未就绪,可重试 | enabled: false、entitlementPending: true、retryable: true、retryAfterSeconds、errorCode |
等 retryAfterSeconds 秒后再调一次本接口 |
| 无法开通 | enabled: false、retryable: false、errorCode、message(可选) |
不要自动重试 |
按 enabled、entitlementPending、retryable 判断,不要按 errorCode 的具体值判断。不带 AI 的商品没有 ai 字段。
离线令牌
- 签名算法 RS256,用客户端内置的公钥验证。公钥见 License 激活。
- 字段:
sub(订单 ID)、pid(必须等于内置的productId)、email、tier、maxDevices、deviceHash、iat、exp。 exp:买断的 License 是这次成功后 7 天;订阅是当前计费周期结束后 3 天;试用是试用期结束时。- 客户端收到后必须在本地校验:签名、
pid、deviceHash、exp。任何一项不符就丢弃。
错误({ "valid": false, "reason": "..." })
reason |
HTTP | 含义 |
|---|---|---|
not_found |
404 | 激活码、邮箱、productId 对不上。不区分是哪一项 |
revoked |
401 | License 已撤销,或这台设备的激活已被撤销。在比对邮箱之前返回 |
expired |
401 | License 已到期。只在到期后的第一次调用返回,之后返回 revoked |
device_limit |
403 | 绑定的设备数已达上限 |
device_conflict |
409 | 设备绑定冲突 |
rate_limited |
429 | 请求过于频繁 |
server_error |
500 | 服务端出错。保留本地离线令牌,稍后重试 |
请求不合格:HTTP 400,响应体没有 valid 和 reason,格式见“错误格式”,code 是 invalid_request 或 invalid_json。
限流:每个“IP + 激活码”10 分钟 30 次。响应带 X-RateLimit-Limit、X-RateLimit-Remaining、X-RateLimit-Reset,429 时另有 Retry-After。
查询已绑定设备
Section titled “查询已绑定设备”POST /api/license/my — 查询 License 和它绑定的设备。鉴权:无(激活码 + 邮箱)。
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
licenseKey |
string | 是 | 激活码。注意字段名和激活接口不同 |
productId |
string(UUID) | 否 | 传了就必须和 License 的商品一致 |
email |
string | 是 | 会员登录返回的邮箱 |
200
{ "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" } ] } }status 是 ACTIVE 或 REVOKED。devices 按 lastActive 从新到旧排列。deviceName 目前固定是 Verified Device。
错误
| HTTP | 响应体 | 含义 |
|---|---|---|
| 404 | { "error": "License not found" } |
激活码、邮箱、productId 对不上 |
| 429 | { "error": "Too many requests" } |
每个 IP 10 分钟 10 次 |
| 400 | 见“错误格式”,code 是 invalid_request 或 invalid_json |
请求不合格 |
| 500 | { "error": "..." } |
服务端出错 |
404、429、500 的响应体没有错误码。这个接口的响应不带限流响应头。
POST /api/license/deactivate — 解绑一台设备。鉴权:无(激活码 + 邮箱)。
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
licenseKey |
string | 是 | 激活码 |
productId |
string(UUID) | 否 | 传了就必须和 License 的商品一致 |
machineId |
string | 是 | 要解绑的设备的 machineId,8 到 256 个字符 |
email |
string | 是 | 会员登录返回的邮箱 |
200:{ "ok": true, "message": "Device unbound successfully" }。
解绑当前设备后,客户端删除本地的离线 License 令牌和 AI 令牌。
错误(格式见“错误格式”)
code |
HTTP | 含义 |
|---|---|---|
not_found |
404 | 激活码、邮箱、productId 对不上 |
device_not_found |
404 | 这台设备没有绑定在这个 License 上。当作已经解绑 |
invalid_request / invalid_json |
400 | 请求不合格 |
rate_limited |
429 | 每个“IP + 激活码”10 分钟 10 次 |
server_error |
500 | 服务端出错 |
订阅管理链接
Section titled “订阅管理链接”POST /api/subscription/portal-link — 取一个 Stripe 订阅管理页面的链接(取消订阅、更换支付方式、查看账单)。鉴权:无(激活码 + 邮箱)。
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
license |
string | 是 | 激活码 |
productId |
string(UUID) | 否 | 传了就必须和 License 的商品一致 |
email |
string | 是 | 会员登录返回的邮箱 |
returnUrl |
string | 是 | 用户从 Stripe 页面返回时去的地址,最多 2048 个字符。只接受以 https://appshelf.gridscale.com/ 开头的地址,或 appshelf:// 开头的地址 |
第三方应用的自定义协议和自己的网站地址不被接受。用 AppShelf 的页面,例如 https://appshelf.gridscale.com/zh/portal。
200:{ "ok": true, "url": "https://billing.stripe.com/p/session/...", "expiresAt": "2026-05-07T01:00:00.000Z" }。链接约 1 小时内有效;expiresAt 可能是 null。
错误(格式见“错误格式”)
code |
HTTP | 含义 |
|---|---|---|
not_found |
404 | 激活码、邮箱、productId 对不上 |
revoked |
401 | License 已撤销 |
not_a_subscription |
400 | License 不是订阅(买断或试用) |
invalid_request / invalid_json |
400 | 请求不合格,包括 returnUrl 不被接受 |
rate_limited |
429 | 每个“IP + 激活码”10 分钟 10 次 |
portal_unavailable |
503 | 暂时无法创建订阅管理页面 |
stripe_not_configured |
503 | AppShelf 的支付没有配置好 |
subscription_misconfigured |
500 | 订单缺少订阅所需的信息 |
internal_error |
500 | 服务端出错 |
AppShelf 的接口有三种错误格式。
一、带错误码的对象。解绑设备、订阅管理,以及所有接口的“请求不合格”:
{ "ok": false, "error": "License not found", "code": "not_found", "errorDetail": { "message": "License not found", "code": "not_found" } }error 是一段文字,错误码在顶层的 code(errorDetail.code 相同)。这和 AI Commerce 的 { "error": { "code": ... } } 不同。
请求不合格时(code 为 invalid_request)另有 details[],每项是 { path, message, code },指出哪个字段不合格。
二、reason。只有激活接口:{ "valid": false, "reason": "..." }。
三、只有文字。查询设备、下载、查询商品:{ "error": "<文字>" },没有错误码,按 HTTP 状态判断。
客户端常量与本地状态
Section titled “客户端常量与本地状态”内置常量:AppShelf 地址 https://appshelf.gridscale.com、商品的 productId、productSlug、License 公钥(RS256)。带 AI 的商品另需 AI Commerce 地址和 Member Center 地址。
本地保存(安全存储):激活码、会员邮箱、machineId、离线 License 令牌、AI 令牌、nextCheckBefore。
不要写进日志和 URL:完整的激活码、下载链接、离线 License 令牌、AI 令牌。