-
Notifications
You must be signed in to change notification settings - Fork 36
/
wxpay_type.go
92 lines (76 loc) · 1.5 KB
/
wxpay_type.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
81
82
83
84
85
86
87
88
89
90
91
92
package wxpay
import (
"encoding/xml"
"errors"
"io"
"net/url"
)
const (
kSandboxURL = "https://api.mch.weixin.qq.com/sandboxnew"
kProductionURL = "https://api.mch.weixin.qq.com"
)
const (
ReturnCodeFail = "FAIL"
ReturnCodeSuccess = "SUCCESS"
)
const (
SignTypeMD5 = "MD5"
)
var (
ErrNotFoundCertFile = errors.New("wxpay: not found cert file")
ErrNotFoundTLSClient = errors.New("wxpay: not found tls client")
)
type Param interface {
// 返回参数列表
Params() url.Values
}
type XMLMap url.Values
type xmlMapEntry struct {
XMLName xml.Name
Value string `xml:",chardata"`
}
func (m XMLMap) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
for {
var e xmlMapEntry
err := d.Decode(&e)
if err == io.EOF {
break
} else if err != nil {
return err
}
(m)[e.XMLName.Local] = []string{e.Value}
}
return nil
}
func (v XMLMap) Get(key string) string {
if v == nil {
return ""
}
vs := v[key]
if len(vs) == 0 {
return ""
}
return vs[0]
}
func (v XMLMap) Set(key, value string) {
v[key] = []string{value}
}
func (v XMLMap) Add(key, value string) {
v[key] = append(v[key], value)
}
func (v XMLMap) Del(key string) {
delete(v, key)
}
type GetSignKeyParam struct {
MchId string
}
func (this *GetSignKeyParam) Params() url.Values {
var m = make(url.Values)
m.Set("mch_id", this.MchId)
return m
}
type GetSignKeyRsp struct {
ReturnCode string `xml:"return_code"`
ReturnMsg string `xml:"return_msg"`
SandboxSignKey string `xml:"sandbox_signkey"`
}