2010-10-01 92 views
1

我試圖實施應用內購買服務器產品模型。我閱讀了蘋果的文檔,我不知道我必須做什麼,但我在某處做錯了什麼。 我的前提是,我不知道任何關於PHP :(所以我只是想了解一些現在,但我也在這個論壇搜索,我發現了很多有趣的事情,幫助我。 現在我列出一步一步一步,我做我的應用程序: - 我創建了從商店購買項目的機制,似乎工作
- 在我的storeobserver我添加了兩種方法:編碼和verifyReceipt(複製從link text)到收據
- 我使用的FTP服務器上傳我的應用程序內購買文件,我想用它來承載PHP驗證器文件。
應用內購買服務器產品型號實施

現在我粘貼我的方法和我的PHP文件,可能我是在這裏做錯了什麼:

verifyReceipt方法

- (BOOL)verifyReceipt:(SKPaymentTransaction *)transaction { 
    NSString *jsonObjectString = [self encode:(uint8_t *)transaction.transactionReceipt.bytes length:transaction.transactionReceipt.length];  
    NSString *completeString = [NSString stringWithFormat:@"ftp://user:[email protected]/DDDD/validator.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]; 
    [validationRequest release]; 
    NSString *responseString = [[NSString alloc] initWithData:responseData encoding: NSUTF8StringEncoding]; 
    NSLog(@"%@",responseString); 
    NSInteger response = [responseString integerValue]; 
    [responseString release]; 
    return (response == 0); 
} 

我打電話verifyReceipt方法是這樣的:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions{ 
    BOOL verification=false; 
    for (SKPaymentTransaction *transaction in transactions) 
    { 
     switch (transaction.transactionState) 
     { 
      case SKPaymentTransactionStatePurchased: 
       verification=[self verifyReceipt:transaction]; 
       if (verification) { 
        [self completeTransaction:transaction]; 
       }    
       break; 
....... 



validator.php FTP服務器

<?PHP 
$receipt = json_encode(array("receipt-data" => $_GET["receipt"])); 
// NOTE: use "buy" vs "sandbox" in production. 
$url = "https://sandbox.itunes.apple.com/verifyReceipt"; 
$curl_handle=curl_init(); 
curl_setopt($curl_handle,CURLOPT_URL,$url); 
curl_setopt($curl_handle, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $receipt); 
$response_json = curl_exec($curl_handle); 
curl_close($curl_handle); 
$response = json_decode($response_json); 

// Save the data here! 
$myFile = "testFile.txt"; 
$fh = fopen($myFile, 'w') or die("can't open file"); 
fwrite($fh, $response); 
fclose($fh); 
echo $response->status; 
?> 

我不能上不了解w但是在服務器上testFile.txt不會生成,並且函數verifyReceipt總是返回true,因爲在我的iPhone上,在模擬期間,事務總是成功結束(也是如果我手動修改jsonObjectString)。任何建議都非常感謝!!!!!

回答

0

看起來像使用ftp協議url調用php腳本。據我所知,你的PHP永遠不會執行。試試http://作爲協議