|
Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/kamariallee.com/public_html/application/helpers/ |
Upload File : |
<?php
function get_rajaongkir_data($uri) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://pro.rajaongkir.com/api/' . $uri,
CURLOPT_RETURNTRANSFER => true, //not to print result, but return curl_exec as string, not as true/false
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10, // The maximum amount of HTTP redirections to follow. Use this option alongside CURLOPT_FOLLOWLOCATION.
CURLOPT_TIMEOUT => 30, //tell the script how long to wait to receive a completely buffered output from the server
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
'key: 29b58cf87972eb123e184225147ce577'
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
return json_decode($response, true); //true means dcode json to array.
}
}
function get_rajaongkir_ongkos($origin_subdistrict_id, $destination_subdistrict_id, $weight, $courier) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'http://pro.rajaongkir.com/api/cost',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => 'origin=' . $origin_subdistrict_id . '&originType=subdistrict&destination=' . $destination_subdistrict_id . '&destinationType=subdistrict&weight=' . $weight . '&courier=' . $courier,
CURLOPT_HTTPHEADER => array(
"content-type: application/x-www-form-urlencoded",
"key: 29b58cf87972eb123e184225147ce577"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
return json_decode($response, true);
}
}
function get_rajaongkir_ongkos_overseas($origin_city_id, $destination_country_id, $weight) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://pro.rajaongkir.com/api/v2/internationalCost",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => 'origin=' . $origin_city_id . '&destination=' . $destination_country_id . '&weight=' . $weight . '&courier=tiki',
CURLOPT_HTTPHEADER => array(
"content-type: application/x-www-form-urlencoded",
"key: 29b58cf87972eb123e184225147ce577"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
return json_decode($response, true);
}
}