Documentation ¶
Index ¶
- Constants
- Variables
- type CertResponse
- type Client
- func (cli *Client) DoGet(url string, needVerify ...bool) (resp []byte, err error)
- func (cli *Client) DoPost(url, body string, needVerify ...bool) (resp []byte, httpCode int, err error)
- func (cli *Client) GetWechatCertificate() (err error)
- func (cli *Client) ImageUpload(content []byte, filename string) (mediaId string, err error)
- func (cli *Client) SecretFieldEncrypt(plaintext []byte) (ciphertext string, err error)
- func (cli *Client) Sign(method, url, body, nonce string) (sign string, err error)
- func (cli *Client) Verify(resp *http.Response, body []byte) bool
Constants ¶
View Source
const DEBUG bool = true
View Source
const (
GATEWAY = "https://api.mch.weixin.qq.com"
)
Variables ¶
View Source
var UserAgent string
Functions ¶
This section is empty.
Types ¶
type CertResponse ¶
type CertResponse struct { Data []struct { SerialNo string `json:"serial_no"` // 证书序列号 EffectiveTime string `json:"effective_time"` // 生效时间 ExpireTime string `json:"expire_time"` // 过期时间 EncryptCertificate struct { Algorithm string `json:"algorithm"` // 算法 Nonce string `json:"nonce"` // 随机串 AssociatedData string `json:"associated_data"` // 附加数据包 Ciphertext string `json:"ciphertext"` // 密文 } `json:"encrypt_certificate"` // 证书内容 } `json:"data"` }
type Client ¶
type Client struct { GateWay string // 网关 MerchantId string // 商户id SerialNumber string // 商户序列号 AppSecret string // 商户密钥 微信支付在回调通知和平台证书下载接口中,对关键信息进行了AES-256-GCM加密 PrivateKey *rsa.PrivateKey // 商户API私钥 Certificate *tls.Certificate // 商户证书 WechatCertificate *x509.Certificate // 平台证书 WechatSerialNumber string // 微信平台序列号 // contains filtered or unexported fields }
var Cli *Client // 默认客户端
func NewClient ¶
func NewClient(merchantId, serialNumber, appSecret, certFile, keyFile string) (cli *Client, err error)
实例化一个客户端
func (*Client) DoPost ¶
func (cli *Client) DoPost(url, body string, needVerify ...bool) (resp []byte, httpCode int, err error)
POST一个API
func (*Client) GetWechatCertificate ¶
获取微信支付平台证书 平台证书会周期性更换。建议商户定时通过API下载新的证书 可以弄个Cronjob线程周期执行这个方法
func (*Client) ImageUpload ¶
图片上传 https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/tool/chapter3_1.shtml
func (*Client) SecretFieldEncrypt ¶
敏感信息加密 https://wechatpay-api.gitbook.io/wechatpay-api-v3/qian-ming-zhi-nan-1/min-gan-xin-xi-jia-mi
Click to show internal directories.
Click to hide internal directories.