JSON收据验证无效

时间:2013-05-16 05:24:21

标签: iphone app-store in-app-purchase

当我使用沙箱环境时,验证收据。当我使用json代码时收到的收据无效。我使用测试用户帐户来测试我的应用程序。我打算将应用程序上传到App Store。

我要用这个:

NSURL *sandboxStoreURL = [[NSURL alloc] initWithString: @"https://sandbox.itunes.apple.com/verifyReceipt"];

或者这个:

#define VERIFY_TRANSACTION_RECEIPT_URL @"http://server/projects/php/verifyTransactionReceipt.php?"

- (int )verifyReceipt:(SKPaymentTransaction *)transaction {

    //[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    //https://sandbox.itunes.apple.com/verifyReceipt  for Sandbox environment
    //https://buy.itunes.apple.com/verifyReceipt      for actual


  //  NSURL *sandboxStoreURL = [[NSURL alloc] initWithString: @"https://sandbox.itunes.apple.com/verifyReceipt"];


    NSString *jsonObjectString = [self encode:(uint8_t *)transaction.transactionReceipt.bytes length:transaction.transactionReceipt.length];
    NSString *completeString = [NSString stringWithFormat:@"%@receipt-data=%@",VERIFY_TRANSACTION_RECEIPT_URL,jsonObjectString];


   NSURL *urlForValidation = [NSURL URLWithString:completeString];


    NSMutableURLRequest *validationRequest = [[NSMutableURLRequest alloc] initWithURL:urlForValidation];
    [validationRequest setHTTPMethod:@"GET"];
    NSData *responseData = [NSURLConnection sendSynchronousRequest:validationRequest returningResponse:nil error:nil];
    [validationRequest release];
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding: NSUTF8StringEncoding];

    NSString *status;
    int returnValue;
    if ([responseString length]) {
        NSMutableDictionary *dict=[responseString JSONValue];
        [responseString release];

        status= [NSString stringWithFormat:@"%@",[dict objectForKey:@"status"]]; // one more key is 'receipt'
        //returnValue=[dict objectForKey:@"status"];

        if ([status isEqual:@"0"])
            returnValue=1;
        else returnValue=0;

    }else returnValue=0;

    return returnValue;

    }

0 个答案:

没有答案