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

相关推荐
niucloud-admin6 小时前
PHP V6 单商户常见问题——云编译报SSL证书错误的处理方案
php
计算机安禾7 小时前
【Linux从入门到精通】第31篇:防火墙漫谈——iptables与firewalld防护指南
linux·运维·php
2401_8734794011 小时前
企业安全团队如何配合公安协查?IP查询在电子取证中的技术实践
tcp/ip·安全·网络安全·php
L16247612 小时前
Win11 共享→Windows Server 访问故障总结(极简可复用)
开发语言·windows·php
niucloud-admin13 小时前
PHP V6 单商户常见问题——本地phpstudy部署,访问域名/admin 、域名/wap无法自动跳转对应首页问题
php
隔窗听雨眠14 小时前
MySQL主从延迟根因诊断法
开发语言·php
niucloud-admin16 小时前
PHP V6 单商户常见问题——运行内存太小导致的报错处理
php
nbwenren16 小时前
办公AI实测:Gemini3、GPT-4o、Claude3.5谁更强?
服务器·数据库·php
hopetomorrow17 小时前
学习路之PHP --PHP 常用扩展及作用表
开发语言·学习·php
幽络源小助理18 小时前
影视脚本分镜在线协作系统源码 PHP剧本创作平台
开发语言·php