in-app satın Sunucu Ürün Modeli Uygulama

0 Cevap php

i'm trying to implement an in-app purchase Server Product model. I read the Apple documentation and i unterstand what i have to do, but i'm doing something wrong somewhere. I premise that i don't know anything about PHP :( , so i'm trying to understand something only now, but i searched also in this forum and i found a lot of interesting things that helped me. Now i list step by step what i do into my app: - i created the mechanism to purchase an item from the store and seems work
- in my storeobserver i added the two methods: encode and verifyReceipt (copied from link text) to very the receipt
- i'm using an ftp server to upload my in-app purchases files and i want to use it also to host the php validator file.

Now i paste my method and my php file, probably i'm doing something wrong here:

verifyReceipt method

- (BOOL)verifyReceipt:(SKPaymentTransaction *)transaction {
    NSString *jsonObjectString = [self encode:(uint8_t *)transaction.transactionReceipt.bytes length:transaction.transactionReceipt.length];      
    NSString *completeString = [NSString stringWithFormat:@"ftp://user:pass@aabbcc.com/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);
}

Ben bu şekilde verifyReceipt yöntemini çağırın:

- (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 on the ftp server

<?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;
?>

Ben tam olarak yanlış giden ne anlayamıyorum, ama sunucuda testFile.txt değil oluşturulur ve işlev simülasyon sırasında, çünkü benim iPhone'da her zaman doğru dönün verifyReceipt i elle değiştirirseniz, işlem de (başarılı hep biter jsonObjectString). Herhangi bir öneri çok çok takdir!!

0 Cevap