node .js 同步_Node.js:iOS订阅状态的自动同步

node .js 同步

Node.js中的iOS订阅自动续订和取消 (Automatic iOS Subscription renewal and cancellation in Node.js)

Managing subscriptions for iOS apps is critical infrastructure to ensure users have access to the correct content, and equally as important, to ensure access to app content is closed off if that subscription expires or is cancelled. This can be achieved in an automated manner in the form of a Node.js runtime service that will automatically update a subscription status, whether renew or cancellation, from your app database upon every subscription period, whether that be on a monthly, bi-yearly or annual basis.

管理iOS应用程序的订阅是至关重要的基础架构,以确保用户可以访问正确的内容,同样重要的是,如果订阅过期或被取消,则确保对应用程序内容的访问被关闭。 这可以通过Node.js运行时服务的形式以自动化方式实现,该服务将在每个订阅期(无论是每月一次,每两年一次)自动从您的应用程序数据库中更新订阅状态(无论是续订还是取消)。或每年。

This issue will be solved in the context of JavaScript utilising a Node.js runtime in this article. A Gist containing the full service logic is included at the end of this article, or alternatively can be viewed here on Github.

本文将在使用Node.js运行时JavaScript上下文中解决此问题。 将含有完整的服务逻辑要点是包括在本文的结尾,或可替代地可被视为这里 Github上。

Although React Native won’t be discussed in detail, this article assumes that the reader is using a package such as react-native-iap to trigger in-app purchases that in turn generate transaction receipts. The solution discussed here also does not rely on Subscription Webhooks, or server to server notifications as the Apple docs term them. One can solely rely on transaction receipt verification to determine the state of a subscription.

尽管将不详细讨论React Native,但本文假定读者正在使用诸如react-native-iap类的包来触发应用内购买,进而产生交易收据。 这里讨论的解决方案也不依赖于Subscription Webhooks,也不依赖于Apple文档所说的服务器到服务器的通知 。 一个人可以完全依靠交易收据验证来确定订阅状态。

Regardless of whether you are using native Swift APIs or a React Native based API such as react-native-iap to offer in-app purchases, you will still be able to adopt the Node.js based solutions discussed in this piece. The key piece of information is the transaction receipt that’ll be used to fetch subscription state and thus determine the current subscription status.

无论您使用的是本机Swift API还是基于React Native的API(例如react-native-iap来提供应用内购买,您仍然可以采用本文中讨论的基于Node.js的解决方案。 关键信息是交易收据,将用于获取订阅状态,从而确定当前订阅状态。

From here the Node.js runtime will be referred to as the Subscription Manager, given that it essentially acts as the middleware between the subscription state on Apple’s servers and the subscription state on your own servers, providing the means to keep your database in sync with Apple’s.

从这里开始,Node.js运行时将被称为“ 订阅管理器” ,因为它实际上充当了Apple服务器上的订阅状态和您自己服务器上的订阅状态之间的中间件,从而提供了使数据库与之保持同步的方法。苹果。

集成此服务的先决条件 (Prerequisites to integrating this service)

If the reader would like to start from the beginning of the in-app purchase journey and set up subscription plans in a React Native app, I have published a piece on how do so using react-native-iap. That article can be found here: React Native: Subscriptions with In-App Purchases.

如果读者想从应用程序内购买之旅的起点开始,并在React Native应用程序中设置订阅计划,我已经发表了一篇有关如何使用react-native-iap 。 该文章可以在这里找到: React Native:带有应用内购买的订阅

Another recommended piece centres around the process of validating and persisting iOS transaction receipts as in-app purchases are made and securely storing them in your app database. The article can be read here: Validating iOS Subscription Receipts in React Native & Node.js. With transaction receipts readily available, they can be leveraged by the Subscription Manager service discussed in this piece.

推荐的另一件作品围绕在进行应用内购买时验证和保留iOS交易收据并将其安全存储在应用数据库中的过程。 可以在此处阅读本文: 在React Native和Node.js中验证iOS订阅收据 。 由于交易收据很容易获得,因此本文中讨论的Subscription Manager服务可以利用它们。

Before diving into the code, the following section will discuss the service in more detail by breaking it down into three stages that will effectively automatically renew or cancel a subscription accordingly.

在深入研究代码之前,以下部分将通过将服务分为三个阶段来更详细地讨论服务,这三个阶段将有效地自动自动更新或取消订阅。

订阅管理器服务如何工作 (How the Subscription Manager service works)

The service is coded as a JavaScript file that should be run with a process manager such as PM2, although one could also simply test with node. The service goes through the following stages:

该服务被编码为一个JavaScript文件,该文件应与流程管理器(例如PM2)一起运行,尽管也可以简单地对node测试。 该服务经历以下阶段:

1.定期检查哪些订阅已超过其到期时间戳 (1. Periodically c

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值