<div id="hh"> </div> <button class=" BTN bTN-default bTN-xs "type="button" id=" aaa"> $(document).ready(function(){ $("#aaa").click(function(){ $.ajax({ type:"post", url:"{:url('Mall/orderface')}", data:'number='+$number+'&id='+$id, dataType:'json', success:function(data){ if (data.ret == 0){ alert(data.msg); }else{ $count = data.data.length; for (var i=0; i<$count; i++){ $('#hh').html(data.data); $('#hh').show(); $("#hh").printArea(); $('#hh').hide(); }}}}); }); }); public function orderface(){ $id = $_POST['id']; $number = $_POST['number']; $config_model = new Config(); $config = $config_model->findOne(['uid'=>UID]); $mall_order_model = new MallOrder(); $order = $mall_order_model->findOne(['uid' => 2, 'id' => $id]); $receiver = ["Name"=>$order['linkman'], $receiver "Mobile"=>$order['mobile_phone'], Will fill a "ProvinceName = > $order [' province '], / /" CityName "= > $order receipt province [' city '], / / receipt city" ExpAreaName "= > $order [' area '], / / a district/county $order[' Address '] =>$order[' Address ']; / / the sender information $sender = [" Name = "" > $config [' sender_name], / / the sender" Mobile "= > $config [' sender_phone], / / phone and Mobile phone, Will fill a "ProvinceName = > $config [' province]," CityName = "/ / receipt province > $config [' city '], / / send a city" ExpAreaName "= > $config [' area '], / / a district/county "Address" = > $config [' sender_address], / / the sender Address]; $commodity = []; if ($id) { $order_id = $id; $mall_order_product_model = new MallOrderProduct(); $order_product = $mall_order_product_model->selectList(['order_id' => array('IN', $order_id)]); foreach ($order_product as $key => $value) { $sku_name = $this->skuToName($value['product_sku'], $value['product_id']); $arr = [ "GoodsName"=>$value['product_name'].$sku_name, "Goodsquantity"=>$value['number'], "GoodsPrice"=>$value['product_price'] ]; array_push($commodity,$arr); } } $kdiniao_express_model = new KdiniaoExpress(); $code = $kdiniao_express_model->where(['id'=>$order['express_id']])->find(); $eORDER = ["ShipperCode"=>$code['encipher'], $eorder =>$order['order_number'], Non-repeatable) "PayType"=>1,// Postage payment method :1- Cash, 2- Collect, 3- monthly settlement, 4- third-party payment (SF only supported) "ExpType"=>1,// Delivery type: $Receiver =>$Receiver, $Receiver =>$Receiver, $Receiver =>$Receiver, $Receiver =>$Receiver "Quantity"=>(int)$number,// number of packages (up to 30 PCS are supported) "Remark"=>"",// Remarks "IsReturnPrintTemplate"=>1// Return electronic surface single template: 0- not required; 1- required]; $jsonParam = json_encode($eorder, JSON_UNESCAPED_UNICODE); $jc_api_model = new JcApi(); $result = $jc_api_model->getExterFaceByKdniao($jsonParam); $result = json_decode($result, true); if ($result['Success'] == false){ return ajaxFalse($result['Reason']); } $PrintTemplate = [ $result['PrintTemplate'] ]; if (array_key_exists('SubPrintTemplates',$result)){ foreach($result['SubPrintTemplates'] as $kay => $val){ array_push($PrintTemplate,$val); } } return ajaxSuccess($PrintTemplate); } function getExterFaceByKdniao($content) { $jc_third_party_config_model = new JcThirdPartyConfig(); $deliver_kdniao_config = $jc_third_party_config_model->getKdniaoDeliveryConfig(); // Test $deliver_kdniAO_config = ['kdniao_user_id'=>'test1597343','kdniao_api_key'=>'07ca9479-e5ff-4e72-81cf-32511eb30000']; $businessid = array(' businessid '=> $deliver_kniao_config [' businessid '], $businessid => $deliver_kniao_user_id '], 'RequestData' => urlencode($content) , 'DataType' => '2', ); $datas['DataSign'] = $this->encrypt($content, $deliver_kdniao_config['kdniao_api_key']); // $url = "http://sandboxapi.kdniao.com:8080/kdniaosandbox/gateway/exterfaceInvoke.json"; / / test $url = "https://api.kdniao.com/api/EOrderService"; $result = $this->sendPost($url, $datas); return $result; Function encrypt($data, $appkey) {return urlencode(base64_encode(md5($data.$appkey))); }/** */ function sendPost($url, $datas) {$temps = array(); foreach ($datas as $key => $value) { $temps[] = sprintf('%s=%s', $key, $value); } $post_data = implode('&', $temps); $url_info = parse_url($url); if(empty($url_info['port'])) { $url_info['port']=80; } $httpheader = "POST". $url_info [' path '] "HTTP / 1.0 \ r \ n"; $httpheader.= "Host:" . $url_info['host'] . "\r\n"; $httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n"; $httpheader.= "Content-Length:" . strlen($post_data) . "\r\n"; $httpheader.= "Connection:close\r\n\r\n"; $httpheader.= $post_data; $fd = fsockopen($url_info['host'], $url_info['port']); fwrite($fd, $httpheader); $gets = ""; $headerFlag = true; while (! feof($fd)) { if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) { break; } } while (! feof($fd)) { $gets.= fread($fd, 128); } fclose($fd); return $gets; }Copy the code
Download the jquery. Printarea. Js: plugins.jquery.com/PrintArea/
Download the official Demo of Express Bird: www.kdniao.com/api-eorder