Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- func (s *Client) Algorithm() string
- func (c *Client) AppPay(d *model.AppNativePay) (*model.AppPayRes, error)
- func (c *Client) Applyment(d *model.ApplymentData) (int, error)
- func (c *Client) CloseOutTradeNo(outtradeno, submchid string) (bool, error)
- func (c *Client) CreateFormField(w *multipart.Writer, fieldName, contentType string, fieldValue []byte) error
- func (c *Client) CreateFormFile(w *multipart.Writer, filename, contentType string, file []byte) error
- func (c *Client) CreateVoucher(data *model.Stocks) (string, error)
- func (c *Client) GenerateAuthorizationHeader(ctx context.Context, method, canonicalURL, signBody string) (string, error)
- func (c *Client) Get(url string) (*http.Response, error)
- func (c *Client) GetCert() ([]*model.ItemCerts, error)
- func (c *Client) GetVoucher(openid string, merchantClient *Client, stockid string) (string, error)
- func (c *Client) ImgUpload(fileName string, filePath string) (string, error)
- func (c *Client) JsApiPay(d *model.JsApiPay) (*model.JsApiPayRes, error)
- func (c *Client) NativePay(d *model.AppNativePay) (string, error)
- func (c *Client) ParseNotifyRequest(ctx context.Context, request *http.Request, content interface{}) (*model.PayNotifyRequest, error)
- func (c *Client) Patch(url string, requestBody interface{}) (*http.Response, error)
- func (c *Client) PauseVoucher(stockid string) (string, error)
- func (c *Client) Post(url string, header map[string]string, requestBody interface{}) (*http.Response, error)
- func (c *Client) QueryApplyment(id string) (*model.ApplymentRes, error)
- func (c *Client) QueryMchBank(mchId string) (*model.ApplymentBankRes, error)
- func (c *Client) QueryOutTradeNo(outtradeno string, submchid string) (*model.AppNativePay, error)
- func (c *Client) QueryRefund(out_refund_no, sub_mchid string) (*model.RefundRes, error)
- func (c *Client) QueryTransactionID(transactionid string, submchid string) (*model.AppNativePay, error)
- func (c *Client) Refund(d *model.Refund) (*model.RefundRes, error)
- func (c *Client) RestartVoucher(stockid string) (string, error)
- func (c *Client) SetHeader(url, method string, requestBody interface{}, header map[string]string) (http.Header, error)
- func (s *Client) Sign(_ context.Context, message string) (*string, error)
- func (c *Client) StartVoucher(stockid string) (string, error)
- func (c *Client) UpdateMchBank(mchId string, d *model.UpdateMchBankData) (bool, error)
- func (c *Client) Upload(url, meta, requestBody string, header map[string]string) (*http.Response, error)
- func (c *Client) Validate(ctx context.Context, request *http.Request) error
- func (c *Client) Verify(ctx context.Context, serial, message, signature string) error
- func (c *Client) VideoUpload(fileName string, filePath string) (string, error)
- type Handler
- type Response
- type ResponseUrl
- type T
- type WechatPayNotifyValidator
Constants ¶
const ( Version = "0.2.8" // SDK 版本 UserAgentFormat = "WechatPay-Go/%s (%s) GO/%s" // UserAgent中的信息 )
SDK 相关信息
const ( SignatureMessageFormat = "%s\n%s\n%d\n%s\n%s\n" // 数字签名原文格式 HeaderAuthorizationFormat = "%s mchid=\"%s\",nonce_str=\"%s\",timestamp=\"%d\",serial_no=\"%s\",signature=\"%s\"" // HeaderAuthorizationFormat 请求头中的 Authorization 拼接格式 )
请求报文签名相关常量
const ( WechatPayTimestamp = "Wechatpay-Timestamp" // 微信支付回包时间戳 WechatPayNonce = "Wechatpay-Nonce" // 微信支付回包随机字符串 WechatPaySignature = "Wechatpay-Signature" // 微信支付回包签名信息 WechatPaySerial = "Wechatpay-Serial" // 微信支付回包平台序列号 RequestID = "Request-Id" // 微信支付回包请求ID )
HTTP 应答报文 Header 相关常量
const ( BaseUrl = "https://api.mch.weixin.qq.com" // 微信支付 API 地址 BaseUrlBackup = "https://api2.mch.weixin.qq.com" // 微信支付 API 备份地址 )
微信支付 API 地址
const ( ApplymentUrl = BaseUrl + "/v3/applyment4sub/applyment/" // 特约商户进件提交申请 QueryApplymentUrl = BaseUrl + "/v3/applyment4sub/applyment/applyment_id/%s" // GET 特约商户进件查询 s 业务申请编号 UpdateMchBankUrl = BaseUrl + "/v3/apply4sub/sub_merchants/%s/modify-settlement" // 修改结算账号 s 商户号 QueryMchBankUrl = BaseUrl + "/v3/apply4sub/sub_merchants/%s/settlement" // GET 查询结算账号 s 商户号 )
进件
const ( ImgUploadUrl = BaseUrl + "/v3/merchant/media/upload" // 图片上传ImgUpload VideoUploadUrl = BaseUrl + "/v3/merchant/media/video_upload" // 视频上传 )
其他能力
const ( VoucherStocksUrl = BaseUrl + "/v3/marketing/favor/coupon-stocks" // 创建优惠卷 VoucherStartStocksUrl = BaseUrl + "/v3/marketing/favor/stocks/%s/start" // 激活优惠卷 VoucherPauseStocksUrl = BaseUrl + "/v3/marketing/favor/stocks/%s/pause" // 暂停优惠卷 VoucherRestartStocksUrl = BaseUrl + "/v3/marketing/favor/stocks/%s/restart" // 重启代金券 VoucherGetStocksUrl = BaseUrl + "/v3/marketing/favor/users/%s/coupons" // 发放代金劵 )
优惠卷
const ( JsapiPayUrl = BaseUrl + "/v3/pay/partner/transactions/jsapi" // jsapi 下单 AppPayUrl = BaseUrl + "/v3/pay/partner/transactions/app" // App 下单 NativePayUrl = BaseUrl + "/v3/pay/partner/transactions/native" // Native下单 QueryTransactionIDUrl = BaseUrl + "/v3/pay/partner/transactions/id/%s?sp_mchid=%s&sub_mchid=%s" // 微信支付订单号查询 QueryOutTradeNoUrl = BaseUrl + "/v3/pay/partner/transactions/out-trade-no/%s?sp_mchid=%s&sub_mchid=%s" // 商户订单号查询 CloseOutTradeNoUrl = BaseUrl + "/v3/pay/partner/transactions/out-trade-no/%s/close" // 通过商户订单号关闭订单 RefundUrl = BaseUrl + "/v3/refund/domestic/refunds" // 订单退款 QueryRefundUrl = BaseUrl + "/v3/refund/domestic/refunds/%s?sub_mchid=%s" // 查询退款订单详情 by OutTradeNo )
支付
const (
FiveMinute = 5 * 60 // 回包校验最长时间(秒)
)
时间相关常量
const (
GetCertsUrl = BaseUrl + "/v3/certificates" // 获取平台证书列表
)
微信支付 API url
获取平台证书列表
Variables ¶
var ( DefaultHeader = map[string]string{ utils.ContentType: utils.ApplicationJSON, } )
默认请求头
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { AppID string // 商户appid应该为公众号的appid或者小程序的appid MchID string // 商户号 CertificateSerialNo string // 商户证书序列号 PrivateKey *rsa.PrivateKey // 商户私钥 MchAPIv3Key string // 商户APIv3Key MchAPIv2Key string // 商户APIv2Key PublicKey *rsa.PublicKey // 平台公钥 WeChatNo string // 平台证书序列号 Ctx context.Context }
Client 基础信息
func NewClient ¶
func NewClient(mchID, certificateSerialNo, privateKey, mchAPIv3Key, mchAPIv2Key, publicKey, weChatNo string) (c *Client, e error)
NewClient 新建一个Client
func (*Client) CloseOutTradeNo ¶
func (*Client) CreateFormField ¶
func (c *Client) CreateFormField(w *multipart.Writer, fieldName, contentType string, fieldValue []byte) error
CreateFormField(w, "meta", "application/json", meta)
func (*Client) CreateFormFile ¶
func (c *Client) CreateFormFile(w *multipart.Writer, filename, contentType string, file []byte) error
CreateFormFile 设置form-data中的文件 示例内容: Content-Disposition: form-data; name="file"; filename="file_test.mp4"; Content-Type: video/mp4 pic1 //pic1即为媒体视频的二进制内容 如果要设置上述内容,则CreateFormFile(w, "file_test.mp4", "video/mp4", pic1)
func (*Client) CreateVoucher ¶
代金劵 CreateVoucher 创建优惠卷
func (*Client) GenerateAuthorizationHeader ¶
func (c *Client) GenerateAuthorizationHeader(ctx context.Context, method, canonicalURL, signBody string) (string, error)
生成请求报文头中的 Authorization 信息 ctx 上下文 method 请求方法 request.URL.RequestURI() 请求url signBody 签名的字符串
func (*Client) GetVoucher ¶
GetVoucher发放优惠卷
func (*Client) NativePay ¶
func (c *Client) NativePay(d *model.AppNativePay) (string, error)
Native 下单
func (*Client) ParseNotifyRequest ¶
func (c *Client) ParseNotifyRequest(ctx context.Context, request *http.Request, content interface{}) (*model.PayNotifyRequest, error)
微信支付通知 ParseNotifyRequest 从 HTTP 请求(http.Request) 中解析
func (*Client) PauseVoucher ¶
PauseVoucher 暂停优惠卷
func (*Client) Post ¶
func (c *Client) Post(url string, header map[string]string, requestBody interface{}) (*http.Response, error)
Post 向微信支付发送一个 HTTP Post 请求
func (*Client) QueryApplyment ¶
func (c *Client) QueryApplyment(id string) (*model.ApplymentRes, error)
查询申请单状态 id 为微信返回id
func (*Client) QueryMchBank ¶
func (c *Client) QueryMchBank(mchId string) (*model.ApplymentBankRes, error)
查询结算账户 mchId 为商户号
func (*Client) QueryOutTradeNo ¶
商户订单号查询
func (*Client) QueryRefund ¶
查询退款
func (*Client) QueryTransactionID ¶
func (c *Client) QueryTransactionID(transactionid string, submchid string) (*model.AppNativePay, error)
微信支付订单号查询
func (*Client) RestartVoucher ¶
PauseVoucher 暂停优惠卷
func (*Client) SetHeader ¶
func (c *Client) SetHeader(url, method string, requestBody interface{}, header map[string]string) (http.Header, error)
设置请求头
func (*Client) StartVoucher ¶
StartVoucher 激活优惠卷 创建批次的商户号 mchid 批次号 stockid
func (*Client) UpdateMchBank ¶
修改结算账号
func (*Client) Upload ¶
func (c *Client) Upload(url, meta, requestBody string, header map[string]string) (*http.Response, error)
CreateFormField 设置form-data 中的普通属性 示例内容 Content-Disposition: form-data; name="meta"; Content-Type: application/json { "filename": "file_test.mp4", "sha256": " hjkahkjsjkfsjk78687dhjahdajhk " } Upload 向微信支付发送上传图片或视频文件请求
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler 微信支付通知 Handler
type ResponseUrl ¶
type ResponseUrl struct {
CodeUrl string `json:"code_url"`
}
type WechatPayNotifyValidator ¶
type WechatPayNotifyValidator struct { }
WechatPayNotifyValidator 微信支付 API v3 通知请求报文验证器
func NewWechatPayNotifyValidator ¶
func NewWechatPayNotifyValidator(verifier interface{}) *WechatPayNotifyValidator
NewWechatPayNotifyValidator 使用 Verifier 初始化一个 WechatPayNotifyValidator