Я пытаюсь проверить свою квитанцию IAP с помощью следующего кода, но он не работает:
- (void)completeTransaction:(SKPaymentTransaction *)transaction {
NSString* receiptString = [self createEncodedString:transaction.transactionReceipt];
NSURL *url = [NSURL URLWithString:@"http://my.website.com/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
receiptString, @"receipt",
NO, @"isSandbox",
nil];
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"/verifyReceipt.php" parameters:params];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
{
NSLog(@"success: %@", operation.responseString);
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"error: %@", operation.responseString);
}
];
[self recordTransaction:transaction];
[self provideContent:transaction.payment.productIdentifier];
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}
- (NSString*) createEncodedString:(NSData*)data
{
static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
const int size = ((data.length + 2)/3)*4;
uint8_t output[size];
const uint8_t* input = (const uint8_t*)[data bytes];
for (int i = 0; i > 18) & 0x3F];
output[index + 1] = table[(value >> 12) & 0x3F];
output[index + 2] = (i + 1) > 6) & 0x3F] : '=';
output[index + 3] = (i + 2) > 0) & 0x3F] : '=';
}
return [[NSString alloc] initWithBytes:output length:size encoding:NSASCIIStringEncoding];
}
Сценарий PHP, который я использую для проверки данных, можно найти здесь: http://www.phpriot.com/articles/verifying-app-store-receipts-php-curl
Что я делаю не так?