用户修改自动订阅商品如何获取服务器通知【苹果支付】

目录

前言

一、需要怎么样的接口呢?

二. 接受通知接口地址


前言

最近开发公司苹果的包月商品支付,假设用户购买的包月商品,在自动续费管理页面修改包季商品,后端接口如何收到通知呢???


通过查看官方文档了解,在开发者账户确实可以配服务器的通知地址,至于怎么配服务起通知这个pass吧,相信大家都可以找到

如果找不到可以参考这个地址:https://help.apple.com/app-store-connect/#/dev0067a330b,里面怎么已经介绍的很详细了。

下面讲讲怎么样的接口能收到app store的通知,首先说需要写一个什么样的接口吧,其次再说说通知的消息类型。

一、需要怎么样的接口呢?

官方原文:

To receive server notifications from the App Store, provide your server URL in App Store Connect. For instructions see Enter a URL for App Store Server Notifications. Ensure that your server establishes a secure connection with the App Store as described in Preventing Insecure Network Connections.

Upon receiving a server notification, respond to the App Store with an HTTP status code of 200 if the post was successful. If the post was unsuccessful, send HTTP 50x or 40x to have the App Store retry the notification.

大概意思如下:苹果服务器需要配一个通知的地址,前提这个地址还需要是安全的,那就是https呗,还有一个关键信息就是苹果的通知还有重试机制,需要重试50x或40x的错误码,200表示服务起已经成功通知不需要重试。responseBody类型是Content-Type: application/json,还是没说请求是GET还是POST,别着急看下面的这原文

官方原文:

When you enable your App Store Server Notifications URL on App Store Connect, you automatically receive server notifications on your secure server. The App Store sends notifications as JSON objects for a number of subscription events. These JSON events, documented in responseBody, contain fields and information you can use to react to transactions according to your business logic. For information on configuring and using server notifications, see Enabling Server-to-Server Notifications.

Receive Server-to-Server Notifications

The App Store delivers JSON objects via an HTTP POST to your server for notable subscription events. Your server is responsible for parsing, interpreting, and responding to all server-to-server notification posts.

The server-to-server notification is an HTTP POST. The body of the POST contains the data elements described in responseBody. The App Store posts notifications for subscription events represented by the values of the notification_type field.

我说一下咱们关心的重点吧

首先App Store通过HTTP POST将JSON对象传递给您的服务器,responseBody中包含JSON数据。notification_type表示订阅事件的通知类型。那下面关系的就是notification_type有几种通知类型呢。类型如下:

CANCEL

Indicates that either Apple customer support canceled the subscription or the user upgraded their subscription. The cancellation_date key contains the date and time of the change.

DID_CHANGE_RENEWAL_PREF

Indicates the customer made a change in their subscription plan that takes effect at the next renewal. The currently active plan is not affected.

事件大概意思用户改变自动续费的计划,在下个自动续费周期生效,当前计划为立即生效

DID_CHANGE_RENEWAL_STATUS

Indicates a change in the subscription renewal status. Check auto_renew_status_change_date_ms and auto_renew_status in the JSON response to know the date and time of the last status update and the current renewal status.

DID_FAIL_TO_RENEW

Indicates a subscription that failed to renew due to a billing issue. Check is_in_billing_retry_period to know the current retry status of the subscription, and grace_period_expires_date to know the new service expiration date if the subscription is in a billing grace period.

DID_RECOVER

Indicates a successful automatic renewal of an expired subscription that failed to renew in the past. Check expires_date to determine the next renewal date and time.

INITIAL_BUY

Occurs at the user's initial purchase of the subscription. Store latest_receipt on your server as a token to verify the user’s subscription status at any time by validating it with the App Store.

INTERACTIVE_RENEWAL

Indicates the customer renewed a subscription interactively, either by using your app’s interface, or on the App Store in the account's Subscriptions settings. Make service available immediately.

RENEWAL

Indicates a successful automatic renewal of an expired subscription that failed to renew in the past. Check expires_date to determine the next renewal date and time.

REFUND

Indicates that App Store successfully refunded a transaction. The cancellation_date_ms contains the timestamp of the refunded transaction; the original_transaction_id and product_id identify the original transaction and product, and cancellation_reason contains the reason.

好了到这基本应该怎么找到写服务器接受通知的地址了吧,下面例子仅供参考:

二. 接受通知接口地址

jesery接口代码如下(示例):

private static final String RESP = "";

@POST
@Path("/callback")
@Produces(value = "text/plain")
public String notify(String body) {
    logger.info("callback from mac iap data {}", body);
    JSONObject j = JSON.parseObject(body);
    if ("DID_CHANGE_RENEWAL_PREF".equals(j.getString("notification_type"))) {
            return RESP;
        }
    }
    /*if (!"PROD".equals(j.getString("environment"))) {
        return RESP;
    }*/
    if (!"true".equals(j.getString("auto_renew_status"))) {
        return RESP;
    }
    if ("INTERACTIVE_RENEWAL".equals(j.getString("notification_type"))
        || "RENEWAL".equals(j.getString("notification_type"))) {
        return RESP;
    }
    return RESP;
}

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
获取苹果电脑用户,可以使用JavaScript编程语言来实现。JavaScript提供了一系列的方法和属性,可以帮助我们进行用户的检测和判断。 首先,我们可以使用`navigator`对象的`userAgent`属性来获取用户的浏览器信息。在苹果电脑上,Safari是默认的浏览器,因此我们可以通过检测`userAgent`中是否包含"Safari"关键词来确定用户是否使用苹果电脑。 同时,我们还可以使用`navigator`对象的`platform`属性来获取用户的操作系统信息。在苹果电脑上,操作系统通常是Mac OS X或者更高版本,因此我们可以通过检测`platform`中是否包含"Mac"关键词来判断用户是否使用苹果电脑。 下面是一段示例代码,演示了如何使用JavaScript来获取苹果电脑用户: ``` <script> var isAppleUser = false; // 检测用户浏览器信息 if (navigator.userAgent.includes("Safari")) { // 检测用户操作系统信息 if (navigator.platform.includes("Mac")) { isAppleUser = true; } } if (isAppleUser) { console.log("用户苹果电脑用户"); // 执行其他相关操作 } else { console.log("用户不是苹果电脑用户"); } </script> ``` 以上代码首先定义了一个变量`isAppleUser`,初始值为`false`。然后,通过检测`navigator.userAgent`和`navigator.platform`中是否包含特定的关键词,如果满足条件,则将`isAppleUser`值设为`true`。 最后,根据`isAppleUser`的值,可以执行不同的操作,例如在控制台输出相应的信息。 需要注意的是,虽然通过JavaScript可以获取用户的浏览器和操作系统信息,但是用户可以手动修改这些信息,因此无法百分之百确定用户的真实设备类型。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值