随着微信小程序的出现,微信已经完全占据了我们的生活,智能化互联网时代的到来,带给我们的便利我想不用说大家都是深有体会,随着小程序的火爆,随之带动着用户对打印的需求,那么,微信小程序是如何对接打印机的呢,这篇文章就为大家介绍微信小程序与小票打印机的具体对接流程。
优声云打印机U7是成都优声科技有限公司推出的一款WIFI/4G联网的打印机。注意这是一款热敏58mm小票打印机,就是大家购物、外卖那样的热敏小票。
优声云打印机与传统打印机不同, 传统打印机需要依赖设备驱动、蓝牙连接,专业的人负责打印,而优声云打印机基于云端开发的云打印平台,只需要连接WiFi即可自动接单打印,支持美团/饿了么/百度外卖/京东到家/小程序/口碑/微盟等20多家订单平台自动接单打印,同时公司也开放接口为第三方公司服务,适合小程序点单,外卖平台,医院、ktv、餐饮、商城、酒店、加油站等场景运用。
接下来就教大家对接云小票机。
现在的云打印机都开放了第三方基于HTTP的接口,支持开发,优声云打印机也支持调用基于http的接口,支持PHP、Python、Java、Go等语言的调用
PHP调用
我们使用优声云提供的PHP SDK来开发对接
使用composer来安装SDK
composer install "ushengyun/printer"
- 微信小程序打印接口
$app_id = '******';
$app_secret = '********';
$rpc = new \ushengyun\protocol\RpcClient($app_id, $app_secret, 'https://open-api.ushengyun.com/printer');
$Zprinter = new \ushengyun\Printer($rpc);
$device_id = '1111111';
$device_secret = '11111111';
$printdata = '优声云拥有自主研发的云打印机,提供稳定高效,高可用的云打印方案';
try {
$Zprinter->set_args($device_id, $device_secret)->cloud_print($printdata);
} catch (Exception $e) {
}
- 设置声音
$app_id = '******';
$app_secret = '********';
$rpc = new \ushengyun\protocol\RpcClient($app_id, $app_secret, 'https://open-api.ushengyun.com/printer');
$Zprinter = new \ushengyun\Printer($rpc);
$device_id = '1111111';
$device_secret = '11111111';
try {
$Zprinter->set_args($device_id, $device_secret)->set_sound(1);
} catch (Exception $e) {
}
- 查询订单打印状态
$app_id = '1111111';
$app_secret = '**********';
$device_id = '1111111';
$device_secret = '**********';
$rpc = new \ushengyun\protocol\RpcClient($app_id, $app_secret);
$Zprinter = new \ushengyun\Printer($rpc);
$id = 100272;
try {
$r = $Zprinter->get_print_status($id);
var_dump($r);
} catch (Exception $e) {
echo $e;
}
- 查询打印机状态
$app_id = '******';
$app_secret = '********';
$rpc = new \ushengyun\protocol\RpcClient($app_id, $app_secret);
$Zprinter = new \ushengyun\Printer($rpc);
$device_id = '1111111';
$device_secret = '11111111';
try {
$Zprinter->set_args($device_id, $device_secret)->get_status();
} catch (Exception $e) {
}
打印效果:
至此微信小程序调用打印机远程打印开发完毕