-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunionpay_type.go
91 lines (74 loc) · 1.59 KB
/
unionpay_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
package unionpay
import (
"fmt"
"net/url"
)
const (
kSandboxGateway = "https://gateway.test.95516.com"
kProductionGateway = "https://gateway.95516.com"
kVersion = "5.1.0"
kSignMethod = "01"
)
const kWebPaymentTemplate = `
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body>
<form id="pay_form" action="{{.Action}}" method="POST">
{{range $k, $v := .Values}}
<input type="hidden" name="{{$k}}" id="{{$k}}" value="{{index $v 0}}" />
{{end}}
</form>
<script type="text/javascript">
document.getElementById("pay_form").submit();
</script>
</body>
</html>
`
type Code string
func (c Code) IsSuccess() bool {
return c == CodeSuccess
}
func (c Code) IsFailure() bool {
return c != CodeSuccess
}
const (
CodeSuccess Code = "00" // 接口调用成功
)
type Error struct {
Code Code `query:"respCode"`
Msg string `query:"respMsg"`
}
func (e Error) Error() string {
return fmt.Sprintf("%s - %s", e.Code, e.Msg)
}
func (e Error) IsSuccess() bool {
return e.Code.IsSuccess()
}
func (e Error) IsFailure() bool {
return e.Code.IsFailure()
}
type Payload struct {
values url.Values
}
func NewPayload() *Payload {
var nPayload = &Payload{}
nPayload.values = url.Values{}
return nPayload
}
func (p *Payload) AddParam(key, value string) *Payload {
if key != "" && value != "" {
p.values.Set(key, value)
}
return p
}
type CallOption func(values url.Values)
func WithPayload(payload *Payload) CallOption {
return func(values url.Values) {
if payload != nil {
for key := range payload.values {
values[key] = payload.values[key]
}
}
}
}