-
Notifications
You must be signed in to change notification settings - Fork 2
/
customer.go
106 lines (98 loc) · 2.33 KB
/
customer.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package unionpay
import (
"encoding/base64"
"github.com/smartwalle/unionpay/internal"
"net/url"
)
// EncodeCustomer 对 Customer 进行编码,不会对 phoneNo,cvn2,expired 进行加密。
//func (this *Client) EncodeCustomer(customer *Customer, accNo string) (string, error) {
// if customer == nil {
// return "", nil
// }
//
// var v = url.Values{}
// if customer.CertType != "" {
// v.Set("certifTp", customer.CertType)
// }
// if customer.CertId != "" {
// v.Set("certifId", customer.CertId)
// }
// if customer.Name != "" {
// v.Set("customerNm", customer.Name)
// }
// if customer.SMSCode != "" {
// v.Set("smsCode", customer.SMSCode)
// }
// if customer.PIN != "" {
// var block, err = this.EncryptPIN(accNo, customer.PIN)
// if err != nil {
// return "", err
// }
// v.Set("pin", block)
// }
// if customer.CVN2 != "" {
// v.Set("cvn2", customer.CVN2)
// }
// if customer.Expired != "" {
// v.Set("expired", customer.Expired)
// }
// if customer.PhoneNo != "" {
// v.Set("phoneNo", customer.PhoneNo)
// }
//
// var r = internal.EncodeValues(v)
// if r != "" {
// r = "{" + r + "}"
// }
//
// return base64.StdEncoding.EncodeToString([]byte(r)), nil
//}
// EncryptCustomer 对 Customer 进行编码,会对 phoneNo,cvn2,expired 进行加密。
func (c *Client) EncryptCustomer(customer *Customer, accNo string) (string, error) {
if customer == nil {
return "", nil
}
var v = url.Values{}
if customer.CertType != "" {
v.Set("certifTp", customer.CertType)
}
if customer.CertId != "" {
v.Set("certifId", customer.CertId)
}
if customer.Name != "" {
v.Set("customerNm", customer.Name)
}
if customer.SMSCode != "" {
v.Set("smsCode", customer.SMSCode)
}
if customer.PIN != "" {
var block, err = c.EncryptPIN(accNo, customer.PIN)
if err != nil {
return "", err
}
v.Set("pin", block)
}
var ev = url.Values{}
if customer.CVN2 != "" {
ev.Set("cvn2", customer.CVN2)
}
if customer.Expired != "" {
ev.Set("expired", customer.Expired)
}
if customer.PhoneNo != "" {
ev.Set("phoneNo", customer.PhoneNo)
}
var evs = internal.EncodeValues(ev)
if evs != "" {
encryptedInfo, err := c.Encrypt(evs)
if err != nil {
return "", err
}
v.Set("encryptedInfo", encryptedInfo)
}
var r = internal.EncodeValues(v)
if r != "" {
r = "{" + r + "}"
}
return base64.StdEncoding.EncodeToString([]byte(r)), nil
}