145 lines
4.5 KiB
Go
145 lines
4.5 KiB
Go
package trenditapi
|
||
|
||
var (
|
||
TiAppID = "1088834319474253824"
|
||
TiAppSecret = "79e3b918aeca427bbbf9d0503f9f9106"
|
||
TestSn = "670020035344" //打印机编号
|
||
TestKey = "6p7wkk" //打印机密钥
|
||
BaseUrl = "https://iot-device.trenditiot.com/openapi"
|
||
)
|
||
|
||
const (
|
||
HttpStatusSuccessCode = 200 //http返回成功状态码
|
||
ResponseCodeSuccess = 0 //请求成功码
|
||
//优先使用语言
|
||
LangLatin = 13 //拉丁文
|
||
LangChinese = 16 //中文
|
||
//打印浓度
|
||
DensityLighter = 4 //较淡
|
||
DensityLight = 5 //淡
|
||
DensityStronger = 6 //较浓(默认)
|
||
DensityStrong = 7 //浓
|
||
//打印机音量 1~5 值越大声越大
|
||
Volume1 = 1
|
||
Volume2 = 2
|
||
Volume3 = 3
|
||
Volume4 = 4
|
||
Volume5 = 5 //(默认)
|
||
//打印机状态
|
||
OnlineStatus = 1 //在线
|
||
OfflineStatus = 0 //当前离线
|
||
WorkStatusReady = 0 //就绪
|
||
WorkStatusPrinting = 1 //打印中
|
||
WorkStatusPaperLack = 2 //缺纸
|
||
WorkStatusOverTemperature = 3 //过温
|
||
WorkStatusPrintFail = 4 //打印故障
|
||
//设备音源
|
||
VoiceMTNew = "1" //美团新订单提醒
|
||
VoiceELMNew = "2" //饿了么新订单提醒
|
||
VoiceJDDJNew = "3" //京东到家新订单提醒
|
||
VoiceNew = "4" //通用新订单
|
||
VoiceCancel = "5" //通用取消订单
|
||
VoiceRefund = "6" //通用退单
|
||
VoiceReminders = "7" //用户催单
|
||
VoiceNewShort = "10" //简短 - 通用新订单提醒
|
||
VoiceCancelShort = "11" //简短 - 取消订单提醒
|
||
)
|
||
|
||
//错误码信息
|
||
var ErrMsg = map[int]string{
|
||
1419: "打印请求过快",
|
||
1420: "设备缓存队列发生溢出",
|
||
31405: "消息发送失败,未知原因",
|
||
31406: "消息发送失败,设备掉线",
|
||
31407: "消息发送失败,接收超时",
|
||
31408: "打印机参数列表为空",
|
||
31409: "打印机SN号超过最大500个的限制",
|
||
31410: "添加的SN号有重复",
|
||
31411: "设备已绑定其他商户",
|
||
31412: "设备已绑定",
|
||
31413: "设备密钥错误",
|
||
31414: "无效设备SN编码",
|
||
31415: "打印请求记录不存在",
|
||
31416: "音量参数无效",
|
||
31417: "浓度参数无效",
|
||
31418: "设备未绑定",
|
||
31419: "无效的打印速度参数",
|
||
1019: " 依具体错误情况返回", //传参数不合法通用异常编码,如缺少必填请求参数,参数值超范围等等
|
||
1021: " 数据格式转换错误",
|
||
}
|
||
|
||
type BaseReq struct {
|
||
AppID string `json:"appid"` //应用ID
|
||
Uid string `json:"uid"` //请求唯一ID,只能用来请求一次,不可以重复
|
||
STime string `json:"stime"` //timestamp,请求时间戳,精确秒(UTC+8)
|
||
Sign string `json:"sign"` //签名 md5(uid+appid+stime+appsecrect+请求Json内容)
|
||
}
|
||
|
||
type TIResponse struct {
|
||
HttpStatusCode int `json:"httpStatusCode"`
|
||
BaseRes *BaseResp `json:"base_res"`
|
||
}
|
||
type BaseResp struct {
|
||
Code int `json:"code"` //响应码
|
||
Message string `json:"message"` //响应码对应说明
|
||
Data interface{} `json:"data"` //操作结果
|
||
}
|
||
|
||
//增加打印机 list
|
||
type AddPrinterReq struct {
|
||
Sn string `json:"sn"` //打印机编号
|
||
Key string `json:"key"` //设备密钥
|
||
//非必填
|
||
Name string `json:"name"` //设备名称或备注
|
||
Lang int `json:"lang"` //优先使用语言 13-拉丁文;16-中文; 只有设备支持对应语言时才生效,不支持时使用默认设置
|
||
}
|
||
type AddPrinterResp struct {
|
||
FailItem []FailItem
|
||
}
|
||
|
||
//批量操作时的错误返回
|
||
type FailItem struct {
|
||
Sn string `json:"sn"`
|
||
Reason string `json:"reason"`
|
||
}
|
||
|
||
//修改打印机信息
|
||
type EditPrinterReq struct {
|
||
Sn string `json:"sn"`
|
||
Name string `json:"name"`
|
||
Lang string `json:"lang"`
|
||
}
|
||
|
||
//查询打印机状态
|
||
type GetDeviceStatusReq struct {
|
||
Sn string `json:"sn"`
|
||
}
|
||
|
||
//设置打印机浓度
|
||
type SetDensityReq struct {
|
||
Sn string `json:"sn"`
|
||
Density int `json:"density"` //4 较淡 5 普通 6 较浓(默认) 7 浓
|
||
}
|
||
|
||
//设置打印机音量
|
||
type SetVolumeReq struct {
|
||
Sn string `json:"sn"`
|
||
Volume int `json:"volume"` //1~5 值越大声越大 (默认5)
|
||
}
|
||
|
||
//打印小票
|
||
type PrintReq struct {
|
||
Sn string `json:"sn"`
|
||
//非必填
|
||
Voice string `json:"voice"` //播报音源,不传参数视为不播报语音,只打印小票;
|
||
VoicePlayTimes int `json:"voicePlayTimes"` //默认播报1次 1-3
|
||
VoicePlayInterval int `json:"voicePlayInterval"` //默认3秒 1-10
|
||
Content string `json:"content"` //最大支持6000字节打印内容
|
||
Copies int `json:"copies"` //不传默认1, 取值范围: 1~5
|
||
}
|
||
|
||
type PrintResp struct {
|
||
PrintID string `json:"printId"`
|
||
QueueSize string `json:"queueSize"`
|
||
}
|