3

我将应用内购买与我的 ios 应用程序集成在一起。但问题是有时Apple在针对iTunes服务器进行应用内购买收据验证后返回“无效响应数据”。我不知道为什么?。此外,这仅发生在少数用户而不是所有人身上。任何人都知道或面临这个问题的实际问题是什么?此外,当收据验证失败时,苹果是否会对该购买收费?

这是我的服务器端代码,用于验证针对 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

4

0 回答 0