速達番号識別
呼び出しsearch_expressは宅配会社のjson配列に戻ります
public function search_express($nid){
$logisticResult = $this->getOrderTracesByJson($nid);
return json_decode(json_encode($logisticResult));
}
/**
* Json
*/
public function getOrderTracesByJson($nid){
$requestData= "{'LogisticCode':".$nid."}";
$datas = array(
'EBusinessID' => 1265911, // id
'RequestType' => '2002',
'RequestData' => urlencode($requestData) ,
'DataType' => '2',
);
$datas['DataSign'] = $this->encrypt($requestData,'ca2ed521-8875-4afb-88f9-566f99c68c6b');//
$result=$this->sendPost("http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx", $datas);
return $result;
}
/**
* post
* @param string $url Url
* @param array $datas
* @return url html
*/
public function sendPost($url, $datas) {
$temps = array();
foreach ($datas as $key => $value) {
$temps[] = sprintf('%s=%s', $key, $value);
}
$post_data = implode('&', $temps);
$url_info = parse_url($url);
if(empty($url_info['port']))
{
$url_info['port']=80;
}
$httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r
";
$httpheader.= "Host:" . $url_info['host'] . "\r
";
$httpheader.= "Content-Type:application/x-www-form-urlencoded\r
";
$httpheader.= "Content-Length:" . strlen($post_data) . "\r
";
$httpheader.= "Connection:close\r
\r
";
$httpheader.= $post_data;
$fd = fsockopen($url_info['host'], $url_info['port']);
fwrite($fd, $httpheader);
$gets = "";
$headerFlag = true;
while (!feof($fd)) {
if (($header = @fgets($fd)) && ($header == "\r
" || $header == "
")) {
break;
}
}
while (!feof($fd)) {
$gets.= fread($fd, 128);
}
fclose($fd);
return $gets;
}
/**
* Sign
* @param data
* @param appkey Appkey
* @return DataSign
*/
public function encrypt($data,$appkey) {
return urlencode(base64_encode(md5($data.$appkey)));
}