PHP code example of leapfu / cloud-printer

1. Go to this page and download the library: Download leapfu/cloud-printer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

leapfu / cloud-printer example snippets


use Leapfu\CloudPrinter\CloudPrinter;

$config = [
    // 默认打印机类型
    'default'    => 'feie',
    // 缓存配置
    'cache_path' => __DIR__ . '/../cache',
    // 日志目录
    'log_path'   => __DIR__ . '/../logs',
    // HTTP客户端配置
    'http'       => [
        'timeout'         => 30,      // 请求超时时间(秒)
        'connect_timeout' => 10, // 连接超时时间(秒)
        'verify'          => true,      // 是否验证SSL证书
    ],

    // 打印机配置
    'drivers'    => [
        // 飞鹅云打印
        'feie'      => [
            'user' => '',  // 飞鹅云后台注册的账号
            'ukey' => '',  // 飞鹅云后台生成的UKEY
        ],

        // 易联云打印
        'yilian'    => [
            'client_id'     => '',  // 易联云应用ID
            'client_secret' => '', // 易联云应用密钥
        ],

        // 芯烨云打印
        'xpyun'     => [
            'user'     => '',     // 芯烨云账号
            'user_key' => '', // 芯烨云用户密钥
        ],

        // 快递100云打印
        'kuaidi100' => [
            'key'    => '',    // 快递100应用key
            'secret' => '', // 快递100应用密钥
        ],

        // 优声云打印
        'usheng'    => [
            'app_id'     => '',    // 优声云应用key
            'app_secret' => '', // 优声云应用密钥
        ],

        // 中午云打印
        'zhongwu'   => [
            'app_id'     => '',    // 中午云应用key
            'app_secret' => '', // 中午云应用密钥
        ],


        // 佳博云打印
        'poscom'    => [
            'api_key'     => '',         // 接口密钥
            'member_code' => '',      // 商户编码
        ],

        // 映美云打印
        'jolimark'  => [
            'app_id'     => '',     // 映美云应用ID
            'app_secret' => '', // 映美云应用密钥
        ],

        // 自定义驱动
        'custom'    => [
            'class' => '', // 驱动类的class, 须继承 Leapfu\CloudPrinter\Drivers\BaseDriver类,
            'key'    => '',    // 自定义应用key
            'secret' => '', // 自定义应用密钥
        ],
    ],
];
$printer = new CloudPrinter($config);

// 使用默认打印机
$result = $printer->driver()->print([
    'content' => '测试内容',
    'sn' => '打印机SN',
    'copies' => 1
]);

// 指定打印机类型
$result = $printer->driver('feie')->print([
    'content' => '内容',
    'sn' => 'SN',
    'copies' => 1
]);

// 直接调用打印机方法(动态代理)
$result = $printer->print([
    'content' => '内容',
    'sn' => 'SN',
    'copies' => 1
]);

if ($result['success']) {
    echo '打印成功';
} else {
    echo '打印失败:' . $result['message'];
}

   use CloudPrinter;
   CloudPrinter::driver()->print([
       'content' => '内容',
       'sn' => 'SN',
       'copies' => 1
   ]);
   

   $printer = app(Leapfu\CloudPrinter\CloudPrinter::class);
   $printer->driver()->print([
       'content' => '内容',
       'sn' => 'SN',
       'copies' => 1
   ]);
   

   app('cloud_printer')->driver()->print([
       'content' => '内容',
       'sn' => 'SN',
       'copies' => 1
   ]);
   
bash
   php artisan vendor:publish --provider="Leapfu\\CloudPrinter\\Laravel\\CloudPrinterServiceProvider" --tag=config