service/vendor/github.com/go-pay/gopay/alipay/util_api.go

37 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package alipay
import (
"context"
"encoding/base64"
"encoding/json"
"fmt"
"github.com/go-pay/gopay"
)
// alipay.open.app.alipaycert.download(应用支付宝公钥证书下载)
// 文档地址https://opendocs.alipay.com/apis/api_9/alipay.open.app.alipaycert.download
func (a *Client) PublicCertDownload(ctx context.Context, bm gopay.BodyMap) (aliRsp *PublicCertDownloadRsp, err error) {
err = bm.CheckEmptyError("alipay_cert_sn")
if err != nil {
return nil, err
}
var bs []byte
if bs, err = a.doAliPay(ctx, bm, "alipay.open.app.alipaycert.download"); err != nil {
return nil, err
}
aliRsp = new(PublicCertDownloadRsp)
if err = json.Unmarshal(bs, aliRsp); err != nil || aliRsp.Response == nil {
return nil, fmt.Errorf("[%w], bytes: %s", gopay.UnmarshalErr, string(bs))
}
if err = bizErrCheck(aliRsp.Response.ErrorResponse); err != nil {
return aliRsp, err
}
certBs, err := base64.StdEncoding.DecodeString(aliRsp.Response.AlipayCertContent)
if err != nil {
return nil, fmt.Errorf("AlipayCertContent(%s)_DecodeErr:%+v", aliRsp.Response.AlipayCertContent, err)
}
aliRsp.Response.AlipayCertContent = string(certBs)
return aliRsp, nil
}