-
Notifications
You must be signed in to change notification settings - Fork 174
/
client.go
52 lines (40 loc) · 1.41 KB
/
client.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
package security
import (
"context"
"github.com/ArtisanCloud/PowerLibs/v3/object"
payment "github.com/ArtisanCloud/PowerWeChat/v3/src/payment/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/payment/security/response"
"net/http"
)
type Client struct {
*payment.BaseClient
}
func NewClient(app *payment.ApplicationPaymentInterface) (*Client, error) {
baseClient, err := payment.NewBaseClient(app)
if err != nil {
return nil, err
}
return &Client{
baseClient,
}, nil
}
// 获取平台证书
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/wechatpay5_1.shtml
func (comp *Client) GetCertificates(ctx context.Context) (*response.ResponseGetCertificates, error) {
result := &response.ResponseGetCertificates{}
endpoint := comp.Wrap("/v3/certificates")
_, err := comp.Request(ctx, endpoint, nil, http.MethodGet, &object.HashMap{}, false, nil, result)
return result, err
}
// Get RSA Public Key.
// https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay_yhk.php?chapter=25_7&index=4
func (comp *Client) GetRSAPublicKey(ctx context.Context) (*response.ResponseGetPublicKey, error) {
config := (*comp.App).GetConfig()
result := &response.ResponseGetPublicKey{}
options := &object.HashMap{
"mch_id": config.GetString("mch_id", ""),
}
url := "https://fraud.mch.weixin.qq.com/risk/getpublickey"
_, err := comp.RequestRawXML(ctx, url, &object.StringMap{}, http.MethodPost, options, nil, result)
return result, err
}