gpt4 book ai didi

ios - 我应该验证什么自动续订订阅收据?

转载 作者:行者123 更新时间:2023-11-29 04:05:40 24 4
gpt4 key购买 nike

我正在使用 IAP 开发应用程序的服务器端,我知道当用户进行订阅时,我需要将收据从应用程序发送到我的服务器,然后通过应用程序商店验证收据的状态,日期到期等,并向用户提供内容。

但我的问题是,我需要什么收据来检查续订状态?我的意思是,我第一次检查收据时,应用程序商店给我返回收据、状态和最新收据,这张最新收据是我下次应该用来检查状态的收据,还是应该始终使用原始收据?我一直在对它们进行测试,它们在应用程序商店中为我提供了相同的状态,但我不确定正确的做法是什么。

谢谢

最佳答案

今天,我遇到了这个问题。

关注Apple doc这里,我用这种方式来检查订阅是否过期。

+ (BOOL)checkInAppPurchaseStatus
{
// Load the receipt from the app bundle.
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
if (receipt) {
BOOL sandbox = [[receiptURL lastPathComponent] isEqualToString:@"sandboxReceipt"];
// Create the JSON object that describes the request
NSError *error;
NSDictionary *requestContents = @{
@"receipt-data": [receipt base64EncodedStringWithOptions:0],@"password":@"SHARE_SECRET_CODE"
};
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
options:0
error:&error];

if (requestData) {
// Create a POST request with the receipt data.
NSURL *storeURL = [NSURL URLWithString:@"https://buy.itunes.apple.com/verifyReceipt"];
if (sandbox) {
storeURL = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];
}
NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL];
[storeRequest setHTTPMethod:@"POST"];
[storeRequest setHTTPBody:requestData];

BOOL rs = NO;
//Can use sendAsynchronousRequest to request to Apple API, here I use sendSynchronousRequest
NSError *error;
NSURLResponse *response;
NSData *resData = [NSURLConnection sendSynchronousRequest:storeRequest returningResponse:&response error:&error];
if (error) {
rs = NO;
}
else
{
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:resData options:0 error:&error];
if (!jsonResponse) {
rs = NO;
}
else
{
NSLog(@"jsonResponse:%@", jsonResponse);

NSDictionary *dictLatestReceiptsInfo = jsonResponse[@"latest_receipt_info"];
long long int expirationDateMs = [[dictLatestReceiptsInfo valueForKeyPath:@"@max.expires_date_ms"] longLongValue];
long long requestDateMs = [jsonResponse[@"receipt"][@"request_date_ms"] longLongValue];
NSLog(@"%lld--%lld", expirationDateMs, requestDateMs);
rs = [[jsonResponse objectForKey:@"status"] integerValue] == 0 && (expirationDateMs > requestDateMs);
}
}
return rs;
}
else
{
return NO;
}
}
else
{
return NO;
}
}

希望这有帮助。

关于ios - 我应该验证什么自动续订订阅收据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15288537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com