IOS:处理应用程序内购买收据验证失败

时间:2013-03-26 06:24:41

标签: iphone ios in-app-purchase

我在ios应用中集成了应用内购买。但问题是,在针对itunes服务器的应用内购买收据验证后,Apple有时会返回“无效的响应数据”。我不知道为什么?。此外,这种情况仅发生在少数用户并非所有用户身上。任何人都知道或面对这个问题,这里的实际问题是什么?此外,当收据验证失败时,苹果会对该购买收费还是不收费?

这是我的服务器端代码,用于验证针对ituens服务器购买的收据:

    <?php

        $devmode = FALSE; //TRUE; // change this to TRUE  testing against sandbox

        $receiptdata        = $_POST['receiptdata'];    
        $email_id           = base64_decode($_POST['user_email_id']);
        $pwd                = $_POST['pwd'];

        if($devmode)
        {
            $appleURL = "https://sandbox.itunes.apple.com/verifyReceipt";

        }
        else
        {
            $appleURL = "https://buy.itunes.apple.com/verifyReceipt";       
        }

        try {
            $receipt = json_encode(array("receipt-data" => $receiptdata));
            $response_json = do_post_request($appleURL, $receipt); 
            $response = json_decode($response_json);

            if (!is_object($response)) {
                throw new Exception('Invalid response data');
            }

            if (!isset($response->status) || $response->status != 0) 
            {           
                throw new Exception('Invalid receipt');
            }

            if($response->{'status'} == 0)
            {
                echo 'receipt verification success';

            } else {

            } 
        catch (Exception $ex) {
            eecho 'exception got: ' . $ex->getMessage();
            exit(0);
        }
function do_post_request($endpoint, $postData, $optional_headers = null)
{
        // create the cURL request
        $ch = curl_init($endpoint);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

        // execute the cURL request and fetch response data
        $response = curl_exec($ch);
        $errno    = curl_errno($ch);
        $errmsg   = curl_error($ch);
        curl_close($ch);

        // ensure the request succeeded
        if ($errno != 0) {
            throw new Exception($errmsg, $errno);
        }

        return $response;
}
    ?>

任何必须得到赞赏的帮助。

谢谢, -loganathan

0 个答案:

没有答案