我正在使用IAP开发应用程序的服务器端,我知道我需要在用户进行订阅时将应用程序从应用程序发送到我的服务器,然后通过应用程序商店验证收据状态,日期到期等,&向用户提供内容。
但我的问题是,我需要检查续订状态的收据是什么?我的意思是,当我第一次检查收据时,应用程序商店会给我一张收据,状态和最新收据,这个最新的收据是我下次应该用来检查状态的收据还是应该始终使用原始收据?我一直在测试他们两个,他们从应用程序商店给我相同的状态,但我不知道这是正确的做法。
由于
答案 0 :(得分:1)
今天,我遇到了这个问题。
在这里关注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;
}
}
希望得到这个帮助。
答案 1 :(得分:0)
完成交易后,您将获得tansaction& trasaction.reciept for this transaction reciept你想提供base64这里是这个
的代码 NSString *jsonObjectString = [self encodeBase64:(uint8_t*)transaction.transactionReceipt.bytes
length:transaction.transactionReceipt.length];
此jsonObjectString会将其保存到服务器,同时验证您要为此verify this link提供sharedsecret的收据