我想检测该客户的订阅现已结束/完成,以便我可以删除我提供给他们的设施。
在每次启动应用程序时,我都会从 Apple 订阅中获得以下详细信息:
public void CheckIfSubscriptionIsActive(){
ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
// Get a reference to IAppleConfiguration during IAP initialization.
IAppleConfiguration appleConfig = builder.Configure<IAppleConfiguration>();
if (!string.IsNullOrEmpty (appleConfig.appReceipt)) {
Debug.Log (appleConfig.appReceipt);
// InstantiateDebugText (DebugInfoPanel, "APP Receipt Base64 " + appleConfig.appReceipt);
var receiptData = System.Convert.FromBase64String (appleConfig.appReceipt);
// InstantiateDebugText (DebugInfoPanel, "receipt Data "+ receiptData);
AppleReceipt receipt = new AppleValidator (AppleTangle.Data ()).Validate (receiptData);
InstantiateDebugText (DebugInfoPanel, "Apple receipt " + receipt);
foreach (AppleInAppPurchaseReceipt productReceipt in receipt.inAppPurchaseReceipts) {
Debug.Log ("RODUCTID: " + productReceipt.productID);
Debug.Log ("URCHASE DATE: " + productReceipt.purchaseDate);
Debug.Log ("EXPIRATION DATE: " + productReceipt.subscriptionExpirationDate);
Debug.Log ("CANCELDATE DATE: " + productReceipt.cancellationDate);
InstantiateDebugText (DebugInfoPanel, "RODUCTID: " + productReceipt.productID);
InstantiateDebugText (DebugInfoPanel, "URCHASE DATE: " + productReceipt.purchaseDate);
InstantiateDebugText (DebugInfoPanel, "EXPIRATION DATE: " + productReceipt.subscriptionExpirationDate);
InstantiateDebugText (DebugInfoPanel, "CANCELDATE DATE: " + productReceipt.cancellationDate);
}
}
因为在检测订阅到期计算时,我无法获取当前 iPhone 日期和时间的帮助,而且我的应用没有使用任何与自定义服务器相关的东西,所以我完全依赖 Apple。
正是因为这个原因,我才使用 Auto Renewable Subscription,以便获得有关订阅期限的信息。
现在请分享您对此的想法,如何检测订阅是否已过期?
您应该先在 Appstore 验证您的收据。 使用您从以下获得的收据数据:
var receiptData = System.Convert.FromBase64String (appleConfig.appReceipt);
您可以从 here 查看如何使用苹果服务器验证收据
但是,不要转发从 status 收到的状态。对于 autoreniew 收据,即使收据有效但已过期,它也会返回成功。 作为回应,您将收到收据。遍历所有收据,检查产品 ID 的“expires_date”字段 = 您所需的产品 ID。 "expires_date"将包含 epoch time. .您可以检查此日期是否大于当前日期,如果您在 (productid = yourproducid && expireDate > currentEpocDate) 找到任何收据,则订阅有效。否则过期或停止或未购买。
创建 json,
{
"receipt-data": "receiptData (string))"
}
并将其发布到苹果的服务器 - ( https://sandbox.itunes.apple.com/verifyReceipt )。作为回应,您将收到带有验证状态的收据。
注意:
In the test environment, use https://sandbox.itunes.apple.com/verifyReceipt as the URL. In production, use https://buy.itunes.apple.com/verifyReceipt as the URL.
关于c# - 检测 Apple 订阅到期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42019936/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |