我们正在为货币兑换商开发一个基于 PHP 的 Web 应用程序。我们正在使用的货币兑换商使用 POS (EPSON TM-U220D) 打印机作为客户收据,因此我们正在寻找一种从 Web 应用程序打印到 POS 打印机的方法,我们尝试了 mike42/escpos-php PHP 库并使用它让 USB 收据打印机在 Windows 教程上工作,但它不起作用。这是我们第一次使用 POS 打印机,所以我们完全迷路了。任何人都可以帮助解决这个问题吗?提前致谢。 细节 :
Printer : [EPSON TM-U220D][1]
PHP Library : [Mike42/Escpos-php][1]
Tutorial : [Getting a USB receipt printer working on Windows][1]
Programming Languages : [PHP 7.2.0][1]
Web Server : [Apache][1]
Database : [MySQL][1]
代码 :
/*
// Call this file 'hello-world.php'
require __DIR__ . '/inc/escpos/vendor/autoload.php';
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\Printer;
$connector = new FilePrintConnector("php://stdout");
$printer = new Printer($connector);
$printer -> text("Hello World!\n");
$printer -> cut();
$printer -> close();
*/
/* Change to the correct path if you copy this example! */
require __DIR__ . '/inc/escpos/vendor/autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
/**
* Install the printer using USB printing support, and the "Generic / Text Only" driver,
* then share it (you can use a firewall so that it can only be seen locally).
*
* Use a WindowsPrintConnector with the share name to print.
*
* Troubleshooting: Fire up a command prompt, and ensure that (if your printer is shared as
* "Receipt Printer), the following commands work:
*
* echo "Hello World" > testfile
* copy testfile "\\%COMPUTERNAME%\Receipt Printer"
* del testfile
*/
try {
// Enter the share name for your USB printer here
$connector = null;
//$connector = new WindowsPrintConnector("Receipt Printer");
/* Print a "Hello world" receipt" */
$printer = new Printer($connector);
$printer -> text("Hello World!\n");
$printer -> cut();
/* Close printer */
$printer -> close();
} catch (Exception $e) {
echo "Couldn't print to this printer: " . $e -> getMessage() . "\n";
}