我正在尝试使用以下代码验证我的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
我做错了什么?