-
Notifications
You must be signed in to change notification settings - Fork 7
/
consume_query.go
82 lines (72 loc) · 2.21 KB
/
consume_query.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
package unionpay
import "net/url"
type ConsumeQueryResponse struct {
Version string
Encoding string
CertID string
Signature string
SignMethod string
TxnType string
TxnSubType string
AccessType string
MerID string
OrderID string
TxnTime string
PayType string
CurrencyCode string
AccNo string
PayCardType string
TxnAmt string // 长度为1到12字节的变长整型数值,以分为单位
ReqReserved string
Reserved string
IssuerIdentifyMode string
QueryID string
TraceNo string
TraceTime string
SettleDate string
SettleCurrencyCode string
SettleAmt string
OrigRespCode string
OrigRespMsg string
RespCode string
RespMsg string
}
func (up *UnionPay) ConsumeQuery(orderID, queryID, txnTime, reserved string) (resp *ConsumeQueryResponse, err error) {
kvs := KVpairs{}
kvs = append(kvs, KVpair{K: "version", V: "5.0.0"})
kvs = append(kvs, KVpair{K: "encoding", V: "UTF-8"})
kvs = append(kvs, KVpair{K: "certId", V: up.publicKey.SerialNumber.String()})
kvs = append(kvs, KVpair{K: "signMethod", V: "01"})
kvs = append(kvs, KVpair{K: "txnType", V: "00"})
kvs = append(kvs, KVpair{K: "txnSubType", V: "00"})
kvs = append(kvs, KVpair{K: "bizType", V: "000000"})
kvs = append(kvs, KVpair{K: "accessType", V: "0"})
kvs = append(kvs, KVpair{K: "channelType", V: "07"})
kvs = append(kvs, KVpair{K: "merId", V: up.mchID})
kvs = append(kvs, KVpair{K: "orderId", V: orderID})
kvs = append(kvs, KVpair{K: "txnTime", V: txnTime})
kvs = append(kvs, KVpair{K: "reserved", V: reserved})
kvs = append(kvs, KVpair{K: "queryId", V: queryID})
var sig string
sig, err = signature(up.privateKey, kvs)
if err != nil {
return
}
kvs = append(kvs, KVpair{K: "signature", V: sig})
data := url.Values{}
for _, v := range kvs {
data.Set(v.K, v.V)
}
var u *url.URL
u, err = url.Parse(up.getHost() + queryTrans)
if err != nil {
return
}
var result ConsumeQueryResponse
err = up.client.PostForm(u, data, &result)
if err != nil {
return
}
resp = &result
return
}