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

发布于 2024-09-25 20:22:52 字数 3149 浏览 0 评论 0原文

我正在尝试实现应用内购买服务器产品模型。我阅读了苹果文档,我明白我必须做什么,但我在某个地方做错了。 我假设我对 PHP 一无所知:(,所以我现在才尝试了解一些东西,但我也在这个论坛中进行了搜索,我发现了很多对我有帮助的有趣的东西。 现在我一步步列出我在应用程序中所做的事情: - 我创建了从商店购买商品的机制,看起来很有效
- 在我的 storeobserver 中,我添加了两种方法:编码和 verifyReceipt (从链接文本复制) 收据
- 我正在使用 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;
.......



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 也是如此)。任何建议都非常非常感谢!!!!

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:[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);
}

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 !!!!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绿萝 2024-10-02 20:22:52

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

Looks like your calling a php script using an ftp protocol url. To my knowledge your php will never execute. Try http:// as protocol

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文