1
This commit is contained in:
@@ -1 +1,219 @@
|
||||
package xpyunapi
|
||||
|
||||
//
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
//
|
||||
const (
|
||||
UserName = "feng.shi@rosy.net.cn" //开发者ID
|
||||
UserKey = "20a24d4332954993b05876e7b3db2a96" //开发者密钥
|
||||
TestPrinterSN = "029JC1ZZD853B4B" //测试打印机SN
|
||||
)
|
||||
|
||||
//
|
||||
var api = New(UserName, UserKey)
|
||||
|
||||
//
|
||||
//测试格式化商品列表
|
||||
func TestFormatPrintOrderItem(t *testing.T) {
|
||||
|
||||
str := FormatPrintOrderItem("测试商品名字", 100, 8.78)
|
||||
fmt.Println(str)
|
||||
request := &PrintRequest{
|
||||
RestRequest: api.GenerateRestRequest(),
|
||||
Sn: TestPrinterSN,
|
||||
Content: str,
|
||||
Copies: 1,
|
||||
Voice: VoicePlayOrder,
|
||||
Mode: ModeCheckYes,
|
||||
}
|
||||
orderID, err := api.Print(request)
|
||||
fmt.Printf("orderID=====%s", orderID)
|
||||
fmt.Printf("err=====%v", err)
|
||||
}
|
||||
func TestPrint(t *testing.T) {
|
||||
printContent := ""
|
||||
printContent = printContent + "<IMG></IMG><BR><C>" + "<B>京西菜市</B>" + "<BR></C>"
|
||||
printContent += StrRepeat("-", 32)
|
||||
printContent += "<BR><L>下单时间:2023-03-16 15:30:28"
|
||||
printContent += "<BR><L>预计送达:2023-03-16 16:30:28"
|
||||
printContent += "<BR><L>" + "客户姓名:杨玺" + "<BR>" + "客户电话:17235643746"
|
||||
printContent += "<BR><HB>订单编号:7764828754021845</HB>" + "<BR>"
|
||||
printContent += "<IMG></IMG><BR><C>" + "<B>京西菜市#23</B>" + "<BR></C>"
|
||||
printContent += "<C><BARCODE t=CODE128 w=2 h=100 p=2>5842160392535156</BARCODE>"
|
||||
printContent += "<C>" + "<QRCODE s=6 e=L l=center>https://www.xpyun.net</QRCODE>" + "</C>"
|
||||
printContent += StrRepeat("-", 32)
|
||||
printContent += "<HB>客户地址:四川省成都市武侯区双流县金华镇门口大院5栋1单元1104号</HB><BR>"
|
||||
printContent += StrRepeat("-", 32)
|
||||
printContent += "<BR>客户备注:缺货时电话与我沟通 收货人隐私号17882904902——5355,手机号 181****6752" + "<BR>"
|
||||
printContent += StrRepeat("-", 32)
|
||||
printContent = printContent + "<BR>商品列表" + StrRepeat(" ", 6) + "<BR>"
|
||||
printContent += "商品名" + StrRepeat(" ", 2) + "数量" + StrRepeat(" ", 3) + "单价" + StrRepeat(" ", 5) + "小计" + "<BR>"
|
||||
printContent += StrRepeat("-", 32)
|
||||
printContent += FormatPrintOrderItem("[优]猪肉馅约250g/份", 1, 999)
|
||||
printContent += FormatPrintOrderItem("鲜鸡蛋约250g/份", 1, 7.8)
|
||||
printContent += FormatPrintOrderItem("豌豆米-手工剥豆约100g/份", 1, 4)
|
||||
printContent += FormatPrintOrderItem("娃娃菜200g/个", 5, 2)
|
||||
printContent += "<L>" + "共4种9件商品" + "<BR></L>"
|
||||
printContent += "<L>" + "实付金额: " + "327.83" + "元" + "<BR></L>"
|
||||
|
||||
printContent = printContent + "<BR><BR>"
|
||||
printContent += StrRepeat("-", 14) + "#23完" + StrRepeat("-", 14)
|
||||
printContent += "<BR>"
|
||||
|
||||
request := PrintRequest{
|
||||
RestRequest: api.GenerateRestRequest(),
|
||||
Sn: TestPrinterSN,
|
||||
Content: printContent,
|
||||
Copies: 1,
|
||||
Voice: 2,
|
||||
Mode: 1,
|
||||
}
|
||||
result, err := api.Print(&request)
|
||||
//序列化
|
||||
reslutJson, _ := json.Marshal(result)
|
||||
var msg = fmt.Sprintf("response result: %+v", string(reslutJson))
|
||||
fmt.Println(msg)
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
////批量添加打印机
|
||||
//func TestAddPrinters(t *testing.T) {
|
||||
// request := &AddPrinterRequest{
|
||||
// Items: []*AddPrinterRequestItem{{
|
||||
// Sn: TestPrinterSN,
|
||||
// Name: "京西测试打印机0315",
|
||||
// }},
|
||||
// RestRequest: api.GenerateRestRequest(),
|
||||
// }
|
||||
// err := api.AddPrinters(request)
|
||||
// fmt.Println(err)
|
||||
//}
|
||||
//
|
||||
////设置打印机语音类型
|
||||
//func TestSetVoiceType(t *testing.T) {
|
||||
// request := &SetVoiceTypeRequest{
|
||||
// RestRequest: api.GenerateRestRequest(),
|
||||
// Sn: TestPrinterSN,
|
||||
// VoiceType: VoiceTypeV10PersonSmall,
|
||||
// VolumeLevel: VolumeLevelSmall,
|
||||
// }
|
||||
// err := api.SetVoiceType(request)
|
||||
// fmt.Println(err)
|
||||
//}
|
||||
//
|
||||
////打印小票订单
|
||||
//func TestPrint(t *testing.T) {
|
||||
// request := &PrintRequest{
|
||||
// RestRequest: api.GenerateRestRequest(),
|
||||
// Sn: TestPrinterSN,
|
||||
// Content: "-----测试打印小票订单---------" +
|
||||
// "kljhsjkfhwiohguoiq" +
|
||||
// "ojkahfohsajkohaowjgokaw",
|
||||
// Copies: 1,
|
||||
// Voice: VoicePlayOrder,
|
||||
// Mode: ModeCheckYes,
|
||||
// }
|
||||
// orderID, err := api.Print(request)
|
||||
// fmt.Println(orderID)
|
||||
// fmt.Println(err)
|
||||
//}
|
||||
//
|
||||
////删除打印机
|
||||
//func TestDelPrinter(t *testing.T) {
|
||||
// request := &DelPrinterRequest{
|
||||
// RestRequest: api.GenerateRestRequest(),
|
||||
// SnList: []string{
|
||||
// TestPrinterSN,
|
||||
// },
|
||||
// }
|
||||
// err := api.DelPrinters(request)
|
||||
// fmt.Println(err)
|
||||
//}
|
||||
//
|
||||
////修改打印机信息
|
||||
//func TestUpdPrinter(t *testing.T) {
|
||||
// request := &UpdPrinterRequest{
|
||||
// RestRequest: api.GenerateRestRequest(),
|
||||
// Sn: "234124",
|
||||
// Name: "京西测试打印机3151",
|
||||
// }
|
||||
// err := api.UpdatePrinter(request)
|
||||
// fmt.Println(err)
|
||||
//}
|
||||
//
|
||||
////清空待打印队列
|
||||
//func TestEmptyPrinterQueue(t *testing.T) {
|
||||
// request := &EmpPrinterQueueRequest{
|
||||
// RestRequest: api.GenerateRestRequest(),
|
||||
// Sn: TestPrinterSN,
|
||||
// }
|
||||
// err := api.EmptyPrinterQueue(request)
|
||||
// fmt.Println(err)
|
||||
//}
|
||||
//
|
||||
////查询订单状态
|
||||
//func TestQueryOrderState(t *testing.T) {
|
||||
// request := &QueryOrderStateRequest{
|
||||
// RestRequest: api.GenerateRestRequest(),
|
||||
// OrderId: "dfhsehsteh",
|
||||
// }
|
||||
// state, err := api.QueryOrderState(request)
|
||||
// fmt.Println(state)
|
||||
// fmt.Println(err)
|
||||
//}
|
||||
//
|
||||
////查询指定某天的订单统计数
|
||||
//func TestQueryOrderStatis(t *testing.T) {
|
||||
// request := &QueryOrderStatisRequest{
|
||||
// RestRequest: api.GenerateRestRequest(),
|
||||
// Sn: "72624647",
|
||||
// Date: "2023-03-15",
|
||||
// }
|
||||
// printed, waiting, err := api.QueryOrderStatis(request)
|
||||
// fmt.Println(printed)
|
||||
// fmt.Println(waiting)
|
||||
// fmt.Println(err)
|
||||
//}
|
||||
//
|
||||
////查询指定打印机状态
|
||||
//func TestQueryPrinterStatus(t *testing.T) {
|
||||
// request := &QueryPrinterStatusRequest{
|
||||
// RestRequest: api.GenerateRestRequest(),
|
||||
// Sn: "7273737",
|
||||
// }
|
||||
// status, err := api.QueryPrinterStatus(request)
|
||||
// fmt.Println(status)
|
||||
// fmt.Println(err)
|
||||
//}
|
||||
//
|
||||
////批量查询打印机状态
|
||||
//func TestBatchQueryPrinterStatus(t *testing.T) {
|
||||
// request := &QueryPrintersStatusRequest{
|
||||
// RestRequest: api.GenerateRestRequest(),
|
||||
// SnList: []string{
|
||||
// TestPrinterSN,
|
||||
// "262623738",
|
||||
// },
|
||||
// }
|
||||
// status, err := api.QueryPrintersStatus(request)
|
||||
// fmt.Println(status)
|
||||
// fmt.Println(err)
|
||||
//}
|
||||
//
|
||||
////金额播报
|
||||
//func TestPlayVoice(t *testing.T) {
|
||||
// request := &PlayVoiceRequest{
|
||||
// RestRequest: api.GenerateRestRequest(),
|
||||
// Sn: TestPrinterSN,
|
||||
// PayType: PayTypeZFB,
|
||||
// PayMode: PayModeReceipt,
|
||||
// Money: 25.8,
|
||||
// }
|
||||
// err := api.PlayVoice(request)
|
||||
// fmt.Println(err)
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user