Model_dhlhz.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. <?php
  2. //申请DHL用
  3. class Model_Dhlhz extends Lin_Model {
  4. function __construct(){
  5. parent::__construct();
  6. }
  7. public function get_data($data)//20210323升级新版API
  8. {
  9. if($data['pay'] == 1)
  10. {
  11. $data['pay'] == 'PayPal';
  12. }
  13. else if($data['pay'] == 2)
  14. {
  15. $data['pay'] == 'Western Union';
  16. }
  17. else if($data['pay'] == 3)
  18. {
  19. $data['pay'] == '微信';
  20. }
  21. else if($data['pay'] == 4)
  22. {
  23. $data['pay'] == '支付宝';
  24. }
  25. else if($data['pay'] == 5)
  26. {
  27. $data['pay'] == '银行转账';
  28. }
  29. else if($data['pay'] == 6)
  30. {
  31. $data['pay'] == '现金收款';
  32. }
  33. else if($data['pay'] == 7)
  34. {
  35. $data['pay'] == 'PingPong金融';
  36. }
  37. $ToState = array('alabama'=>'AL','alaska'=>'AK','arizona'=>'AZ','arkansas'=>'AR','california'=>'CA','colorado'=>'CO','connecticut'=>'CT','delaware'=>'DE','florida'=>'FL','georgia'=>'GA','hawaii'=>'HI','idaho'=>'ID','illinois'=>'IL','indiana'=>'IN','iowa'=>'IA','kansas'=>'KS','kentucky'=>'KY','louisiana'=>'LA','maine'=>'ME','maryland'=>'MD','massachusetts'=>'MA','michigan'=>'MI','minnesota'=>'MN','mississippi'=>'MS','missouri'=>'MO','montana'=>'MT','nebraska'=>'NE','nevada'=>'NV','new hampshire'=>'NH','new jersey'=>'NJ','new mexico'=>'NM','new york'=>'NY','north carolina'=>'NC','north dakota'=>'ND','ohio'=>'OH','oklahoma'=>'OK','oregon'=>'OR','pennsylvania'=>'PA','rhode island'=>'RI','south carolina'=>'SC','south dakota'=>'SD','tennessee'=>'TN','texas'=>'TX','utah'=>'UT','vermont'=>'VT','virginia'=>'VA','washington'=>'WA','west virginia'=>'WV','wisconsin'=>'WI','wyoming'=>'WY','district of columbia'=>'DC','virgin islands'=>'VI','puerto rico'=>'PR');
  38. $data['province'] = preg_replace('/( | | |\s)/',' ',$data['province']);
  39. $data['province'] = trim($data['province'],' ');
  40. if(isset($ToState[strtolower($data['province'])]))
  41. {
  42. $dataprovince = strlen($data['province'])==2?$data['province']:$ToState[strtolower($data['province'])];
  43. $data['province'] = $dataprovince;
  44. }
  45. $sid = '606946403';
  46. $username = 'longyitechnCN';
  47. $password = 'S#5uZ#4vZ$2b';
  48. $xmend = "\n";
  49. $json = "<?xml version='1.0' encoding='UTF-8'?>".$xmend;
  50. $json .= '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ship="http://scxgxtt.phx-dc.dhl.com/euExpressRateBook/ShipmentMsgRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">'.$xmend;
  51. $json .= '<soapenv:Header>'.$xmend;
  52. $json .= '<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soapenv:mustUnderstand="1">'.$xmend;
  53. $json .= '<wsse:UsernameToken wsu:Id="">'.$xmend;
  54. $json .= '<wsse:Username>'.$username.'</wsse:Username>'.$xmend;
  55. $json .= "<wsse:Password Type='PasswordText'>".$password."</wsse:Password>".$xmend;
  56. $json .= "<wsse:Nonce EncodingType='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary'> eUYebYfsjztETJ4Urt8AJw ==</wsse:Nonce>".$xmend;
  57. $json .= '<wsu:Created>'.date('c').'</wsu:Created>'.$xmend;
  58. $json .= '</wsse:UsernameToken>'.$xmend;
  59. $json .= '</wsse:Security>'.$xmend;
  60. $json .= '</soapenv:Header>'.$xmend;
  61. $json .= '<soapenv:Body>'.$xmend;
  62. $json .= '<ship:ShipmentRequest>'.$xmend;
  63. $json .= '<Request>'.$xmend;
  64. $json .= '<ServiceHeader>'.$xmend;
  65. $json .= '<MessageTime>'.date('c').'</MessageTime>'.$xmend;//发送请求的时间
  66. $json .= '<MessageReference>'.time().time().rand(10000000,99999999).'</MessageReference>'.$xmend;//报文唯一标识
  67. $json .= '<WebstorePlatform>LYERP</WebstorePlatform>'.$xmend;//客户网店平台名称
  68. $json .= '<WebstorePlatformVersion>LY_V1.0.0</WebstorePlatformVersion>'.$xmend;//客户网店平台版本号
  69. $json .= '<ShippingSystemPlatform>LYERP</ShippingSystemPlatform>'.$xmend;//客户发件系统名称
  70. $json .= '<ShippingSystemPlatformVersion>LY_V1.0.0</ShippingSystemPlatformVersion>'.$xmend;//客户发件系统版本号
  71. $json .= '<PlugIn>LYERP</PlugIn>'.$xmend;//客户系统插件名称
  72. $json .= '<PlugInVersion>LY_V1.0.0</PlugInVersion>'.$xmend;//插件版本号
  73. $json .= '</ServiceHeader>'.$xmend;
  74. $json .= '</Request>'.$xmend;
  75. /** 请求装运信息 **/
  76. $json .= '<RequestedShipment>'.$xmend;
  77. /** 运单输出 **/
  78. $json .= '<ShipmentInfo>'.$xmend;
  79. $json .= '<DropOffType>REGULAR_PICKUP</DropOffType>'.$xmend;//取件类型 REGULAR_PICKUP不预约取件,REQUEST_COURIER预约取件
  80. $json .= '<ServiceType>P</ServiceType>'.$xmend;//产品代码,普通包裹:P,正午特派包裹:Y
  81. $json .= '<LocalServiceType>P</LocalServiceType>'.$xmend;//与ServiceType一致,可不保留
  82. $json .= '<Billing>'.$xmend;
  83. $json .= '<ShipperAccountNumber>'.$sid.'</ShipperAccountNumber>'.$xmend;//账号
  84. $json .= '<ShippingPaymentType>S</ShippingPaymentType>'.$xmend;//支付方式S--发件人,R--收件人,T--第三方
  85. $json .= '<BillingAccountNumber>'.$sid.'</BillingAccountNumber>'.$xmend;//DHL付款账号,当ShippingPaymentType为R或T时,此项为必填项
  86. $json .= '</Billing>'.$xmend;
  87. $json .= '<SpecialServices>'.$xmend;
  88. $json .= '<Service>'.$xmend;
  89. $json .= '<ServiceType>WY</ServiceType>'.$xmend;//WY无纸化贸易,DTP服务代码DD,PLT服务代码WY
  90. $json .= '</Service>'.$xmend;
  91. if($data['bx'] > 0)
  92. {
  93. $json .= '<Service>'.$xmend;
  94. $json .= '<ServiceType>II</ServiceType>'.$xmend;//II购买保险
  95. $json .= '<ServiceValue>'.$data['bx'].'</ServiceValue>'.$xmend;//保险金额
  96. $json .= '<CurrencyCode>USD</CurrencyCode>'.$xmend;//保险货币
  97. $json .= '</Service>'.$xmend;
  98. }
  99. $json .= '</SpecialServices>'.$xmend;
  100. $json .= '<Currency>USD</Currency>'.$xmend;//运费币种
  101. $json .= '<UnitOfMeasurement>SI</UnitOfMeasurement>'.$xmend;//重量单位SI表示千克和厘米,SU表示英镑和英寸
  102. $json .= '<ShipmentReferences>'.$xmend;
  103. $json .= '<ShipmentReference>'.$xmend;
  104. $json .= '<ShipmentReference>'.$data['number'].'</ShipmentReference>'.$xmend;
  105. $json .= '</ShipmentReference>'.$xmend;
  106. $json .= '</ShipmentReferences>'.$xmend;
  107. $json .= '<LabelType>PDF</LabelType>'.$xmend;//面单输出格式
  108. $json .= '<LabelTemplate>ECOM26_84_001</LabelTemplate>'.$xmend;//面单规格ECOM26_84_A4_001:A4纸运单,ECOM26_84_001:标签运单
  109. $json .= '<ArchiveLabelTemplate>ARCH_8x4</ArchiveLabelTemplate>'.$xmend;//ARCH_8X4_A4_002:A4纸运单,ARCH_8X4:标签运单Request中未添加该元素时,将默认为标签运单
  110. $json .= '<CustomsInvoiceTemplate>COMMERCIAL_INVOICE_L_10</CustomsInvoiceTemplate>'.$xmend;//海关发票模板
  111. $json .= '<PaperlessTradeEnabled>true</PaperlessTradeEnabled>'.$xmend;//启用无纸贸易
  112. $json .= '<LabelOptions>'.$xmend;
  113. $json .= '<PrinterDPI>200</PrinterDPI>'.$xmend;
  114. $json .= '<RequestWaybillDocument>N</RequestWaybillDocument>'.$xmend;//是否打印运单WaybillDoc联
  115. $json .= '<HideAccountInWaybillDocument>N</HideAccountInWaybillDocument>'.$xmend;//是否隐藏付款账号,Y隐藏,N不隐藏
  116. $json .= '<NumberOfWaybillDocumentCopies>1</NumberOfWaybillDocumentCopies>'.$xmend;//打印数量
  117. $json .= '<RequestDHLCustomsInvoice>Y</RequestDHLCustomsInvoice>'.$xmend;//是否需要发票
  118. $json .= '<DHLCustomsInvoiceLanguageCode>eng</DHLCustomsInvoiceLanguageCode>'.$xmend;//海关发票语言代码
  119. $json .= '<DHLCustomsInvoiceType>COMMERCIAL_INVOICE</DHLCustomsInvoiceType>'.$xmend;//海关发票类型
  120. $json .= '<RequestDHLLogoOnLabel>N</RequestDHLLogoOnLabel>'.$xmend;//是否打印DHL LOGO
  121. $json .= '</LabelOptions>'.$xmend;
  122. $json .= '</ShipmentInfo>'.$xmend;
  123. $json .= '<ShipTimestamp>'.date('Y-m-d',time()+19*3600).'T'.date('H:i:s',time()+19*3600).'GMT+08:00</ShipTimestamp>'.$xmend;//发货时间(预约取货时间开始)
  124. $json .= '<PaymentInfo>DAP</PaymentInfo>'.$xmend;//付款信息 !*
  125. /** 包裹和文件 **/
  126. $json .= '<InternationalDetail>'.$xmend;
  127. $json .= '<Commodities>'.$xmend;
  128. $json .= '<Description>'.$data['sbpm'].'</Description>'.$xmend;//商品描述,写报关货物内容,品名
  129. $json .= '<CustomsValue>'.$data['zsbjz'].'</CustomsValue>'.$xmend;//申报价值
  130. $json .= '</Commodities>'.$xmend;
  131. $json .= '<Content>NON_DOCUMENTS</Content>'.$xmend;//NON_DOCUMENTS为包裹,DOCUMENTS为文件
  132. $json .= '<ExportDeclaration>'.$xmend;
  133. $json .= '<ExportReasonType>COMMERCIAL_PURPOSE_OR_SALE</ExportReasonType>'.$xmend;
  134. $json .= '<PlaceOfIncoterm> </PlaceOfIncoterm>'.$xmend;//说是打空格可以通过 港口
  135. //循环开始
  136. $json .= '<ExportLineItems>'.$xmend;
  137. //(1)
  138. $json .= '<ExportLineItem>'.$xmend;
  139. $json .= '<CommodityCode>'.$data['hgbm'].'</CommodityCode>'.$xmend;//海关编码
  140. $json .= '<ExportReasonType>PERMANENT</ExportReasonType>'.$xmend;//出口原因可选值如下: - ‘PERMANENT’- ‘TEMPORARY’- ‘RETURN’
  141. $json .= '<ItemNumber>1</ItemNumber>'.$xmend;//物品序号
  142. $json .= '<Quantity>'.$data['ts'].'</Quantity>'.$xmend;//数量
  143. $json .= '<QuantityUnitOfMeasurement>PCS</QuantityUnitOfMeasurement>'.$xmend;//数量单位,条
  144. $json .= '<ItemDescription>'.$data['sbpm'].'</ItemDescription>'.$xmend;//商品描述
  145. $json .= '<UnitPrice>'.$data['dtsbjz'].'</UnitPrice>'.$xmend;//单条申报价
  146. $json .= '<NetWeight>'.$data['zzl'].'</NetWeight>'.$xmend;//净重
  147. $json .= '<GrossWeight>'.$data['zzl'].'</GrossWeight>'.$xmend;//总重量
  148. $json .= '<ManufacturingCountryCode>CN</ManufacturingCountryCode>'.$xmend;//制造国家代码
  149. $json .= '</ExportLineItem>'.$xmend;
  150. //循环结束
  151. $json .= '</ExportLineItems>'.$xmend;
  152. $json .= '<InvoiceDate>'.date('Y-m-d',time()).'</InvoiceDate>'.$xmend;//发票日期
  153. $json .= '<InvoiceNumber>'.$data['paypal'].' '.$data['pay'].'</InvoiceNumber>'.$xmend;//发票号码
  154. $json .= '<Remarks>'.$xmend;
  155. $json .= '<Remark>'.$xmend;
  156. $json .= '<RemarkDescription>'.$data['number'].'</RemarkDescription>'.$xmend;//备注说明
  157. $json .= '</Remark>'.$xmend;
  158. $json .= '</Remarks>'.$xmend;
  159. $json .= '</ExportDeclaration>'.$xmend;
  160. $json .= '</InternationalDetail>'.$xmend;
  161. $json .= '<Ship>'.$xmend;
  162. $json .= '<Shipper>'.$xmend;
  163. $json .= '<Contact>'.$xmend;
  164. $json .= '<PersonName>He Chong Bo</PersonName>'.$xmend;//发货人 '.$data['warehouse']['company'].'
  165. $json .= '<CompanyName>Kun Peng Fazhipin</CompanyName>'.$xmend;//'.$data['warehouse']['company'].'
  166. $json .= '<PhoneNumber>15939964739</PhoneNumber>'.$xmend;
  167. //$json .= '<EmailAddress></EmailAddress>'.$xmend;//发件人电子邮件
  168. $json .= '<MobilePhoneNumber>256345673</MobilePhoneNumber>'.$xmend;//发件人固话
  169. $json .= '</Contact>'.$xmend;
  170. $json .= '<Address>'.$xmend;
  171. $json .= '<StreetLines>4703,building C,</StreetLines>'.$xmend;//'.$data['warehouse']['address'].'
  172. $json .= '<StreetLines2>bodi center,ningwei street</StreetLines2>'.$xmend;//'.$data['warehouse']['address2'].'
  173. //$json .= '<StreetLines3></StreetLines3>'.$xmend;
  174. $json .= '<City>Hang Zhou</City>'.$xmend;//'.$data['warehouse']['city'].'
  175. $json .= '<StateOrProvinceCode>Zhe Jiang</StateOrProvinceCode>'.$xmend;//'.$data['warehouse']['province'].'
  176. $json .= '<PostalCode>311200</PostalCode>'.$xmend;//'.$data['warehouse']['zipcode'].'
  177. $json .= '<CountryCode>'.$data['warehouse']['lb'].'</CountryCode>'.$xmend;//国家代码
  178. $json .= '</Address>'.$xmend;
  179. $json .= '</Shipper>'.$xmend;
  180. $json .= '<Recipient>'.$xmend;
  181. $json .= '<Contact>'.$xmend;
  182. $json .= '<PersonName>'.$data['name'].'</PersonName>'.$xmend;//收货人
  183. $json .= '<CompanyName>'.$data['client'].'</CompanyName>'.$xmend;
  184. $json .= '<PhoneNumber>'.$data['phone'].'</PhoneNumber>'.$xmend;
  185. //$json .= '<EmailAddress></EmailAddress>'.$xmend;//发件人电子邮件
  186. //$json .= '<MobilePhoneNumber></MobilePhoneNumber>'.$xmend;//发件人固话
  187. $json .= '</Contact>'.$xmend;
  188. $json .= '<Address>'.$xmend;
  189. if(strlen($data['address'].$data['address2']) > 44)
  190. {
  191. $adl = $data['address'].$data['address2'];
  192. $adl1 = substr($adl,0,44);//截取44字符前内容
  193. $adlnum = strripos($adl1," ");//查找最后一次出现空格位置
  194. $adl1 = substr($adl,0,$adlnum);//0到空格前之间的内容
  195. $adl2 = substr($adl,$adlnum+1,strlen($adl));//空格后到最后的内容
  196. $json .= '<StreetLines>'.$adl1.'</StreetLines>'.$xmend;//收货人地址1
  197. $json .= '<StreetLines2>'.$adl2.'</StreetLines2>'.$xmend;//收货人地址2
  198. }
  199. else
  200. {
  201. $json .= '<StreetLines>'.$data['address'].$data['address2'].'</StreetLines>'.$xmend;//收货人地址
  202. }
  203. //$json .= '<StreetLines3></StreetLines3>'.$xmend;
  204. $json .= '<City>'.$data['city'].'</City>'.$xmend;
  205. if($data['lb'] == 'US')
  206. {
  207. $json .= '<StateOrProvinceCode>'.$data['province'].'</StateOrProvinceCode>'.$xmend;
  208. }
  209. $json .= '<PostalCode>'.$data['zipcode'].'</PostalCode>'.$xmend;
  210. $json .= '<CountryCode>'.$data['lb'].'</CountryCode>'.$xmend;//国家代码
  211. $json .= '</Address>'.$xmend;
  212. $json .= '</Recipient>'.$xmend;
  213. $json .= '</Ship>'.$xmend;
  214. $json .= '<Packages>'.$xmend;
  215. //多箱这里循环
  216. $json .= '<RequestedPackages number="'.$data['zjs'].'">'.$xmend;
  217. $json .= '<Weight>'.$data['zzl'].'</Weight>'.$xmend;
  218. $json .= '<Dimensions>'.$xmend;
  219. $json .= '<Length>5</Length>'.$xmend;
  220. $json .= '<Width>15</Width>'.$xmend;
  221. $json .= '<Height>3</Height>'.$xmend;
  222. $json .= '</Dimensions>'.$xmend;
  223. $json .= '<CustomerReferences>'.$data['number'].'</CustomerReferences>'.$xmend;
  224. $json .= '</RequestedPackages>'.$xmend;
  225. $json .= '</Packages>'.$xmend;
  226. //循环结束
  227. $json .= '</RequestedShipment>'.$xmend;
  228. $json .= '</ship:ShipmentRequest>'.$xmend;
  229. $json .= '</soapenv:Body>'.$xmend;
  230. $json .= '</soapenv:Envelope>'.$xmend;
  231. $ch = curl_init();
  232. //curl_setopt($ch, CURLOPT_URL,'https://wsbexpress.dhl.com:443/sndpt/expressRateBook');
  233. curl_setopt($ch, CURLOPT_URL,'https://wsbexpress.dhl.com:443/gbl/expressRateBook');
  234. curl_setopt($ch, CURLOPT_POST, 1);
  235. curl_setopt($ch, CURLOPT_HEADER, 0);
  236. curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml; charset=utf-8"));
  237. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  238. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  239. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  240. curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
  241. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  242. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,35);
  243. $data = curl_exec($ch);
  244. curl_close($ch);
  245. $xml = simplexml_load_string($data);
  246. $xml->registerXPathNamespace('shipresp', 'http://scxgxtt.phx-dc.dhl.com/euExpressRateBook/ShipmentMsgResponse');
  247. $data = array();
  248. foreach ($xml->xpath('//ShipmentIdentificationNumber') as $item)
  249. {
  250. $json = json_encode($item);
  251. $convrt_arr = json_decode($json, true);
  252. $data['waybill'] = $convrt_arr[0];
  253. break;
  254. }
  255. foreach ($xml->xpath('//GraphicImage') as $item)
  256. {
  257. $json = json_encode($item);
  258. $convrt_arr = json_decode($json, true);
  259. $data['yd'] = $convrt_arr[0];
  260. break;
  261. }
  262. foreach ($xml->xpath('//DocumentImage') as $item)
  263. {
  264. $json = json_encode($item);
  265. $convrt_arr = json_decode($json, true);
  266. $data['fp'] = $convrt_arr[0];
  267. break;
  268. }
  269. if(isset($data['yd']))
  270. {
  271. return array('c'=>1,'data'=>$data);exit;
  272. }
  273. else
  274. {
  275. $error = '';
  276. foreach ($xml->xpath('//Notification') as $item)
  277. {
  278. $errorjson = json_encode($item);
  279. $errorjson = json_decode($errorjson, true);
  280. $error .= isset($errorjson['Message'])?$errorjson['Message'].';':'错误信息获取失败;';
  281. }
  282. if(isset($error))
  283. {
  284. return array('c'=>2,'data'=>$error);exit;
  285. }
  286. else
  287. {
  288. return array('c'=>2,'data'=>'获取数据失败,未知错误!');exit;
  289. }
  290. }
  291. /**
  292. $ch = curl_init();
  293. $url = 'http://z.wepolicy.cn/dhlhz.php';
  294. curl_setopt($ch,CURLOPT_URL,$url);
  295. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  296. curl_setopt($ch,CURLOPT_HEADER,0);
  297. curl_setopt($ch,CURLOPT_POST, 1);
  298. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,35);
  299. //设置post数据
  300. $post = array();
  301. $post['data'] = $json;
  302. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  303. $res = curl_exec($ch);
  304. curl_close($ch);
  305. $data = json_decode($res,true);
  306. if(isset($data['yd']))
  307. {
  308. return array('c'=>1,'data'=>$data);exit;
  309. }
  310. else
  311. {
  312. if(isset($data['$error']))
  313. {
  314. return array('c'=>2,'data'=>$error);exit;
  315. }
  316. else
  317. {
  318. return array('c'=>2,'data'=>'获取数据失败,未知错误!');exit;
  319. }
  320. }
  321. **/
  322. }
  323. public function get_data2($data)//旧版API
  324. {
  325. if($data['pay'] == 1)
  326. {
  327. $data['pay'] == 'PayPal';
  328. }
  329. else if($data['pay'] == 2)
  330. {
  331. $data['pay'] == 'Western Union';
  332. }
  333. else if($data['pay'] == 3)
  334. {
  335. $data['pay'] == '微信';
  336. }
  337. else if($data['pay'] == 4)
  338. {
  339. $data['pay'] == '支付宝';
  340. }
  341. else if($data['pay'] == 5)
  342. {
  343. $data['pay'] == '银行转账';
  344. }
  345. else if($data['pay'] == 6)
  346. {
  347. $data['pay'] == '现金收款';
  348. }
  349. else if($data['pay'] == 7)
  350. {
  351. $data['pay'] == 'PingPong金融';
  352. }
  353. $ToState = array('alabama'=>'AL','alaska'=>'AK','arizona'=>'AZ','arkansas'=>'AR','california'=>'CA','colorado'=>'CO','connecticut'=>'CT','delaware'=>'DE','florida'=>'FL','georgia'=>'GA','hawaii'=>'HI','idaho'=>'ID','illinois'=>'IL','indiana'=>'IN','iowa'=>'IA','kansas'=>'KS','kentucky'=>'KY','louisiana'=>'LA','maine'=>'ME','maryland'=>'MD','massachusetts'=>'MA','michigan'=>'MI','minnesota'=>'MN','mississippi'=>'MS','missouri'=>'MO','montana'=>'MT','nebraska'=>'NE','nevada'=>'NV','new hampshire'=>'NH','new jersey'=>'NJ','new mexico'=>'NM','new york'=>'NY','north carolina'=>'NC','north dakota'=>'ND','ohio'=>'OH','oklahoma'=>'OK','oregon'=>'OR','pennsylvania'=>'PA','rhode island'=>'RI','south carolina'=>'SC','south dakota'=>'SD','tennessee'=>'TN','texas'=>'TX','utah'=>'UT','vermont'=>'VT','virginia'=>'VA','washington'=>'WA','west virginia'=>'WV','wisconsin'=>'WI','wyoming'=>'WY','district of columbia'=>'DC','virgin islands'=>'VI');
  354. $data['province'] = preg_replace('/( | | |\s)/',' ',$data['province']);
  355. $data['province'] = trim($data['province'],' ');
  356. if(isset($ToState[strtolower($data['province'])]))
  357. {
  358. $dataprovince = strlen($data['province'])==2?$data['province']:$ToState[strtolower($data['province'])];
  359. $data['province'] = $dataprovince;
  360. }
  361. $sid = '606946403';
  362. $username = 'longyitechnCN';
  363. $password = 'S#5uZ#4vZ$2b';
  364. $xmend = "\n";
  365. $json = "<?xml version='1.0' encoding='UTF-8'?>".$xmend;
  366. $json .= '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ship="http://scxgxtt.phx-dc.dhl.com/euExpressRateBook/ShipmentMsgRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">'.$xmend;
  367. $json .= '<soapenv:Header>'.$xmend;
  368. $json .= '<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soapenv:mustUnderstand="1">'.$xmend;
  369. $json .= '<wsse:UsernameToken wsu:Id="">'.$xmend;
  370. $json .= '<wsse:Username>'.$username.'</wsse:Username>'.$xmend;
  371. $json .= "<wsse:Password Type='PasswordText'>".$password."</wsse:Password>".$xmend;
  372. $json .= "<wsse:Nonce EncodingType='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary'> eUYebYfsjztETJ4Urt8AJw ==</wsse:Nonce>".$xmend;
  373. $json .= '<wsu:Created>'.date('c').'</wsu:Created>'.$xmend;
  374. $json .= '</wsse:UsernameToken>'.$xmend;
  375. $json .= '</wsse:Security>'.$xmend;
  376. $json .= '</soapenv:Header>'.$xmend;
  377. $json .= '<soapenv:Body>'.$xmend;
  378. $json .= '<ship:ShipmentRequest>'.$xmend;
  379. $json .= '<Request>'.$xmend;
  380. $json .= '<ServiceHeader>'.$xmend;
  381. $json .= '<MessageTime>'.date('c').'</MessageTime>'.$xmend;//发送请求的时间
  382. $json .= '<MessageReference>'.time().time().rand(10000000,99999999).'</MessageReference>'.$xmend;//报文唯一标识
  383. $json .= '<WebstorePlatform>LYERP</WebstorePlatform>'.$xmend;//客户网店平台名称
  384. $json .= '<WebstorePlatformVersion>LY_V1.0.0</WebstorePlatformVersion>'.$xmend;//客户网店平台版本号
  385. $json .= '<ShippingSystemPlatform>LYERP</ShippingSystemPlatform>'.$xmend;//客户发件系统名称
  386. $json .= '<ShippingSystemPlatformVersion>LY_V1.0.0</ShippingSystemPlatformVersion>'.$xmend;//客户发件系统版本号
  387. $json .= '<PlugIn>LYERP</PlugIn>'.$xmend;//客户系统插件名称
  388. $json .= '<PlugInVersion>LY_V1.0.0</PlugInVersion>'.$xmend;//插件版本号
  389. $json .= '</ServiceHeader>'.$xmend;
  390. $json .= '</Request>'.$xmend;
  391. /** 请求装运信息 **/
  392. $json .= '<RequestedShipment>'.$xmend;
  393. /** 运单输出 **/
  394. $json .= '<ShipmentInfo>'.$xmend;
  395. $json .= '<DropOffType>REGULAR_PICKUP</DropOffType>'.$xmend;//取件类型 REGULAR_PICKUP不预约取件,REQUEST_COURIER预约取件
  396. $json .= '<ServiceType>P</ServiceType>'.$xmend;//产品代码,普通包裹:P,正午特派包裹:Y
  397. $json .= '<LocalServiceType>P</LocalServiceType>'.$xmend;//与ServiceType一致,可不保留
  398. $json .= '<Billing>'.$xmend;
  399. $json .= '<ShipperAccountNumber>'.$sid.'</ShipperAccountNumber>'.$xmend;//账号
  400. $json .= '<ShippingPaymentType>S</ShippingPaymentType>'.$xmend;//支付方式S--发件人,R--收件人,T--第三方
  401. $json .= '<BillingAccountNumber>'.$sid.'</BillingAccountNumber>'.$xmend;//DHL付款账号,当ShippingPaymentType为R或T时,此项为必填项
  402. $json .= '</Billing>'.$xmend;
  403. $json .= '<SpecialServices>'.$xmend;
  404. $json .= '<Service>'.$xmend;
  405. $json .= '<ServiceType>WY</ServiceType>'.$xmend;//WY无纸化贸易,DTP服务代码DD,PLT服务代码WY
  406. $json .= '</Service>'.$xmend;
  407. if($data['bx'] > 0)
  408. {
  409. $json .= '<Service>'.$xmend;
  410. $json .= '<ServiceType>II</ServiceType>'.$xmend;//II购买保险
  411. $json .= '<ServiceValue>'.$data['bx'].'</ServiceValue>'.$xmend;//保险金额
  412. $json .= '<CurrencyCode>USD</CurrencyCode>'.$xmend;//保险货币
  413. $json .= '</Service>'.$xmend;
  414. }
  415. $json .= '</SpecialServices>'.$xmend;
  416. $json .= '<Currency>USD</Currency>'.$xmend;//运费币种
  417. $json .= '<UnitOfMeasurement>SI</UnitOfMeasurement>'.$xmend;//重量单位SI表示千克和厘米,SU表示英镑和英寸
  418. $json .= '<ShipmentReferences>'.$xmend;
  419. $json .= '<ShipmentReference>'.$xmend;
  420. $json .= '<ShipmentReference>'.$data['number'].'</ShipmentReference>'.$xmend;
  421. $json .= '</ShipmentReference>'.$xmend;
  422. $json .= '</ShipmentReferences>'.$xmend;
  423. $json .= '<LabelType>PDF</LabelType>'.$xmend;//面单输出格式
  424. $json .= '<LabelTemplate>ARCH_8X4</LabelTemplate>'.$xmend;//面单规格:ECOM26_84_A4_001是A4,ECOM26_84_A4_001是标签
  425. $json .= '<ArchiveLabelTemplate>ARCH_8x4</ArchiveLabelTemplate>'.$xmend;//ARCH_8X4_A4_002:A4纸运单,ARCH_8X4:标签运单Request中未添加该元素时,将默认为标签运单
  426. $json .= '<CustomsInvoiceTemplate>COMMERCIAL_INVOICE_03</CustomsInvoiceTemplate>'.$xmend;//海关发票模板
  427. $json .= '<PaperlessTradeEnabled>true</PaperlessTradeEnabled>'.$xmend;//启用无纸贸易
  428. $json .= '<LabelOptions>'.$xmend;
  429. $json .= '<PrinterDPI>200</PrinterDPI>'.$xmend;
  430. $json .= '<RequestWaybillDocument>N</RequestWaybillDocument>'.$xmend;//是否打印运单WaybillDoc联
  431. $json .= '<HideAccountInWaybillDocument>N</HideAccountInWaybillDocument>'.$xmend;//是否隐藏付款账号,Y隐藏,N不隐藏
  432. $json .= '<NumberOfWaybillDocumentCopies>1</NumberOfWaybillDocumentCopies>'.$xmend;//打印数量
  433. $json .= '<RequestDHLCustomsInvoice>Y</RequestDHLCustomsInvoice>'.$xmend;//是否需要发票
  434. $json .= '<DHLCustomsInvoiceLanguageCode>eng</DHLCustomsInvoiceLanguageCode>'.$xmend;//海关发票语言代码
  435. $json .= '<DHLCustomsInvoiceType>COMMERCIAL_INVOICE</DHLCustomsInvoiceType>'.$xmend;//海关发票类型
  436. $json .= '</LabelOptions>'.$xmend;
  437. $json .= '</ShipmentInfo>'.$xmend;
  438. $json .= '<ShipTimestamp>'.date('Y-m-d',time()+19*3600).'T'.date('H:i:s',time()+19*3600).'GMT+08:00</ShipTimestamp>'.$xmend;//发货时间(预约取货时间开始)
  439. $json .= '<PaymentInfo>DAP</PaymentInfo>'.$xmend;//付款信息 !*
  440. /** 包裹和文件 **/
  441. $json .= '<InternationalDetail>'.$xmend;
  442. $json .= '<Commodities>'.$xmend;
  443. $json .= '<Description>'.$data['sbpm'].'</Description>'.$xmend;//商品描述,写报关货物内容,品名
  444. $json .= '<CustomsValue>'.$data['zsbjz'].'</CustomsValue>'.$xmend;//申报价值
  445. $json .= '</Commodities>'.$xmend;
  446. $json .= '<Content>NON_DOCUMENTS</Content>'.$xmend;//NON_DOCUMENTS为包裹,DOCUMENTS为文件
  447. $json .= '<ExportDeclaration>'.$xmend;
  448. //循环开始
  449. $json .= '<ExportLineItems>'.$xmend;
  450. //(1)
  451. $json .= '<ExportLineItem>'.$xmend;
  452. $json .= '<CommodityCode>'.$data['hgbm'].'</CommodityCode>'.$xmend;//海关编码
  453. $json .= '<ExportReasonType>PERMANENT</ExportReasonType>'.$xmend;//出口原因可选值如下: - ‘PERMANENT’- ‘TEMPORARY’- ‘RETURN’
  454. $json .= '<ItemNumber>1</ItemNumber>'.$xmend;//物品序号
  455. $json .= '<Quantity>'.$data['ts'].'</Quantity>'.$xmend;//数量
  456. $json .= '<QuantityUnitOfMeasurement>PCS</QuantityUnitOfMeasurement>'.$xmend;//数量单位,条
  457. $json .= '<ItemDescription>'.$data['sbpm'].'</ItemDescription>'.$xmend;//商品描述
  458. $json .= '<UnitPrice>'.$data['dtsbjz'].'</UnitPrice>'.$xmend;//单条申报价
  459. $json .= '<NetWeight>'.$data['zzl'].'</NetWeight>'.$xmend;//净重
  460. $json .= '<GrossWeight>'.$data['zzl'].'</GrossWeight>'.$xmend;//总重量
  461. $json .= '<ManufacturingCountryCode>CN</ManufacturingCountryCode>'.$xmend;//制造国家代码
  462. $json .= '</ExportLineItem>'.$xmend;
  463. //循环结束
  464. $json .= '</ExportLineItems>'.$xmend;
  465. $json .= '<InvoiceDate>'.date('Y-m-d',time()).'</InvoiceDate>'.$xmend;//发票日期
  466. $json .= '<InvoiceNumber>'.$data['paypal'].' '.$data['pay'].'</InvoiceNumber>'.$xmend;//发票号码
  467. $json .= '<Remarks>'.$xmend;
  468. $json .= '<Remark>'.$xmend;
  469. $json .= '<RemarkDescription>'.$data['number'].'</RemarkDescription>'.$xmend;//备注说明
  470. $json .= '</Remark>'.$xmend;
  471. $json .= '</Remarks>'.$xmend;
  472. $json .= '</ExportDeclaration>'.$xmend;
  473. $json .= '</InternationalDetail>'.$xmend;
  474. $json .= '<Ship>'.$xmend;
  475. $json .= '<Shipper>'.$xmend;
  476. $json .= '<Contact>'.$xmend;
  477. $json .= '<PersonName>He Chong Bo</PersonName>'.$xmend;//发货人 '.$data['warehouse']['company'].'
  478. $json .= '<CompanyName>Kun Peng Fazhipin</CompanyName>'.$xmend;//'.$data['warehouse']['company'].'
  479. $json .= '<PhoneNumber>15939964739</PhoneNumber>'.$xmend;
  480. $json .= '<EmailAddress>test@test.com</EmailAddress>'.$xmend;//发件人电子邮件
  481. $json .= '<MobilePhoneNumber>256345673</MobilePhoneNumber>'.$xmend;//发件人固话
  482. $json .= '</Contact>'.$xmend;
  483. $json .= '<Address>'.$xmend;
  484. $json .= '<StreetLines>4703,building C,</StreetLines>'.$xmend;//'.$data['warehouse']['address'].'
  485. $json .= '<StreetLines2>bodi center,ningwei street</StreetLines2>'.$xmend;//'.$data['warehouse']['address2'].'
  486. //$json .= '<StreetLines3></StreetLines3>'.$xmend;
  487. $json .= '<City>Hang Zhou</City>'.$xmend;//'.$data['warehouse']['city'].'
  488. $json .= '<StateOrProvinceCode>Zhe Jiang</StateOrProvinceCode>'.$xmend;//'.$data['warehouse']['province'].'
  489. $json .= '<PostalCode>310000</PostalCode>'.$xmend;//'.$data['warehouse']['zipcode'].'
  490. $json .= '<CountryCode>'.$data['warehouse']['lb'].'</CountryCode>'.$xmend;//国家代码
  491. $json .= '</Address>'.$xmend;
  492. $json .= '</Shipper>'.$xmend;
  493. $json .= '<Recipient>'.$xmend;
  494. $json .= '<Contact>'.$xmend;
  495. $json .= '<PersonName>'.$data['name'].'</PersonName>'.$xmend;//收货人
  496. $json .= '<CompanyName>'.$data['client'].'</CompanyName>'.$xmend;
  497. $json .= '<PhoneNumber>'.$data['phone'].'</PhoneNumber>'.$xmend;
  498. //$json .= '<EmailAddress></EmailAddress>'.$xmend;//发件人电子邮件
  499. //$json .= '<MobilePhoneNumber></MobilePhoneNumber>'.$xmend;//发件人固话
  500. $json .= '</Contact>'.$xmend;
  501. $json .= '<Address>'.$xmend;
  502. if(strlen($data['address'].$data['address2']) > 44)
  503. {
  504. $adl = $data['address'].$data['address2'];
  505. $adl1 = substr($adl,0,44);//截取44字符前内容
  506. $adlnum = strripos($adl1," ");//查找最后一次出现空格位置
  507. $adl1 = substr($adl,0,$adlnum);//0到空格前之间的内容
  508. $adl2 = substr($adl,$adlnum+1,strlen($adl));//空格后到最后的内容
  509. $json .= '<StreetLines>'.$adl1.'</StreetLines>'.$xmend;//收货人地址1
  510. $json .= '<StreetLines2>'.$adl2.'</StreetLines2>'.$xmend;//收货人地址2
  511. }
  512. else
  513. {
  514. $json .= '<StreetLines>'.$data['address'].$data['address2'].'</StreetLines>'.$xmend;//收货人地址
  515. }
  516. //$json .= '<StreetLines3></StreetLines3>'.$xmend;
  517. $json .= '<City>'.$data['city'].'</City>'.$xmend;
  518. if($data['lb'] == 'US')
  519. {
  520. $json .= '<StateOrProvinceCode>'.$data['province'].'</StateOrProvinceCode>'.$xmend;
  521. }
  522. $json .= '<PostalCode>'.$data['zipcode'].'</PostalCode>'.$xmend;
  523. $json .= '<CountryCode>'.$data['lb'].'</CountryCode>'.$xmend;//国家代码
  524. $json .= '</Address>'.$xmend;
  525. $json .= '</Recipient>'.$xmend;
  526. $json .= '</Ship>'.$xmend;
  527. $json .= '<Packages>'.$xmend;
  528. //多箱这里循环
  529. $json .= '<RequestedPackages number="'.$data['zjs'].'">'.$xmend;
  530. $json .= '<Weight>'.$data['zzl'].'</Weight>'.$xmend;
  531. $json .= '<Dimensions>'.$xmend;
  532. $json .= '<Length>5</Length>'.$xmend;
  533. $json .= '<Width>15</Width>'.$xmend;
  534. $json .= '<Height>3</Height>'.$xmend;
  535. $json .= '</Dimensions>'.$xmend;
  536. $json .= '<CustomerReferences>'.$data['number'].'</CustomerReferences>'.$xmend;
  537. $json .= '</RequestedPackages>'.$xmend;
  538. $json .= '</Packages>'.$xmend;
  539. //循环结束
  540. $json .= '</RequestedShipment>'.$xmend;
  541. $json .= '</ship:ShipmentRequest>'.$xmend;
  542. $json .= '</soapenv:Body>'.$xmend;
  543. $json .= '</soapenv:Envelope>'.$xmend;
  544. /**
  545. $ch = curl_init();
  546. //curl_setopt($ch, CURLOPT_URL,'https://wsbexpress.dhl.com:443/sndpt/expressRateBook');
  547. curl_setopt($ch, CURLOPT_URL,'https://wsbexpress.dhl.com:443/gbl/expressRateBook');
  548. curl_setopt($ch, CURLOPT_POST, 1);
  549. curl_setopt($ch, CURLOPT_HEADER, 0);
  550. curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml; charset=utf-8"));
  551. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  552. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  553. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  554. curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
  555. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  556. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,35);
  557. $data = curl_exec($ch);
  558. curl_close($ch);
  559. $xml = simplexml_load_string($data);
  560. $xml->registerXPathNamespace('shipresp', 'http://scxgxtt.phx-dc.dhl.com/euExpressRateBook/ShipmentMsgResponse');
  561. $data = array();
  562. foreach ($xml->xpath('//ShipmentIdentificationNumber') as $item)
  563. {
  564. $json = json_encode($item);
  565. $convrt_arr = json_decode($json, true);
  566. $data['waybill'] = $convrt_arr[0];
  567. break;
  568. }
  569. foreach ($xml->xpath('//GraphicImage') as $item)
  570. {
  571. $json = json_encode($item);
  572. $convrt_arr = json_decode($json, true);
  573. $data['yd'] = $convrt_arr[0];
  574. break;
  575. }
  576. foreach ($xml->xpath('//DocumentImage') as $item)
  577. {
  578. $json = json_encode($item);
  579. $convrt_arr = json_decode($json, true);
  580. $data['fp'] = $convrt_arr[0];
  581. break;
  582. }
  583. if(isset($data['yd']))
  584. {
  585. return array('c'=>1,'data'=>$data);exit;
  586. }
  587. else
  588. {
  589. $error = '';
  590. foreach ($xml->xpath('//Notification') as $item)
  591. {
  592. $errorjson = json_encode($item);
  593. $errorjson = json_decode($errorjson, true);
  594. $error .= isset($errorjson['Message'])?$errorjson['Message'].';':'错误信息获取失败;';
  595. }
  596. if(isset($error))
  597. {
  598. return array('c'=>2,'data'=>$error);exit;
  599. }
  600. else
  601. {
  602. return array('c'=>2,'data'=>'获取数据失败,未知错误!');exit;
  603. }
  604. }
  605. **/
  606. $ch = curl_init();
  607. $url = 'http://z.wepolicy.cn/dhlhz.php';
  608. curl_setopt($ch,CURLOPT_URL,$url);
  609. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  610. curl_setopt($ch,CURLOPT_HEADER,0);
  611. curl_setopt($ch,CURLOPT_POST, 1);
  612. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,35);
  613. //设置post数据
  614. $post = array();
  615. $post['data'] = $json;
  616. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  617. $res = curl_exec($ch);
  618. curl_close($ch);
  619. $data = json_decode($res,true);
  620. if(isset($data['yd']))
  621. {
  622. return array('c'=>1,'data'=>$data);exit;
  623. }
  624. else
  625. {
  626. if(isset($data['$error']))
  627. {
  628. return array('c'=>2,'data'=>$error);exit;
  629. }
  630. else
  631. {
  632. return array('c'=>2,'data'=>'获取数据失败,未知错误!');exit;
  633. }
  634. }
  635. }
  636. public function get_epod($data)
  637. {
  638. $sid = '606946403';
  639. $username = 'longyitechnCN';
  640. $password = 'S#5uZ#4vZ$2b';
  641. $xmend = "\n";
  642. $xml = '<?xml version="1.0" encoding="UTF-8"?>'.$xmend;
  643. $xml .= '<SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="glDHLExpressePOD/providers/DocumentRetrieve" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">'.$xmend;
  644. $xml .= '<SOAP-ENV:Header>'.$xmend;
  645. $xml .= '<wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">'.$xmend;
  646. $xml .= '<wsse:UsernameToken wsu:Id="">'.$xmend;
  647. $xml .= '<wsse:Username>'.$username.'</wsse:Username>'.$xmend;
  648. $xml .= "<wsse:Password Type='PasswordText'>".$password."</wsse:Password>".$xmend;
  649. $xml .= "<wsse:Nonce EncodingType=''></wsse:Nonce>".$xmend;
  650. $xml .= '<wsu:Created>'.date('c').'</wsu:Created>'.$xmend;
  651. $xml .= '</wsse:UsernameToken>'.$xmend;
  652. $xml .= '</wsse:Security>'.$xmend;
  653. $xml .= '</SOAP-ENV:Header>'.$xmend;
  654. $xml .= '<SOAP-ENV:Body>'.$xmend;
  655. $xml .= '<tns:shipmentDocumentRetrieveReq>'.$xmend;
  656. $xml .= '<MSG>'.$xmend;
  657. $xml .= '<Hdr Dtm="'.date('c').'" Id="'.time().rand(100,999).'" Ver="1.038">'.$xmend;
  658. $xml .= '<Sndr AppCd="DCGAP" AppNm="DCGAP"/>'.$xmend;
  659. $xml .= '</Hdr>'.$xmend;
  660. $xml .= '<Bd>'.$xmend;
  661. $xml .= '<Shp Id="'.$data['waybill'].'">'.$xmend;
  662. $xml .= '<ShpTr>'.$xmend;
  663. $xml .= '<SCDtl AccNo="'.$sid.'" CRlTyCd="PY"/>'.$xmend;
  664. $xml .= '</ShpTr>'.$xmend;
  665. $xml .= '<ShpInDoc>'.$xmend;
  666. $xml .= '<SDoc DocTyCd="POD"/>'.$xmend;
  667. $xml .= '</ShpInDoc>'.$xmend;
  668. $xml .= '</Shp>'.$xmend;
  669. $xml .= '<GenrcRq>'.$xmend;
  670. $xml .= '<GenrcRqCritr TyCd="IMG_CONTENT" Val="epod-detail"/>'.$xmend;
  671. $xml .= '<GenrcRqCritr TyCd="IMG_FORMAT" Val="PDF"/>'.$xmend;
  672. $xml .= '<GenrcRqCritr TyCd="DOC_RND_REQ" Val="true"/>'.$xmend;
  673. $xml .= '<GenrcRqCritr TyCd="DUPL_HANDL" Val="CORE_WB_NO"/>'.$xmend;
  674. $xml .= '<GenrcRqCritr TyCd="SORT_BY" Val="$INGEST_DATE,D"/>'.$xmend;
  675. $xml .= '<GenrcRqCritr TyCd="LANGUAGE" Val="zh"/>'.$xmend;
  676. $xml .= '</GenrcRq>'.$xmend;
  677. $xml .= '</Bd>'.$xmend;
  678. $xml .= '</MSG>'.$xmend;
  679. $xml .= '</tns:shipmentDocumentRetrieveReq>'.$xmend;
  680. $xml .= '</SOAP-ENV:Body>'.$xmend;
  681. $xml .= '</SOAP-ENV:Envelope>'.$xmend;
  682. //echo $xml;exit;
  683. $ch = curl_init();
  684. curl_setopt($ch, CURLOPT_URL,'https://wsbexpress.dhl.com:443/gbl/getePOD');
  685. curl_setopt($ch, CURLOPT_POST, 1);
  686. curl_setopt($ch, CURLOPT_HEADER, 0);
  687. curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml; charset=utf-8"));
  688. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  689. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  690. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  691. curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
  692. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  693. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,35);
  694. $data = curl_exec($ch);
  695. curl_close($ch);
  696. //header("Content-type: application/xml");
  697. $xml = simplexml_load_string($data);
  698. $xml->registerXPathNamespace('tns','http://scxgxtt.phx-dc.dhl.com/glDHLExpressePOD/providers/DocumentRetrieve');
  699. if($xml->xpath('//Img'))
  700. {
  701. foreach ($xml->xpath('//Img') as $item)
  702. {
  703. $json = json_encode($item);
  704. $convrt_arr = json_decode($json, true);
  705. return array('c'=>1,'d'=>$convrt_arr['@attributes']['Img']);
  706. }
  707. }
  708. else
  709. {
  710. foreach ($xml->xpath('//ErrMsgDtl ') as $item)
  711. {
  712. $json = json_encode($item);
  713. $convrt_arr = json_decode($json, true);
  714. return array('c'=>2,'d'=>$convrt_arr['@attributes']['DtlDsc']);
  715. }
  716. }
  717. }
  718. public function _a($data)
  719. {
  720. $token = $this->c();
  721. $file_header = array(
  722. 'x-request-id: 606946403',
  723. 'Authorization: '.$token,
  724. 'Content-Type: application/json'
  725. );
  726. $ch = curl_init();
  727. $url = 'https://webhub.cndhl.com/dps/dps-declaration-api/api/declare/submit-declare';
  728. curl_setopt($ch,CURLOPT_URL,$url);
  729. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  730. curl_setopt($ch, CURLOPT_HTTPHEADER, $file_header);
  731. curl_setopt($ch,CURLOPT_HEADER,0);
  732. curl_setopt($ch,CURLOPT_POST, 1);
  733. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  734. //设置post数据
  735. $post = array();
  736. $post['decMessage']['decHead']['iEFlag']="E";
  737. $post['decMessage']['decHead']['tradeName']="杭州龙熠科技有限公司";
  738. $post['decMessage']['decHead']['tradeCoScc']="91330106MA2GMD3N8R";
  739. $post['decMessage']['decHead']['tradeCode']="3316960A6A";
  740. $post['decMessage']['decHead']['ownerName']="杭州龙熠科技有限公司";
  741. $post['decMessage']['decHead']['ownerCodeScc']="91330106MA2GMD3N8R";
  742. $post['decMessage']['decHead']['tradeMode']="3010";
  743. $post['decMessage']['decHead']['transMode']="2";
  744. $post['decMessage']['decHead']['cutMode']="101";
  745. $post['decMessage']['decHead']['feeMark']="3";
  746. $post['decMessage']['decHead']['feeRate']="10";
  747. $post['decMessage']['decHead']['feeCurr']="USD";
  748. $post['decMessage']['decLists']['decList'][0]['gNo']="1";
  749. $post['decMessage']['decLists']['decList'][0]['declGoodsEname']=$data['sbpm'];//申报品名
  750. $post['decMessage']['decLists']['decList'][0]['gName']=$data['zwpm'];//中文品名
  751. $post['decMessage']['decLists']['decList'][0]['codeTs']=$data['hgbm'];//海关编码
  752. $post['decMessage']['decLists']['decList'][0]['gModel']="0|2|假发|化纤";
  753. $post['decMessage']['decLists']['decList'][0]['gQty']=$data['ts'];//数量
  754. $post['decMessage']['decLists']['decList'][0]['gUnit']="007";
  755. $post['decMessage']['decLists']['decList'][0]['declPrice']=$data['dtsbjz'];//申报单价
  756. $post['decMessage']['decLists']['decList'][0]['declTotal']=$data['zsbjz'];//申报总价
  757. $post['decMessage']['decLists']['decList'][0]['tradeCurr']="USD";
  758. $post['decMessage']['decLists']['decList'][0]['firstQty']="0.10000";
  759. $post['decMessage']['decLists']['decList'][0]['firstUnit']="035";
  760. $post['decMessage']['decLists']['decList'][0]['goodsBrand']="无";
  761. $post['decMessage']['decLists']['decList'][0]['dutyMode']="1";
  762. $post['decMessage']['decLists']['decList'][0]['originCountry']="CHN";
  763. $post['decMessage']['msgHead']['action']="A";
  764. $post['decMessage']['msgHead']['awbGenDtm']= date("Y-m-d H:i:s",time()-3600);
  765. $post['decMessage']['msgHead']['awbNo']=$data['waybill'];//运单号
  766. $post['decMessage']['msgHead']['declareType']="C";
  767. $post['decMessage']['msgHead']['msgGenDtm']=date("Y-m-d H:i:s",time());
  768. $post['decMessage']['msgHead']['msgId']="7b67817a-9c81-412d-bedd-10a65ac22508";
  769. $post['decMessage']['msgHead']['version']="1.0";
  770. $data = json_encode($post);
  771. curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
  772. $res = curl_exec($ch);
  773. curl_close($ch);
  774. $resp = json_decode($res,true);
  775. echo "<pre>";
  776. print_r($resp);
  777. }
  778. public function c()
  779. {
  780. $token_header = array(
  781. 'x-request-id: 606946403',
  782. 'Content-Type: application/json'
  783. );
  784. $ch = curl_init();
  785. $url = 'https://webhub.cndhl.com/dps/dps-auth-server/api/gateway-token/generate';
  786. curl_setopt($ch,CURLOPT_URL,$url);
  787. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  788. curl_setopt($ch, CURLOPT_HTTPHEADER, $token_header);
  789. curl_setopt($ch,CURLOPT_HEADER,0);
  790. curl_setopt($ch,CURLOPT_POST, 1);
  791. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  792. //设置post数据
  793. $post = array();
  794. $post['consumerCode'] = 'T_mkfsq4ez3w';
  795. $post['key'] = '8BsPOT:Sib_Vc*$=';
  796. $data = json_encode($post);
  797. curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
  798. $res = curl_exec($ch);
  799. curl_close($ch);
  800. $resp = json_decode($res,true);
  801. $token = $resp['result']['token'];
  802. return $token;
  803. }
  804. } //end class