/
base.go
62 lines (51 loc) · 1.36 KB
/
base.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* Created by GoLand.
* User: 姜伟
* Date: 2019/12/27 0027
* Time: 19:46
*/
package mpprint
import (
"crypto/tls"
"regexp"
"github.com/a07061625/gompf/mpf"
"github.com/a07061625/gompf/mpf/api"
"github.com/a07061625/gompf/mpf/mpconstant/errorcode"
"github.com/a07061625/gompf/mpf/mpconstant/project"
"github.com/a07061625/gompf/mpf/mperr"
"github.com/valyala/fasthttp"
)
type basePrint struct {
api.APIInner
}
func newBase() basePrint {
return basePrint{api.NewAPIInner()}
}
type BaseFeYin struct {
basePrint
appId string // 应用ID
}
func (p *BaseFeYin) SetAppId(appId string) {
match, _ := regexp.MatchString(project.RegexDigitAlpha, appId)
if match {
p.appId = appId
} else {
panic(mperr.NewPrintFeYin(errorcode.PrintFeYinParam, "应用ID不合法", nil))
}
}
func (p *BaseFeYin) GetAppId() string {
return p.appId
}
func (p *BaseFeYin) GetRequest() (*fasthttp.Client, *fasthttp.Request) {
client := &fasthttp.Client{}
client.TLSConfig = &tls.Config{InsecureSkipVerify: true}
req := fasthttp.AcquireRequest()
req.Header.SetRequestURI(p.ReqURI)
req.Header.SetContentType(p.ReqContentType)
req.Header.SetMethod(p.ReqMethod)
mpf.HTTPAddReqHeader(req, p.ReqHeader)
return client, req
}
func NewBaseFeYin() BaseFeYin {
return BaseFeYin{newBase(), ""}
}