| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 | 
							- <?php
 
- /**
 
-  * 对接的是its的小包
 
-  */
 
- class Model_itsxb extends Lin_Model {
 
-     function __construct(){
 
-         parent::__construct();
 
-         $this->load->_model("Model_logic_ding",'logic_ding');
 
-     }
 
-     private $usertoken = "1ef5f2dee1084467b6e399238fa88233";
 
-     private  $apikey = "47608e3aca7c41d6af9c454cfa29fd60";
 
-     private  $appSecret ="a10ad09fdbfe4478b111894099d2ef4e";
 
-     private  $baseUrl = "http://oms.weiku.com.cn";
 
-     private  $useUrl =  "http://oms.weiku.com.cn/its-api/cs/api/";
 
-     /**
 
-      * 获取签名
 
-      */
 
-     private function getSign($requestBody,$time){
 
-         
 
-         $signStr = $this->apikey.$this->appSecret.$this->usertoken.$time.$requestBody;
 
-     
 
-         $sign = md5($signStr);
 
-     
 
-         return $sign;
 
-     }
 
-     /**
 
-      * 获取打印单数据
 
-      */
 
-     public function get_data($data){
 
-        
 
-         $url = $this->useUrl."createOrder";
 
-         $params = $this->set_params($data);
 
-         $this->logic_ding->sendToDing("3PE发货单请求的报文"."【".$data['number']."】".json_encode($params,JSON_UNESCAPED_SLASHES));
 
-         $start_time = time();
 
-         $res = $this->send($url,$params);
 
-         $this->logic_ding->sendToDing("3PE发货单返回的报文"."【".$data['number']."】".$res);
 
-         $res = json_decode($res,true);
 
-         if(!isset($res['code']) || $res['code']!= 0){
 
-             $g =array('x'=>'0','Description'=>json_encode($res ,JSON_UNESCAPED_UNICODE));
 
-             return $g;
 
-         }
 
-         $rr = $this->getLabel($res['data']['waybillNo']);
 
-         $this->logic_ding->sendToDing("3PE发货单获取返回label"."【".$data['number']."】".$rr);
 
-         $rr = json_decode($rr,true);
 
-         if(!isset($rr['code']) || $rr['code']!= 0){
 
-             $g =array('x'=>'0','Description'=>json_encode($rr ,JSON_UNESCAPED_UNICODE));
 
-             return $g;
 
-         }
 
-         $g = array('x'=>'1','waybill'=>$res['data']['deliveryNo'],'waybill2'=>'','label'=>$rr['labelUrl']);
 
-         $end_time = time();
 
-         if($g['x'] == 1){
 
- 			if( $end_time - $start_time  > 45){
 
- 				$this->logic_ding->addJobs('outtime_order',['number'=>$data['number']]);
 
- 			}
 
- 		}
 
-         return $g;
 
-         
 
-     }
 
-    
 
-     /**
 
-      * 转化数据格式
 
-      */
 
-     private function set_params($data){
 
-         //WK-EUUK-01 欧洲  WK-US-01 中美   WK-JP-01  日本
 
-         $shipper = [
 
-             'shipperName'=>"LongYing",//姓名
 
-             'shipperCountry'=>"CN",//国家二字简码
 
-             'shipperProvince'=>'HeNan',//省
 
-             'shipperCity'=>'Xuchang',//市
 
-           //  'shipperDistrict'=>'',//区
 
-             'shipperStreet'=>'Shangji Economic Development Zone',
 
-             'shipperAddress'=>'LongYingShiYe, Yinghao Rd.',//详细地址
 
-             'shipperPhone'=>'15939964739',//手机号
 
-             
 
-         ];
 
-         $address = $data['address'];
 
-         if(!empty($data['address2'])){
 
-             $address = $address." ".$data['address2'];
 
-         }
 
-         $consignee = [
 
-             'consigneeName'=>$data['name'],//姓名
 
-             'consigneeCountry'=>$data['lb'],
 
-             'consigneeProvince'=>$data['province'],
 
-             'consigneeCity'=>$data['city'],
 
-             'consigneeAddress'=>$address,
 
-             'consigneePhone'=>$data['phone'],
 
-             'consigneePostcode'=>$data['zipcode'],
 
-             'consigneeEmail'=>$data['email'],
 
-         ];
 
-         $unit_weight = $data['zzl'] / $data['ts'];
 
-         $unit_weight = sprintf("%.2f", $unit_weight);
 
-         $orderDeclareList = [
 
-             [
 
-                 'englishName'=>$data['sbpm'],//英文名称
 
-                 'chineseName'=>$data['zwpm'],
 
-                 'quantity'=>$data['ts'],
 
-                 'unitNetWeightD'=> $unit_weight,
 
-                 'unitDeclarePriceD'=>$data['dtsbjz'],
 
-             ]
 
-         ];
 
-         $packageList = [
 
-             [
 
-                 'packageLengthD'=>15,
 
-                 'packageWidthD'=>10,
 
-                 'packageHeightD'=>5,
 
-                 'packageWeightD'=>$data['zzl'],
 
-             ]
 
-         ];
 
-         $logisticsProductCode = "WK-US-01";
 
-         if($data['printcode'] == '3PE_NONBOX'){
 
-             $logisticsProductCode = "US-NONBOX";
 
-         }
 
-         $number = $data['number'];
 
-         if($data['printnumber'] > 0){
 
-             $number = $number."_".$data['printnumber'];
 
-         }
 
-         $params = [
 
-             'customerOrderNo'=>$number,
 
-             'logisticsProductCode'=>$logisticsProductCode,//中美特快专线  输方式代码/物流产品代码
 
-             'parcelType'=>11,// 10:包裹/11:PAK 袋/12:文件  包裹类型
 
-             'taxPayMode'=>11,//税金支付方式 10:DDU/11:DDP
 
-             'shipper'=>$shipper,
 
-             'consignee'=>$consignee,
 
-             'orderDeclareList'=>$orderDeclareList,
 
-             'packageList'=>$packageList,
 
-         ];
 
-         return $params;
 
-     }
 
-     public function getLabel($waybill){
 
-         $url = $this->useUrl."label";
 
-         $params = [
 
-             'mergePdf'=>1,
 
-             'nos'=>[$waybill]
 
-         ];
 
-        
 
-         
 
-         return $this->send($url,$params);
 
-         
 
-     }
 
-     /**
 
-      * 获取物流方式   这种用curl比较不友好 还是用post直接查吧
 
-      */
 
-     public function getWuliuFs(){
 
-         echo "<pre>";
 
-         $url = $this->useUrl."getLogistics";
 
-         $rr = $this->send($url,"");
 
-        
 
-        
 
-         var_dump($rr);
 
-         die;
 
-     }
 
-     public function cancel_order($number){
 
-         $url = $this->useUrl."cancelOrder";
 
-         $params = [
 
-             'customerOrderNo'=>$number,
 
-         ]; 
 
-         $res =  $this->send($url,$params);
 
-         $this->logic_ding->sendToDing("3PE发货单取消返回"."【".$number."】".json_encode($params,JSON_UNESCAPED_SLASHES));
 
-         return $res;
 
-     }
 
-     public function send($url , $params){
 
-        
 
-         $time = time();
 
-         
 
-         // 统一处理参数
 
-         $params = empty($params) ? '' : json_encode($params,JSON_UNESCAPED_SLASHES);
 
-         $signature = $this->getSign($params, $time);
 
-         
 
-         $headers = [
 
-             'apikey:'.$this->apikey,
 
-             'signature:'.$signature,  // 修正拼写
 
-             'timestamp:'.$time,
 
-             'usertoken:'.$this->usertoken,
 
-             'Content-Type:application/json;charset=UTF-8'  // 建议添加
 
-         ];
 
-         
 
-         $ch = curl_init($url);
 
-         $options = [
 
-             CURLOPT_RETURNTRANSFER => true,
 
-             CURLOPT_POST => true,
 
-             CURLOPT_POSTFIELDS => $params,
 
-             CURLOPT_HTTPHEADER => $headers,
 
-             CURLOPT_TIMEOUT => 30,  // 添加超时
 
-             CURLOPT_CONNECTTIMEOUT => 10,
 
-             // 生产环境应启用SSL验证
 
-             // CURLOPT_SSL_VERIFYPEER => true,
 
-             // CURLOPT_SSL_VERIFYHOST => 2,
 
-         ];
 
-         
 
-         curl_setopt_array($ch, $options);
 
-         $response = curl_exec($ch);
 
-         
 
-         // 检查HTTP状态码
 
-         // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
 
-         // if ($response === false || $httpCode >= 400) {
 
-         //     $error = curl_error($ch);
 
-         //     curl_close($ch);
 
-         //     return [
 
-         //         "code" => -1,
 
-         //         "msg" => $error ?: "HTTP $httpCode",
 
-         //         "http_code" => $httpCode
 
-         //     ];
 
-         // }
 
-         
 
-         curl_close($ch);
 
-         return $response;
 
-     }
 
-      /**
 
-      * 获取3pe的订单详情
 
-      */
 
-     public function getDetail($number){
 
-         $url = $this->useUrl."getOrderInfo";
 
-         
 
-         $params = [
 
-             'customerOrderNo'=>$number,
 
-         ]; 
 
-         $res =  $this->send($url,$params);
 
-         //$this->logic_ding->sendToDing("3PE发货单详情返回"."【".$number."】".$res);
 
-         return $res;
 
-     }
 
- }
 
 
  |