启用 App Store 服务器通知

Adapty SDK 会上报应用内发生的购买行为。服务器通知则用于上报在应用外部发生的变更,例如:

  • 订阅续费。
  • 用户关闭自动续费。
  • 因账单问题导致付款失败。
  • 订阅到期。
  • 用户申请退款。Refund Saver 处理该请求。
  • Apple 退款。

在 App Store Connect 中填写 Adapty 的通知 URL,然后确认通知已成功到达 Adapty。

在 App Store Connect 中输入通知 URL

如果已有其他服务器在接收您应用的通知,请在替换其 URL 之前先为其设置转发。

  1. 在 Adapty 中,打开你要连接的应用:每个 Adapty 应用都有自己独立的通知 URL。前往 App settings > iOS SDK。在 App Store server notifications 部分,从 URL for App Store server notifications 字段中复制 URL。

    URL for App Store server notifications in the App Store server notifications section in Adapty
  2. 在 App Store Connect 中,打开你的应用的 App Information 页面。

  3. 在 App Store Server Notifications 部分,找到 Production Server URL。如果已有 URL,点击 Edit;否则点击 Set Up URL。

    App Store Server Notifications section on the App Information page in App Store Connect
  4. 粘贴来自 Adapty 的 URL,然后点击 Save。

    Production Server URL dialog in App Store Connect with the URL from Adapty
  5. 若要让沙盒测试中的通知也能到达 Adapty,请对 Sandbox Server URL 重复步骤 3 和 4。

检查通知是否到达 Adapty

要确认通知是否到达 Adapty,请先进行沙盒购买。然后在 Adapty 中查看 App Store server notifications 部分的状态。即使没有通知,购买记录也会出现在 Adapty 中,因为 SDK 会自行上报。一旦 Apple 发送了关于该购买的通知,Adapty 会将状态从 Waiting 更改为 Active。来自 Apple 的测试通知不会更改状态。

状态会显示上次通知到达的时间:

  • Active:不到 24 小时前。
  • Delayed:24 到 72 小时前。
  • Stalled:72 小时前或更早。

Delayed 和 Stalled 并不一定意味着配置有问题:如果应用的订阅用户较少,可能好几天都不会触发通知。Active 只表示通知已成功发送到该 URL。

要确认收到的通知确实来自你的应用,请验证以下配置:

  1. 在 App Store Connect 中,打开应用的 App Information 页面。
  2. 确认 Production Server URL 和 Sandbox Server URL 均与 Adapty 中的 URL 一致。
  3. 再次进行沙盒购买,确认状态显示为 Active。

将通知转发至其他服务器

如果另一台服务器也需要接收来自 Apple 的通知,Adapty 可以将通知转发给该服务器。在 Adapty 中,前往 App settings > iOS SDK。在 App Store server notifications 部分,将该服务器的 URL 填入 URL for forwarding raw Apple events 字段,然后点击 Save。

app-settings-forwarding-url.webp

Adapty 会将从 Apple 收到的通知转发给其他服务器。如果你在 App Store Connect 的 Sandbox Server URL 中填入 Adapty 提供的通知 URL,Adapty 也会转发沙盒通知。转发的请求体保留 Apple 原始签名负载,因此其他服务器可以验证签名。Adapty 不会转发 Apple 的请求头。

Adapty 不转发以下内容:

  • SDK 上报但未收到 Apple 通知的购买。
  • Apple 发送的测试通知。
  • Adapty 在过去一小时内已接收过的通知。

为防止循环,请不要将转发的通知再次回传到通知 URL。也不要在 URL for forwarding raw Apple events 字段中填写 Adapty 的 URL。

如果您的后端必须在 App Store Connect 中保留其 URL,请改为从您的后端将通知传递给 Adapty。

通知真实性

将通知 URL 视为凭证妥善保管。Adapty 仅凭 URL 识别应用,因此任何持有该 URL 的人都可以向其发送负载数据。

测试通知无论由谁发送,都不会在事件记录中创建事件。

后续步骤

为以下平台配置 Adapty SDK:

然后发起沙盒购买,检查通知是否成功到达 Adapty。