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

相关推荐
Q_Q51100828517 小时前
python+nodejs+springboot在线车辆租赁信息管理信息可视化系统
spring boot·python·信息可视化·django·flask·node.js·php
_Re.17 小时前
DSC 归档配置相关
数据库·oracle·php
BingoGo1 天前
PHP 快速集成 ChatGPT 用 AI 让你的应用更聪明
后端·php
JaguarJack1 天前
PHP 快速集成 ChatGPT 用 AI 让你的应用更聪明
后端·php
Q_Q5110082851 天前
python+django/flask哈利波特书影音互动科普网站
spring boot·python·django·flask·node.js·php
qq_10055170751 天前
WordPress给指定分类文章添加一个自动化高亮(一键复制)功能
运维·前端·自动化·php
YC运维1 天前
LNMP架构(分离部署)PHP与数据库交互示例
数据库·架构·php
Q_Q5110082852 天前
python+django/flask+springboot实践性教学系统 实训任务发布 学生作业提交 教师评阅管理系统
spring boot·python·django·flask·node.js·php
喝奶茶的Blair2 天前
PHP应用&文件操作安全&上传下载&任意读取删除&目录遍历&文件包含(2024小迪安全Day32笔记)
笔记·安全·web安全·php
qq_252924192 天前
PHP 8.0+ 高级特性深度探索:架构设计与性能优化
android·性能优化·php