IOS receipt validation error 21002

前端 未结 5 476
旧巷少年郎
旧巷少年郎 2021-01-01 03:01

I\'m trying to use receipt validation with my server side. Everything is ok, but sometimes I see strange: 10 times validation is OK, but on 11 i get 21002 error. I dont know

5条回答
  •  囚心锁ツ
    2021-01-01 03:26

    The Receipt Data is already base64 encoded. Refer to Receipt Validation Programming Guide

    $receipt_data = "MII.................KY\/6oc9w==";
    
    $data = "{\"receipt-data\":\"$receipt_data\"}";
    
    $url = "https://buy.itunes.apple.com/verifyReceipt";        // if use this to test sandbox will return "{"status":21007}"
    //$url = "https://sandbox.itunes.apple.com/verifyReceipt";  // for sandbox
    
    var_dump(post($url,$data));
    
    function post($url, $data, $headerArray = array())
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,FALSE);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        if (array() === $headerArray)
            curl_setopt($curl, CURLOPT_HTTPHEADER,["Content-type:application/json;charset='utf-8'","Accept:application/json"]);
    
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    }
    

提交回复
热议问题