| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383 | 
							- <?php
 
- class Model_hualei extends Lin_Model {
 
- function __construct(){
 
- 		parent::__construct();
 
- 		$this->load->_model("Model_logic_ding",'logic_ding');
 
- }
 
- //渠道 http://123.207.33.169:8082/getProductList.htm
 
- //$ys = 1;//延时获取运单
 
-     public function get_data($data)
 
- 	{
 
- 		$duty_type = '';//区分快递承担税费人的选项   DDU或DDP  ddp好像是收件人承担税费
 
- 		if($data['printcode'] == "HUALEI-FEDEX")
 
- 		{
 
- 			$product_id = 6021;
 
- 			$link = 'param=';
 
- 			$ys = 0;//非延时获取运单
 
- 		}
 
- 		else if($data['printcode'] == "HUALEI-ARAMEX-G")
 
- 		{
 
- 			$product_id = 3361;
 
- 			$link = 'param=';
 
- 			$ys = 0;//非延时获取运单
 
- 		}
 
- 		else if($data['printcode'] == "HUALEI-ARAMEX-S")
 
- 		{
 
- 			$product_id = 8161;//南非
 
- 			$link = 'param=';
 
- 			$ys = 0;//非延时获取运单
 
- 		}
 
- 		else if ($data['printcode'] == "HUALEI-GES-EU")
 
- 		{
 
- 			$product_id = 4301;
 
- 			$link = 'param=';
 
- 			$ys = 0;//非延时获取运单
 
- 			if($data['printnumber'] > 0)
 
- 			{
 
- 				$data['number'] = $data['number'].'-'.($data['printnumber']+1);
 
- 			}
 
- 		}
 
- 		else if ($data['printcode'] == "HUALEI-WMS")//DPEX
 
- 		{
 
- 			$product_id = 5781;
 
- 			$link = 'param=';
 
- 			$ys = 0;//非延时获取运单
 
- 		}
 
- 		else if ($data['printcode'] == "HUALEI-DHL-A1")//TNT
 
- 		{
 
- 			$product_id = 7281;
 
- 			$link = 'param=';
 
- 			$ys = 0;//非延时获取运单
 
- 		}
 
- 		else if ($data['printcode'] == "HUALEI-DHL")//TNT
 
- 		{
 
- 			$product_id = 7141;
 
- 			$link = 'param=';
 
- 			$ys = 0;//
 
- 			$duty_type = "DDP";
 
- 		}
 
- 		else if($data['printcode'] == 'HUALEI-MLXY'){
 
- 			$product_id  = 7581;
 
- 			$link = 'param=';
 
- 			$ys = 0;//
 
- 			//$duty_type = "DDP";
 
- 		}else if($data['printcode'] == 'HUALEI-MGLB'){
 
- 			$product_id  = 8641;
 
- 			$link = 'param=';
 
- 			$ys = 0;//
 
- 		}
 
- 		$rs = $this->curlRequest('http://123.207.33.169:8082/selectAuth.htm',"username=LY&password=ly999");
 
- 		$reData = json_decode(str_replace("'", "\"", $rs['result']));
 
- 		$customer_id = $reData->customer_id;
 
- 		$customer_userid = $reData->customer_userid;
 
-  
 
- 		//$product_id = 4461;  //产品id 运输方式由APT给出
 
- 		$format = 'lbl_NL_XIN.frx';   //打印类型
 
- 		$printType = 1;  //打印类型
 
-  
 
- 		/**
 
- 		 * 2, 预报订单
 
- 		 */
 
- 		 if($data['ioss'] != '')//如果有IOSS
 
- 		 {
 
- 			//预报数据
 
- 			$count = Array(
 
- 				'buyerid' => '',//买家ID
 
- 				'consignee_address' => ($data['address2'] != '')?$data['address'].' '.$data['address2']:$data['address'],//地址
 
- 				'consignee_city' => $data['city'],//城市
 
- 				'consignee_mobile' => '',//收货人手机号 选填
 
- 				'consignee_name' => $data['name'],//收件人
 
- 				'trade_type' => 'ZYXT',//交易类型
 
- 				'consignee_postcode' => $data['zipcode'],//邮编
 
- 				'consignee_state' => $data['province'],//省/州
 
- 				'consignee_telephone' => $data['phone'],//收货人电话 必填
 
- 				'country' => $data['lb'],//收货人国家二字码
 
- 				'shipper_taxno' => $data['ioss'],
 
- 				'shipper_taxnotype'=>'IOSS',
 
- 				'shipper_taxnocountry' => 'NL',
 
- 				'customer_id' => $customer_id,
 
- 				'customer_userid' => $customer_userid,
 
- 				'orderInvoiceParam' => Array(
 
- 						'0' => Array
 
- 						(
 
- 								'invoice_amount' => $data['zsbjz'],
 
- 								'invoice_pcs' => $data['ts'],
 
- 								'invoice_title' => $data['sbpm'],
 
- 								'invoice_weight' => sprintf("%.3f",$data['zzl']/$data['ts']),//单条重量
 
- 								'item_id' => '',
 
- 								'item_transactionid' => '',
 
- 								'sku' => $data['zwpm'],
 
- 								'sku_code' => $data['zwpm'],
 
- 								'hs_code'=> $data['hgbm'],//海关编码
 
- 						),
 
- 				),
 
- 				'order_customerinvoicecode' => $data['number'],//原单号
 
- 				'product_id' => $product_id,
 
- 				'weight' => 0,
 
- 				'product_imagepath' => '',
 
- 				'consignee_email'=>isset($data['email'])?$data['email']:'',
 
- 				'consignee_companyname'=>$data['client'],//收件公司
 
- 				//'order_cargoamount'=>'',//订单实际金额
 
- 				//'order_insurance'=>'',//保险金额
 
- 				'duty_type'=>$duty_type,
 
- 			);
 
- 		}
 
- 		else
 
- 		{
 
- 			//预报数据
 
- 			$count = Array(
 
- 				'buyerid' => '',//买家ID
 
- 				'consignee_address' => ($data['address2'] != '')?$data['address'].' '.$data['address2']:$data['address'],//地址
 
- 				'consignee_city' => $data['city'],//城市
 
- 				'consignee_mobile' => '',//收货人手机号 选填
 
- 				'consignee_name' => $data['name'],//收件人
 
- 				'trade_type' => 'ZYXT',//交易类型
 
- 				'consignee_postcode' => $data['zipcode'],//邮编
 
- 				'consignee_state' => $data['province'],//省/州
 
- 				'consignee_telephone' => $data['phone'],//收货人电话 必填
 
- 				'country' => $data['lb'],//收货人国家二字码
 
- 				'customer_id' => $customer_id,
 
- 				'customer_userid' => $customer_userid,
 
- 				'orderInvoiceParam' => Array(
 
- 						'0' => Array
 
- 						(
 
- 								'invoice_amount' => $data['zsbjz'],
 
- 								'invoice_pcs' => $data['ts'],
 
- 								'invoice_title' => $data['sbpm'],
 
- 								'invoice_weight' => sprintf("%.3f",$data['zzl']/$data['ts']),//单条重量
 
- 								'item_id' => '',
 
- 								'item_transactionid' => '',
 
- 								'sku' => $data['zwpm'],
 
- 								'sku_code' => $data['zwpm'],
 
- 								'hs_code'=> $data['hgbm'],//海关编码
 
- 						),
 
- 				),
 
- 				'order_customerinvoicecode' => $data['number'],//原单号
 
- 				'product_id' => $product_id,
 
- 				'weight' => 0,
 
- 				'product_imagepath' => '',
 
- 				'consignee_email'=>isset($data['email'])?$data['email']:'',
 
- 				'consignee_companyname'=>$data['client'],//收件公司
 
- 				//'order_cargoamount'=>'',//订单实际金额
 
- 				//'order_insurance'=>'',//保险金额
 
- 				'duty_type'=>$duty_type,
 
- 			);
 
- 		}
 
- // 		var_dump($link);
 
- // 		var_dump(json_encode($count));
 
- 		$this->logic_ding->sendToDing("hualei发货单请求的报文".$link.json_encode($count));
 
- 		$start_time = time();
 
- 		$result = $this->curlRequest('http://123.207.33.169:8082/createOrderApi.htm',$link.json_encode($count));
 
- 		$this->logic_ding->sendToDing("hualei发货单回执的报文result".json_encode($result,JSON_UNESCAPED_UNICODE));
 
- 		
 
- 		$resultData = json_decode($result['result'], true);
 
- 		
 
- 		if(isset($resultData['message'])){
 
- 			$resultData['message'] = urldecode($resultData['message']);
 
- 		}
 
- 		$this->logic_ding->sendToDing("hualei发货单回执的报文resultData".json_encode($resultData,JSON_UNESCAPED_UNICODE));
 
- 		if($resultData['ack'] == 'true')
 
- 		{
 
- 			//if($resultData['tracking_number'] == $resultData['reference_number'])
 
- 			if($ys == 1)
 
- 			{
 
- 				$g = array('x'=>'1','ys'=>1,'waybill'=>'');
 
- 			}
 
- 			else
 
- 			{
 
- 				$pdf = $this->get_pdf($resultData['order_id']);
 
- 				if($pdf['x'] == 1)
 
- 				{
 
- 					if($product_id == 4361)
 
- 					{
 
- 					    $g = array('x'=>'1','ys'=>0,'waybill'=>$resultData['order_privatecode'],'waybill2'=>$resultData['tracking_number'],'label'=>$pdf['label']);
 
- 					}
 
- 					else
 
- 					{
 
- 						$g = array('x'=>'1','ys'=>0,'waybill'=>$resultData['tracking_number'],'label'=>$pdf['label']);
 
- 					}
 
- 				}
 
- 				else
 
- 				{
 
- 					$g = array('x'=>'0','Description'=>json_encode($pdf,JSON_UNESCAPED_UNICODE));
 
- 				}
 
- 			}
 
- 		}
 
- 		else
 
- 		{
 
- 			$resultData['message'] = urldecode($resultData['message']);
 
- 			$g = array('x'=>'0','Description'=>json_encode($resultData ,JSON_UNESCAPED_UNICODE));
 
- 		}
 
- 		$end_time = time();
 
- 		if($g['x'] == 1){
 
- 			if( $end_time - $start_time  > 45){
 
- 				$this->logic_ding->addJobs('outtime_order',['number'=>$data['number']]);
 
- 			}
 
- 		}
 
- 		
 
- 		$this->logic_ding->sendToDing("hualei发货单回执的pdf报文".json_encode($g,JSON_UNESCAPED_UNICODE));
 
- 		return $g;exit;
 
- 	}
 
- 	
 
- 	public function curlRequest($url,$czdata = '') 
 
- 	{
 
- 		$return = array('state' => 0, 'message' => '', 'result' => '', 'errNo' => 0);
 
- 		try 
 
- 		{
 
- 			$ch = curl_init($url);
 
- 			curl_setopt($ch, CURLOPT_URL, $url);
 
- 			curl_setopt($ch, CURLOPT_POST, 1);
 
- 			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/x-www-form-urlencoded;charset=UTF-8'));
 
- 			curl_setopt($ch, CURLOPT_POSTFIELDS, $czdata);
 
- 			//设置超时时间
 
- 			curl_setopt($ch, CURLOPT_TIMEOUT, 120);
 
- 			//API返回数据
 
- 			$apiResult = curl_exec($ch);
 
- 			$errNo = curl_errno($ch);
 
- 			if ($errNo)
 
- 			{
 
- 				//返回错误码
 
- 				$return['errNo'] = $errNo;
 
- 				$errorStr = curl_error($ch);
 
- 				switch ((int)$errNo)
 
- 				{
 
- 				    case 6: //避免一直发邮件 URL报错
 
- 					break;
 
- 				    case 7: //无法通过 connect() 连接至主机或代理服务器
 
- 					break;
 
- 				    case 28: //超时
 
- 					break;
 
- 				    case 56: //接收网络数据失败
 
- 					break;
 
- 				    default:
 
- 					break;
 
- 			    }
 
- 			    throw new Exception($errorStr);
 
- 		    }
 
- 		    curl_close($ch);
 
- 		    $return['state'] = 1;
 
- 		    //返回数据
 
- 		    $return['result'] = $apiResult;
 
- 	    } 
 
- 		catch (Exception $e) 
 
- 		{
 
- 		    $return['state'] = 0;
 
- 		    $return['message'] = $e->getMessage();
 
- 	    }
 
- 	    return $return;
 
- 	}
 
- 	
 
- 	public function get_hqwaybill($number)
 
- 	{
 
- 	   $ch = curl_init();
 
-         curl_setopt($ch, CURLOPT_URL, 'http://123.207.33.169:8082/getOrderTrackingNumber.htm?documentCode='.$number);
 
-         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
- 		curl_setopt($ch, CURLOPT_HTTPGET, true);
 
-         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
 
-         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 
-         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
 
-         $res = curl_exec($ch);
 
-         curl_close($ch);
 
- 		$res = json_decode($res,true);
 
- 		if(isset($res['childno'][0]))
 
- 		{
 
- 			$g = array('x'=>'1','ys'=>0,'waybill'=>$res['order_serveinvoicecode']);
 
- 		}
 
- 		else
 
- 		{
 
- 			$g = array('x'=>'0','Description'=>$res['msg']);
 
- 		}
 
- 		return $g;
 
- 	}
 
- 	
 
- 	public function get_pdf($orderid)
 
- 	{
 
- 	    $ch = curl_init("http://123.207.33.169:8089/order/FastRpt/PDF_NEW.aspx?PrintType=lab10_10&order_id=".$orderid);
 
-         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 
-         curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
 
-         curl_setopt($ch, CURLOPT_NOBODY, 1);
 
-         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
-         curl_setopt($ch, CURLOPT_HEADER, 1);
 
-         curl_exec($ch);
 
-         $res = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
 
- 		curl_close($ch);
 
- 		if(stripos($res,'.pdf') !== false)
 
- 		{
 
- 			$g = array('x'=>'1','label'=>$res);
 
- 		}
 
- 		else
 
- 		{
 
- 			$g = array('x'=>'0','Description'=>"获取运单失败,请重试");
 
- 		}
 
- 		return $g;
 
- 	}
 
- 	
 
- 	public function get_manifest($fullorder) //生成发货清单
 
- 	{
 
- 	   
 
- 	}
 
- 	
 
- 	public function get_logistics($number)//追踪快递
 
- 	{
 
- 		
 
- 	}
 
- 	//http://123.207.33.169:8089/order/FastRpt/PDF_NEW.aspx?Format=lbl_NL_XIN.frx&PrintType=lab10_10&order_id=5456516打印
 
- 	
 
- 	/**
 
- 	 * 获取华磊的抓单号
 
- 	 */
 
- 	public function getDetail($number_str){
 
- 		$url = "http://123.207.33.169:8082/logistics/api";
 
- 		$ch = curl_init($url);
 
- 		$headers = [
 
- 			'auth'=>'FACFD061CAEC49D048AD9158084D6669',
 
- 			'Content-Type:application/json;charset=UTF-8' ,
 
- 		];
 
- 		$params = [
 
- 			'method'=>"order.selectorderandchildbycode",
 
- 			'content'=>[
 
- 				'order_customerinvoicecode'=>$number_str,
 
- 			]
 
- 		];
 
- 		$params = json_encode($params);
 
-         $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;
 
- 	}
 
- }  //end class
 
 
  |