映美打印机-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>
相关推荐
Bruce_Liuxiaowei4 小时前
.htaccess 文件上传漏洞绕过总结
windows·安全·网络安全·php·apache
云罗ymh63815 小时前
碰一碰NFC开发写好评php语言源码
开发语言·php
一只 Lemon7 小时前
PHP-单引号和双引号(通俗易懂讲解版)
开发语言·php
德迅云安全-小潘17 小时前
网络安全风险评估:企业安全防护的核心基石
安全·web安全·php
Ai财富密码1 天前
【Python爬虫】正则表达式入门及在数据提取中的高效应用
数据库·mysql·php
WordPress学习笔记1 天前
wordpress的wp-config.php文件的详解
php·wordpress·wp-config
小楓12011 天前
後端開發技術教學(三) 表單提交、數據處理
前端·后端·html·php
Bruce_Liuxiaowei1 天前
利用哥斯拉(Godzilla)进行文件上传漏洞渗透实战分析
网络·网络安全·php·哥斯拉
CF14年老兵1 天前
5 个最佳工具,可立即从代码生成 API 文档
前端·后端·api
TeroBox2 天前
GPT-5 API 请求参数调整,避坑指南(汇总)
openai·api·gpt-5·poixeai