wechat

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Version         = "0.2.8"                      // SDK 版本
	UserAgentFormat = "WechatPay-Go/%s (%s) GO/%s" // UserAgent中的信息
)

SDK 相关信息

View Source
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 拼接格式
)

请求报文签名相关常量

View Source
const (
	WechatPayTimestamp = "Wechatpay-Timestamp" // 微信支付回包时间戳
	WechatPayNonce     = "Wechatpay-Nonce"     // 微信支付回包随机字符串
	WechatPaySignature = "Wechatpay-Signature" // 微信支付回包签名信息
	WechatPaySerial    = "Wechatpay-Serial"    // 微信支付回包平台序列号
	RequestID          = "Request-Id"          // 微信支付回包请求ID
)

HTTP 应答报文 Header 相关常量

View Source
const (
	BaseUrl       = "https://api.mch.weixin.qq.com"  // 微信支付 API 地址
	BaseUrlBackup = "https://api2.mch.weixin.qq.com" // 微信支付 API 备份地址
)

微信支付 API 地址

View Source
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 商户号
)

进件

View Source
const (
	ImgUploadUrl   = BaseUrl + "/v3/merchant/media/upload"       // 图片上传ImgUpload
	VideoUploadUrl = BaseUrl + "/v3/merchant/media/video_upload" // 视频上传
)

其他能力

View Source
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"  // 发放代金劵
)

优惠卷

View Source
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
)

支付

View Source
const (
	FiveMinute = 5 * 60 // 回包校验最长时间(秒)
)

时间相关常量

View Source
const (
	GetCertsUrl = BaseUrl + "/v3/certificates" // 获取平台证书列表
)

微信支付 API url

获取平台证书列表

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplymentResponse

type ApplymentResponse struct {
	ApplymentID int `json:"applyment_id"`
}

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          // 平台证书序列号
}

func NewClient

func NewClient(mchID, certificateSerialNo, privateKey, mchAPIv3Key, mchAPIv2Key, publicKey, weChatNo string) (c *Client, e error)

func (*Client) Algorithm

func (s *Client) Algorithm() string

Algorithm 返回使用的签名算法:SHA256-RSA2048

func (*Client) AppPay

func (c *Client) AppPay(d *model.AppNativePay) (*model.AppPayResult, error)

App 下单

func (*Client) Applyment

func (c *Client) Applyment(d *model.ApplymentData) (int, error)

提交申请

func (*Client) CloseOutTradeNo

func (c *Client) CloseOutTradeNo(outtradeno, submchid string) (bool, error)

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

func (c *Client) CreateVoucher(data *model.Stocks) (string, error)

代金劵 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) Get

func (c *Client) Get(ctx context.Context, url string) (*http.Response, error)

Get 向微信支付发送一个 HTTP Get 请求

func (*Client) GetCert

func (c *Client) GetCert() ([]*model.ItemCerts, error)

func (*Client) GetVoucher

func (c *Client) GetVoucher(openid string, merchantClient *Client, stockid string) (string, error)

GetVoucher发放优惠卷

func (*Client) ImgUpload

func (c *Client) ImgUpload(fileName string, filePath string) (string, error)

func (*Client) JsApiPay

func (c *Client) JsApiPay(d *model.JsApiPay) (*model.JsApiPayResult, error)

jsapi、小程序下单

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) Patch

func (c *Client) Patch(ctx context.Context, url string, requestBody interface{}) (*http.Response, error)

/ Patch 向微信支付发送一个 HTTP Patch 请求

func (*Client) PauseVoucher

func (c *Client) PauseVoucher(stockid string) (string, error)

PauseVoucher 暂停优惠卷

func (*Client) Post

func (c *Client) Post(ctx context.Context, url string, header map[string]string, requestBody interface{}) (*http.Response, error)

Post 向微信支付发送一个 HTTP Post 请求

func (*Client) QueryApplyment

func (c *Client) QueryApplyment(id string) (*model.ApplymentResult, error)

查询申请单状态 id 为微信返回id

func (*Client) QueryMchBank

func (c *Client) QueryMchBank(mchId string) (*model.ApplymentBankResult, error)

查询结算账户 mchId 为商户号

func (*Client) QueryOutTradeNo

func (c *Client) QueryOutTradeNo(outtradeno string, submchid string) (*model.AppNativePay, error)

商户订单号查询

func (*Client) QueryRefund

func (c *Client) QueryRefund(out_refund_no, sub_mchid string) (*model.RefundResult, error)

查询退款

func (*Client) QueryTransactionID

func (c *Client) QueryTransactionID(transactionid string, submchid string) (*model.AppNativePay, error)

微信支付订单号查询

func (*Client) Refund

func (c *Client) Refund(d *model.Refund) (*model.RefundResult, error)

退款申请

func (*Client) RestartVoucher

func (c *Client) RestartVoucher(stockid string) (string, error)

PauseVoucher 暂停优惠卷

func (*Client) SetHeader

func (c *Client) SetHeader(ctx context.Context, url, method string, requestBody interface{}, header map[string]string) (http.Header, error)

func (*Client) Sign

func (s *Client) Sign(_ context.Context, message string) (*string, error)

Sign 对信息使用 SHA256WithRSA 算法进行签名

func (*Client) StartVoucher

func (c *Client) StartVoucher(stockid string) (string, error)

StartVoucher 激活优惠卷 创建批次的商户号 mchid 批次号 stockid

func (*Client) UpdateMchBank

func (c *Client) UpdateMchBank(mchId string, d *model.UpdateMchBankData) (bool, error)

修改结算账号

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, 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 向微信支付发送上传图片或视频文件请求

func (*Client) Validate

func (c *Client) Validate(ctx context.Context, request *http.Request) error

Validate 对接收到的微信支付 API v3 通知请求报文进行验证

func (*Client) Verify

func (c *Client) Verify(ctx context.Context, serial, message, signature string) error

Verifier 数字签名验证器

func (*Client) VideoUpload

func (c *Client) VideoUpload(fileName string, filePath string) (string, error)

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler 微信支付通知 Handler

func NewNotifyHandler

func NewNotifyHandler(mchAPIv3Key string) *Handler

NewNotifyHandler 创建通知处理器

type Response

type Response struct {
	PrepayID string `json:"prepay_id"`
}

type ResponseUrl

type ResponseUrl struct {
	CodeUrl string `json:"code_url"`
}

type T

type T interface {
}

type WechatPayNotifyValidator

type WechatPayNotifyValidator struct {
}

WechatPayNotifyValidator 微信支付 API v3 通知请求报文验证器

func NewWechatPayNotifyValidator

func NewWechatPayNotifyValidator(verifier interface{}) *WechatPayNotifyValidator

NewWechatPayNotifyValidator 使用 Verifier 初始化一个 WechatPayNotifyValidator

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL