增加打印机声音设置
This commit is contained in:
@@ -52,6 +52,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
|
platformapi.APICookie
|
||||||
|
|
||||||
user string
|
user string
|
||||||
ukey string
|
ukey string
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
|||||||
65
platformapi/feieapi/feiepage.go
Normal file
65
platformapi/feieapi/feiepage.go
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package feieapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi"
|
||||||
|
"git.rosy.net.cn/baseapi/platformapi"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
url = "http://admin.feieyun.com"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (a *API) AccessStorePage(subURL string, params map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||||
|
if a.GetCookieCount() == 0 {
|
||||||
|
return nil, fmt.Errorf("需要设置Store Cookie才能使用此方法")
|
||||||
|
}
|
||||||
|
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||||
|
func() *http.Request {
|
||||||
|
request, _ := http.NewRequest(http.MethodPost, utils.GenerateGetURL(url, subURL, nil), strings.NewReader(utils.Map2URLValues(params).Encode()))
|
||||||
|
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
a.FillRequestCookies(request)
|
||||||
|
return request
|
||||||
|
},
|
||||||
|
a.config,
|
||||||
|
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
|
||||||
|
if jsonResult1 == nil {
|
||||||
|
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||||
|
}
|
||||||
|
retVal = jsonResult1
|
||||||
|
baseapi.SugarLogger.Debugf("ebai AccessStorePage failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true))
|
||||||
|
return platformapi.ErrLevelSuccess, err
|
||||||
|
})
|
||||||
|
return retVal, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置打印机声音
|
||||||
|
func (a *API) SetSound(sn, beeperalarm string) (err error) {
|
||||||
|
size := translateSoundSize(beeperalarm)
|
||||||
|
_, err = a.AccessStorePage("api.php", map[string]interface{}{
|
||||||
|
"action": "Printer_setPrinterConfig",
|
||||||
|
"uid": "2013191",
|
||||||
|
"sn": sn,
|
||||||
|
"printautocut": "N",
|
||||||
|
"beeperalarm": size,
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func translateSoundSize(beeperalarm string) (size string) {
|
||||||
|
switch beeperalarm {
|
||||||
|
case "0":
|
||||||
|
size = "N"
|
||||||
|
case "1":
|
||||||
|
size = "U"
|
||||||
|
case "2":
|
||||||
|
size = "V"
|
||||||
|
case "3":
|
||||||
|
size = "W"
|
||||||
|
}
|
||||||
|
return size
|
||||||
|
}
|
||||||
12
platformapi/feieapi/feiepage_test.go
Normal file
12
platformapi/feieapi/feiepage_test.go
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
package feieapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSetSound(t *testing.T) {
|
||||||
|
err := api.SetSound("218510310", "2")
|
||||||
|
baseapi.SugarLogger.Debug(err)
|
||||||
|
}
|
||||||
@@ -278,3 +278,13 @@ func (a *API) GetOrderPagingList(machineCode, token string, pageIndex, pageSize
|
|||||||
}
|
}
|
||||||
return orderResultList, err
|
return orderResultList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 设置打印机声音
|
||||||
|
func (a *API) SetSound(machineCode, voice string) (err error) {
|
||||||
|
_, err = a.AccessAPI("printer/setsound", map[string]interface{}{
|
||||||
|
"machine_code": machineCode,
|
||||||
|
"response_type": "horn", //蜂鸣器buzzer或喇叭,易连云默认喇叭
|
||||||
|
"voice": voice,
|
||||||
|
}, "")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func init() {
|
|||||||
|
|
||||||
// 自有应用
|
// 自有应用
|
||||||
api = New("1039586024", "4885d07c2997b661102e4b6099c0bf3b")
|
api = New("1039586024", "4885d07c2997b661102e4b6099c0bf3b")
|
||||||
api.SetToken("3a38e3cec7974b459a6f0a381c9b0312")
|
api.SetToken("852dd259dc244c579e2a987857932606")
|
||||||
|
|
||||||
// 开放应用
|
// 开放应用
|
||||||
// api = New("1098307169", "d5eedb40c99e6691b1ca2ba82a363d6a")
|
// api = New("1098307169", "d5eedb40c99e6691b1ca2ba82a363d6a")
|
||||||
@@ -103,3 +103,8 @@ func TestGetOrderPagingList(t *testing.T) {
|
|||||||
handleError(t, err)
|
handleError(t, err)
|
||||||
t.Log(utils.Format4Output(result, true))
|
t.Log(utils.Format4Output(result, true))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetSound(t *testing.T) {
|
||||||
|
err := api.SetSound("4004617180", "2")
|
||||||
|
handleError(t, err)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user