PHP SDK for 飞鹅云
Overtrue! Respect!
$ composer require antcool/easy-feieyun -vvv
$config = [
'default' => 'default',
'accounts' => [
'default' => [
'user' => '[email protected]',
'key' => '.....',
'notify_url' => '', // 打印状态回调地址
'valid_duration' => 60 * 60 * 2, // 打印订单有效时长, 最大 24 小时
],
// 可配置多个账号
'test' => [
'user' => '[email protected]',
'key' => '.....',
// 其他参数非必须
],
],
'public_key' => '', // 飞鹅云公钥文件路径或内容
'debug' => true, // 开启将会在 runtime_path 下生成请求日志文件
'runtime_path' => __DIR__ . '/_runtime',
'http' => [
'base_uri' => 'http://api.feieyun.cn/Api/Open/', // 飞鹅云 API 请求 URL
'timeout' => 30,
'verify' => false,
],
];
$app = new \AntCool\Feieyun\Application($config);
// 使用其他账号配置
$app->getConfig()->withAccount('test');
$config = $app->getConfig();
$client = $app->getClient();
$server = $app->getServer();
// 添加打印机
$client->addPrinter(['111111111#xxxxx#测试4G', '22222222#xxxxxx#测试WIFI',])
// 小票打印
$client->printOrder(sn: '', content: '', items: 1, notifyUrl: false, duration: false);
// 标签打印
$client->printLabelOrder(sn: '', content: '', img: '', items: 1, notifyUrl: false, duration: false)
// 批量移除打印机
$client->deletePrinter(sn: 'string|array');
// 编辑打印机信息
$client->editPrinter(sn: '', name: '', phoneNum: '');
// 清除打印机队列
$client->clearPrinterSqs(sn: '');
// 查询订单打印状态
$client->queryOrderStatus(orderId: '');
// 查询指定打印机某天的订单统计数
$client->queryOrderCountByDate(sn: '', date: 'yyyy-mm-dd');
// 获取某台打印机状态
$client->queryPrinterStatus(sn: '');
$server = $app->getServer();
// 通知内容处理逻辑, 可多次调用
$server->with(function (array $message) {
// $message 为经过签名验证的通知内容
// $message['orderId'] 订单ID,由接口Open_printMsg返回。
// $message['status'] 订单状态 1:打印成功
// $message['stime'] 订单状态变更UNIX时间戳,10位,精确到秒。
// $message['sign'] 数字签名
});
// Laravel 内可以直接 return $response
$response = $server->serve();
// 其他需要自己创建响应内容的, 可以参考下面代码
$statusCode = $response->getStatusCode();
foreach ($response->getHeaders() as $name => $values) {
header(sprintf('%s: %s', $name, implode(', ', $values)), true, $statusCode);
}
echo $response->getBody();
You can contribute in one of three ways:
- ...
- ...
MIT