| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 | <?phpclass Model_Dhl extends Lin_Model {function __construct(){		parent::__construct();}	public function get_data($data)	{		if($data['pay'] == 1)		{			$data['pay'] == 'PayPal';		}		else if($data['pay'] == 2)		{			$data['pay'] == 'Western Union';		}		else if($data['pay'] == 3)		{			$data['pay'] == '微信';		}		else if($data['pay'] == 4)		{			$data['pay'] == '支付宝';		}		else if($data['pay'] == 5)		{			$data['pay'] == '银行转账';		}		else if($data['pay'] == 6)		{			$data['pay'] == '现金收款';		}		else if($data['pay'] == 7)		{			$data['pay'] == 'PingPong金融';		}		$id = 'XUCHANGLONGY';		$pass = 'dJ84as3ELr';		$sid = '603521441';		$xmend = "\n";		$Pieces = '';		for($i=0;$i<$data['zjs'];$i++)		{		    $Pieces .= "<Piece>".$xmend;		    $Pieces .= "<PieceID>".($i+1)."</PieceID>".$xmend;		    $Pieces .= "<PackageType>EE</PackageType>".$xmend;			$Pieces .= "</Piece>".$xmend;		}		/**  此内容是添加发票信息		$dataadress = array();$baddress = '';$ba1 = '';$ba2 = '';		for($i=5;$i<count($data['baddress']);$i++)		{			$dataadress[] = $data['baddress'][$i];		}				if(count($dataadress) > 1)		{			for($i=0;$i<count($dataadress);$i++)		    {				if($i < 2)				{					$ba1 .= $dataadress[$i].',';				}				else				{					$ba2 .= $dataadress[$i].',';				}			}				$baddress .= "<BillToAddressLine>".rtrim($ba1,',')."</BillToAddressLine>".$xmend;				$baddress .= "<BillToAddressLine>".rtrim($ba2,',')."</BillToAddressLine>".$xmend;		}		else		{			for($i=0;$i<count($dataadress);$i++)		    {				$ba1 .= $dataadress[$i].',';		    }			$baddress .= "<BillToAddressLine>".rtrim($ba1,',')."</BillToAddressLine>".$xmend;		}		**/		$xml = "";		$xml .= "<?xml version='1.0' encoding='UTF-8'?>".$xmend;        $xml .= "<req:ShipmentRequest schemaVersion='6.2' xmlns:req='http://www.dhl.com' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.dhl.com ship-val-global-req-6.2.xsd'>".$xmend;		$xml .= "<Request>".$xmend;		$xml .= "<ServiceHeader>".$xmend;		$xml .= "<MessageTime>".date('c')."</MessageTime>".$xmend;		$xml .= "<MessageReference>".time().$data['orderinfo'].rand(10000000,99999999)."</MessageReference>".$xmend;		$xml .= "<SiteID>".$id."</SiteID>".$xmend;//DHL账号		$xml .= "<Password>".$pass."</Password>".$xmend;//DHL密码		$xml .= "</ServiceHeader>".$xmend;		$xml .= "<MetaData>".$xmend;		$xml .= "<SoftwareName>LongYi ERP</SoftwareName>".$xmend;		$xml .= "<SoftwareVersion>V1.0.0</SoftwareVersion>".$xmend;		$xml .= "</MetaData>".$xmend;		$xml .= "</Request>".$xmend;		$xml .= "<RegionCode>AP</RegionCode>".$xmend;//地区代码		$xml .= "<LanguageCode>en</LanguageCode>".$xmend;//语言		$xml .= "<PiecesEnabled>Y</PiecesEnabled>".$xmend;		$xml .= "<Billing>".$xmend;		$xml .= "<ShipperAccountNumber>".$sid."</ShipperAccountNumber>".$xmend;		$xml .= "<ShippingPaymentType>S</ShippingPaymentType>".$xmend;		$xml .= "<BillingAccountNumber>".$sid."</BillingAccountNumber>".$xmend;		$xml .= "<DutyPaymentType>R</DutyPaymentType>".$xmend;//R为收件人付关税 S发件人付关税		$xml .= "</Billing>".$xmend;		$xml .= "<Consignee>".$xmend;		$xml .= "<CompanyName>".$data['name']."</CompanyName>".$xmend;//收货人名称		if(strlen($data['address'].$data['address2']) > 44)		{			$adl = $data['address'].$data['address2'];			$adl1 = substr($adl,0,44);//截取44字符前内容			$adlnum = strripos($adl1," ");//查找最后一次出现空格位置			$adl1 = substr($adl,0,$adlnum);//0到空格前之间的内容			$adl2 = substr($adl,$adlnum+1,strlen($adl));//空格后到最后的内容			$xml .= "<AddressLine>".$adl1."</AddressLine>".$xmend;//收货人地址1			$xml .= "<AddressLine>".$adl2."</AddressLine>".$xmend;//收货人地址2		}		else		{		    $xml .= "<AddressLine>".$data['address'].$data['address2']."</AddressLine>".$xmend;//收货人地址		}		if($data['street'] != '')		{		    $xml .= "<AddressLine>".$data['street']."</AddressLine>".$xmend;//收货人街道		}		$xml .= "<City>".$data['city']."</City>".$xmend;//城市		if($data['lb'] == 'US')		{			$xml .= "<DivisionCode>".$data['province']."</DivisionCode>".$xmend;//州代码,仅美国		}		$xml .= "<PostalCode>".trim($data['zipcode'],' ')."</PostalCode>".$xmend;//邮编		$xml .= "<CountryCode>".$data['lb']."</CountryCode>".$xmend;//国家代码		$xml .= "<CountryName>".$data['country']."</CountryName>".$xmend;//国家名称		$xml .= "<Contact>".$xmend;		$xml .= "<PersonName>".$data['client']."</PersonName>".$xmend;//名称		$xml .= "<PhoneNumber>".preg_replace('/\D/s','',$data['phone'])."</PhoneNumber>".$xmend;//联系方式		//$xml .= "<Email>".$data['email']."</Email>".$xmend;//联系邮箱		$xml .= "</Contact>".$xmend;		$xml .= "</Consignee>".$xmend;		$xml .= "<Commodity>".$xmend;//多商品循环此外层标签及内层标签		$xml .= "<CommodityCode>".$data['sbbm']."</CommodityCode>".$xmend;//商品编码		$xml .= "<CommodityName>".$data['sbpm']."</CommodityName>".$xmend;//商品名称		$xml .= "</Commodity>".$xmend;		$xml .= "<Dutiable>".$xmend;		$xml .= "<DeclaredValue>".$data['zsbjz']."</DeclaredValue>".$xmend;//申报价值		$xml .= "<DeclaredCurrency>".$data['currencytitle']."</DeclaredCurrency>".$xmend;//货币代码		$xml .= "</Dutiable>".$xmend;		/** 发票信息开始 **/		$xml .= "<UseDHLInvoice>Y</UseDHLInvoice>".$xmend;	    $xml .= "<DHLInvoiceLanguageCode>en</DHLInvoiceLanguageCode>".$xmend;	    $xml .= "<DHLInvoiceType>CMI</DHLInvoiceType>".$xmend;	    $xml .= "<ExportDeclaration>".$xmend;		$xml .= "<ExportReasonCode>P</ExportReasonCode>".$xmend;		$xml .= "<InvoiceNumber>".$data['paypal'].' '.$data['pay']."</InvoiceNumber>".$xmend;		$xml .= "<InvoiceDate>".date('Y-m-d',time())."</InvoiceDate>".$xmend;		/**		$xml .= "<BillToCompanyName>".$data['client']."</BillToCompanyName>".$xmend;		$xml .= "<BillToContanctName>".$data['client']."</BillToContanctName>".$xmend;//账单名称		$xml .= $baddress;//地址		$xml .= "<BillToCity>".$data['baddress'][4]."</BillToCity>".$xmend;//城市		$xml .= "<BillToPostcode>".$data['baddress'][2]."</BillToPostcode>".$xmend;//邮编		$xml .= "<BillToSuburb/>".$xmend;//所在郊区		if($data['baddress'][1] == 'United States')		{			$xml .= "<BillToState>".$data['baddress'][3]."</BillToState>".$xmend;//省、州		}		$xml .= "<BillToCountryName>".$data['baddress'][1]."</BillToCountryName>".$xmend;//国家		$xml .= "<BillToPhoneNumber>".preg_replace('/\D/s','',$data['baddress'][0])."</BillToPhoneNumber>".$xmend;//号码		**/		$xml .= "<ExportLineItem>".$xmend;		$xml .= "<LineNumber>1</LineNumber>".$xmend;//顺序号		$xml .= "<Quantity>".$data['ts']."</Quantity>".$xmend;//数量		$xml .= "<QuantityUnit>PCS</QuantityUnit>".$xmend;//单位		$xml .= "<Description>".$data['sbpm']."</Description>".$xmend;//品名		$xml .= "<Value>".$data['dtsbjz']."</Value>".$xmend;//单价		$xml .= "<IsDomestic>Y</IsDomestic>".$xmend;//是否国产,Y本国,N国外		$xml .= "<CommodityCode>".$data['sbbm']."</CommodityCode>".$xmend;//品名编码		$xml .= "<Weight>".$xmend;		$xml .= "<Weight>".$data['zzl']."</Weight>".$xmend;//净重		$xml .= "<WeightUnit>K</WeightUnit>".$xmend;//重量单位,K千克		$xml .= "</Weight>".$xmend;		$xml .= "<GrossWeight>".$xmend;		$xml .= "<Weight>".$data['zzl']."</Weight>".$xmend;//毛重		$xml .= "<WeightUnit>K</WeightUnit>".$xmend;//毛重单位,K千克		$xml .= "</GrossWeight>".$xmend;		$xml .= "<ManufactureCountryName>CN</ManufactureCountryName>".$xmend;//原产国名称		$xml .= "</ExportLineItem>".$xmend;	    $xml .= "</ExportDeclaration>".$xmend;		/** 发票信息结束 **/		$xml .= "<Reference>".$xmend;		$xml .= "<ReferenceID>".$data['number']."</ReferenceID>".$xmend;		$xml .= "</Reference>".$xmend;		$xml .= "<ShipmentDetails>".$xmend;		$xml .= "<NumberOfPieces>".$data['zjs']."</NumberOfPieces>".$xmend;		$xml .= "<Pieces>".$xmend;		$xml .= $Pieces;		$xml .= "</Pieces>".$xmend;		$xml .= "<Weight>".$data['zzl']."</Weight>".$xmend;		$xml .= "<WeightUnit>K</WeightUnit>".$xmend;		$xml .= "<GlobalProductCode>P</GlobalProductCode>".$xmend;		$xml .= "<LocalProductCode>P</LocalProductCode>".$xmend;		$xml .= "<Date>".date('Y-m-d',time())."</Date>".$xmend;		$xml .= "<Contents>".$data['sbpm']."</Contents>".$xmend;//内容		$xml .= "<DoorTo>DD</DoorTo>".$xmend;		$xml .= "<DimensionUnit>C</DimensionUnit>".$xmend;		$xml .= "<InsuredAmount>".$data['bx']."</InsuredAmount>".$xmend;//保险金额		$xml .= "<PackageType>EE</PackageType>".$xmend;		$xml .= "<IsDutiable>Y</IsDutiable>".$xmend;		$xml .= "<CurrencyCode>".$data['currencytitle']."</CurrencyCode>".$xmend;//货币代码		$xml .= "</ShipmentDetails>".$xmend;		$xml .= "<Shipper>".$xmend;		$xml .= "<ShipperID>".$sid."</ShipperID>".$xmend;		$xml .= "<CompanyName>".$data['warehouse']['company']."</CompanyName>".$xmend;//发货公司名称		$xml .= "<AddressLine>".$data['warehouse']['address']."</AddressLine>".$xmend;//发货地址		$xml .= "<AddressLine>".$data['warehouse']['address2']."</AddressLine>".$xmend;//发货地址		$xml .= "<AddressLine>".$data['warehouse']['province']."</AddressLine>".$xmend;//发货省、州		$xml .= "<City>".$data['warehouse']['city']."</City>".$xmend;//发货城市		$xml .= "<PostalCode>".$data['warehouse']['zipcode']."</PostalCode>".$xmend;		$xml .= "<CountryCode>".$data['warehouse']['lb']."</CountryCode>".$xmend;//发货国家代码		$xml .= "<CountryName>".$data['warehouse']['country']."</CountryName>".$xmend;//发货国家名称		$xml .= "<Contact>".$xmend;		$xml .= "<PersonName>".$data['warehouse']['company']."</PersonName>".$xmend;//发货人名称		$xml .= "<PhoneNumber>".preg_replace('/\D/s','',$data['warehouse']['phone'])."</PhoneNumber>".$xmend;//发货人电话		$xml .= "</Contact>".$xmend;	    $xml .= "</Shipper>".$xmend;		/** 无纸化 PLT 开始 **/		$xml .= "<SpecialService>".$xmend;		$xml .= "<SpecialServiceType>WY</SpecialServiceType>".$xmend;		$xml .= "</SpecialService>".$xmend;		/** 无纸化 PLT 结束 **/		if($data['bx'] > 0)		{		    $xml .= "<SpecialService>".$xmend;		    $xml .= "<SpecialServiceType>II</SpecialServiceType>".$xmend;		    $xml .= "</SpecialService>".$xmend;		}	    $xml .= "<LabelImageFormat>PDF</LabelImageFormat>".$xmend;		/** 无纸化 PLT 启用这个 **/		$xml .= "<RequestArchiveDoc>N</RequestArchiveDoc>".$xmend;		/** 无纸化 PLT 启用这个 **/		/** 无纸化 PLT 关闭这个		$xml .= "<RequestArchiveDoc>Y</RequestArchiveDoc>".$xmend;        $xml .= "<NumberOfArchiveDoc>1</NumberOfArchiveDoc>".$xmend;		**/		$xml .= "<Label>".$xmend;		$xml .= "<HideAccount>N</HideAccount>".$xmend;		$xml .= "<LabelTemplate>8X4_PDF</LabelTemplate>".$xmend;		$xml .= "<Resolution>200</Resolution>".$xmend;	    $xml .= "</Label>".$xmend;        $xml .= "</req:ShipmentRequest>".$xmend;		$ch = curl_init(); 		curl_setopt($ch, CURLOPT_URL,'https://xmlpi-ea.dhl.com/XMLShippingServlet'); 		curl_setopt($ch, CURLOPT_POST, 1);		curl_setopt($ch, CURLOPT_HEADER, 0);		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);		curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);		curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);		$data = curl_exec($ch);		curl_close($ch);		$data = utf8_encode($data);        libxml_disable_entity_loader(true);        @$values = json_decode(json_encode(simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA)), true);		return $values;	}}  //end class
 |