2011-07-24 96 views
2

我有收到我的應用程序內購買收據驗證迴應的麻煩。你能看看下面的代碼,並告訴我爲什麼我沒有得到任何回報?另外,如果有關於驗收驗證的好方法的建議,請告訴我!在應用程序購買收據驗證

非常感謝提前!

的Xcode:

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

NSString *jsonObjectString = [self encode:(uint8_t *)transaction.transactionReceipt.bytes length:transaction.transactionReceipt.length];  
NSString *completeString = [NSString stringWithFormat:@"http://www.myURL.com/vReceipt.php?receipt=%@", jsonObjectString];        
NSURL *urlForValidation = [NSURL URLWithString:completeString];    
NSMutableURLRequest *validationRequest = [[NSMutableURLRequest alloc] initWithURL:urlForValidation];       
[validationRequest setHTTPMethod:@"GET"];    
NSData *responseData = [NSURLConnection sendSynchronousRequest:validationRequest returningResponse:nil error:nil]; 
NSString *responseString = [[NSString alloc] initWithData:responseData encoding: NSUTF8StringEncoding]; 
NSInteger response = [responseString intValue]; 
NSLog(@"Response String: %@", jsonObjectString); 
NSLog(@"Response Integer: %@", response); 
return (response = 0);} 

- (NSString *)encode:(const uint8_t *)input length:(NSInteger)length { 
static char table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/="; 

NSMutableData *data = [NSMutableData dataWithLength:((length + 2)/3) * 4]; 
uint8_t *output = (uint8_t *)data.mutableBytes; 

for (NSInteger i = 0; i < length; i += 3) { 
    NSInteger value = 0; 
    for (NSInteger j = i; j < (i + 3); j++) { 
      value <<= 8; 

      if (j < length) { 
       value |= (0xFF & input[j]); 
      } 
    } 

    NSInteger index = (i/3) * 4; 
    output[index + 0] =     table[(value >> 18) & 0x3F]; 
    output[index + 1] =     table[(value >> 12) & 0x3F]; 
    output[index + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '='; 
    output[index + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '='; 
} 

return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];} 

PHP代碼:

<?php 

$myreceipt = json_encode(array('receipt-data' => $_GET['receipt'])); 
$url = "https://sandbox.itunes.apple.com/verifyReceipt"; 

//create cURL Request 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $myreceipt); 

//execute cURL Request 
$response = curl_exec($ch); 
$errno = curl_errno($ch); 
$errmsg = curl_error($ch); 
curl_close($ch); 

$response_json = json_decode($response); 

print $response_json->{'status'}; 

?> 
+0

你遇到了什麼麻煩? –

+0

curl_setopt($ ch,CURLOPT_POSTFIELDS,$ myreceipt); < - 需要鍵值字符串或鍵值數組。你給它一個JSON,它不會像你期望的那樣解釋JSON –

回答

0

你應該做的stripslashes()你從iPhone獲得的數據或許

1

這個字符串總是返回0:

return (response = 0);} 

Co立一:

return (response == 0);} 
相關問題