1.form表单传递数据,到控制器,之后的复制操作
1 顺丰信息 2 //快递信息 3 $eorder = []; 4 $eorder["ShipperCode"] = $express_number[$number]; //快递公司编码 5 $eorder["OrderCode"] = $ship_order_data[‘ship_order_number‘]; //发货单编号() 6 7 $eorder["PayType"] = 3; //支付快递方式 1现付 2到付 3月结 4第三方 8 $eorder["ExpType"] = $express_type; //快递类型 1次日达 2 隔日达 9 $eorder["IsReturnPrintTemplate"] = 1; //是否需要电子面单 1需要 0不 10 //目前接口中每家快递公司配置需求与值都不相同 部分需单独当地网点申请帐号密码 11 if($number == 1){ //顺丰 12 // $eorder["MonthCode"] = ‘5270013057‘; //月结卡号 月结类型必填 13 $eorder["MonthCode"] = ‘5270325075‘; //月结卡号 月结类型必填 14 } 15 16 //发货信息 17 $sender = []; 18 $sender["Name"] = $ship_order_data[‘send_username‘]; 19 $sender["Mobile"] = $ship_order_data[‘send_phone‘]; 20 $sender["ProvinceName"] = $ship_order_data[‘send_province‘]; 21 $sender["CityName"] = $ship_order_data[‘send_city‘]; 22 $sender["ExpAreaName"] = $ship_order_data[‘send_exparea‘]; 23 $sender["Address"] = $ship_order_data[‘send_address‘]; 24 // $sender["Name"] = ‘豹子头‘; 25 // $sender["Mobile"] = ‘13588243329‘; 26 // $sender["ProvinceName"] = ‘江苏省‘; 27 // $sender["CityName"] = ‘宿迁市‘; 28 // $sender["ExpAreaName"] = ‘泗阳县‘; 29 // $sender["Address"] = ‘淮海东路11号‘; 30 //收货信息 31 $receiver = []; 32 $receiver["Name"] = $ship_order_data[‘username‘]; 33 $receiver["Mobile"] = $ship_order_data[‘phone‘]; 34 $receiver["ProvinceName"] = $ship_order_data[‘province‘]; 35 $receiver["CityName"] = $ship_order_data[‘city‘]; 36 $receiver["ExpAreaName"] = $ship_order_data[‘exparea‘]; 37 $receiver["Address"] = $ship_order_data[‘address‘]; 38 // $receiver["Name"] = ‘王先生‘; 39 // $receiver["Mobile"] = ‘15282334566‘; 40 // $receiver["ProvinceName"] = ‘四川省‘; 41 // $receiver["CityName"] = ‘成都市‘; 42 // $receiver["ExpAreaName"] = ‘青羊区‘; 43 // $receiver["Address"] = ‘一环路东四段‘; 44 45 $commodityOne = []; 46 $commodityOne["GoodsName"] = ‘衬衫*‘.$total_number.‘件‘; //商品名 数量 47 // dump($commodityOne);die; 48 $commodity = []; 49 $commodity[] = $commodityOne; 50 51 $eorder["Sender"] = $sender; 52 $eorder["Receiver"] = $receiver; 53 $eorder["Commodity"] = $commodity; 54 55 //备注 56 $ship_order_data[‘ship_order_number‘]; 57 $eorder["Remark"] = db(‘ship_box‘)->where(‘ship_order_num‘, $ship)->value(‘box_num‘); 58 $eorder["Remark"] .= ‘号框‘; 59 60 //调用电子面单 61 $jsonParam = json_encode($eorder, JSON_UNESCAPED_UNICODE); 62 //电子面单提交结果 63 $jsonResult = $this->submitEOrder($jsonParam); 64 // dump($eorder);die; 65 //解析电子面单返回结果 66 $result = json_decode($jsonResult, true); 67 68 echo "<script>alert(‘发货信息已成功提交至快递公司,请打印电子面单!‘);parent.location.reload();</script>"; 69 echo $result[‘PrintTemplate‘];//打印PrintTemplate的数据
70 echo "<script>print()</script>";
第二部.这是签名和提交的方法
1 /** 2 * Json方式 调用电子面单接口 3 */ 4 public function submitEOrder($requestData) 5 { 6 $express_config = config(‘KUAIDINIAO‘);//信息配置在config的信息,你也可以写死 7 $datas = array(//必须 8 ‘EBusinessID‘ => $express_config[‘EBusinessID‘], 9 ‘RequestType‘ => ‘1007‘, 10 ‘RequestData‘ => urlencode($requestData), 11 ‘DataType‘ => ‘2‘, 12 ); 13 $datas[‘DataSign‘] = $this->encrypt($requestData, $express_config[‘AppKey‘]);//获取签名 14 $result = $this->sendPost($express_config[‘ReqURL‘], $datas);//提交数据 15 return $result; 16 } 17 /** 18 * 电商Sign签名生成 19 * @param data 内容 20 * @param appkey Appkey 21 * @return DataSign签名 22 */ 23 public function encrypt($data, $appkey) 24 { 25 return urlencode(base64_encode(md5($data . $appkey))); 26 } 27 /** 28 * post提交数据 29 * @param string $url 请求Url 30 * @param array $datas 提交的数据 31 * @return url响应返回的html 32 */ 33 public function sendPost($url, $datas) 34 { 35 $temps = array(); 36 foreach ($datas as $key => $value) { 37 $temps[] = sprintf(‘%s=%s‘, $key, $value); 38 } 39 $post_data = implode(‘&‘, $temps); 40 $url_info = parse_url($url); 41 if (empty($url_info[‘port‘])) { 42 $url_info[‘port‘] = 80; 43 } 44 $httpheader = "POST " . $url_info[‘path‘] . " HTTP/1.0\r\n"; 45 $httpheader .= "Host:" . $url_info[‘host‘] . "\r\n"; 46 $httpheader .= "Content-Type:application/x-www-form-urlencoded\r\n"; 47 $httpheader .= "Content-Length:" . strlen($post_data) . "\r\n"; 48 $httpheader .= "Connection:close\r\n\r\n"; 49 $httpheader .= $post_data; 50 $fd = fsockopen($url_info[‘host‘], $url_info[‘port‘]); 51 fwrite($fd, $httpheader); 52 $gets = ""; 53 $headerFlag = true; 54 while (!feof($fd)) { 55 if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) { 56 break; 57 } 58 } 59 while (!feof($fd)) { 60 $gets .= fread($fd, 128); 61 } 62 fclose($fd); 63 64 return $gets; 65 }
快递鸟的顺丰比较简单,这就完成了,如果你有什么不理解的,可以给我留言