This commit is contained in:
richboo111
2023-03-28 14:39:34 +08:00
parent da93ae79da
commit 09959ccddb
9 changed files with 592 additions and 21 deletions

View File

@@ -0,0 +1,106 @@
package trenditapi
import (
"fmt"
"testing"
)
var api = New(TiAppID, TiAppSecret)
func TestLen(t *testing.T) {
str := "--------------------------------"
fmt.Println(len(str))
}
//打印
func TestAPI_Print(t *testing.T) {
content := `<C><font# bolder=1 height=2 width=2>美团外卖</font#></C>
<font# bolder=1 height=1 width=1>--------------------------------</font#>
<LEFT>下单时间2023-03-27 13:22:05</LEFT>
<LEFT>期望送达2023-03-27 14:22:05</LEFT>
<LEFT>客户姓名:梅朵(女士)</LEFT>
<LEFT>客户电话163473526172</LEFT>
<LEFT><font# bolder=0 height=2 width=1>订单编号: E22092832084572779</font#></LEFT><BR>
<C><font# bolder=1 height=2 width=2>美团外卖#20</font#></C>
<C><BAR>E22092832084572779</BAR></C>
<C><font# bolder=1 height=1 width=1>--------------------------------</font#></C>
<LEFT><font# bolder=0 height=2 width=1>客户地址:四川省成都市武侯区双流县金华镇芳草街道小区5栋1单元104号</font#></LEFT>
<C><font# bolder=0 height=1 width=1>--------------------------------</font#></C>
<LEFT><font# bolder=0 height=2 width=1>客户备注:缺货时电话与我沟通 收货人隐私号17882904902——5355手机号 181****6752</font#></LEFT>
<font# bolder=1 height=1 width=1>--------------------------------</font#>
<LEFT>商品列表</LEFT><BR>`
content += "商品名" + StrRepeat(" ", 3) + "数量" + StrRepeat(" ", 4) + "单价" + StrRepeat(" ", 6) + "小计" + "<BR>"
content += `--------------------------------`
content += FormatPrintOrderItem("[优]猪肉馅约250g/份", 1, 999)
content += FormatPrintOrderItem("鲜鸡蛋约250g/份", 1, 17.8)
content += FormatPrintOrderItem("豌豆米-手工剥豆约100g/份", 1, 40)
content += FormatPrintOrderItem("娃娃菜200g/个", 5, 2)
content += `<LEFT>共4种9件商品
实付金额: 327.83元</LEFT><BR>
<font# bolder=0 height=1 width=1>--------------#20完-------------</font#>`
msg, err := api.Print(TestSn, content, VoiceNewShort)
fmt.Println(msg)
fmt.Println(err)
}
//打印取消/退货模板
func TestAPI_Print2(t *testing.T) {
content := `<C><font# bolder=1 height=2 width=2>京西菜市</font#></C><BR>`
content += StrRepeat("-", 32) + `
<LEFT><font# bolder=1 height=1 width=1>下单时间2023-03-27 13:22:05</font#></LEFT>
<LEFT><font# bolder=0 height=2 width=1>订单编号: E22092832084572779</font#></LEFT><BR>
<font# bolder=1 height=2 width=2>美团外卖#20</font#>
<font# bolder=1 height=2 width=2>取消订单</font#>
<font# bolder=1 height=1 width=1>--------------------------------</font#>`
content += `<LEFT><font# bolder=1 height=2 width=1>共4种9件商品</font#></LEFT>
<LEFT><font# bolder=1 height=2 width=1>实付金额: 327.83元</font#></LEFT><BR>
<font# bolder=0 height=1 width=1>--------------#20完-------------</font#>`
msg, err := api.Print(TestSn, content, VoiceCancelShort)
fmt.Println(msg)
fmt.Println(err)
}
//增加打印机
func TestAddPrinter(t *testing.T) {
err := api.AddPrinter(TestSn, TestKey, "京西菜市打印机0327")
fmt.Println(err)
}
//修改打印机信息
func TestEditPrinter(t *testing.T) {
msg, err := api.EditPrinter("763675325672", "京西菜市打印机v2")
fmt.Println(msg)
fmt.Println(err)
}
//删除打印机
func TestAPI_DelPrinter(t *testing.T) {
err := api.DelPrinter([]string{TestSn})
fmt.Println(err)
}
//设置打印浓度
func TestAPI_SetDensity(t *testing.T) {
err := api.SetDensity(TestSn, DensityStronger)
fmt.Println(err)
}
//设置音量
func TestAPI_SetVolume(t *testing.T) {
err := api.SetVolume(TestSn, Volume1)
fmt.Println(err)
}
//查询打印机状态
func TestGetDevicesStatus(t *testing.T) {
onlineStatus, workStatus, err := api.GetDeviceStatus(TestSn)
fmt.Println(onlineStatus)
fmt.Println(workStatus)
fmt.Println(err)
}
//清空设备待打印队列
func TestAPI_CleanWaitingQueue(t *testing.T) {
err := api.CleanWaitingQueue(TestSn)
fmt.Println(err)
}