c# - 检测 Apple 订阅到期
<p><p>我想检测该客户的订阅现已结束/完成,以便我可以删除我提供给他们的设施。</p>
<p>在每次启动应用程序时,我都会从 Apple 订阅中获得以下详细信息:</p>
<pre><code>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 ("PRODUCTID: " + productReceipt.productID);
Debug.Log ("PURCHASE DATE: " + productReceipt.purchaseDate);
Debug.Log ("EXPIRATION DATE: " + productReceipt.subscriptionExpirationDate);
Debug.Log ("CANCELDATE DATE: " + productReceipt.cancellationDate);
InstantiateDebugText (DebugInfoPanel, "PRODUCTID: " + productReceipt.productID);
InstantiateDebugText (DebugInfoPanel, "PURCHASE DATE: " + productReceipt.purchaseDate);
InstantiateDebugText (DebugInfoPanel, "EXPIRATION DATE: " + productReceipt.subscriptionExpirationDate);
InstantiateDebugText (DebugInfoPanel, "CANCELDATE DATE: " + productReceipt.cancellationDate);
}
}
</code></pre>
<p>因为在检测订阅到期计算时,我无法获取当前 iPhone 日期和时间的帮助,而且我的应用没有使用任何与自定义服务器相关的东西,所以我完全依赖 Apple。</p>
<p>正是因为这个原因,我才使用 Auto Renewable Subscription,以便获得有关订阅期限的信息。</p>
<p>现在请分享您对此的想法,如何检测订阅是否已过期?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您应该先在 Appstore 验证您的收据。
使用您从以下获得的收据数据:</p>
<pre><code>var receiptData = System.Convert.FromBase64String (appleConfig.appReceipt);
</code></pre>
<p>您可以从 <a href="https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html" rel="noreferrer noopener nofollow">here</a> 查看如何使用苹果服务器验证收据</p>
<p>但是,不要转发从 status 收到的状态。对于 autoreniew 收据,即使收据有效但已过期,它也会返回成功。
作为回应,您将收到收据。遍历所有收据,检查产品 ID 的“expires_date”字段 = 您所需的产品 ID。 "expires_date"将包含 <a href="http://www.epochconverter.com/" rel="noreferrer noopener nofollow">epoch time.</a> .您可以检查此日期是否大于当前日期,如果您在 (productid = yourproducid && expireDate > currentEpocDate) 找到任何收据,则订阅有效。否则过期或停止或未购买。</p>
<p>创建 json,</p>
<pre><code>{
"receipt-data": "receiptData (string))"
}
</code></pre>
<p>并将其发布到苹果的服务器 - ( <a href="https://sandbox.itunes.apple.com/verifyReceipt" rel="noreferrer noopener nofollow">https://sandbox.itunes.apple.com/verifyReceipt</a> )。作为回应,您将收到带有验证状态的收据。</p>
<p>注意:</p>
<blockquote>
<p>In the test environment, use
<a href="https://sandbox.itunes.apple.com/verifyReceipt" rel="noreferrer noopener nofollow">https://sandbox.itunes.apple.com/verifyReceipt</a> as the URL. In
production, use <a href="https://buy.itunes.apple.com/verifyReceipt" rel="noreferrer noopener nofollow">https://buy.itunes.apple.com/verifyReceipt</a> as the URL.</p>
</blockquote></p>
<p style="font-size: 20px;">关于c# - 检测 Apple 订阅到期,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/42019936/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/42019936/
</a>
</p>
页:
[1]