/
config.go
80 lines (66 loc) · 1.73 KB
/
config.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package yop
const (
// 加密算法
//algAes = "AES"
//algSha = "SHA"
//algSha1 = "SHA1"
// 保护参数
serverRoot = "https://openapi.yeepay.com/yop-center" //"http://58.83.141.72/yop-center"//
yosServerRoot = "https://yos.yeepay.com/yop-center"
//encoding = "UTF-8"
//success = "SUCCESS"
//callback = "callback"
// 方法的默认参数名
method = "method"
// 会话id默认参数名
sessionId = "sessionId"
// 应用键的默认参数名
appKey = "appKey"
// 服务版本号的默认参数名
version = "v"
// 签名的默认参数名
sign = "sign"
// 商户编号
customerNo = "customerNo"
// 时间戳
//timestamp = "ts"
)
type Config struct {
ServerRoot string
YosServerRoot string
AppKey string
AesSecretKey string //非对称加密密钥
HmacSecretKey string //对称加密密钥
YopPublicKey string //易宝公钥
Debug bool
ConnectTimeout int
ReadTimeout int
MaxUploadLimit int
PublicEdKeys []string
}
func NewDefaultConfig() *Config {
return NewConfig(parentMerchantNo, privateKey, hmacKey, yopPublicKey)
}
func NewConfig(parentMerchantNo string, privateKey string, hmacKey string, yopPublicKey string) *Config {
return &Config{
ServerRoot: serverRoot,
YosServerRoot: yosServerRoot,
AppKey: parentMerchantNo,
AesSecretKey: privateKey,
HmacSecretKey: hmacKey,
YopPublicKey: yopPublicKey,
Debug: false,
ConnectTimeout: 30000,
ReadTimeout: 60000,
MaxUploadLimit: 4096000,
PublicEdKeys: []string{appKey, version, sign, method, sessionId, customerNo, ""},
}
}
func (c *Config) IsPublicEdKey(key string) bool {
for _, val := range c.PublicEdKeys {
if val == key {
return true
}
}
return false
}