-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsettings.go
57 lines (51 loc) · 1.69 KB
/
settings.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
package wxpayv3
import (
"crypto/x509"
"github.com/louismax/wxpayv3/core"
)
//InjectWechatPayParameter InjectWechatPayParameter
func InjectWechatPayParameter(mchID string, apiCert core.ApiCert, mchAPIv3Key string) core.ClientOption {
return core.BasicInformation{
MchID: mchID,
MchAPIv3Key: mchAPIv3Key,
ApiCert: apiCert,
}
}
//InjectWechatPayParameterUseCertPath InjectWechatPayParameterUseCertPath
func InjectWechatPayParameterUseCertPath(mchID string, mchAPIv3Key string, privateKeyPath string, certificatePath string) core.ClientOption {
pv, err := core.LoadPrivateKeyWithPath(privateKeyPath)
if err != nil {
return core.ErrorOption{Error: err}
}
ct, err := core.LoadCertificateWithPath(certificatePath)
if err != nil {
return core.ErrorOption{Error: err}
}
return core.BasicInformation{
MchID: mchID,
MchAPIv3Key: mchAPIv3Key,
ApiCert: core.ApiCert{
ApiSerialNo: core.GetCertificateSerialNumber(*ct),
ApiPrivateKey: pv,
ApiCertificate: ct,
},
}
}
//InjectWechatPayPlatformCert InjectWechatPayPlatformCert
func InjectWechatPayPlatformCert(platformSerialNo string, platformCertificate *x509.Certificate) core.ClientOption {
return core.PlatformCert{
PlatformSerialNo: platformSerialNo,
PlatformCertificate: platformCertificate,
}
}
//InjectWechatPayPlatformCertUseCertPath InjectWechatPayPlatformCertUseCertPath
func InjectWechatPayPlatformCertUseCertPath(platformCertificatePath string) core.ClientOption {
ct, err := core.LoadCertificateWithPath(platformCertificatePath)
if err != nil {
return core.ErrorOption{Error: err}
}
return core.PlatformCert{
PlatformSerialNo: core.GetCertificateSerialNumber(*ct),
PlatformCertificate: ct,
}
}