创建 Server Key
在 Console 为指定 App 和环境创建后端凭据。
API v1更新于
凭据与身份#
谁持有什么凭据| 调用方 | 凭据 | 用途 |
|---|
| Longplay 控制台成员 | Better Auth 账号会话 | 登录 Console 和 CLI、创建 App 和 Key;不能调用 SDK API |
| 你的后端 | Server Key / gg_sk_ | 在 Key 绑定的 App、环境和权限内调用 API |
| 你的用户 | externalUserId | 由你自己的登录系统验证;不是 Longplay 登录凭据 |
| 浏览器或 App | Access Token / gg_ct_ | 以已验证的 Customer 身份调用业务接口 |
| 浏览器或 App | Refresh Token / gg_rt_ | 仅用于刷新同一个会话,不能调用业务接口 |
谁持有什么凭据
Longplay 控制台成员
- 凭据
- Better Auth 账号会话
- 用途
- 登录 Console 和 CLI、创建 App 和 Key;不能调用 SDK API
你的后端
- 凭据
- Server Key / gg_sk_
- 用途
- 在 Key 绑定的 App、环境和权限内调用 API
你的用户
- 凭据
- externalUserId
- 用途
- 由你自己的登录系统验证;不是 Longplay 登录凭据
浏览器或 App
- 凭据
- Access Token / gg_ct_
- 用途
- 以已验证的 Customer 身份调用业务接口
浏览器或 App
- 凭据
- Refresh Token / gg_rt_
- 用途
- 仅用于刷新同一个会话,不能调用业务接口
Server Key 证明后端的接入权限,不证明最终用户身份。后端先验证用户,再将稳定的用户 ID 传给 Decide。
进入创建入口#
- 打开 https://console.longplayai.com/workspace/developers?tab=keys,选择当前 App 和 Sandbox。
- 在左侧导航选择 接入 → 服务端 Key,点击「新建 Key」。
- 账号需要该 App 的 apiKeys:write 权限;Owner、具备 App 访问权的 Admin 或 Developer 可操作。
填写并保存#
填写名称和有效期,只勾选实际要用的权限(见下方权限表)。例如第一次请求只需 customers:write;Funnel 服务端决策需要 customers:write, sessions:create, funnels:run。Run 使用启动它的 Key 的权限:Paywall 和 Offering 步骤需要 entitlements:read;在 Paywall 购买还需要 billing:write(报价、确认和取消)和 billing:read(读取结算与恢复结果);领取或展示 Coupon 需要 offers:resolve。在 Console 创建 Key 时点击「选择 Funnel 启动权限」,会一次选中这些权限:funnels:run、sessions:create、customers:write、entitlements:read、offers:resolve、billing:read、billing:write。
Key 绑定一个 App 和环境,有效期为 1–365 天;每个 App/环境最多保留 20 把有效 Key。点击「生成 Key」后,完整 Key 只显示一次。复制到可信后端的密钥系统或被 Git 忽略的本地 .env,命名为 LONGPLAY_SERVER_KEY;不要放进浏览器或公开文档。
相关:打开 Console 的服务端 Key·安装 SDK 与 CLI·环境说明
权限列表#
Server Key 可授予的权限| 权限 | 允许的操作 |
|---|
messaging:write | 管理客户的消息接收同意状态和设备;服务端发送及查询消息。 |
customers:read | 读取 Customer、列表与席位。 |
customers:write | 创建、更新与认领 Customer。 |
sessions:create | 签发、续期与撤销 Customer/访客会话;Funnel 启动也需要。 |
content:read | 按资源或固定版本读取独立 Page、Popup、Banner;需要已验证的 Customer/Guest。 |
entitlements:read | 检查权益、读取持有,解析 Offering 与 Paywall;Key 启动的 Funnel Run 走到 Paywall 或 Offering 步骤时也需要。 |
credits:read | 读取余额、用量、账本、对账单、分析与 AI 定价。 |
credits:consume | 上报用量、执行余额消耗与预留。 |
credits:manage | 发放、调整余额,设定用量,管理 Entity。 |
billing:read | 读取支付、订阅、试用、发票与退款;Key 启动的 Funnel Run 读取 Paywall 购买的结算与恢复结果时也需要。 |
billing:write | 购买、变更订阅、退款、开票、计费控制、席位与原生购买;Key 启动的 Funnel Run 在 Paywall 报价、确认或取消购买时也需要。 |
offers:resolve | Customer 兑换、领取与列出优惠,推荐码与奖励;Key 启动的 Funnel Run 领取或展示 Coupon 时也需要。 |
offers:grant | 后端向 Customer 定向发券。 |
features:read | 下载与求值功能开关。 |
events:write | 上报行为、曝光与功能开关使用事件。 |
funnels:run | 启动与推进 Funnel、服务端决策与采纳回执。 |
code-references:read | CLI/CI 读取代码引用扫描配置。 |
code-references:write | CLI/CI 上传代码引用扫描报告。 |
app-manifests:write | 构建时上传 App 页面目录(IAM);必须单独放在一把 Key 上。 |
Server Key 可授予的权限
messaging:write
- 允许的操作
- 管理客户的消息接收同意状态和设备;服务端发送及查询消息。
customers:read
- 允许的操作
- 读取 Customer、列表与席位。
customers:write
- 允许的操作
- 创建、更新与认领 Customer。
sessions:create
- 允许的操作
- 签发、续期与撤销 Customer/访客会话;Funnel 启动也需要。
content:read
- 允许的操作
- 按资源或固定版本读取独立 Page、Popup、Banner;需要已验证的 Customer/Guest。
entitlements:read
- 允许的操作
- 检查权益、读取持有,解析 Offering 与 Paywall;Key 启动的 Funnel Run 走到 Paywall 或 Offering 步骤时也需要。
credits:read
- 允许的操作
- 读取余额、用量、账本、对账单、分析与 AI 定价。
credits:consume
- 允许的操作
- 上报用量、执行余额消耗与预留。
credits:manage
- 允许的操作
- 发放、调整余额,设定用量,管理 Entity。
billing:read
- 允许的操作
- 读取支付、订阅、试用、发票与退款;Key 启动的 Funnel Run 读取 Paywall 购买的结算与恢复结果时也需要。
billing:write
- 允许的操作
- 购买、变更订阅、退款、开票、计费控制、席位与原生购买;Key 启动的 Funnel Run 在 Paywall 报价、确认或取消购买时也需要。
offers:resolve
- 允许的操作
- Customer 兑换、领取与列出优惠,推荐码与奖励;Key 启动的 Funnel Run 领取或展示 Coupon 时也需要。
offers:grant
- 允许的操作
- 后端向 Customer 定向发券。
features:read
- 允许的操作
- 下载与求值功能开关。
events:write
- 允许的操作
- 上报行为、曝光与功能开关使用事件。
funnels:run
- 允许的操作
- 启动与推进 Funnel、服务端决策与采纳回执。
code-references:read
- 允许的操作
- CLI/CI 读取代码引用扫描配置。
code-references:write
- 允许的操作
- CLI/CI 上传代码引用扫描报告。
app-manifests:write
- 允许的操作
- 构建时上传 App 页面目录(IAM);必须单独放在一把 Key 上。
签发 Customer 会话的 Key 决定该会话在浏览器中能调用的范围:例如浏览器要读取权益、购买和兑换优惠,签发会话的 Key 需要 sessions:create 以及 entitlements:read、billing:read、billing:write、offers:resolve。CI 代码引用扫描使用只含 code-references:read 与 code-references:write 的独立 Key。
轮换与撤销#
权限需要调整、Key 丢失或即将过期时,在同一 App/环境创建替代 Key,更新后端配置并确认请求成功,然后撤销旧 Key。撤销或到期只影响后续鉴权,不会回滚已经提交的操作。