178 lines
6.5 KiB
Go
178 lines
6.5 KiB
Go
package trenditapi
|
||
|
||
import (
|
||
"fmt"
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
"testing"
|
||
"time"
|
||
)
|
||
|
||
var api = New(TiAppID, TiAppSecret)
|
||
|
||
func TestLen(t *testing.T) {
|
||
str := "--------------------------------"
|
||
fmt.Println(len(str))
|
||
}
|
||
|
||
//打印
|
||
func TestAPI_Print(t *testing.T) {
|
||
name1 := "[优]猪肉馅约250g/份"
|
||
name2 := "鲜鸡蛋约250g/份"
|
||
name3 := "[精选优品][精选优品][精选优品][精选优品][精选优品]豌豆米-手工剥豆约100g/份"
|
||
name4 := "娃娃菜200g/个"
|
||
len1 := len(name1)
|
||
len2 := len(name2)
|
||
len3 := len(name3)
|
||
len4 := len(name4)
|
||
len5 := len("--------------------------------")
|
||
fmt.Println(len1, len2, len3, len4, len5)
|
||
content := `
|
||
<LEFT>商品列表</LEFT><BR>`
|
||
content += "商品名" + StrRepeat(" ", 13) + "数量" + "<BR>"
|
||
content += `--------------------------------`
|
||
content += FormatPrintOrderItemV2(name1, 1, 1)
|
||
content += FormatPrintOrderItemV2(name2, 1, 2)
|
||
content += FormatPrintOrderItemV2(name3, 1, 3)
|
||
content += FormatPrintOrderItemV2(name4, 5, 4)
|
||
content += `<BR><LEFT><font# bolder=0 height=2 width=1>共4种9件商品</font#></LEFT><BR>`
|
||
content += `<font# bolder=0 height=2 width=1>--------------#20完-------------</font#>`
|
||
msg, err := api.Print(TestSn, content, VoiceNewShort)
|
||
fmt.Println(msg)
|
||
fmt.Println(err)
|
||
}
|
||
|
||
func TestAPI_AddPrinterOrder(t *testing.T) {
|
||
|
||
orderParams := []interface{}{}
|
||
data := `
|
||
<font# bolder=0 height=2 width=1>--------------------------------</font#>
|
||
<LEFT>下单时间: %s</LEFT>
|
||
<LEFT>期望送达: %s</LEFT>
|
||
<LEFT>客户姓名: %s</LEFT>
|
||
<LEFT>客户电话: %s</LEFT>
|
||
<LEFT>店铺名称: %s</LEFT>
|
||
<LEFT><font# bolder=1 height=2 width=1>订单编号: %s</font#></LEFT><BR>
|
||
<C><font# bolder=0 height=2 width=2>%s#%d</font#>
|
||
<QR>%s</QR></C>
|
||
` + `` + `<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||
<LEFT><font# bolder=0 height=2 width=1>客户地址: %s</font#></LEFT>
|
||
<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||
<LEFT><font# bolder=0 height=2 width=1>客户备注:%s</font#></LEFT>
|
||
<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||
商品名` + StrRepeat(" ", 15) + `数量` + StrRepeat(" ", 3) + `金额` + StrRepeat("-", 32) + `
|
||
`
|
||
orderParams = append(orderParams,
|
||
"2024-05-21 13:10:00",
|
||
"2024-05-21 14:10:00",
|
||
"花花(先生)",
|
||
"18582476194,7712",
|
||
"成都若溪科技有限公司",
|
||
"2301082344187999120",
|
||
"美团外卖",
|
||
19,
|
||
"2301082344187999120",
|
||
"仁恒置地广场 (12层)@#四川省成都市锦江区春熙路街道仁恒置地广场",
|
||
"【如遇缺货】:缺货时电话与我沟通 收货人隐私号 18582476194,7712,手机号 173****9503",
|
||
)
|
||
|
||
data += FormatPrintOrderItemBigV2("娃哈哈纯净水24瓶装", 8, 1)
|
||
data += `<BR><LEFT><font# bolder=0 height=2 width=1>共%d种%d件商品 实付:%s</font#></LEFT>
|
||
<font# bolder=0 height=2 width=1>--------------#%d完-------------</font#>`
|
||
orderParams = append(orderParams, 1, 8, "321.00", 19)
|
||
context := fmt.Sprintf(data, orderParams...)
|
||
|
||
//context := `<font# bolder=0 height=2 width=1>--------------------------------</font#>
|
||
//<LEFT>下单时间: 2024-05-21 13:10:00</LEFT>
|
||
//<LEFT>期望送达: 2024-05-21 14:10:00</LEFT>
|
||
//<LEFT>客户姓名: 花花(先生)</LEFT>
|
||
//<LEFT>客户电话: 18582476194,7712</LEFT>
|
||
//<LEFT>店铺名称: 成都若溪科技有限公司</LEFT>
|
||
//<LEFT><font# bolder=1 height=2 width=1>订单编号: 2301082344187999120</font#></LEFT><BR>
|
||
//<C><font# bolder=0 height=2 width=2>美团外卖#19</font#>
|
||
//<QR>2301082344187999120</QR></C>
|
||
// 美团外卖#19<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||
//<LEFT><font# bolder=0 height=2 width=1>客户地址: 仁恒置地广场 (12层)@#四川省成都市锦江区春熙路街道仁恒置地广场</font#></LEFT>
|
||
//<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||
//<LEFT><font# bolder=0 height=2 width=1>客户备注:【如遇缺货】:缺货时电话与我沟通 收货人隐私号 18582476194,7712,手机号 173****9503</font#></LEFT>
|
||
//<font# bolder=0 height=1 width=1>--------------------------------</font#>
|
||
//商品名 数量 金额
|
||
//--------------------------------
|
||
//<font# bolder=1 height=2 width=1>1.哇哈哈纯净水24瓶装 x8 ¥321.0</font#><BR><BR><LEFT><font# bolder=0 height=2 width=1>共1种8件商品</font#></LEFT>
|
||
//<font# bolder=0 height=2 width=1>--------------#19完-------------</font#>`
|
||
result, err := api.Print("670020035344", context, "10")
|
||
fmt.Println(result)
|
||
fmt.Println(err)
|
||
}
|
||
|
||
func TestCal(t *testing.T) {
|
||
fmt.Println(utils.Time2Str(time.Now()))
|
||
}
|
||
|
||
//打印取消/退货模板
|
||
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, DensityStrong)
|
||
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("570010021789")
|
||
fmt.Println(onlineStatus)
|
||
fmt.Println(workStatus)
|
||
fmt.Println(err)
|
||
}
|
||
|
||
//清空设备待打印队列
|
||
func TestAPI_CleanWaitingQueue(t *testing.T) {
|
||
err := api.CleanWaitingQueue(TestSn)
|
||
fmt.Println(err)
|
||
}
|
||
|
||
func TestInt(t *testing.T) {
|
||
|
||
temp := 1000
|
||
fmt.Println(int(temp / 1000))
|
||
}
|