проверка квитанции Apple с PHP иногда не работает - PullRequest
0 голосов
/ 26 марта 2020

Я использую приведенный ниже код для проверки получения Apple, используя PHP, используя CURL. Я звоню на сервер Apple и пытаюсь получить ответ. Этот код работает нормально, но иногда ответ Apple JSON становится пустым, и я ' Я также не получаю никаких сообщений об ошибках. Он просто пропадает.

Это единственный метод проверки получения яблок с использованием PHP? или, пожалуйста, исправьте меня в моем коде, какую ошибку я допустил, потому что, когда я пытаюсь отладить это, я получаю пустой ответ, но эта проблема возникает не всегда, если я отправляю 10 запросов, 7 дают ответ, а 3 возвращаются пустым / пустым.

Спасибо.

function subscription_curl ($request)
{
ini_set('max_execution_time', 0);
                $decodeResponse = "";   
                $appleurl = "https://buy.itunes.apple.com/verifyReceipt"; // for production                 
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_URL, $appleurl);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
                $encodedResponse = curl_exec($ch);//Encoded apple response
                curl_close($ch);
                $decodeResponse = json_decode($encodedResponse, TRUE);//Decoded apple response
                $applestatus1 = $decodeResponse['status'];
                if($applestatus1 == 21007)
                {
                    $appleurl = "https://sandbox.itunes.apple.com/verifyReceipt"; // for sandbox                                    
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                    curl_setopt($ch, CURLOPT_URL, $appleurl);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                    curl_setopt($ch, CURLOPT_POST, true);
                    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
                    $encodedResponse = curl_exec($ch);//Encoded apple response
                    curl_close($ch);
                    $decodeResponse = json_decode($encodedResponse, TRUE);//Decoded apple response
                }
            return array($encodedResponse, $decodeResponse);
}

$decodeResponse1 = subscription_curl($request); // Call curl function to send request to apple  
$encodedResponse = $decodeResponse1[0];
$decodeResponse = $decodeResponse1[1];
print_r($decodeResponse)
...