123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- <?php
- class Model_Dpd extends Lin_Model {
- function __construct(){
- parent::__construct();
- }
- public function get_data($data)
- {
- if($data['printcode'] == 'DPD')
- {
- $PtId = 'ESBRM';
- }
- else if($data['printcode'] == 'FTFEDEX')
- {
- $PtId = 'FEDEX-EU';
- }
- $ItemId = time().rand(10,99);
- $url = "http://exorderwebapi.flytcloud.com/api/OrderSyn/ErpUploadOrder";
- $UAccount = '37014';
- $Password = strtoupper(md5('921657'));
- $Token = '39F63970-CA4C-D919-636A-6F703FD55D82';
- //创建并预报订单
- $json = array(
- 'Token' => $Token,
- 'UAccount'=>$UAccount,
- 'Password'=>$Password,
- 'OrderList' => array(
- 0 => array(
- 'Address1' => $data['address'],
- 'Address2' => $data['address2'],
- 'ApiOrderId' => $data['number'],
- 'City' => $data['city'],
- 'CiId' => $data['lb'],
- 'County' => $data['province'],
- 'PackType' => 3,//包装类型(1:信封,2:文件,3:包裹)(默认包裹)
- 'Phone'=>$data['phone'],
- 'PtId' => $PtId,//邮政方式简码
- 'ReceiverName' => $data['name'],
- 'Remark'=> $data['number'],
- 'SalesPlatformFlag' => 0,
- 'SyncPlatformFlag' => 'flyt.logistics.longying',//第三平台标识
- 'Zip' => trim($data['zipcode'],' '),
- 'OrderDetailList' => array(0=>array(
- 'ItemName'=>$data['sbpm'],
- 'OriginalPlatformOrderId'=>$data['orderinfo'],
- 'Price'=>$data['dtsbjz'],
- 'Quantities'=>$data['ts']
- )
- ),
- 'HaikwanDetialList' => array(0=>array(
- 'HwCode'=>'67041100',
- 'ItemCnName'=>$data['zwpm'],
- 'ItemEnName'=>$data['sbpm'],
- 'ProducingArea'=>'CN',
- 'Quantities'=>$data['ts'],
- 'UnitPrice'=>$data['dtsbjz'],
- 'Weight'=>$data['zzl'],
- 'CCode'=>'USD',
- )
- )
- )
- )
- );
-
- $json = json_encode($json,true);
-
- $ch = curl_init();
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Accept-Language: zh-cn',
- 'Connection: Keep-Alive',
- 'Cache-Control: no-cache',
- 'Content-type: application/json;charset=UTF-8'));
- curl_setopt($ch,CURLOPT_POST, 1);
- curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
- curl_setopt($ch, CURLOPT_POSTFIELDS,$json);
- $res = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($res,true);
- if(!isset($res['ErpSuccessOrders'][0]['TraceId']) && !isset($res['ErpSuccessOrders'][0]['OrderId']))
- {
- $g = array('x'=>'0','Description'=>$res['Remark'].':'.$res['ErpFailOrders'][0]['Remark'],'res'=>json_encode(array($res),true));
- }
- else
- {
- if(!$res['ErpSuccessOrders'][0]['TraceId'])
- {
- for($i=0;$i<20;$i++)
- {
- sleep(6);
- $ch = curl_init();
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Accept-Language: zh-cn',
- 'Connection: Keep-Alive',
- 'Cache-Control: no-cache',
- 'Content-type: application/json;charset=UTF-8'));
- curl_setopt($ch,CURLOPT_POST, 1);
- curl_setopt($ch,CURLOPT_TIMEOUT,5);
- curl_setopt($ch, CURLOPT_POSTFIELDS,$json);
- $res = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($res,true);
- if($res['ErpSuccessOrders'][0]['TraceId'] != '' || $res['ErpSuccessOrders'][0]['TraceId'] != 'null' || $res['ErpSuccessOrders'][0]['TraceId'] != NULL)
- {
- break;
- }
- }
- }
- /**
- //判断是否有运单
- $yd = $this->get_yd($res['ErpSuccessOrders'][0]['TraceId']);
- if($yd[0] != '2')
- {
- $g = array('x'=>'1','waybill'=>$res['ErpSuccessOrders'][0]['TraceId'],'yd'=>$yd[1],'res'=>json_encode(array($res,$yd),true));
- }
- else
- {
- $g = array('x'=>'0','Description'=>$yd[1],'res'=>json_encode(array($res,$yd),true));
- }
- **/
- if($res['Success'] == 'true')
- {
- $g = array('x'=>'1','waybill'=>$res['ErpSuccessOrders'][0]['TraceId'],'yd'=>'','res'=>json_encode(array($res),true));
- }
- else
- {
- $g = array('x'=>'0','Description'=>$yd[1],'res'=>json_encode(array($res,$yd),true));
- }
- }
- return $g;
-
- }
-
- public function get_token()
- {
- $url = "http://exapi.flytcloud.com/api/auth/Authorization/GetAccessToken";
- $grant_type = 'password';
- $username = 'longying';
- $password = md5('ljygt&0IP!');
-
- //创建并预报订单
- $json = array(
- 'grant_type' => $grant_type,
- 'username' => $username,
- 'password' => $password,
- );
-
- $json = json_encode($json,true);
-
- $ch = curl_init();
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Accept-Language: zh-cn',
- 'Connection: Keep-Alive',
- 'Cache-Control: no-cache',
- 'Content-type: application/json;charset=UTF-8'));
- curl_setopt($ch,CURLOPT_POST, 1);
- curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
- curl_setopt($ch, CURLOPT_POSTFIELDS,$json);
- $res = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($res,true);
- return $res;
- }
-
- public function get_yd($data)
- {
- $path = $_SERVER["DOCUMENT_ROOT"] . '/data/dpd_access_token.txt';
- $access_token = '';
- if(file_exists($path))
- {
- $file_read = fopen($path, 'r');
- $access_str = fgets($file_read);
- fclose($file_read);
- $access_arr = explode(':', $access_str);
- if (time() < intval($access_arr[0]))
- {
- $access_token = isset($access_arr[1]) ? $access_arr[1] : '';
- }
- }
- if(!$access_token)
- {
- $file = fopen($path, 'w');
- $info = $this->get_token();
- if(!$info['expires_in'])
- {
- return array(2,'令牌获取错误,请重试!');exit;
- }
- $access_new = (time() + $info['expires_in']) . ':' . $info['access_token'];
- fwrite($file, $access_new);
- fclose($file);
- $access_token = $info['access_token'];
- }
- $url = "http://exapi.flytcloud.com/api/label/LabelProvider/GetLabelBatchExt";
- $Token = $access_token;
-
- //创建并预报订单
- $json = array(
- 'OrderIdlst' => array($data),
- 'Format' => '0'
- );
-
- $json = json_encode($json,true);
-
- $ch = curl_init();
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'token:'.$Token,
- 'Content-type: application/json;charset=UTF-8'));
- curl_setopt($ch,CURLOPT_POST, 1);
- curl_setopt($ch,CURLOPT_TIMEOUT,3);
- curl_setopt($ch, CURLOPT_POSTFIELDS,$json);
- $res = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($res,true);
- if(isset($res['Data']['Label']))
- {
- return array(1,$res['Data']['Label']);exit;
- }
- else
- {
- return array(2,$res['ErrMsg']);exit;
- }
- }
-
- public function get_logistics($waybill)
- {
- $url = "http://tracking.flytcloud.com/Trackingod/TrackOrder";
- $Token = '119904B54744499F9C7A29A84C2C7051';
-
- //创建并预报订单
- $json = array(
- 'key' => $Token,
- 'tracking_number' => $waybill,
- );
-
- $json = json_encode($json,true);
-
- $ch = curl_init();
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Accept-Language: zh-cn',
- 'Connection: Keep-Alive',
- 'Cache-Control: no-cache',
- 'Content-type: application/json;charset=UTF-8'));
- curl_setopt($ch,CURLOPT_POST, 1);
- curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
- curl_setopt($ch, CURLOPT_POSTFIELDS,$json);
- $res = curl_exec($ch);
- curl_close($ch);
- $res = json_decode($res,true);
- $list = '';
- if(isset($res['dat']['0']['track']['z1'][0]['trackingStatus']))
- {
- if($res['dat']['0']['track']['e'] > '0')
- {
- $zt = $res['dat']['0']['track']['e'];
- if($zt >= '2' && $zt< '10')
- {
- $exstate = 1;
- }
- else if($zt >= '10' && $zt < '30')
- {
- $exstate = 2;
- }
- else if($zt >= '30' && $zt < '40')
- {
- $exstate = 3;
- }
- else if($zt == '40' || $zt == '41')
- {
- $exstate = 4;
- }
- else
- {
- $exstate = 0;
- }
- if($se)
- {
- $list = array('f'=>2);
- }
- else
- {
- foreach($res['dat']['0']['track']['z1'] as $v)
- {
- $xq .= date('m-d H:i',strtotime($v['a'])).' '.$v['z'].'<br />';
- }
- $content = date('Y-m-d H',time()).'-查询成功';
- $list = array('exstate'=>$exstate,'content'=>$content,'f'=>1,'data'=>$xq);//正常可发送站内信
- }
- }
- else
- {
- $list = '';
- }
- }
- return $res;
- }
-
- } //end class
|