应用程序内购买服务器产品模型实现

时间:2010-10-01 09:58:44

标签: php iphone in-app-purchase

我正在尝试实施应用内购买服务器产品型号。我阅读了Apple文档,然后我解释了我必须做的事情,但我在某处做错了什么。 我的前提是我对PHP一无所知:(所以我现在只想了解一些东西,但我也在这个论坛上搜索过,我发现了很多有趣的东西帮助了我。 现在我逐步列出我在我的应用程序中执行的操作: - 我创建了从商店购买商品的机制,似乎工作 - 在我的storeobserver中,我添加了两个方法:encode和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: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);
}

我以这种方式调用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;
.......



ftp服务器上的validator.php

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

我无法理解到底出了什么问题,但是在服务器上没有生成testFile.txt并且函数verifyReceipt总是返回true,因为在我的iPhone上,在模拟过程中,事务总是成功结束(如果我手动修改jsonObjectString)。任何建议都非常感谢!!!!!

1 个答案:

答案 0 :(得分:0)

看起来你使用ftp协议网址调用php脚本。据我所知,你的php永远不会执行。尝试使用http://作为协议