Kaskus

Tech

bachorsAvatar border
TS
bachors
Begini cara cURL ongkir JNE dan TIKI menggunakan PHP
Simple fungtion untuk mengambil ongkir Tiki dan JNE langsung melalui web tiki-online.com dan jne.co.id dengan menggunakan PHP cURL dan librarie simple html dom.

1. cURL ongkir TIKI
Code:
function tiki($dari,$ke,$kg,$user_agent){
$ch = curl_init();
$url="http://www.tiki-online.com/?cat=KgfdshfF7788KHfskF";
$post = "&get_ori=$dari&get_des=$ke&get_wg=$kg&submit=Check";
curl_setopt( $ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post );
$site = curl_exec( $ch );
return ongkos_tiki($site);
}
function ongkos_tiki($site){
// include simple html dom
require("lib/simple_html_dom.php");
$html = str_get_html($site);
$table = $html->find('table[cellpadding=4]',0);
return $table;
}


2. cURL ongkir JNE
Code:
function jne($dari,$ke,$kg,$user_agent){
$json_dari = "http://www.jne.co.id/server/server_city_from.php?term=$dari";
$json_daric = file_get_contents($json_dari);
$hasil_dari = json_decode($json_daric);

$json_ke = "http://www.jne.co.id/server/server_city.php?term=$ke";
$json_kec = file_get_contents($json_ke);
$hasil_ke = json_decode($json_kec);

$daric = $hasil_dari[0]->code;
$darib = $hasil_dari[0]->label;
$kec = $hasil_ke[0]->code;
$keb = $hasil_ke[0]->label;
$ch = curl_init();
$url="http://www.jne.co.id/getDetailFare.php";
$post = "origin=$daric&dest=$kec&weight=$kg&originlabel=$darib&destlabel=$keb";
curl_setopt( $ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post );
$site = curl_exec( $ch );
return $site;
}


Cara memanggil fungsi.y
Code:
$dari = 'bandung';
$ke = 'surabaya';
$berat = 4;

$user_agent = "Googlebot/2.1 (http://www.googlebot.com/bot.html)";

// menampilkan ongkir TIKI
echo tiki($dari,$ke,$berat,$user_agent);

// menampilkan ongkir JNE
echo jne($dari,$ke,$berat,$user_agent);


Untuk demonya bisa lihat disiniemoticon-Betty (S)
0
5.1K
14
GuestAvatar border
Komentar yang asik ya
Urutan
Terbaru
Terlama
GuestAvatar border
Komentar yang asik ya
Komunitas Pilihan