Skip to content

Instantly share code, notes, and snippets.

@CB9TOIIIA
Created September 8, 2017 06:12
Show Gist options
  • Save CB9TOIIIA/f2cc306b8d2c2c4da8bfecf97997aa48 to your computer and use it in GitHub Desktop.
Save CB9TOIIIA/f2cc306b8d2c2c4da8bfecf97997aa48 to your computer and use it in GitHub Desktop.
RussianPostCalc
<?php
function _russianpostcalc_api_communicate($request)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://russianpostcalc.ru/api_beta_077.php");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($curl);
curl_close($curl);
if($data === false)
{
return "10000 server error";
}
$js = json_decode($data, $assoc=true);
return $js;
}
function russianpostcalc_api_calc($apikey, $password, $from_index, $to_index, $weight, $ob_cennost_rub)
{
$request = array("apikey"=>$apikey,
"method"=>"calc",
"from_index"=>$from_index,
"to_index"=>$to_index,
"weight"=>$weight,
"ob_cennost_rub"=>$ob_cennost_rub
);
if ($password != "")
{
//если пароль указан, аутентификация по методу API ключ + API пароль.
$all_to_md5 = $request;
$all_to_md5[] = $password;
$hash = md5(implode("|", $all_to_md5));
$request["hash"] = $hash;
}
$ret = _russianpostcalc_api_communicate($request);
return $ret;
}
//запрос расчета стоимости отправления из 101000 МОСКВА во ВЛАДИМИР 600000.
$ret = russianpostcalc_api_calc("API ключ", "API пароль", "101000", "600000", "1.34", "1000");
if (isset($ret['msg']['type']) && $ret['msg']['type'] == "done")
{
echo "success! codepage: UTF-8 <br/>";
print_r($ret);
echo "<br/>";
echo "успешно! кодировка: CP1251 <br/>";
echo iconv ("utf-8", "cp1251", print_r($ret, true));
}else
{
echo "error! codepage: UTF-8 <br/>";
print_r($ret);
echo "<br/>";
echo "ошибка! кодировка: CP1251 <br/>";
echo iconv ("utf-8", "cp1251", print_r($ret, true));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment