PHP 打印扩展开发:从易联云到小鹅通的多驱动集成实践

目前已有易联云WIFI打印机扩展

<>扩展入口文件

文件目录 crmeb\services\printer\Printer.php

复制代码
namespace crmeb\services\printer;

use crmeb\basic\BaseManager;
use think\facade\Config;
use think\Container;

/**
 * Class Printer
 * @package crmeb\services\auth
 * @mixin \crmeb\services\printer\storage\YiLianYun
 */
class Printer extends BaseManager
{
    //...
}

<>使用打印扩展

复制代码
use crmeb\services\printer\Printer;

$printer = new Printer([
    'clientId'=>'',
    'apiKey'=>'',
    'partner'=>' ',
    'terminal'=>'',
]);

$res = $printer->setPrinterContent([
    'name'=> '标题',
    'orderInfo'=> [],//订单信息
    'product'=> [],//商品信息
])->startPrinter();

var_dump($res);

<>举例增加:小鹅通打印扩展

创建文件:crmeb\services\printer\storage\XiaoETong.php

复制代码
namespace crmeb\services\printer\storage;

class XiaoETong extends BasePrinter
{
    //初始化
    protected function initialize(array $config)
    {

    }

    //开始打印
    public function startPrinter()
    {

    }

    //设置打印内容
    public function setPrinterContent(array $config): self
    {

        return $this;
    }

}

增加小鹅通获取AccessToken

复制代码
namespace crmeb\services\printer;

class AccessToken extends HttpService
{
    /**
     * 获取token
     * @return mixed|null|string
     * @throws \Exception
     */
    public function getAccessToken()
    {
        if (isset($this->accessToken[$this->name])) {
            return $this->accessToken[$this->name];
        }

        $action = 'get' . Str::studly($this->name) . 'AccessToken';
        if (method_exists($this, $action)) {
            return $this->{$action}();
        } else {
            throw new \RuntimeException(__CLASS__ . '->' . $action . '(),Method not worn in');
        }
    }

    //增加小鹅通获取access_token类
    protected function getXiaoETongAccessToken()
    {
          /** @var CacheServices $cacheServices */
        $cacheServices = app()->make(CacheServices::class);
        $this->accessToken[$this->name] = $cacheServices->getDbCache('XET_access_token', function () {
            //写获取$access_token的逻辑
            //...
            $access_token = '';
            return $access_token;
        }, 86400);

        if (!$this->accessToken[$this->name])
            throw new AdminException(400718);

        return $this->accessToken[$this->name];
    }

}

使用小鹅通打印机

复制代码
use crmeb\services\printer\Printer;

$printer = new Printer('xiao_e_tong',[
    'clientId'=>'',//小鹅通打印配置
    'apiKey'=>'',//小鹅通打印配置
    'partner'=>' ',//小鹅通打印配置
    'terminal'=>'',//小鹅通打印配置
]);

$res = $printer->setPrinterContent([
    'name'=> '标题',
    'orderInfo'=> [],//订单信息
    'product'=> [],//商品信息
])->startPrinter();

var_dump($res);

附件:https://gitee.com/ZhongBangKeJi/CRMEB

相关推荐
小鼻崽纸7 小时前
cacti漏洞CVE-2022-46169的复现
php
stand_forever12 小时前
laravel框架优化
php·laravel
Python涛哥14 小时前
PHP框架之Laravel框架教程:1. laravel搭建
开发语言·php·laravel
大白玉米1 天前
TVBOXOS6.0双端APP二开源码完整版全开源源码重构版
java·重构·php
布说在见1 天前
踩坑与成长:WordPress、MyBatis-Plus 及前端依赖问题解决记录
服务器·学习·php
八月的雨季 最後的冰吻2 天前
php算法-- 关联数组使用,优化sip账号去重
开发语言·php
rockmelodies2 天前
【PHP安全】免费解密支持:zend52、zend53、zend54好工具
开发语言·安全·php
速易达网络2 天前
PHP 与 Vue.js 结合的前后端分离架构
vue.js·php
Clownseven2 天前
使用 eBPF 实时捕获 TCP 重传告警:精准定位网络抖动问题
网络·tcp/ip·php