You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
wechatpayopen/certificates.go

49 lines
1.6 KiB

package wechatpayopen
import (
"context"
"encoding/json"
"go.dtapp.net/gorequest"
"net/http"
"time"
)
type CertificatesResponse struct {
Data []struct {
EffectiveTime time.Time `json:"effective_time"` // 过期时间
EncryptCertificate struct {
Algorithm string `json:"algorithm"`
AssociatedData string `json:"associated_data"`
Ciphertext string `json:"ciphertext"`
Nonce string `json:"nonce"`
} `json:"encrypt_certificate"` // 加密证书
ExpireTime time.Time `json:"expire_time"` // 有效时间
SerialNo string `json:"serial_no"` // 序列号
} `json:"data"`
}
type CertificatesResult struct {
Result CertificatesResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
Err error // 错误
}
func newCertificatesResult(result CertificatesResponse, body []byte, http gorequest.Response, err error) *CertificatesResult {
return &CertificatesResult{Result: result, Body: body, Http: http, Err: err}
}
// Certificates 获取平台证书列表
// https://pay.weixin.qq.com/wiki/doc/apiv3/apis/wechatpay5_1.shtml
func (c *Client) Certificates(ctx context.Context) *CertificatesResult {
// 请求
request, err := c.request(ctx, apiUrl+"/v3/certificates", map[string]interface{}{}, http.MethodGet)
if err != nil {
return newCertificatesResult(CertificatesResponse{}, request.ResponseBody, request, err)
}
// 定义
var response CertificatesResponse
err = json.Unmarshal(request.ResponseBody, &response)
return newCertificatesResult(response, request.ResponseBody, request, err)
}