in-app purchase Server Product Model Implementation
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 wron开发者_开发知识库g 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);
}
I call verifyReceipt method in this way:
- (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;
?>
I can't understand what exactly goes wrong, but on the server the testFile.txt isn't generated and the function verifyReceipt return always true because on my iPhone, during the simulation, the transaction ends always successfully (also if i manually modify the jsonObjectString). Any suggestion is very very appreciated !!!!!
Looks like your calling a php script using an ftp protocol url. To my knowledge your php will never execute. Try http:// as protocol
精彩评论