diff --git a/platformapi/mtwmapi/mtwmapi_test.go b/platformapi/mtwmapi/mtwmapi_test.go
index bf0ba738..75a6a131 100644
--- a/platformapi/mtwmapi/mtwmapi_test.go
+++ b/platformapi/mtwmapi/mtwmapi_test.go
@@ -20,10 +20,10 @@ func init() {
baseapi.Init(sugarLogger)
// 菜市
- //api = New("589", "a81eb3df418d83d6a1a4b7c572156d2f", "", "")
+ api = New("589", "a81eb3df418d83d6a1a4b7c572156d2f", "", "")
// 果园
- api = New("4123", "df2c88338b85f830cebce2a9eab56628", "", "")
+ //api = New("4123", "df2c88338b85f830cebce2a9eab56628", "", "")
//商超
//api = New("5873", "41c479790a76f86326f89e8048964739", "", "") //token_nH_IlcWQKAkZBqklwItNRw
diff --git a/platformapi/mtwmapi/poi_test.go b/platformapi/mtwmapi/poi_test.go
index 842a5318..c63ddf7c 100644
--- a/platformapi/mtwmapi/poi_test.go
+++ b/platformapi/mtwmapi/poi_test.go
@@ -24,7 +24,7 @@ func TestPoiGetIDs(t *testing.T) {
}
func TestPoiMGet(t *testing.T) {
- result, err := api.PoiMGet([]string{"16708848"})
+ result, err := api.PoiMGet([]string{"8040306"})
t.Log(utils.Format4Output(result, false))
if err != nil {
t.Fatal(err)
@@ -45,8 +45,8 @@ func TestPoiSave(t *testing.T) {
poiParams := map[string]interface{}{}
//utils.FilterMapNilMembers(utils.Struct2FlatMap(result[0]))
//poiParams["address"] = "成都市温江区柳城学海路585号"
- poiParams["name"] = "福果驿站·果果铺子"
- err := api.PoiSave("15467875", poiParams)
+ poiParams["pic_url"] = "http://image.jxc4.com/image/5c9fc4fffb4d5ff1aecf85a2d2543e00.jpg"
+ err := api.PoiSave("17218722", poiParams)
fmt.Println(err)
}
diff --git a/platformapi/tiktok_shop/tiktok_api/afs_test.go b/platformapi/tiktok_shop/tiktok_api/afs_test.go
index a707d100..243cfe48 100644
--- a/platformapi/tiktok_shop/tiktok_api/afs_test.go
+++ b/platformapi/tiktok_shop/tiktok_api/afs_test.go
@@ -18,7 +18,7 @@ import (
// "authority_id": ""
//}`
-var token = `{"access_token":"c2e78f4f-fb23-4729-b9b1-8330209df50b","expires_in":1679259342,"scope":"SCOPE","shop_id":57939570,"shop_name":"京西菜市速食","refresh_token":"83548fb9-d9ea-4665-bd8c-4dbb949338de","authority_id":""}`
+var token = `{"access_token":"2edc427e-9ab8-430b-a502-6802f1dee387","expires_in":1679861437,"scope":"SCOPE","shop_id":57939570,"shop_name":"京西菜市速食","refresh_token":"dda56ad5-521b-4b87-9d74-bd6df13df1aa","authority_id":""}`
//var token = `{"access_token":"e3173e9f-266f-4d87-88e7-e7cd837bc9d9","expires_in":1672882632,"scope":"SCOPE","shop_id":68023619,"shop_name":"京西到家","refresh_token":"5070aae2-493f-46bd-b5d6-6ea0cd64729f","authority_id":""}`
diff --git a/platformapi/tiktok_shop/tiktok_api/store_test.go b/platformapi/tiktok_shop/tiktok_api/store_test.go
index 85a9c471..f2c11a0d 100644
--- a/platformapi/tiktok_shop/tiktok_api/store_test.go
+++ b/platformapi/tiktok_shop/tiktok_api/store_test.go
@@ -379,19 +379,27 @@ func TestGetAns(t *testing.T) {
//运费模板
//创建运费模板
-//func TestCreateFreightTemplate(t *testing.T) {
-// param := &freightTemplate_create_request.FreightTemplateCreateParam{
-// Template: &freightTemplate_create_request.Template{
-// TemplateName: "这是一个测试固定运费模板",
-// ProductProvince: utils.Str2Int64(utils.Int2Str(storeDetail.ProvinceCode)[:2]),
-// ProductCity: int64(storeDetail.CityCode),
-// CalculateType: 2, //计价方式-1.按重量 2.按数量
-// TransferType: 1,
-// RuleType: 1, //固定运费&卖家包邮
-// FixedAmount: 500, //固定运费 单位:分
-// },
-// }
-//}
+func TestCreateFreightTemplate(t *testing.T) {
+ param := &freightTemplate_create_request.FreightTemplateCreateParam{
+ Template: &freightTemplate_create_request.Template{
+ TemplateName: "这是一个测试满减运费模板0323",
+ ProductProvince: 31,
+ ProductCity: 310000,
+ CalculateType: 2, //计价方式-1.按重量 2.按数量
+ TransferType: 1,
+ RuleType: 1, //固定运费&卖家包邮
+ FixedAmount: 500, //固定运费 单位:分
+ },
+ Columns: []freightTemplate_create_request.ColumnsItem{{
+ IsOverFree: true,
+ IsLimited: false,
+ OverAmount: 12,
+ }},
+ }
+ freightID, err := a.FreightTemplateCreate(param)
+ fmt.Println(freightID)
+ fmt.Println(err)
+}
//更新运费模板
func TestUpdateFreightTemplate(t *testing.T) {
diff --git a/platformapi/trenditapi/trendit.go b/platformapi/trenditapi/trendit.go
new file mode 100644
index 00000000..952d374d
--- /dev/null
+++ b/platformapi/trenditapi/trendit.go
@@ -0,0 +1,156 @@
+package trenditapi
+
+import (
+ "errors"
+ "fmt"
+)
+
+//增加打印机
+func (a *API) AddPrinter(sn, key, name string) error {
+ params := []AddPrinterReq{{
+ Sn: sn,
+ Key: key,
+ Name: name,
+ }}
+ resp := a.HttpPostJson("addPrinter", params)
+ if resp.HttpStatusCode != HttpStatusSuccessCode {
+ return errors.New("HTTP请求错误,请检查重试")
+ }
+ if resp.BaseRes.Code != ResponseCodeSuccess {
+ return fmt.Errorf("添加打印机错误: %v", resp.BaseRes.Message)
+ }
+ retVal, _ := resp.BaseRes.Data.(map[string]interface{})
+ failMsg := ""
+ if len(retVal["fail"].([]interface{})) > 0 {
+ for _, v := range retVal["fail"].([]interface{}) {
+ t := v.(FailItem)
+ failMsg += t.Sn + ":" + t.Reason + " "
+ }
+ return fmt.Errorf("添加打印机错误: %v", failMsg)
+ }
+ return nil
+}
+
+//修改打印机信息
+func (a *API) EditPrinter(sn, name string) (string, error) {
+ resp := a.HttpPostJson("editPrinter", []EditPrinterReq{{
+ Sn: sn,
+ Name: name,
+ },
+ })
+ if resp.HttpStatusCode != HttpStatusSuccessCode {
+ return "", errors.New("HTTP请求错误,请检查重试")
+ }
+ if resp.BaseRes.Code != ResponseCodeSuccess {
+ return "", fmt.Errorf("修改打印机信息错误:%v", resp.BaseRes.Message)
+ }
+ retVal, _ := resp.BaseRes.Data.(map[string]interface{})
+ failMsg := ""
+ if len(retVal["fail"].([]interface{})) > 0 {
+ for _, v := range retVal["fail"].([]interface{}) {
+ t := v.(FailItem)
+ failMsg += t.Sn + ":" + t.Reason + " "
+ }
+ return fmt.Sprintf("修改打印机信息错误:%v", failMsg), nil
+ }
+ return "", nil
+}
+
+//删除打印机
+func (a *API) DelPrinter(snList []string) error {
+ resp := a.HttpPostJson("delPrinter", snList)
+ if resp.HttpStatusCode != HttpStatusSuccessCode {
+ return errors.New("HTTP请求错误,请检查重试")
+ }
+ if resp.BaseRes.Code != ResponseCodeSuccess {
+ return fmt.Errorf("删除打印机错误:%v", resp.BaseRes.Message)
+ }
+ retVal, _ := resp.BaseRes.Data.(map[string]interface{})
+ failMsg := ""
+ if len(retVal["fail"].([]interface{})) > 0 {
+ for _, v := range retVal["fail"].([]interface{}) {
+ t := v.(FailItem)
+ failMsg += t.Sn + ":" + t.Reason + " "
+ }
+ return fmt.Errorf("删除打印机错误:%v", failMsg)
+ }
+ return nil
+}
+
+//设置打印机浓度
+func (a *API) SetDensity(sn string, density int) error {
+ resp := a.HttpPostJson("setDensity", SetDensityReq{
+ Sn: sn,
+ Density: density,
+ })
+ if resp.HttpStatusCode != HttpStatusSuccessCode {
+ return errors.New("HTTP请求错误,请检查重试")
+ }
+ if resp.BaseRes.Code != ResponseCodeSuccess {
+ return fmt.Errorf("设置打印机浓度错误:%v", resp.BaseRes.Message)
+ }
+ return nil
+}
+
+//设置音量
+func (a *API) SetVolume(sn string, volume int) error {
+ resp := a.HttpPostJson("setVolume", SetVolumeReq{
+ Sn: sn,
+ Volume: volume,
+ })
+ if resp.HttpStatusCode != HttpStatusSuccessCode {
+ return errors.New("HTTP请求错误,请检查重试")
+ }
+ if resp.BaseRes.Code != ResponseCodeSuccess {
+ return fmt.Errorf("设置打印机音量错误:%v", resp.BaseRes.Message)
+ }
+ return nil
+}
+
+//查询打印机状态
+func (a *API) GetDeviceStatus(sn string) (float64, float64, error) {
+ resp := a.HttpPostJson("getDeviceStatus", GetDeviceStatusReq{Sn: sn})
+ if resp.HttpStatusCode != HttpStatusSuccessCode {
+ return 0, 0, errors.New("HTTP请求错误,请检查重试")
+ }
+ if resp.BaseRes.Code != ResponseCodeSuccess {
+ return 0, 0, fmt.Errorf("查询打印机状态错误:%v", resp.BaseRes.Message)
+ }
+ retVal, _ := resp.BaseRes.Data.(map[string]interface{})
+ return retVal["onlineStatus"].(float64), retVal["workStatus"].(float64), nil
+}
+
+//清空设备待打印队列
+func (a *API) CleanWaitingQueue(sn string) error {
+ resp := a.HttpPostJson("cleanWaitingQueue", sn)
+ if resp.HttpStatusCode != HttpStatusSuccessCode {
+ return errors.New("HTTP请求错误,请检查重试")
+ }
+ if resp.BaseRes.Code != ResponseCodeSuccess {
+ return fmt.Errorf("清空设备待打印队列错误:%v", resp.BaseRes.Message)
+ }
+ return nil
+}
+
+//打印小票
+func (a *API) Print(sn, content, voice string) (string, error) {
+ resp := a.HttpPostJson("print", PrintReq{
+ Sn: sn,
+ Content: content,
+ Voice: voice,
+ VoicePlayTimes: 1,
+ VoicePlayInterval: 3,
+ Copies: 1,
+ })
+ if resp.HttpStatusCode != HttpStatusSuccessCode {
+ return "", errors.New("HTTP请求错误,请检查重试")
+ }
+ if resp.BaseRes.Code != ResponseCodeSuccess {
+ return "", fmt.Errorf("打印错误:%v", resp.BaseRes.Message)
+ }
+ retVal := resp.BaseRes.Data.(map[string]interface{})
+ if retVal["printId"].(string) != "" {
+ return retVal["printId"].(string), nil
+ }
+ return "", nil
+}
diff --git a/platformapi/trenditapi/trendit_model.go b/platformapi/trenditapi/trendit_model.go
new file mode 100644
index 00000000..4b9843eb
--- /dev/null
+++ b/platformapi/trenditapi/trendit_model.go
@@ -0,0 +1,144 @@
+package trenditapi
+
+var (
+ TiAppID = "1088834319474253824"
+ TiAppSecret = "79e3b918aeca427bbbf9d0503f9f9106"
+ TestSn = "670020035344" //打印机编号
+ TestKey = "6p7wkk" //打印机密钥
+ BaseUrl = "https://printer.juhesaas.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"`
+}
diff --git a/platformapi/trenditapi/trendit_test.go b/platformapi/trenditapi/trendit_test.go
new file mode 100644
index 00000000..9593ff71
--- /dev/null
+++ b/platformapi/trenditapi/trendit_test.go
@@ -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 := `美团外卖
+--------------------------------
+下单时间:2023-03-27 13:22:05
+期望送达:2023-03-27 14:22:05
+客户姓名:梅朵(女士)
+客户电话:163473526172
+订单编号: E22092832084572779
+美团外卖#20
+E22092832084572779
+--------------------------------
+客户地址:四川省成都市武侯区双流县金华镇芳草街道小区5栋1单元104号
+--------------------------------
+客户备注:缺货时电话与我沟通 收货人隐私号17882904902——5355,手机号 181****6752
+--------------------------------
+商品列表
`
+ content += "商品名" + StrRepeat(" ", 3) + "数量" + StrRepeat(" ", 4) + "单价" + StrRepeat(" ", 6) + "小计" + "
"
+ content += `--------------------------------`
+ content += FormatPrintOrderItem("[优]猪肉馅约250g/份", 1, 999)
+ content += FormatPrintOrderItem("鲜鸡蛋约250g/份", 1, 17.8)
+ content += FormatPrintOrderItem("豌豆米-手工剥豆约100g/份", 1, 40)
+ content += FormatPrintOrderItem("娃娃菜200g/个", 5, 2)
+ content += `共4种9件商品
+实付金额: 327.83元
+--------------#20完-------------`
+ msg, err := api.Print(TestSn, content, VoiceNewShort)
+ fmt.Println(msg)
+ fmt.Println(err)
+}
+
+//打印取消/退货模板
+func TestAPI_Print2(t *testing.T) {
+ content := `京西菜市
`
+ content += StrRepeat("-", 32) + `
+下单时间:2023-03-27 13:22:05
+订单编号: E22092832084572779
+美团外卖#20
+取消订单
+--------------------------------`
+ content += `共4种9件商品
+实付金额: 327.83元
+--------------#20完-------------`
+ 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)
+}
diff --git a/platformapi/trenditapi/trenditapi.go b/platformapi/trenditapi/trenditapi.go
new file mode 100644
index 00000000..215d6746
--- /dev/null
+++ b/platformapi/trenditapi/trenditapi.go
@@ -0,0 +1,157 @@
+package trenditapi
+
+import (
+ "crypto/md5"
+ "encoding/json"
+ "fmt"
+ "git.rosy.net.cn/baseapi/platformapi"
+ "git.rosy.net.cn/baseapi/utils"
+ "io/ioutil"
+ r "math/rand"
+ "net/http"
+ "strconv"
+ "strings"
+ "sync"
+ "time"
+)
+
+type API struct {
+ locker sync.RWMutex
+ accessToken string
+
+ appID string
+ appSecret string
+ client *http.Client
+ config *platformapi.APIConfig
+}
+
+func New(appID, appSecret string, config ...*platformapi.APIConfig) *API {
+ curConfig := platformapi.DefAPIConfig
+ if len(config) > 0 {
+ curConfig = *config[0]
+ }
+ return &API{
+ appID: appID,
+ appSecret: appSecret,
+ client: &http.Client{Timeout: curConfig.ClientTimeout},
+ config: &curConfig,
+ }
+}
+
+//生成BaseReq
+func (a *API) GenBaseReq(bizParams interface{}) *BaseReq {
+ //生成通用参数
+ uid := utils.Time2Str(time.Now()) + RandString()
+ timestamp := utils.Int64ToStr(time.Now().Unix())
+ return &BaseReq{
+ AppID: a.appID,
+ Uid: uid,
+ STime: timestamp,
+ Sign: a.sign(uid, timestamp, "bizParams"),
+ }
+}
+
+//生成随机字符串
+func RandString() string {
+ bytes := make([]byte, 16)
+ for i := 0; i < 16; i++ {
+ b := r.Intn(26) + 65
+ bytes[i] = byte(b)
+ }
+ return string(bytes)
+}
+
+func (a *API) sign(uid, timestamp string, param string) (sign string) {
+ aa := uid + a.appID + timestamp + a.appSecret + param
+ return fmt.Sprintf("%x", md5.Sum([]byte(aa)))
+}
+
+func (a *API) HttpPostJson(url string, data interface{}) *TIResponse {
+ //序列化参数
+ b, err := json.Marshal(&data)
+ if err != nil {
+ var msg = fmt.Sprintf("json serialize err:%+v", err)
+ fmt.Println(msg)
+ result := TIResponse{
+ HttpStatusCode: 500,
+ }
+ return &result
+ }
+
+ fullUrl := utils.GenerateGetURL(BaseUrl, url, nil)
+
+ request, err := http.NewRequest(http.MethodPost, fullUrl, strings.NewReader(string(b)))
+ client := &http.Client{}
+ timestamp := utils.Int64ToStr(time.Now().Unix())
+ uid := timestamp + RandString()
+ sign := a.sign(uid, timestamp, string(b))
+
+ request.Header.Set("Content-Type", "application/json;charset=UTF-8")
+ request.Header.Set("appid", a.appID)
+ request.Header.Set("uid", uid)
+ request.Header.Set("stime", timestamp)
+ request.Header.Set("sign", sign)
+
+ resp, err := client.Do(request)
+ //resp, err := http.Post(utils.GenerateGetURL(BaseUrl, url, nil), "application/json;charset=UTF-8", bytes.NewBuffer(b))
+ if err != nil {
+ fmt.Println(err)
+ }
+ defer resp.Body.Close()
+ body, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ var msg = fmt.Sprintf("post json error:%+v", err)
+ fmt.Println(msg)
+ }
+
+ result := TIResponse{
+ HttpStatusCode: resp.StatusCode,
+ }
+
+ var content BaseResp
+ err = json.Unmarshal(body, &content)
+ if err == nil {
+ result.BaseRes = &content
+ } else {
+ var msg = fmt.Sprintf("unmarshal body failed, error:%+v", err)
+ fmt.Println(msg)
+ }
+
+ return &result
+}
+
+func StrRepeat(str string, repeatTimes int) string {
+ return strings.Repeat(str, repeatTimes)
+}
+
+func CalcAsciiLenForPrint(data string) int {
+ return len(data)
+}
+
+func FormatPrintOrderItemBig(foodName string, quantity int, price float64) string {
+ orderNameEmpty := StrRepeat(" ", 8)
+ quantityStr := strconv.Itoa(quantity)
+ temprice := price / 100
+ priceStr := fmt.Sprintf("%.2f", temprice)
+ subtotalStr := fmt.Sprintf("%.2f", utils.Int2Float64(quantity)*temprice)
+ result := `` + foodName + "
"
+ result += `` + orderNameEmpty + "x" + quantityStr + ` `
+ result += `` + "¥" + priceStr + ` `
+ result += `` + "¥" + subtotalStr + ``
+ //result += "
"
+ return result
+}
+
+func FormatPrintOrderItem(foodName string, quantity int, price float64) string {
+ orderNameEmpty := StrRepeat(" ", 8)
+ quantityStr := strconv.Itoa(quantity)
+ temprice := price / 100
+ priceStr := fmt.Sprintf("%.2f", temprice)
+ subtotalStr := fmt.Sprintf("%.2f", utils.Int2Float64(quantity)*temprice)
+ result := foodName + "
"
+ result += orderNameEmpty + "x" + quantityStr + ` `
+ result += "¥" + priceStr + ` `
+ result += "¥" + subtotalStr
+ result += "
"
+ return result
+}
diff --git a/platformapi/xpyunapi/xpuapi_test.go b/platformapi/xpyunapi/xpuapi_test.go
index 4cef66f6..e29f14fe 100644
--- a/platformapi/xpyunapi/xpuapi_test.go
+++ b/platformapi/xpyunapi/xpuapi_test.go
@@ -21,7 +21,7 @@ var api = New(UserName, UserKey)
//测试格式化商品列表
func TestFormatPrintOrderItem(t *testing.T) {
- str := FormatPrintOrderItem("测试商品名字", 100, 8.78)
+ str := "鱼不用杀😁【如遇缺货】:缺货时电话与我沟通 收货人隐私号 17882960804_9913,手机号 191****1675"
fmt.Println(str)
request := &PrintRequest{
RestRequest: api.GenerateRestRequest(),
@@ -37,7 +37,7 @@ func TestFormatPrintOrderItem(t *testing.T) {
}
func TestPrint(t *testing.T) {
printContent := ""
- printContent = printContent + "![]()
" + "京西菜市" + "
"
+ printContent = printContent + "
" + "京西菜市" + "
"
printContent += StrRepeat("-", 32)
printContent += "
下单时间:2023-03-16 15:30:28"
printContent += "
预计送达:2023-03-16 16:30:28"