'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'); $data['province'] = preg_replace('/( | | |\s)/',' ',$data['province']); $data['province'] = trim($data['province'],' '); if(isset($ToState[strtolower($data['province'])])) { $dataprovince = strlen($data['province'])==2?$data['province']:$ToState[strtolower($data['province'])]; $data['province'] = $dataprovince; } $sid = '606946403'; $username = 'longyitechnCN'; $password = 'S#5uZ#4vZ$2b'; $xmend = "\n"; $json = "".$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$username.''.$xmend; $json .= "".$password."".$xmend; $json .= " eUYebYfsjztETJ4Urt8AJw ==".$xmend; $json .= ''.date('c').''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.date('c').''.$xmend;//发送请求的时间 $json .= ''.time().time().rand(10000000,99999999).''.$xmend;//报文唯一标识 $json .= 'LYERP'.$xmend;//客户网店平台名称 $json .= 'LY_V1.0.0'.$xmend;//客户网店平台版本号 $json .= 'LYERP'.$xmend;//客户发件系统名称 $json .= 'LY_V1.0.0'.$xmend;//客户发件系统版本号 $json .= 'LYERP'.$xmend;//客户系统插件名称 $json .= 'LY_V1.0.0'.$xmend;//插件版本号 $json .= ''.$xmend; $json .= ''.$xmend; /** 请求装运信息 **/ $json .= ''.$xmend; /** 运单输出 **/ $json .= ''.$xmend; $json .= 'REGULAR_PICKUP'.$xmend;//取件类型 REGULAR_PICKUP不预约取件,REQUEST_COURIER预约取件 $json .= 'P'.$xmend;//产品代码,普通包裹:P,正午特派包裹:Y $json .= 'P'.$xmend;//与ServiceType一致,可不保留 $json .= ''.$xmend; $json .= ''.$sid.''.$xmend;//账号 $json .= 'S'.$xmend;//支付方式S--发件人,R--收件人,T--第三方 $json .= ''.$sid.''.$xmend;//DHL付款账号,当ShippingPaymentType为R或T时,此项为必填项 $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= 'WY'.$xmend;//WY无纸化贸易,DTP服务代码DD,PLT服务代码WY $json .= ''.$xmend; if($data['bx'] > 0) { $json .= ''.$xmend; $json .= 'II'.$xmend;//II购买保险 $json .= ''.$data['bx'].''.$xmend;//保险金额 $json .= 'USD'.$xmend;//保险货币 $json .= ''.$xmend; } $json .= ''.$xmend; $json .= 'USD'.$xmend;//运费币种 $json .= 'SI'.$xmend;//重量单位SI表示千克和厘米,SU表示英镑和英寸 $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$data['number'].''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= 'PDF'.$xmend;//面单输出格式 $json .= 'ECOM26_84_001'.$xmend;//面单规格ECOM26_84_A4_001:A4纸运单,ECOM26_84_001:标签运单 $json .= 'ARCH_8x4'.$xmend;//ARCH_8X4_A4_002:A4纸运单,ARCH_8X4:标签运单Request中未添加该元素时,将默认为标签运单 $json .= 'COMMERCIAL_INVOICE_L_10'.$xmend;//海关发票模板 $json .= 'true'.$xmend;//启用无纸贸易 $json .= ''.$xmend; $json .= '200'.$xmend; $json .= 'N'.$xmend;//是否打印运单WaybillDoc联 $json .= 'N'.$xmend;//是否隐藏付款账号,Y隐藏,N不隐藏 $json .= '1'.$xmend;//打印数量 $json .= 'Y'.$xmend;//是否需要发票 $json .= 'eng'.$xmend;//海关发票语言代码 $json .= 'COMMERCIAL_INVOICE'.$xmend;//海关发票类型 $json .= 'N'.$xmend;//是否打印DHL LOGO $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.date('Y-m-d',time()+19*3600).'T'.date('H:i:s',time()+19*3600).'GMT+08:00'.$xmend;//发货时间(预约取货时间开始) $json .= 'DAP'.$xmend;//付款信息 !* /** 包裹和文件 **/ $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$data['sbpm'].''.$xmend;//商品描述,写报关货物内容,品名 $json .= ''.$data['zsbjz'].''.$xmend;//申报价值 $json .= ''.$xmend; $json .= 'NON_DOCUMENTS'.$xmend;//NON_DOCUMENTS为包裹,DOCUMENTS为文件 $json .= ''.$xmend; $json .= 'COMMERCIAL_PURPOSE_OR_SALE'.$xmend; $json .= ' '.$xmend;//说是打空格可以通过 港口 //循环开始 $json .= ''.$xmend; //(1) $json .= ''.$xmend; $json .= ''.$data['hgbm'].''.$xmend;//海关编码 $json .= 'PERMANENT'.$xmend;//出口原因可选值如下: - ‘PERMANENT’- ‘TEMPORARY’- ‘RETURN’ $json .= '1'.$xmend;//物品序号 $json .= ''.$data['ts'].''.$xmend;//数量 $json .= 'PCS'.$xmend;//数量单位,条 $json .= ''.$data['sbpm'].''.$xmend;//商品描述 $json .= ''.$data['dtsbjz'].''.$xmend;//单条申报价 $json .= ''.$data['zzl'].''.$xmend;//净重 $json .= ''.$data['zzl'].''.$xmend;//总重量 $json .= 'CN'.$xmend;//制造国家代码 $json .= ''.$xmend; //循环结束 $json .= ''.$xmend; $json .= ''.date('Y-m-d',time()).''.$xmend;//发票日期 $json .= ''.$data['paypal'].' '.$data['pay'].''.$xmend;//发票号码 $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$data['number'].''.$xmend;//备注说明 $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= 'He Chong Bo'.$xmend;//发货人 '.$data['warehouse']['company'].' $json .= 'Kun Peng Fazhipin'.$xmend;//'.$data['warehouse']['company'].' $json .= '15939964739'.$xmend; //$json .= ''.$xmend;//发件人电子邮件 $json .= '256345673'.$xmend;//发件人固话 $json .= ''.$xmend; $json .= '
'.$xmend; $json .= '4703,building C,'.$xmend;//'.$data['warehouse']['address'].' $json .= 'bodi center,ningwei street'.$xmend;//'.$data['warehouse']['address2'].' //$json .= ''.$xmend; $json .= 'Hang Zhou'.$xmend;//'.$data['warehouse']['city'].' $json .= 'Zhe Jiang'.$xmend;//'.$data['warehouse']['province'].' $json .= '311200'.$xmend;//'.$data['warehouse']['zipcode'].' $json .= ''.$data['warehouse']['lb'].''.$xmend;//国家代码 $json .= '
'.$xmend; $json .= '
'.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$data['name'].''.$xmend;//收货人 $json .= ''.$data['client'].''.$xmend; $json .= ''.$data['phone'].''.$xmend; //$json .= ''.$xmend;//发件人电子邮件 //$json .= ''.$xmend;//发件人固话 $json .= ''.$xmend; $json .= '
'.$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));//空格后到最后的内容 $json .= ''.$adl1.''.$xmend;//收货人地址1 $json .= ''.$adl2.''.$xmend;//收货人地址2 } else { $json .= ''.$data['address'].$data['address2'].''.$xmend;//收货人地址 } //$json .= ''.$xmend; $json .= ''.$data['city'].''.$xmend; if($data['lb'] == 'US') { $json .= ''.$data['province'].''.$xmend; } $json .= ''.$data['zipcode'].''.$xmend; $json .= ''.$data['lb'].''.$xmend;//国家代码 $json .= '
'.$xmend; $json .= '
'.$xmend; $json .= '
'.$xmend; $json .= ''.$xmend; //多箱这里循环 $json .= ''.$xmend; $json .= ''.$data['zzl'].''.$xmend; $json .= ''.$xmend; $json .= '5'.$xmend; $json .= '15'.$xmend; $json .= '3'.$xmend; $json .= ''.$xmend; $json .= ''.$data['number'].''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; //循环结束 $json .= '
'.$xmend; $json .= '
'.$xmend; $json .= '
'.$xmend; $json .= '
'.$xmend; $ch = curl_init(); //curl_setopt($ch, CURLOPT_URL,'https://wsbexpress.dhl.com:443/sndpt/expressRateBook'); curl_setopt($ch, CURLOPT_URL,'https://wsbexpress.dhl.com:443/gbl/expressRateBook'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml; charset=utf-8")); 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, $json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,35); $data = curl_exec($ch); curl_close($ch); $xml = simplexml_load_string($data); $xml->registerXPathNamespace('shipresp', 'http://scxgxtt.phx-dc.dhl.com/euExpressRateBook/ShipmentMsgResponse'); $data = array(); foreach ($xml->xpath('//ShipmentIdentificationNumber') as $item) { $json = json_encode($item); $convrt_arr = json_decode($json, true); $data['waybill'] = $convrt_arr[0]; break; } foreach ($xml->xpath('//GraphicImage') as $item) { $json = json_encode($item); $convrt_arr = json_decode($json, true); $data['yd'] = $convrt_arr[0]; break; } foreach ($xml->xpath('//DocumentImage') as $item) { $json = json_encode($item); $convrt_arr = json_decode($json, true); $data['fp'] = $convrt_arr[0]; break; } if(isset($data['yd'])) { return array('c'=>1,'data'=>$data);exit; } else { $error = ''; foreach ($xml->xpath('//Notification') as $item) { $errorjson = json_encode($item); $errorjson = json_decode($errorjson, true); $error .= isset($errorjson['Message'])?$errorjson['Message'].';':'错误信息获取失败;'; } if(isset($error)) { return array('c'=>2,'data'=>$error);exit; } else { return array('c'=>2,'data'=>'获取数据失败,未知错误!');exit; } } /** $ch = curl_init(); $url = 'http://z.wepolicy.cn/dhlhz.php'; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,35); //设置post数据 $post = array(); $post['data'] = $json; curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post)); $res = curl_exec($ch); curl_close($ch); $data = json_decode($res,true); if(isset($data['yd'])) { return array('c'=>1,'data'=>$data);exit; } else { if(isset($data['$error'])) { return array('c'=>2,'data'=>$error);exit; } else { return array('c'=>2,'data'=>'获取数据失败,未知错误!');exit; } } **/ } public function get_data2($data)//旧版API { 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金融'; } $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'); $data['province'] = preg_replace('/( | | |\s)/',' ',$data['province']); $data['province'] = trim($data['province'],' '); if(isset($ToState[strtolower($data['province'])])) { $dataprovince = strlen($data['province'])==2?$data['province']:$ToState[strtolower($data['province'])]; $data['province'] = $dataprovince; } $sid = '606946403'; $username = 'longyitechnCN'; $password = 'S#5uZ#4vZ$2b'; $xmend = "\n"; $json = "".$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$username.''.$xmend; $json .= "".$password."".$xmend; $json .= " eUYebYfsjztETJ4Urt8AJw ==".$xmend; $json .= ''.date('c').''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.date('c').''.$xmend;//发送请求的时间 $json .= ''.time().time().rand(10000000,99999999).''.$xmend;//报文唯一标识 $json .= 'LYERP'.$xmend;//客户网店平台名称 $json .= 'LY_V1.0.0'.$xmend;//客户网店平台版本号 $json .= 'LYERP'.$xmend;//客户发件系统名称 $json .= 'LY_V1.0.0'.$xmend;//客户发件系统版本号 $json .= 'LYERP'.$xmend;//客户系统插件名称 $json .= 'LY_V1.0.0'.$xmend;//插件版本号 $json .= ''.$xmend; $json .= ''.$xmend; /** 请求装运信息 **/ $json .= ''.$xmend; /** 运单输出 **/ $json .= ''.$xmend; $json .= 'REGULAR_PICKUP'.$xmend;//取件类型 REGULAR_PICKUP不预约取件,REQUEST_COURIER预约取件 $json .= 'P'.$xmend;//产品代码,普通包裹:P,正午特派包裹:Y $json .= 'P'.$xmend;//与ServiceType一致,可不保留 $json .= ''.$xmend; $json .= ''.$sid.''.$xmend;//账号 $json .= 'S'.$xmend;//支付方式S--发件人,R--收件人,T--第三方 $json .= ''.$sid.''.$xmend;//DHL付款账号,当ShippingPaymentType为R或T时,此项为必填项 $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= 'WY'.$xmend;//WY无纸化贸易,DTP服务代码DD,PLT服务代码WY $json .= ''.$xmend; if($data['bx'] > 0) { $json .= ''.$xmend; $json .= 'II'.$xmend;//II购买保险 $json .= ''.$data['bx'].''.$xmend;//保险金额 $json .= 'USD'.$xmend;//保险货币 $json .= ''.$xmend; } $json .= ''.$xmend; $json .= 'USD'.$xmend;//运费币种 $json .= 'SI'.$xmend;//重量单位SI表示千克和厘米,SU表示英镑和英寸 $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$data['number'].''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= 'PDF'.$xmend;//面单输出格式 $json .= 'ARCH_8X4'.$xmend;//面单规格:ECOM26_84_A4_001是A4,ECOM26_84_A4_001是标签 $json .= 'ARCH_8x4'.$xmend;//ARCH_8X4_A4_002:A4纸运单,ARCH_8X4:标签运单Request中未添加该元素时,将默认为标签运单 $json .= 'COMMERCIAL_INVOICE_03'.$xmend;//海关发票模板 $json .= 'true'.$xmend;//启用无纸贸易 $json .= ''.$xmend; $json .= '200'.$xmend; $json .= 'N'.$xmend;//是否打印运单WaybillDoc联 $json .= 'N'.$xmend;//是否隐藏付款账号,Y隐藏,N不隐藏 $json .= '1'.$xmend;//打印数量 $json .= 'Y'.$xmend;//是否需要发票 $json .= 'eng'.$xmend;//海关发票语言代码 $json .= 'COMMERCIAL_INVOICE'.$xmend;//海关发票类型 $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.date('Y-m-d',time()+19*3600).'T'.date('H:i:s',time()+19*3600).'GMT+08:00'.$xmend;//发货时间(预约取货时间开始) $json .= 'DAP'.$xmend;//付款信息 !* /** 包裹和文件 **/ $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$data['sbpm'].''.$xmend;//商品描述,写报关货物内容,品名 $json .= ''.$data['zsbjz'].''.$xmend;//申报价值 $json .= ''.$xmend; $json .= 'NON_DOCUMENTS'.$xmend;//NON_DOCUMENTS为包裹,DOCUMENTS为文件 $json .= ''.$xmend; //循环开始 $json .= ''.$xmend; //(1) $json .= ''.$xmend; $json .= ''.$data['hgbm'].''.$xmend;//海关编码 $json .= 'PERMANENT'.$xmend;//出口原因可选值如下: - ‘PERMANENT’- ‘TEMPORARY’- ‘RETURN’ $json .= '1'.$xmend;//物品序号 $json .= ''.$data['ts'].''.$xmend;//数量 $json .= 'PCS'.$xmend;//数量单位,条 $json .= ''.$data['sbpm'].''.$xmend;//商品描述 $json .= ''.$data['dtsbjz'].''.$xmend;//单条申报价 $json .= ''.$data['zzl'].''.$xmend;//净重 $json .= ''.$data['zzl'].''.$xmend;//总重量 $json .= 'CN'.$xmend;//制造国家代码 $json .= ''.$xmend; //循环结束 $json .= ''.$xmend; $json .= ''.date('Y-m-d',time()).''.$xmend;//发票日期 $json .= ''.$data['paypal'].' '.$data['pay'].''.$xmend;//发票号码 $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$data['number'].''.$xmend;//备注说明 $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= 'He Chong Bo'.$xmend;//发货人 '.$data['warehouse']['company'].' $json .= 'Kun Peng Fazhipin'.$xmend;//'.$data['warehouse']['company'].' $json .= '15939964739'.$xmend; $json .= 'test@test.com'.$xmend;//发件人电子邮件 $json .= '256345673'.$xmend;//发件人固话 $json .= ''.$xmend; $json .= '
'.$xmend; $json .= '4703,building C,'.$xmend;//'.$data['warehouse']['address'].' $json .= 'bodi center,ningwei street'.$xmend;//'.$data['warehouse']['address2'].' //$json .= ''.$xmend; $json .= 'Hang Zhou'.$xmend;//'.$data['warehouse']['city'].' $json .= 'Zhe Jiang'.$xmend;//'.$data['warehouse']['province'].' $json .= '310000'.$xmend;//'.$data['warehouse']['zipcode'].' $json .= ''.$data['warehouse']['lb'].''.$xmend;//国家代码 $json .= '
'.$xmend; $json .= '
'.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; $json .= ''.$data['name'].''.$xmend;//收货人 $json .= ''.$data['client'].''.$xmend; $json .= ''.$data['phone'].''.$xmend; //$json .= ''.$xmend;//发件人电子邮件 //$json .= ''.$xmend;//发件人固话 $json .= ''.$xmend; $json .= '
'.$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));//空格后到最后的内容 $json .= ''.$adl1.''.$xmend;//收货人地址1 $json .= ''.$adl2.''.$xmend;//收货人地址2 } else { $json .= ''.$data['address'].$data['address2'].''.$xmend;//收货人地址 } //$json .= ''.$xmend; $json .= ''.$data['city'].''.$xmend; if($data['lb'] == 'US') { $json .= ''.$data['province'].''.$xmend; } $json .= ''.$data['zipcode'].''.$xmend; $json .= ''.$data['lb'].''.$xmend;//国家代码 $json .= '
'.$xmend; $json .= '
'.$xmend; $json .= '
'.$xmend; $json .= ''.$xmend; //多箱这里循环 $json .= ''.$xmend; $json .= ''.$data['zzl'].''.$xmend; $json .= ''.$xmend; $json .= '5'.$xmend; $json .= '15'.$xmend; $json .= '3'.$xmend; $json .= ''.$xmend; $json .= ''.$data['number'].''.$xmend; $json .= ''.$xmend; $json .= ''.$xmend; //循环结束 $json .= '
'.$xmend; $json .= '
'.$xmend; $json .= '
'.$xmend; $json .= '
'.$xmend; /** $ch = curl_init(); //curl_setopt($ch, CURLOPT_URL,'https://wsbexpress.dhl.com:443/sndpt/expressRateBook'); curl_setopt($ch, CURLOPT_URL,'https://wsbexpress.dhl.com:443/gbl/expressRateBook'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml; charset=utf-8")); 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, $json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,35); $data = curl_exec($ch); curl_close($ch); $xml = simplexml_load_string($data); $xml->registerXPathNamespace('shipresp', 'http://scxgxtt.phx-dc.dhl.com/euExpressRateBook/ShipmentMsgResponse'); $data = array(); foreach ($xml->xpath('//ShipmentIdentificationNumber') as $item) { $json = json_encode($item); $convrt_arr = json_decode($json, true); $data['waybill'] = $convrt_arr[0]; break; } foreach ($xml->xpath('//GraphicImage') as $item) { $json = json_encode($item); $convrt_arr = json_decode($json, true); $data['yd'] = $convrt_arr[0]; break; } foreach ($xml->xpath('//DocumentImage') as $item) { $json = json_encode($item); $convrt_arr = json_decode($json, true); $data['fp'] = $convrt_arr[0]; break; } if(isset($data['yd'])) { return array('c'=>1,'data'=>$data);exit; } else { $error = ''; foreach ($xml->xpath('//Notification') as $item) { $errorjson = json_encode($item); $errorjson = json_decode($errorjson, true); $error .= isset($errorjson['Message'])?$errorjson['Message'].';':'错误信息获取失败;'; } if(isset($error)) { return array('c'=>2,'data'=>$error);exit; } else { return array('c'=>2,'data'=>'获取数据失败,未知错误!');exit; } } **/ $ch = curl_init(); $url = 'http://z.wepolicy.cn/dhlhz.php'; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,35); //设置post数据 $post = array(); $post['data'] = $json; curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post)); $res = curl_exec($ch); curl_close($ch); $data = json_decode($res,true); if(isset($data['yd'])) { return array('c'=>1,'data'=>$data);exit; } else { if(isset($data['$error'])) { return array('c'=>2,'data'=>$error);exit; } else { return array('c'=>2,'data'=>'获取数据失败,未知错误!');exit; } } } public function get_epod($data) { $sid = '606946403'; $username = 'longyitechnCN'; $password = 'S#5uZ#4vZ$2b'; $xmend = "\n"; $xml = ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$username.''.$xmend; $xml .= "".$password."".$xmend; $xml .= "".$xmend; $xml .= ''.date('c').''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; $xml .= ''.$xmend; //echo $xml;exit; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,'https://wsbexpress.dhl.com:443/gbl/getePOD'); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:text/xml; charset=utf-8")); 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); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,35); $data = curl_exec($ch); curl_close($ch); //header("Content-type: application/xml"); $xml = simplexml_load_string($data); $xml->registerXPathNamespace('tns','http://scxgxtt.phx-dc.dhl.com/glDHLExpressePOD/providers/DocumentRetrieve'); if($xml->xpath('//Img')) { foreach ($xml->xpath('//Img') as $item) { $json = json_encode($item); $convrt_arr = json_decode($json, true); return array('c'=>1,'d'=>$convrt_arr['@attributes']['Img']); } } else { foreach ($xml->xpath('//ErrMsgDtl ') as $item) { $json = json_encode($item); $convrt_arr = json_decode($json, true); return array('c'=>2,'d'=>$convrt_arr['@attributes']['DtlDsc']); } } } public function _a($data) { $token = $this->c(); $file_header = array( 'x-request-id: 606946403', 'Authorization: '.$token, 'Content-Type: application/json' ); $ch = curl_init(); $url = 'https://webhub.cndhl.com/dps/dps-declaration-api/api/declare/submit-declare'; curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_HTTPHEADER, $file_header); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600); //设置post数据 $post = array(); $post['decMessage']['decHead']['iEFlag']="E"; $post['decMessage']['decHead']['tradeName']="杭州龙熠科技有限公司"; $post['decMessage']['decHead']['tradeCoScc']="91330106MA2GMD3N8R"; $post['decMessage']['decHead']['tradeCode']="3316960A6A"; $post['decMessage']['decHead']['ownerName']="杭州龙熠科技有限公司"; $post['decMessage']['decHead']['ownerCodeScc']="91330106MA2GMD3N8R"; $post['decMessage']['decHead']['tradeMode']="3010"; $post['decMessage']['decHead']['transMode']="2"; $post['decMessage']['decHead']['cutMode']="101"; $post['decMessage']['decHead']['feeMark']="3"; $post['decMessage']['decHead']['feeRate']="10"; $post['decMessage']['decHead']['feeCurr']="USD"; $post['decMessage']['decLists']['decList'][0]['gNo']="1"; $post['decMessage']['decLists']['decList'][0]['declGoodsEname']=$data['sbpm'];//申报品名 $post['decMessage']['decLists']['decList'][0]['gName']=$data['zwpm'];//中文品名 $post['decMessage']['decLists']['decList'][0]['codeTs']=$data['hgbm'];//海关编码 $post['decMessage']['decLists']['decList'][0]['gModel']="0|2|假发|化纤"; $post['decMessage']['decLists']['decList'][0]['gQty']=$data['ts'];//数量 $post['decMessage']['decLists']['decList'][0]['gUnit']="007"; $post['decMessage']['decLists']['decList'][0]['declPrice']=$data['dtsbjz'];//申报单价 $post['decMessage']['decLists']['decList'][0]['declTotal']=$data['zsbjz'];//申报总价 $post['decMessage']['decLists']['decList'][0]['tradeCurr']="USD"; $post['decMessage']['decLists']['decList'][0]['firstQty']="0.10000"; $post['decMessage']['decLists']['decList'][0]['firstUnit']="035"; $post['decMessage']['decLists']['decList'][0]['goodsBrand']="无"; $post['decMessage']['decLists']['decList'][0]['dutyMode']="1"; $post['decMessage']['decLists']['decList'][0]['originCountry']="CHN"; $post['decMessage']['msgHead']['action']="A"; $post['decMessage']['msgHead']['awbGenDtm']= date("Y-m-d H:i:s",time()-3600); $post['decMessage']['msgHead']['awbNo']=$data['waybill'];//运单号 $post['decMessage']['msgHead']['declareType']="C"; $post['decMessage']['msgHead']['msgGenDtm']=date("Y-m-d H:i:s",time()); $post['decMessage']['msgHead']['msgId']="7b67817a-9c81-412d-bedd-10a65ac22508"; $post['decMessage']['msgHead']['version']="1.0"; $data = json_encode($post); curl_setopt($ch, CURLOPT_POSTFIELDS,$data); $res = curl_exec($ch); curl_close($ch); $resp = json_decode($res,true); echo "
";
		print_r($resp);
	}
	
	public function c()
	{
		$token_header = array(
            'x-request-id: 606946403',
			'Content-Type: application/json'
        );
		$ch = curl_init();
		$url = 'https://webhub.cndhl.com/dps/dps-auth-server/api/gateway-token/generate';
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_HTTPHEADER, $token_header);
		curl_setopt($ch,CURLOPT_HEADER,0);
		curl_setopt($ch,CURLOPT_POST, 1);
		curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
        //设置post数据
		$post = array();
		$post['consumerCode'] = 'T_mkfsq4ez3w';
		$post['key'] = '8BsPOT:Sib_Vc*$=';
		$data = json_encode($post);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
		$res = curl_exec($ch);
		curl_close($ch);
		$resp = json_decode($res,true);
		$token = $resp['result']['token'];
		return $token;
	}
}  //end class