跳到主要内容
Refund Sensor

Google Play 接入

通过实时通知将 Refund Sensor 连接到 Google Play Console。自动化拒付审核,并在 24 小时内回应以保护收入。

开始之前

Refund Sensor 用一个你在自己 Google Cloud 项目里创建的服务账号连接 Google Play。它永不过期,也不需要重新授权。你需要:

  • 一个在拥有你 Play Console 的账户下的 Google Cloud 项目(免费的即可)。
  • 一个带有可下载 JSON 密钥的服务账号。
  • 授予该账号的 Play Console 访问权限以及 Pub/Sub Admin。
  • 你想防御的包名或 Play Store URL。

创建服务账号和密钥

  1. 用拥有你 Play Console 的账户打开 Google Cloud Console,选择或创建一个项目。在左侧菜单打开 IAM & Admin 并点击 Service accounts
  2. 点击 + Create service account,起一个名字,比如 RefundSensor Google Play API,然后点击 Create and continueDone。这里可以跳过可选角色。
  3. 复制服务账号邮箱(以 .iam.gserviceaccount.com 结尾)。接下来的步骤会用到它。
  4. 打开该服务账号,切换到 Keys 标签,点击 Add key → Create new key,选择 JSON,点击 Create。Google 会下载一个 .json 文件。请妥善保管;Google 不会让你再次下载。

启用所需的 API

你的项目需要启用两个 Google API(每个项目一次性操作)。在 Google Cloud Console 中,选中你的项目,搜索并分别启用:

  • Google Play Android Developer API,它让服务账号读取你的退款和订单数据。
  • Cloud Pub/Sub API,它驱动实时退款通知。确认是 Cloud Pub/Sub,而不是 Pub/Sub Lite,那是另一个产品。

添加你的凭据

在 Refund Sensor 中打开 Add app,选择 Google Play,上传 .json 密钥文件。我们会向 Google 验证它,并用 AES-256-GCM 做静态加密存储。

授予 Play Console 权限

把服务账号邀请进 Play Console,并在两个地方给它财务访问权限,因为退款(作废购买)数据是在账户层面读取的:

  1. Google Play Console 中打开 Users and permissions → Invite new users,粘贴服务账号邮箱。服务账号在你保存时就会生效;它不会自己接受邀请。
  2. App permissions 下,添加你想防御的每个应用,并打开 View financial dataManage orders and subscriptions
  3. 切换到 Account permissions 标签(容易漏掉),在 Financial data 下打开 View financial data, orders and cancellation survey responsesManage orders and subscriptions,然后保存。

授予 Pub/Sub Admin

实时通知通过一个由我们为你创建并接好的 Pub/Sub 主题到达 Refund Sensor,所以没有东西需要粘贴到 Play Console。它只需要管理 Pub/Sub 的权限。在 IAM & Admin → IAM 中点击 Grant access,把你的服务账号邮箱粘贴为主体,选择角色 Pub/Sub Adminroles/pubsub.admin),保存。选 Pub/Sub Admin,不要选 Pub/Sub Lite Admin;Lite 角色不起作用,也是自动配置失败最常见的原因。

添加你的应用

Add apps 这一步,每行粘贴一个 Play Store URL 或包名(包名是 Play Store 链接里 ?id= 之后的值,例如 com.yourcompany.app)。Refund Sensor 会在导入前,按已连接账户的 Play Console 访问权限校验每一个,并标出它看不到的那些。

实时通知

在启用 API 并授予 Pub/Sub Admin 后,导入一个应用会自动创建主题和推送订阅,并把它注册为该应用的 RTDN 端点。随后应用会显示 Awaiting first refund event,直到 Google 送来第一个真实事件(Google 那边没有测试按钮)。如果自动配置失败,应用卡片会显示 Real-time notifications not set up,并附带回到本指南的链接。

Refund Sensor 在 Google Play 上回应什么

并非每一笔 Google Play 退款都能争议。普通的用户退款由 Google 自行决定,所以那些会被记录以供查看,但不去争议。

你真正能回应的唯一退款是审核中的拒付(Google 的 pendingRefundReviewNotification)。它给你约 24 小时,并以第一条回应为准。Refund Sensor 会自动用拒绝建议回应,远在窗口内完成。

作为兜底,Refund Sensor 还会与 Google 的作废购买 API 对账,所以即使没有可争议的内容,每一笔退款和作废购买也都会记录在你的仪表盘里。

On this page