映美打印机-URL页面打印

php 复制代码
<?php
/**
打印 - 映美云 https://open.jolimark.com/doc/
*/
namespace Home\Controller;
use Admin\Logic\OrderLogic;

class PrintController extends BaseController {
	
	private $appid = "";
	private $appkey = "";
	//打印机编号
	private $deviceIds = "";
	
	//订单打印 - URL地址打印
	public function order_print($order_id = 0)
	{
		$orderLogic = new OrderLogic();
		$order = $orderLogic->getOrderInfo($order_id);
		if (empty($order)) {
			$this->error('订单不存在');
            exit;
		}
		$url = "https://mcp.jolimark.com/mcp/v3/sys/PrintHtmlUrl";
		$access_token = $this->get_access_token();
		$params = [
			'app_id'		=> $this->appid,
			'access_token'	=> $access_token,
			'device_ids'	=> $this->deviceIds,
			'cus_orderid'	=> $order['order_sn'],
			'bill_content'	=> "http://xxxxx.com/Home/Print/order_print_view/id/".$order_id,
			'paper_width'	=> 98,    //打印纸宽度
			'paper_height'	=> 98,    //打印纸高度
			'paper_type'	=> 2,     //标签纸
		];
		$res = httpRequest($url, "POST", $params);
		$res  = json_decode($res, true);
		if ($res['return_code'] == 0) {
			return true;
		}
		else {
			return false;
		}
	}
	
	//订单打印页
	public function order_print_view()
	{
		$order_id = I("get.id",'0');
		$orderLogic = new OrderLogic();
        $order = $orderLogic->getOrderInfo($order_id);
		if (empty($order)) {
			$this->error('订单不存在');
            exit;
		}
        $orderGoods = $orderLogic->getOrderGoods($order_id);
		
		$this->assign('order', $order);
		$this->assign('orderGoods',$orderGoods);
		$this->display();
	}
	
	//获取access_token
	private function get_access_token()
	{
		$access_token = S('jolimark_access_token');
		if (!$access_token)
		{
			$url = "https://mcp.jolimark.com/mcp/v3/sys/GetAccessToken";
			$time_stamp = time();
			$param_url = "app_id={$this->appid}&sign_type=MD&time_stamp={$time_stamp}&key={$this->appkey}";
			$sign = strtoupper( MD5($param_url) );
			$url .= "?".$param_url."&sign=".$sign;
			$res  = httpRequest($url, "GET");
			$res  = json_decode($res, true);
			if ($res['return_code'] == 0)
			{
				$access_token = $res['return_data']['access_token'];
				S('jolimark_access_token', $access_token, $res['return_data']['expires_in']);
			}
		}
		return $access_token;
	}
}

URL订单页面排版代码

html 复制代码
<html> 
 <head> 
   <title>配送小票</title> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     </head> 
   <body> 
   <!--小票基本信息--> 
     <p><label style="font-size:48px;font-weight:bold;">订单打印</label></p> 
         <!--配送信息--> 
     <hr style="print-char:*;"> 
     <p><label style="font-size:34px;font-weight:bold;">{$order.address2} - <if condition="$order.shipping_price eq '0.00'">到店自取<else />{$order.shipping_name}</if></label></p> 
     <p><label style="font-size:34px;font-weight:bold;">{$order.consignee}</label></p> 
     <p><label style="font-size:34px;font-weight:bold;">{$order.mobile}</label></p> 
     <hr style="print-char:*;"> 
     <p><label>订单编号: </label><label>{$order.order_sn}</label></p> 
     <p><label>下单时间: </label><label>{$order.add_time|date='Y-m-d H:i',###}</label></p>
	 <p><label>支付方式: </label><label>{$order.pay_name}</label></p>
	 <p><label>客服电话: </label><label>13245566789</label></p>
     <p><label style="font-weight:bold;">到店取件码: </label><label style="font-weight:bold;">{$order.pickup_code}</label></p>
     <!--小票明细--> 
     <hr style="print-char:-;print-text:物品;"> 
	<volist name="orderGoods" id="good">
    <p> 
		<label style="width:71%;font-weight:bold;">{$good.goods_name}</label> 
       <label style="width:13%;font-weight:bold;text-align:center;">X{$good.goods_num}</label> 
       <label style="width:16%;font-weight:bold;text-align:right;">{$good[goods_total] - $good[zhekou]}</label> 
    </p>
	</volist>
     <p>
     <!--费用明细--> 
     <hr style="print-char:-;print-text:其它费用;"> 
     <p> 
     <label style="width:85%;font-weight:bold;">运费</label> 
       <label style="width: 15%;font-weight:bold;text-align:right;">{$order.shipping_price}</label> 
	 </p>
	 <p> 
     <label style="width:85%;font-weight:bold;">新人立领</label> 
       <label style="width: 15%;font-weight:bold;text-align:right;">{$order.fuli_price}</label> 
	 </p> 
	 <p> 
     <label style="width:85%;font-weight:bold;">活动优惠</label> 
       <label style="width: 15%;font-weight:bold;text-align:right;">{$order.cut_fee}</label> 
	 </p> 
     <p><label style="text-align:right;font-weight:bold;font-size:36px;">总计: {$order.order_amount}</label></p> 
     <!-- <br /> -->
     <!-- <h3 style="text-align:center;font-size:48px;font-weight:bold;">=== #1 完 ===</h3>  -->
     <!-- <br />  -->
     </body> 
   </html>
相关推荐
蓝倾1 天前
淘宝利用商品关键词获取商品信息指南
api·fastapi
子兮曰1 天前
🚀 震惊!这20个现代JavaScript API,让90%的前端开发者直呼"相见恨晚"!
javascript·api
Amber_371 天前
深入理解Go 与 PHP 在参数传递上的核心区别
android·golang·php
onelafite1 天前
淘宝/天猫店铺商品搜索API(taobao.item_search_shop)返回值详解
api·fastapi
BingoGo1 天前
PHP 并不慢 你的架构才是瓶颈 大规模性能优化实战
后端·php
JaguarJack1 天前
PHP 并不慢 你的架构才是瓶颈 大规模性能优化实战
php
蹦极的考拉2 天前
网站日志里面老是出现{pboot:if((\x22file_put_co\x22.\x22ntents\x22)(\x22temp.php\x22.....
android·开发语言·php
暴走十八步2 天前
配置windows下apache+PHP环境
windows·php·apache
RestCloud2 天前
iPaaS实施的前提是先进行集成关系的梳理
api
用户268001379192 天前
小红书笔记详情API接口系列,json数据返回
api