应用购买收据?

我试图用下面的代码来验证我的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

我究竟做错了什么?

链接地址: http://www.djcxy.com/p/68083.html

上一篇: app purchase receipt?

下一篇: Spring Test Service Autowiring resulting in null