스마트폰 프로그래밍/Swift

인앱결재 영수증 확인 php소스

삽질중 2014. 4. 29. 19:54

<?php

header("Content-Type: text/html; charset=UTF-8");

header("Cache-Control:no-cache");

header("Pragma:no-cache");

    /**

     * Verify a receipt and return receipt data

     *

     * @param   string  $receipt    Base-64 encoded data

     * @param   bool    $isSandbox  Optional. True if verifying a test receipt

     * @throws  Exception   If the receipt is invalid or cannot be verified

     * @return  array       Receipt info (including product ID and quantity)

     */

    function getReceiptData($receipt, $isSandbox)

    {

    //echo $receipt;

        // determine which endpoint to use for verifying the receipt

        //if ($isSandbox == "true") {

        //    $endpoint = 'https://sandbox.itunes.apple.com/verifyReceipt';

            

        //}

        //else {

            $endpoint = 'https://buy.itunes.apple.com/verifyReceipt';

        //}

 

         // build the post data        

        $postData = json_encode( Array('receipt-data' => $receipt) );        

        

        // create the cURL request

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_URL, $endpoint);

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

            echo "WebError".$errmsg;

        }

 

        return $response;

    }

 

    // fetch the receipt data and sandbox indicator from the post data

    $receipt   = $_POST['receipt'];

    $isSandbox = $_POST['sandbox'];

 

    // verify the receipt

    try {

   

        $info = getReceiptData($receipt, $isSandbox);

        echo $info;

        // receipt is valid, now do something with $info

    }

    catch (Exception $ex) {

        // unable to verify receipt, or receipt is not valid

    }

?>

'스마트폰 프로그래밍 > Swift' 카테고리의 다른 글

인앱결재 영수증 서버인증 PHP  (0) 2013.11.22
4단계 개발자 디바이스 빌드  (0) 2013.06.24
3단계 디바이스 추가  (0) 2013.06.24
2단계 어플 ID등록  (0) 2013.06.24
1단계 인증서 인증  (0) 2013.06.24