123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <?php
- class Model_Ali extends Lin_Model {
- function __construct(){
- parent::__construct();
- }
- public function get_data($data)
- {
- $appToken = '070c4a24fdeb23fa3e0270858cd2ceda';
- $appKey = '070c4a24fdeb23fa3e0270858cd2cedabfd75d1f2e461ee13e69646d3437a302';
-
- $data['address'] = str_replace(array('&'),array('&'),$data['address']);
- $data['address2'] = str_replace(array('&'),array('&'),$data['address2']);
- $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','guam'=>'GU');
- $data['province'] = preg_replace('/( | |\s)/',' ',$data['province']);
- $data['province'] = trim($data['province'],' ');
- $data['province'] = (strlen($data['province'])==2 || $data['lb'] != 'US')?$data['province']:$ToState[strtolower($data['province'])];
- $data['city'] = preg_replace('/( | |\s)/',' ',$data['city']);
- if($data['printcode'] == 'FEDEX')
- {
- $code = 'YB0004';
- }
- else if($data['printcode'] == 'TOLL')
- {
- $code = 'DPEX';
- }
- else if($data['printcode'] == 'ARAMEX')
- {
- $code = 'YB0001';
- }
- else
- {
- $code = $data['printcode'];
- }
-
- $list = array();
- $list['reference_no'] = $data['number'];//客户参考号
- //$list['shipper_hawbcode'] = 'YT'.$data['orderinfo'];//运单号,必须YT开头
- $list['shipping_method'] = $code;//配送方式
- $list['order_weight'] = '0.400';//订单重量
- $list['country_code'] = $data['lb'];//收件人国家二字码
- if($data['bx'] > 0)
- {
- $list['insurance_value'] = $data['bx'];//投保金额,默认RMB
- }
- $list['order_pieces'] = $data['zjs'];//外包装件数,默认
- $list['Consignee'] = array();//收件人信息
- $list['Consignee']['consignee_company'] = $data['client'];
- $list['Consignee']['consignee_province'] = $data['province'];
- $list['Consignee']['consignee_city'] = $data['city'];
- $list['Consignee']['consignee_street'] = $data['address'];
- if($data['address2'])
- {
- $list['Consignee']['consignee_street2'] = $data['address2'];
- }
- $list['Consignee']['consignee_postcode'] = trim($data['zipcode'],' ');
- $list['Consignee']['consignee_name'] = $data['name'];
- $list['Consignee']['consignee_telephone'] = $data['phone'];
- $list['Shipper'] = array();//发件人信息
- $list['Shipper']['shipper_company'] = $data['warehouse']['company'];
- $list['Shipper']['shipper_countrycode'] = $data['warehouse']['lb'];
- $list['Shipper']['shipper_province'] = $data['warehouse']['province'];
- $list['Shipper']['shipper_city'] = $data['warehouse']['city'];
- $list['Shipper']['shipper_street'] = $data['warehouse']['address'].$data['warehouse']['address2'];
- $list['Shipper']['shipper_postcode'] = $data['warehouse']['zipcode'];
- $list['Shipper']['shipper_name'] = $data['warehouse']['company'];
- $list['Shipper']['shipper_telephone'] = preg_replace('/\D/s','',$data['warehouse']['phone']);
- $list['Shipper']['shipper_mobile'] = '03747050111';
- $list['Shipper']['shipper_email'] = '3002735981@qq.com';
- $list['ItemArr'] = array();
- $list['ItemArr'][0]['invoice_enname'] = $data['sbpm'];
- $list['ItemArr'][0]['invoice_cnname'] = $data['zwpm'];
- //$zzl = sprintf("%.2f",0.4/($data['ts']+1));
- $list['ItemArr'][0]['invoice_weight'] = '0.005';
- $list['ItemArr'][0]['invoice_quantity'] = $data['ts'];
- $list['ItemArr'][0]['invoice_unitcharge'] = $data['dtsbjz'];
- //$list['ItemArr']['invoice_currencycode'] = 'USD';
-
- $xml = '<?xml version="1.0" encoding="UTF-8"?>';
- $xml.='<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.org/Ec/">';
- $xml.='<SOAP-ENV:Body>';
- $xml.='<ns1:callService>';
- $xml.='<paramsJson>'.json_encode($list).'</paramsJson>';
- $xml.='<appToken>'.$appToken.'</appToken>';
- $xml.='<appKey>'.$appKey.'</appKey>';
- $xml.='<service>createOrder</service>';
- $xml.='</ns1:callService>';
- $xml.='</SOAP-ENV:Body>';
- $xml.='</SOAP-ENV:Envelope>';
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'http://120.78.181.120/default/svc/web-service');
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
- curl_setopt($ch, CURLOPT_VERBOSE, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- $result_xml = curl_exec($ch);
- $result_xml = $response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $result_xml);
- $xml = new SimpleXMLElement($result_xml);
- $body = $xml->xpath('//ns1callServiceResponse');
- $array = json_decode(json_encode((array)$body),true);
- $result_xml = json_decode($array[0]['response'],true);
- if($result_xml['ask'] == 'Failure')
- {
- return array('a'=>1,'m'=>$result_xml['message'].':'.$result_xml['Error']['errMessage']);
- }
- else
- {
- return array('a'=>2,'number'=>$result_xml['shipping_method_no']);
- }
-
- }
-
- public function get_label($number,$type)
- {
- $appToken = '070c4a24fdeb23fa3e0270858cd2ceda';
- $appKey = '070c4a24fdeb23fa3e0270858cd2cedabfd75d1f2e461ee13e69646d3437a302';
-
- $list = array();
- $list['reference_no'] = $number;
- $list['label_type'] = $type;
-
- $xml = '<?xml version="1.0" encoding="UTF-8"?>';
- $xml.='<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.org/Ec/">';
- $xml.='<SOAP-ENV:Body>';
- $xml.='<ns1:callService>';
- $xml.='<paramsJson>'.json_encode($list).'</paramsJson>';
- $xml.='<appToken>'.$appToken.'</appToken>';
- $xml.='<appKey>'.$appKey.'</appKey>';
- $xml.='<service>getLabelUrl</service>';
- $xml.='</ns1:callService>';
- $xml.='</SOAP-ENV:Body>';
- $xml.='</SOAP-ENV:Envelope>';
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'http://120.78.181.120/default/svc/web-service');
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
- curl_setopt($ch, CURLOPT_VERBOSE, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- $result_xml = curl_exec($ch);
- $result_xml = $response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $result_xml);
- $xml = new SimpleXMLElement($result_xml);
- $body = $xml->xpath('//ns1callServiceResponse');
- $array = json_decode(json_encode((array)$body),true);
- $result_xml = json_decode($array[0]['response'],true);
- if($result_xml['ask'] == 'Failure')
- {
- return array('a'=>1,'m'=>$result_xml['Error']['errMessage']);
- }
- else
- {
- return array('a'=>2,'pdf'=>$result_xml['url']);
- }
-
- }
-
- public function get_ps()//配送方式 getShippingMethod
- {
- $appToken = '070c4a24fdeb23fa3e0270858cd2ceda';
- $appKey = '070c4a24fdeb23fa3e0270858cd2cedabfd75d1f2e461ee13e69646d3437a302';
- $xml = '<?xml version="1.0" encoding="UTF-8"?>';
- $xml.='<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.org/Ec/">';
- $xml.='<SOAP-ENV:Body>';
- $xml.='<ns1:callService>';
- $xml.='<paramsJson>'.json_encode(array('true')).'</paramsJson>';
- $xml.='<appToken>'.$appToken.'</appToken>';
- $xml.='<appKey>'.$appKey.'</appKey>';
- $xml.='<service>getShippingMethod</service>';
- $xml.='</ns1:callService>';
- $xml.='</SOAP-ENV:Body>';
- $xml.='</SOAP-ENV:Envelope>';
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'http://120.78.181.120/default/svc/web-service');
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
- curl_setopt($ch, CURLOPT_VERBOSE, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- $result_xml = curl_exec($ch);
- $result_xml = str_replace(array(':','-'), '', $result_xml);
- @$result_xml = json_decode(json_encode(simplexml_load_string($result_xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
- $result_xml = str_replace(array('""','"[','time_cost(s)"','err_code"','"{'),array('":"','":[','time_cost(s)":','err_code":','":{'),$result_xml['SOAPENVBody']['ns1callServiceResponse']['response']);
- $result_xml = json_decode($result_xml,true);
- return $result_xml;
- }
-
- public function get_lj($number,$type)//取消
- {
- $appToken = '070c4a24fdeb23fa3e0270858cd2ceda';
- $appKey = '070c4a24fdeb23fa3e0270858cd2cedabfd75d1f2e461ee13e69646d3437a302';
-
- $list = array();
- $list['reference_no'] = $number;
- $list['type'] = $type;
- $xml = '<?xml version="1.0" encoding="UTF-8"?>';
- $xml.='<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.example.org/Ec/">';
- $xml.='<SOAP-ENV:Body>';
- $xml.='<ns1:callService>';
- $xml.='<paramsJson>'.json_encode($list).'</paramsJson>';
- $xml.='<appToken>'.$appToken.'</appToken>';
- $xml.='<appKey>'.$appKey.'</appKey>';
- $xml.='<service>cancelOrder</service>';
- $xml.='</ns1:callService>';
- $xml.='</SOAP-ENV:Body>';
- $xml.='</SOAP-ENV:Envelope>';
-
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'http://120.78.181.120/default/svc/web-service');
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
- curl_setopt($ch, CURLOPT_VERBOSE, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- $result_xml = curl_exec($ch);
- $result_xml = $response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $result_xml);
- $xml = new SimpleXMLElement($result_xml);
- $body = $xml->xpath('//ns1callServiceResponse');
- $array = json_decode(json_encode((array)$body),true);
- $result_xml = json_decode($array[0]['response'],true);
- if($result_xml['ask'] == 'Success')
- {
- return 1;
- }
- else
- {
- return $result_xml['Error']['errMessage'];
- }
- }
- } //end class
|