$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $api_url.http_build_query($data),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
// CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HEADER => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
));
$response = curl_exec($curl);
if (curl_errno($curl)) {
$this->modx->log(1, print_r(curl_error($curl), true));
}
curl_close($curl);
$isWinCharset = mb_check_encoding($response, "windows-1251");
if ($isWinCharset) {
$response = iconv("windows-1251", "UTF-8", $response);
}
SSL operation failed with code 1. OpenSSL Error messages:
error:0A000152:SSL routines::unsafe legacy renegotiation disabled
Options = UnsafeLegacyRenegotiation
const API_ADDRESS = 'https://otpravka-api.pochta.ru';
private function __construct($appToken, $userKey)
{
$this->headers = [
'Content-Type: application/json',
'Accept: application/json;charset=UTF-8',
'Authorization: AccessToken ' . $appToken,
'X-User-Authorization: Basic ' . $userKey
];
}
private function rawRequest($dataInUtf8, $url, $method = self::METHOD_POST)
{
$headers = $this->headers;
$ch = curl_init(self::API_ADDRESS . $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
if(count($dataInUtf8) > 0) {
$dataString = json_encode($dataInUtf8);
$headers[] = 'Content-Length: ' . strlen($dataString);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
return curl_exec($ch);
}