API 参考
Google Play 订阅验证接口
POST
/v1/google-play/verify用这个 API key 上配置的服务账号(控制台 → API 密钥 → 编辑 → Google Play 订阅验证)查询 Google Play 购买凭证。结果直接来自 Google;网关不收费,解锁哪些功能由你的 App 决定。同一凭证的结果缓存一分钟。
#请求参数
purchase_tokenstring必填Play Billing 返回的购买凭证。在 Flutter 的 in_app_purchase 里就是 purchaseDetails.verificationData.serverVerificationData。
subscribed:只要是这个 App 的真实订阅就为 true,包括已过期的;active:只有当前还能使用时才为 true。已取消的订阅在 expiry_time 之前仍为 active,因为用户只是关闭了自动续费。in_trial:当前处于免费试用期时为 true,此时 expiry_time 就是试用结束时间。无法识别的凭证返回 200,subscribed 为 false,state 为 NOT_FOUND。
怎么配置 Google、怎么在 Flutter App 里调用、怎么决定解锁,见接入指南。 App 接入 Google Play 订阅验证 →
每次调用(包括命中缓存和失败的)都会出现在控制台 → 请求日志里,记为发起调用的那个 key 下一条免费的“Google Play 验证”,带结果、订单号和凭证末尾几位。可以在那里用完整凭证、末尾几位或订单号搜索。这些记录不计入请求数。
#相关错误码
- 400 invalid_request请求体不是 JSON,或缺少 purchase_token。
- 400 google_play_not_configured这个 API key 还没有设置包名和服务账号。
- 401bearer token 无效或缺失。
- 429按 key 限制验证次数:默认每分钟 120 次,可由客服为单个 key 调高,当前上限显示在 key 的 Google Play 设置里。按 Retry-After 等待,并沿用上次的结果。
- 502 google_play_api_disabled服务账号所在的 Google Cloud 项目还没有启用 Google Play Android Developer API。启用后几分钟再试。
- 502 google_play_permission_deniedGoogle 拒绝访问:请在 Play Console 邀请该服务账号,并授予查看财务数据、管理订单和订阅的权限。新授权可能要一天左右才生效。
- 502 google_play_credentials_invalidGoogle 不接受已保存的服务账号密钥,请在 key 上重新上传。
- 503 google_play_unavailableGoogle 没有及时响应,几秒后重试。
#请求示例
curl https://www.aisplice.store/v1/google-play/verify \
-H "Authorization: Bearer sk-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"purchase_token": "PURCHASE_TOKEN_FROM_PLAY_BILLING"}'#响应
response.json
{
"package_name": "com.example.app",
"subscribed": true,
"active": true,
"in_trial": false,
"state": "SUBSCRIPTION_STATE_ACTIVE",
"product_id": "vip_monthly",
"expiry_time": 1793000000,
"auto_renewing": true,
"acknowledged": true,
"test_purchase": false,
"order_id": "GPA.3300-1111-2222-44444..2",
"checked_at": 1790400000
}还是没解决?
把请求 ID 或报错信息发给我们,我们来查。