gowxpay

package module
v0.0.0-...-ba2b824 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: MIT Imports: 30 Imported by: 0

README

gowxpay

封装微信支付api sdk

直连商户V2接口文档:
    https://pay.weixin.qq.com/wiki/doc/api/index.html
服务商V2接口文档:
    https://pay.weixin.qq.com/wiki/doc/api/sl.html
    
直连商户V3文档:
    https://pay.weixin.qq.com/wiki/doc/apiv3/index.shtml
    https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/index.shtml
服务商V3接口文档:
    https://pay.weixin.qq.com/wiki/doc/apiv3_partner/index.shtml

名词表:接入模式、支付产品、参数等说明
    https://pay.weixin.qq.com/wiki/doc/apiv3_partner/terms_definition/chapter1_1.shtml

微信支付商户平台:https://pay.weixin.qq.com/
https://wechatpay-api.gitbook.io/wechatpay-api-v3/

下载与更新依赖

go get -u github.com/jellycheng/gowxpay
    或者
GO111MODULE=on GOPROXY=https://goproxy.cn/,direct go get -u github.com/jellycheng/gowxpay

微信支付v2与v3版本差异

v2版本:
    使用XML作为数据交互格式

v3版本:
    遵循统一的RESTful的设计风格
    使用JSON作为数据交互的格式,不再使用XML
    使用基于非对称密钥的SHA256-RSA的数字签名算法,不再使用MD5或HMAC-SHA256
    不再要求HTTPS客户端证书
    使用AES-256-GCM加密,对回调中的关键信息进行加密保护
    仅支持UTF-8字符编码

规则差异 V2 V3 备注
参数格式 XML JSON
提交方式 POST POST、GET、PUT、PATCH、DELETE
回调加密 无需加密 AES-256-GCM加密
敏感加密 RSA加密 RSA加密
编码方式 UTF-8 UTF-8
签名方式 MD5或HMAC-SHA256 非对称密钥SHA256-RSA

注意事项

1. 仅有JSAPI支付和Native支付需要在微信支付后台配置支付域名(产品中心->开发配置->支付配置,域名支持http和https的协议),
    APP支付、付款码支付无需配置域名
2. 所有使用JSAPI方式发起支付请求的链接地址,都必须是在微信支付后台配置的支付授权目录之下。
    下单前需要调用【网页授权获取用户信息】接口获取到用户的openid
3. 微信平台接到Native支付请求时,会回调用在微信支付后台配置的支付回调链接,用于传递订单信息
    其它方式的通知地址通过接口入参notify_url设置(支持http、https协议)

JSAPI支付:公众号中拉起支付、小程序支付,需要在商户后台配置JSAPI支付授权目录(最多可添加5个域名地址)
Native支付: 用户扫码支付,即生成二维码提供用户扫码支付,需要在商户后台配置Native支付回调链接,一般用于扫pc网站二维码支付、收银台二维码场景
APP支付: 使用ios、android app发起支付
H5支付:在移动浏览器中的支付
付款码支付:扫用户的"付款码"支付,适用于商超、便利店、餐饮等系统
微信刷脸支付: 用户刷脸支付
小程序支付:使用JSAPI下单场景,申请入口在小程序后台申请支付(https://mp.weixin.qq.com/),关联支付商户号
        小程序后台-》功能-》微信支付

支付场景与用途说明:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/terms_definition/chapter1_1_0.shtml

密钥相关

生成公钥: openssl x509 -in apiclient_cert.pem -pubkey -noout > apiclient_pub.pem

示例

调用示例请参考以 _test.go 结尾的文件

Documentation

Index

Constants

View Source
const (
	Fail    = "FAIL"
	Success = "SUCCESS"
	//支付接口域名,不用写以/结尾哦
	PayDomainUrl = "https://api.mch.weixin.qq.com"

	//货币类型-人民币
	FeeTypeCNY = "CNY"

	//交易类型,不同trade_type决定了调起支付的方式,请根据支付产品正确上传
	TradeTypeJSAPI    = "JSAPI"    //JSAPI支付、小程序支付、公众号内支付
	TradeTypeNATIVE   = "NATIVE"   //Native支付,微信扫一扫支付
	TradeTypeAPP      = "APP"      //app支付
	TradeTypeMWEB     = "MWEB"     //H5支付,微信之外的浏览器中支付
	TradeTypeMICROPAY = "MICROPAY" //付款码支付,付款码支付有单独的支付接口,所以接口不需要上传,该字段在对账单中会出现

	PaySdkVersion = "1.0.0"
	PaySdkName    = "paysdk"

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

微信支付应答报文头相关常量

View Source
const (
	FiveMinute     = 5 * 60           // 回包校验最长时间(秒)
	DefaultTimeout = 30 * time.Second // HTTP请求默认超时时间
)

时间相关常量

View Source
const (
	EventTypeTransactionSucc = "TRANSACTION.SUCCESS" // 正向,支付成功通知
	EventTypeRefundSucc      = "REFUND.SUCCESS"      //退款成功通知
	EventTypeRefundAbnormal  = "REFUND.ABNORMAL"     //退款异常通知
	EventTypeRefundClosed    = "REFUND.CLOSED"       //退款关闭通知
)

Variables

View Source
var CloseCheckTime bool = false

关闭校验时间,true关闭,false不关闭

Functions

func AppPrepayV3

func AppPrepayV3(dto PrepayReqV3Dto, acc AccountV3) (string, map[string]string, error)

AppPrepayV3 app下单

func BoolPtr

func BoolPtr(b bool) *bool

func BuildMessage

func BuildMessage(headerArgs WechatPayHeader, body []byte) string

根据微信支付签名格式构造验签原文: https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_1.shtml

func CheckSignV3

func CheckSignV3(allHeaders map[string]string, body []byte, certificate *x509.Certificate) error

验证签名

func CheckWechatPayHeader

func CheckWechatPayHeader(args WechatPayHeader) error

CheckWechatPayHeader 检查请求头的Timestamp 与当前时间之差不得超过 FiveMinute

func CloseOrder

func CloseOrder(q CloseOrderReqDto, acc AccountV3) (bool, map[string]string, error)

CloseOrder 关闭订单

func DecryptAES256GCM

func DecryptAES256GCM(aesKey, associatedData, nonce, ciphertext string) (plaintext string, err error)

DecryptAES256GCM 微信支付平台证书和回调报文内容解密,详见: https://wechatpay-api.gitbook.io/wechatpay-api-v3/qian-ming-zhi-nan-1/zheng-shu-he-hui-tiao-bao-wen-jie-mi

func DecryptOAEP

func DecryptOAEP(ciphertext string, privateKey *rsa.PrivateKey) (message string, err error)

使用私钥进行解密

func EncryptOAEPWithCertificate

func EncryptOAEPWithCertificate(message string, certificate *x509.Certificate) (ciphertext string, err error)

先解析出证书中的公钥,然后使用公钥进行加密

func EncryptOAEPWithPublicKey

func EncryptOAEPWithPublicKey(message string, publicKey *rsa.PublicKey) (ciphertext string, err error)

使用公钥进行加密

func Float32Ptr

func Float32Ptr(f float32) *float32

func Float64Ptr

func Float64Ptr(f float64) *float64

func GetCertData

func GetCertData(certPath string) ([]byte, error)

GetCertData 获取证书内容

func GetCertificateSerialNumber

func GetCertificateSerialNumber(certificate x509.Certificate) string

从证书中获取证书序列号

func GetCertificatesV3

func GetCertificatesV3(acc AccountV3) (string, map[string]string, error)

GetCertificatesV3 获取平台证书列表: https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay5_1.shtml

func H5PrepayV3

func H5PrepayV3(dto PrepayReqV3Dto, acc AccountV3) (string, map[string]string, error)

H5PrepayV3 h5下单

func Int32Ptr

func Int32Ptr(i int32) *int32

func Int64Ptr

func Int64Ptr(i int64) *int64

func IntPtr

func IntPtr(i int) *int

func IsCertExpired

func IsCertExpired(certificate x509.Certificate, now time.Time) bool

判定证书在特定时间是否过期

func IsCertValid

func IsCertValid(certificate x509.Certificate, now time.Time) bool

判定证书在特定时间是否有效

func IsCommentLine

func IsCommentLine(str string) bool

IsCommentLine 判断是否注释字符串,以 #;开头的字符就算

func JsapiPrepayV3

func JsapiPrepayV3(dto PrepayReqV3Dto, acc AccountV3) (string, map[string]string, error)

JsapiPrepayV3 jsapi下单(公众号中拉起支付)和小程序下单

func JsonUnmarshal

func JsonUnmarshal(str string, obj interface{}) error

func LoadCertificate

func LoadCertificate(certificateStr string) (certificate *x509.Certificate, err error)

通过证书的文本内容加载证书

func LoadCertificateWithPath

func LoadCertificateWithPath(path string) (certificate *x509.Certificate, err error)

通过证书的文件路径加载证书: apiclient_cert.pem,内容格式如:-----BEGIN CERTIFICATE-----

func LoadPrivateKey

func LoadPrivateKey(privateKeyStr string) (privateKey *rsa.PrivateKey, err error)

通过私钥的文本内容加载私钥:私钥文件内容类似-----BEGIN PRIVATE KEY----- 这种

func LoadPrivateKeyWithPath

func LoadPrivateKeyWithPath(path string) (privateKey *rsa.PrivateKey, err error)

通过私钥的文件路径内容加载私钥: 通过apiclient_key.pem 文件内容来加载,内容格式如:-----BEGIN PRIVATE KEY-----

func LoadPublicKey

func LoadPublicKey(publicKeyStr string) (publicKey *rsa.PublicKey, err error)

通过公钥的文本内容加载公钥

func LoadPublicKeyWithPath

func LoadPublicKeyWithPath(path string) (publicKey *rsa.PublicKey, err error)

通过公钥的文件路径加载公钥

func NativePrepayV3

func NativePrepayV3(dto PrepayReqV3Dto, acc AccountV3) (string, map[string]string, error)

NativePrepayV3 native下单(用户扫码支付,即生成二维码提供用户扫码支付,一般用于扫pc网站二维码支付、收银台二维码场景)

func PinAuthorizationHeaderVal

func PinAuthorizationHeaderVal(mchid string, nonceStr string, timestamp int64, serialNo string, sign string) string

func PinReqMessage

func PinReqMessage(method string, urlPath string, timestamp int64, nonce string, body string) string

PinReqMessage 拼接请求签名原文格式: HTTP请求方法\n支付接口URL Path\n请求时间戳\n请求随机串\n请求报文主体\n

func PinRespMessage

func PinRespMessage(appid string, timeStamp int64, nonceStr string, prepayId string) string

PinRespMessage 拼接响应客户端签名串,prepayId为预单号,如 prepay_id=xxx

func Pkcs12ToPem

func Pkcs12ToPem(p12 []byte, password string) (tls.Certificate, error)

Pkcs12ToPem 将Pkcs12转成Pem

func QueryOrder4OutTradeNo

func QueryOrder4OutTradeNo(q QueryOrderReqDto, acc AccountV3) (string, map[string]string, error)

QueryOrder4OutTradeNo 商户订单号查询

func QueryOrder4TransactionId

func QueryOrder4TransactionId(q QueryOrderReqDto, acc AccountV3) (string, map[string]string, error)

QueryOrder4TransactionId 微信支付订单号查询

func RefundOrder

func RefundOrder(reqDto RefundReqV3Dto, acc AccountV3) (string, map[string]string, error)

RefundOrder 申请退款

func RefundQuery

func RefundQuery(reqDto QueryByOutRefundNoReqV3Dto, acc AccountV3) (string, map[string]string, error)

RefundQuery 退款查询

func SignSHA256WithRSA

func SignSHA256WithRSA(sourceStr string, privateKey *rsa.PrivateKey) (string, error)

通过私钥对字符串以 SHA256WithRSA 算法生成签名信息

func SimpleIni2Map

func SimpleIni2Map(fileName string) map[string]string

func SplitLine

func SplitLine(s string, l int)

SplitLine 打印分割线

func StringPtr

func StringPtr(s string) *string

func TimePtr

func TimePtr(t time.Time) *time.Time

Types

type APIErrDetail

type APIErrDetail struct {
	StatusCode int               // 应答报文的 HTTP 状态码
	Header     map[string]string // 应答报文的 Header 信息
	Body       string            // 应答报文的 Body 原文
	Code       string            `json:"code"`             // 应答报文的 Body 解析后的错误码信息,仅不符合预期/发生系统错误时存在
	Message    string            `json:"message"`          // 应答报文的 Body 解析后的文字说明信息,仅不符合预期/发生系统错误时存在
	Detail     interface{}       `json:"detail,omitempty"` // 应答报文的 Body 解析后的详细信息,仅不符合预期/发生系统错误时存在
}

APIErrDetail 微信支付API v3 版本错误结构

type Account

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

Account 支付商户号,微信支付v2版本的商户信息,appid和mch_id两者之间需要具备绑定关系,直连模式:appid和mch_id之间的绑定关系可以是多对多

func NewAccount

func NewAccount(appID string, mchID string, apiKey string) *Account

NewAccount 创建微信支付账号,支付商户号

func (*Account) EditCertData

func (a *Account) EditCertData(certCon []byte) *Account

EditCertData 修改证书内容

func (*Account) GetIsSandbox

func (a *Account) GetIsSandbox() bool

func (*Account) SetCertData

func (a *Account) SetCertData(certPath string) (*Account, error)

SetCertData 设置证书

func (*Account) SetIsSandbox

func (a *Account) SetIsSandbox(isSandbox bool) *Account

type AccountV3

type AccountV3 struct {
	AppID                string // 小程序等appid
	MchID                string // 支付商户号
	SerialNo             string // 支付商户api证书序列号
	ApiClientKeyPemFile  string // apiclient_key.pem文件
	ApiClientKeyCertFile string // apiclient_cert.pem文件
	ApiV3Key             string // api v3 key
}

type AmountReqV3Dto

type AmountReqV3Dto struct {
	// 订单总金额,单位为分
	Total *int64 `json:"total"`
	// CNY:人民币,境内商户号仅支持人民币。
	Currency *string `json:"currency,omitempty"`
}

AmountReqV3Dto 订单金额信息,入参

type AmountRespV3Dto

type AmountRespV3Dto struct {
	// 订单总金额,单位为分
	Total *int64 `json:"total,omitempty"`
	// 用户实付金额,单位分,订单总金额Total - 优惠券金额
	PayerTotal *int64 `json:"payer_total,omitempty"`
	// CNY:人民币,境内商户号仅支持人民币。
	Currency *string `json:"currency,omitempty"`
	// 用户支付币种 CNY:人民币
	PayerCurrency *string `json:"payer_currency,omitempty"`
}

AmountRespV3Dto 订单金额信息,出参

type CertificateDto

type CertificateDto struct {
	// 证书序列号
	SerialNo *string `json:"serial_no"`
	// 证书有效期开始时间
	EffectiveTime *time.Time `json:"effective_time"`
	// 证书过期时间
	ExpireTime *time.Time `json:"expire_time"`
	// 为了保证安全性,微信支付在回调通知和平台证书下载接口中,对关键信息进行了AES-256-GCM加密
	EncryptCertificate *EncryptCertificateDto `json:"encrypt_certificate"`
}

微信支付平台证书信息

type CertificatesRespDto

type CertificatesRespDto struct {
	Data []CertificateDto `json:"data,omitempty"`
}

平台证书列表

type CloseOrderReqDto

type CloseOrderReqDto struct {
	OutTradeNo *string `json:"out_trade_no"`
	// 直连商户号
	Mchid *string `json:"mchid"`
}

CloseOrderReqDto 关单入参

type ClosePostBodyReqDto

type ClosePostBodyReqDto struct {
	// 直连商户号
	Mchid *string `json:"mchid"`
}

ClosePostBodyReqDto 关单入参,post内容

type DetailReqV3Dto

type DetailReqV3Dto struct {
	// 订单原价
	CostPrice *int64 `json:"cost_price,omitempty"`
	// 商家小票ID。
	InvoiceId *string `json:"invoice_id,omitempty"`
	// 单品列表信息
	GoodsDetail []GoodsDetailReqV3Dto `json:"goods_detail,omitempty"`
}

DetailReqV3Dto 优惠功能,入参

type EncryptCertificateDto

type EncryptCertificateDto struct {
	// 加密所使用的算法,目前可能取值仅为 AEAD_AES_256_GCM
	Algorithm *string `json:"algorithm"`
	// 加密所使用的随机字符串
	Nonce *string `json:"nonce"`
	// 附加数据包(可能为空)
	AssociatedData *string `json:"associated_data"`
	// 证书内容密文,解密后会获得证书完整内容,Base64编码后的密文
	Ciphertext *string `json:"ciphertext"`
}

为了保证安全性,微信支付在回调通知和平台证书下载接口中,对关键信息进行了AES-256-GCM加密

type EncryptedResourceDto

type EncryptedResourceDto struct {
	Algorithm      string `json:"algorithm"`       //加密算法类型
	Ciphertext     string `json:"ciphertext"`      //数据密文
	AssociatedData string `json:"associated_data"` //附加数据
	OriginalType   string `json:"original_type"`   //原始类型
	Nonce          string `json:"nonce"`           //随机串
	Plaintext      string // 解密后内容,正向,对应 QueryOrderRespDto
}

EncryptedResourceDto 通知资源数据:微信支付通知请求中的内容

type EventType

type EventType string

EventType 通知类型

func (EventType) Ptr

func (m EventType) Ptr() *EventType

type FundsFromItemReqV3Dto

type FundsFromItemReqV3Dto struct {
	// 出资账户类型,AVAILABLE : 可用余额 UNAVAILABLE : 不可用余额
	Account *string `json:"account"`
	// 出资金额
	Amount *int64 `json:"amount"`
}

FundsFromItemReqV3Dto 退款出资账户及金额,入参

type FundsFromItemRespV3Dto

type FundsFromItemRespV3Dto struct {
	// 出资账户类型,AVAILABLE : 可用余额 UNAVAILABLE : 不可用余额
	Account *string `json:"account"`
	// 出资金额
	Amount *int64 `json:"amount"`
}

FundsFromItemRespV3Dto 退款出资账户及金额,出参

type GoodsDetailReqV3Dto

type GoodsDetailReqV3Dto struct {
	// 由半角的大小写字母、数字、中划线、下划线中的一种或几种组成
	MerchantGoodsId *string `json:"merchant_goods_id"`
	// 微信支付定义的统一商品编号(没有可不传)
	WechatpayGoodsId *string `json:"wechatpay_goods_id,omitempty"`
	// 商品的实际名称
	GoodsName *string `json:"goods_name,omitempty"`
	// 用户购买的数量
	Quantity *int64 `json:"quantity"`
	// 商品单价,单位为分
	UnitPrice *int64 `json:"unit_price"`
}

GoodsDetailReqV3Dto 单品列表信息

type H5InfoReqV3Dto

type H5InfoReqV3Dto struct {
	Type        string `json:"type"`                   //场景类型
	AppName     string `json:"app_name,omitempty"`     //应用名称
	AppUrl      string `json:"app_url,omitempty"`      //网站URL
	BundleId    string `json:"bundle_id,omitempty"`    //iOS平台BundleID
	PackageName string `json:"package_name,omitempty"` //Android平台PackageName
}

H5InfoReqV3Dto H5场景信息

type MapParams

type MapParams map[string]string

func MicropayV2

func MicropayV2(c PayClient, params MapParams) (MapParams, error)

MicropayV2 付款码支付

func OrderQueryV2

func OrderQueryV2(c PayClient, params MapParams) (MapParams, error)

OrderQueryV2 订单查询

func RefundQueryV2

func RefundQueryV2(c PayClient, params MapParams) (MapParams, error)

RefundQueryV2 退款查询

func RefundV2

func RefundV2(c PayClient, params MapParams) (MapParams, error)

RefundV2 申请退款

func UnifiedOrderV2

func UnifiedOrderV2(c PayClient, params MapParams) (MapParams, error)

UnifiedOrderV2 统一下单

func XmlToMap

func XmlToMap(xmlStr string) MapParams

func (MapParams) ContainsKey

func (p MapParams) ContainsKey(key string) bool

ContainsKey 判断key是否存在

func (MapParams) GetInt64

func (p MapParams) GetInt64(k string) int64

func (MapParams) GetString

func (p MapParams) GetString(k string) string

func (MapParams) SetInt64

func (p MapParams) SetInt64(k string, i int64) MapParams

func (MapParams) SetString

func (p MapParams) SetString(k, s string) MapParams

SetString map本来已经是引用类型了,所以不需要 *MapParams

type NotifiesReturnV2

type NotifiesReturnV2 struct{}

NotifiesReturnV2 用于微信支付通知,响应微信支付服务的参数,使用V2接口通知响应

func (*NotifiesReturnV2) Fail

func (n *NotifiesReturnV2) Fail(errMsg string) string

Fail 通知处理失败返回-不成功

func (*NotifiesReturnV2) OK

func (n *NotifiesReturnV2) OK() string

OK 通知成功返回

type NotifiesReturnV3

type NotifiesReturnV3 struct{}

NotifiesReturnV3 用于微信支付通知,响应微信支付服务的参数,使用V3接口通知响应

func (*NotifiesReturnV3) Fail

func (n *NotifiesReturnV3) Fail(errMsg string) string

Fail 通知处理失败返回-不成功

func (*NotifiesReturnV3) OK

func (n *NotifiesReturnV3) OK() string

OK 通知成功返回

type NotifyDto

type NotifyDto struct {
	ID           string                `json:"id"`            //通知ID
	CreateTime   *time.Time            `json:"create_time"`   //通知创建时间
	EventType    string                `json:"event_type"`    //通知类型
	ResourceType string                `json:"resource_type"` //通知数据类型
	Resource     *EncryptedResourceDto `json:"resource"`      // 通知资源数据
	Summary      string                `json:"summary"`       //回调摘要
}

NotifyDto 微信支付通知结果结构,正向

func PayNotifyParse

func PayNotifyParse(parseBody string, allHeaders map[string]string, acc AccountV3, isSkipSign ...bool) (NotifyDto, error)

PayNotifyParse 正向支付通知内容解析

type PayClient

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

封装支付api v2版本的请求

func NewPayClient

func NewPayClient(account *Account) *PayClient

创建微信支付客户端

func (*PayClient) AppendRequestData

func (c *PayClient) AppendRequestData(params MapParams) MapParams

向 params 中添加 appid、mch_id、nonce_str、sign_type、sign 公共参数

func (*PayClient) Post4Cert

func (c *PayClient) Post4Cert(url string, params MapParams) (string, error)

https need cert post

func (*PayClient) Post4NotCert

func (c *PayClient) Post4NotCert(url string, params MapParams) (string, error)

https no cert post

func (*PayClient) ProcessResponseXml

func (c *PayClient) ProcessResponseXml(xmlStr string) (MapParams, error)

处理 HTTPS API返回数据,转换成Map对象。return_code为SUCCESS时,验证签名。

func (*PayClient) SetAccount

func (c *PayClient) SetAccount(account *Account) *PayClient

func (*PayClient) SetHttpConnectTimeoutMs

func (c *PayClient) SetHttpConnectTimeoutMs(ms int) *PayClient

func (*PayClient) SetHttpReadTimeoutMs

func (c *PayClient) SetHttpReadTimeoutMs(ms int) *PayClient

func (*PayClient) SetSignType

func (c *PayClient) SetSignType(signType string) *PayClient

func (*PayClient) Sign

func (c *PayClient) Sign(params MapParams) string

签名

func (*PayClient) ValidSign

func (c *PayClient) ValidSign(params MapParams) bool

验证签名

type PayV3Dto

type PayV3Dto struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

type PayerReqV3Dto

type PayerReqV3Dto struct {
	// 用户在商户appid下的唯一标识。
	Openid *string `json:"openid,omitempty"`
}

PayerReqV3Dto 支付者信息,入参

type PayerRespV3Dto

type PayerRespV3Dto struct {
	// 用户在商户appid下的唯一标识。
	Openid *string `json:"openid,omitempty"`
}

PayerRespV3Dto 支付者信息,出参

type PrepayReqV3Dto

type PrepayReqV3Dto struct {
	// 公众号ID、小程序ID
	Appid *string `json:"appid"`
	// 直连商户号
	Mchid *string `json:"mchid"`
	// 商品描述
	Description *string `json:"description"`
	// 商户订单号
	OutTradeNo *string `json:"out_trade_no"`
	// 订单失效时间,格式为rfc3339格式,交易结束时间
	TimeExpire *time.Time `json:"time_expire,omitempty"`
	// 附加数据
	Attach *string `json:"attach,omitempty"`
	// 通知地址, 有效性:1. HTTPS协议;2. 不允许携带查询串即不能带参数
	NotifyUrl *string `json:"notify_url"`
	// 订单优惠标记,商品标记,代金券或立减优惠功能的参数。
	GoodsTag *string `json:"goods_tag,omitempty"`
	// 订单金额信息
	Amount *AmountReqV3Dto `json:"amount"`
	// 支付者信息
	Payer *PayerReqV3Dto `json:"payer,omitempty"`
	// 优惠功能
	Detail *DetailReqV3Dto `json:"detail,omitempty"`
	// 场景信息
	SceneInfo *SceneInfoReqV3Dto `json:"scene_info,omitempty"`
	// 结算信息
	SettleInfo *SettleInfoReqV3Dto `json:"settle_info,omitempty"`
}

PrepayReqV3Dto 预下单请求参数,适配JSAPI、App、H5、Native、小程序等下单

type PrepayRespV3Dto

type PrepayRespV3Dto struct {
	// 预支付交易会话标识
	PrepayId *string `json:"prepay_id"`
}

PrepayRespV3Dto 预下单返回的内容

type PrepayWithRequestPaymentRespV3Dto

type PrepayWithRequestPaymentRespV3Dto struct {
	// 预支付交易会话标识,预单号
	PrepayId *string `json:"prepayId"`
	// 商户号
	PartnerId *string `json:"partnerId"`
	// 时间戳
	TimeStamp *string `json:"timeStamp"`
	// 随机字符串
	NonceStr *string `json:"nonceStr"`
	// 订单详情扩展字符串
	Package *string `json:"package"`
	// 签名
	Sign *string `json:"sign"`
}

PrepayWithRequestPaymentRespV3Dto 响应小程序拉起支付的参数

type PromotionDetailRespV3Dto

type PromotionDetailRespV3Dto struct {
	// 券ID
	CouponId *string `json:"coupon_id,omitempty"`
	// 优惠名称
	Name *string `json:"name,omitempty"`
	// 优惠范围,GLOBAL:全场代金券;SINGLE:单品优惠
	Scope *string `json:"scope,omitempty"`
	// 优惠类型,CASH:充值;NOCASH:预充值。
	Type *string `json:"type,omitempty"`
	// 优惠券面额
	Amount *int64 `json:"amount,omitempty"`
	// 活动ID,批次ID
	StockId *string `json:"stock_id,omitempty"`
	// 微信出资,单位为分
	WechatpayContribute *int64 `json:"wechatpay_contribute,omitempty"`
	// 商户出资,单位为分
	MerchantContribute *int64 `json:"merchant_contribute,omitempty"`
	// 其他出资,单位为分
	OtherContribute *int64 `json:"other_contribute,omitempty"`
	// 优惠币种,CNY:人民币,境内商户号仅支持人民币。
	Currency *string `json:"currency,omitempty"`
	// 单品列表
	GoodsDetail []PromotionGoodsDetailRespV3Dto `json:"goods_detail,omitempty"`
}

PromotionDetailRespV3Dto 优惠功能,出参

type PromotionGoodsDetailRespV3Dto

type PromotionGoodsDetailRespV3Dto struct {
	// 商品编码
	GoodsId *string `json:"goods_id"`
	// 商品数量
	Quantity *int64 `json:"quantity"`
	// 商品价格
	UnitPrice *int64 `json:"unit_price"`
	// 商品优惠金额
	DiscountAmount *int64 `json:"discount_amount"`
	// 商品备注
	GoodsRemark *string `json:"goods_remark,omitempty"`
}

PromotionGoodsDetailRespV3Dto 单品列表,出参

type PromotionScope

type PromotionScope string

PromotionScope 优惠范围

const (
	PromotionScopeGlobal PromotionScope = "GLOBAL" //全场代金券, 全场优惠类型
	PromotionScopeSingle PromotionScope = "SINGLE" //单品优惠, 单品优惠类型
)

func (PromotionScope) Ptr

func (m PromotionScope) Ptr() *PromotionScope

type PromotionType

type PromotionType string

PromotionType 优惠类型

const (
	PromotionTypeCoupon   PromotionType = "COUPON"   //代金券类型,需要走结算资金的充值型代金券
	PromotionTypeDiscount PromotionType = "DISCOUNT" //优惠券类型,不走结算资金的免充值型优惠券
)

func (PromotionType) Ptr

func (m PromotionType) Ptr() *PromotionType

type QueryByOutRefundNoReqV3Dto

type QueryByOutRefundNoReqV3Dto struct {
	// 商户退款单号,商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔
	OutRefundNo *string `json:"out_refund_no"`
	// 子商户的商户号,由微信支付生成并下发。服务商模式下必须传递此参数,直连模式不需要该参数
	SubMchid *string `json:"sub_mchid,omitempty"`
}

QueryByOutRefundNoReqV3Dto 查询退款申请入参

type QueryOrderReqDto

type QueryOrderReqDto struct {
	Mchid         *string // 直连商户号
	TransactionId *string // 微信支付订单号
	OutTradeNo    *string // 商户订单号
}

QueryOrderReqDto 查询订单条件

type QueryOrderRespDto

type QueryOrderRespDto struct {
	Appid           *string                    `json:"appid,omitempty"`            //应用appid
	Mchid           *string                    `json:"mchid,omitempty"`            //商户ID
	OutTradeNo      *string                    `json:"out_trade_no,omitempty"`     //商户订单号
	TransactionId   *string                    `json:"transaction_id,omitempty"`   //微信支付订单号
	TradeType       *string                    `json:"trade_type,omitempty"`       //交易类型,如JSAPI、NATIVE
	TradeState      *string                    `json:"trade_state,omitempty"`      //交易状态,SUCCESS成功,CLOSED已关闭
	TradeStateDesc  *string                    `json:"trade_state_desc,omitempty"` //交易状态描述
	BankType        *string                    `json:"bank_type,omitempty"`        //付款银行
	Attach          *string                    `json:"attach,omitempty"`           //附加数据
	SuccessTime     *string                    `json:"success_time,omitempty"`     //支付完成时间
	Payer           *PayerRespV3Dto            `json:"payer,omitempty"`            // 支付者信息
	Amount          *AmountRespV3Dto           `json:"amount,omitempty"`           //订单金额信息
	SceneInfo       *SceneInfoRespV3Dto        `json:"scene_info,omitempty"`       //支付场景描述
	PromotionDetail []PromotionDetailRespV3Dto `json:"promotion_detail,omitempty"` //优惠功能信息
}

QueryOrderRespDto 查询订单返回结果,正向通知resource解析后存入Plaintext的结果

type RefundAccount

type RefundAccount string

RefundAccount 退款资金账户类型

const (
	RefundAccountUnsettled   RefundAccount = "UNSETTLED"   //未结算资金
	RefundAccountAvailable   RefundAccount = "AVAILABLE"   // 可用余额
	RefundAccountUnavailable RefundAccount = "UNAVAILABLE" // 不可用余额
	RefundAccountOperation   RefundAccount = "OPERATION"   //运营户
	RefundAccountBasic       RefundAccount = "BASIC"       //基本账户(含可用余额和不可用余额)

)

func (RefundAccount) Ptr

func (m RefundAccount) Ptr() *RefundAccount

type RefundAmountReqV3Dto

type RefundAmountReqV3Dto struct {
	// 退款金额,币种的最小单位,只能为整数,不能超过原订单支付金额
	Refund *int64 `json:"refund"`
	// 退款需要从指定账户出资时,传递此参数指定出资金额(币种的最小单位,只能为整数)。 同时指定多个账户出资退款的使用场景需要满足以下条件:1、未开通退款支出分离产品功能;2、订单属于分账订单,且分账处于待分账或分账中状态。 参数传递需要满足条件:1、基本账户可用余额出资金额与基本账户不可用余额出资金额之和等于退款金额;2、账户类型不能重复。 上述任一条件不满足将返回错误
	From []FundsFromItemReqV3Dto `json:"from,omitempty"`
	// 原支付交易的订单总金额,币种的最小单位,只能为整数
	Total *int64 `json:"total"`
	// 符合ISO 4217标准的三位字母代码,目前只支持人民币:CNY
	Currency *string `json:"currency"`
}

RefundAmountReqV3Dto 退款金额信息,入参

type RefundAmountRespV3Dto

type RefundAmountRespV3Dto struct {
	// 订单总金额,单位为分
	Total *int64 `json:"total"`
	// 退款标价金额,单位为分,可以做部分退款
	Refund *int64 `json:"refund"`
	// 退款出资的账户类型及金额信息
	From []FundsFromItemRespV3Dto `json:"from,omitempty"`
	// 现金支付金额,单位为分,只能为整数
	PayerTotal *int64 `json:"payer_total"`
	// 退款给用户的金额,不包含所有优惠券金额
	PayerRefund *int64 `json:"payer_refund"`
	// 去掉非充值代金券退款金额后的退款金额,单位为分,退款金额=申请退款金额-非充值代金券退款金额,退款金额<=申请退款金额
	SettlementRefund *int64 `json:"settlement_refund"`
	// 应结订单金额=订单金额-免充值代金券金额,应结订单金额<=订单金额,单位为分
	SettlementTotal *int64 `json:"settlement_total"`
	// 优惠退款金额<=退款金额,退款金额-代金券或立减优惠退款金额为现金,说明详见代金券或立减优惠,单位为分
	DiscountRefund *int64 `json:"discount_refund"`
	// 退款币种,目前只支持人民币:CNY。
	Currency *string `json:"currency"`
}

RefundAmountRespV3Dto 退款金额详细信息

type RefundChannel

type RefundChannel string

RefundChannel 退款渠道类型

const (
	RefundChannelOriginal      RefundChannel = "ORIGINAL"       //原路退款
	RefundChannelBalance       RefundChannel = "BALANCE"        //退回到余额
	RefundChannelOtherBalance  RefundChannel = "OTHER_BALANCE"  //原账户异常退到其他余额账户
	RefundChannelOtherBankcard RefundChannel = "OTHER_BANKCARD" //原银行卡异常退到其他银行卡
)

func (RefundChannel) Ptr

func (m RefundChannel) Ptr() *RefundChannel

type RefundEncryptedResourceDto

type RefundEncryptedResourceDto struct {
	Algorithm      string `json:"algorithm"`       //加密算法类型,AEAD_AES_256_GCM
	Ciphertext     string `json:"ciphertext"`      //数据密文
	AssociatedData string `json:"associated_data"` //附加数据,refund
	OriginalType   string `json:"original_type"`   //原始类型,refund
	Nonce          string `json:"nonce"`           //随机串
	Plaintext      string // 解密后内容,对应 RefundNotifyResourceDto
}

RefundEncryptedResourceDto 微信退款通知资源数据

type RefundGoodsDetailReqV3Dto

type RefundGoodsDetailReqV3Dto struct {
	// 商户侧商品编码,由半角的大小写字母、数字、中划线、下划线中的一种或几种组成
	MerchantGoodsId *string `json:"merchant_goods_id"`
	// 微信支付商品编码,微信支付定义的统一商品编号(没有可不传)
	WechatpayGoodsId *string `json:"wechatpay_goods_id,omitempty"`
	// 商品的实际名称
	GoodsName *string `json:"goods_name,omitempty"`
	// 商品单价金额,单位为分
	UnitPrice *int64 `json:"unit_price"`
	// 商品退款金额,单位为分
	RefundAmount *int64 `json:"refund_amount"`
	// 对应商品的退货数量
	RefundQuantity *int64 `json:"refund_quantity"`
}

RefundGoodsDetailReqV3Dto 退款商品

type RefundGoodsDetailRespV3Dto

type RefundGoodsDetailRespV3Dto struct {
	// 商户侧商品编码,由半角的大小写字母、数字、中划线、下划线中的一种或几种组成
	MerchantGoodsId *string `json:"merchant_goods_id"`
	// 微信支付商品编码,微信支付定义的统一商品编号(没有可不传)
	WechatpayGoodsId *string `json:"wechatpay_goods_id,omitempty"`
	// 商品的实际名称
	GoodsName *string `json:"goods_name,omitempty"`
	// 商品单价金额,单位为分
	UnitPrice *int64 `json:"unit_price"`
	// 商品退款金额,单位为分
	RefundAmount *int64 `json:"refund_amount"`
	// 对应商品的退货数量
	RefundQuantity *int64 `json:"refund_quantity"`
}

RefundGoodsDetailRespV3Dto 优惠商品发生退款时返回商品信息

type RefundNotifyDto

type RefundNotifyDto struct {
	ID           string                      `json:"id"`            //通知ID,唯一
	CreateTime   *time.Time                  `json:"create_time"`   //通知创建时间,2021-12-13T18:08:31+08:00
	EventType    string                      `json:"event_type"`    //通知类型 REFUND.SUCCESS
	ResourceType string                      `json:"resource_type"` //通知数据类型 encrypt-resource
	Resource     *RefundEncryptedResourceDto `json:"resource"`      // 通知资源数据
	Summary      string                      `json:"summary"`       //回调摘要 退款成功
}

RefundNotifyDto 微信退款通知结果结构

func RefundNotifyParse

func RefundNotifyParse(parseBody string, allHeaders map[string]string, acc AccountV3, isSkipSign ...bool) (RefundNotifyDto, error)

RefundNotifyParse 退款通知内容解析

type RefundNotifyResourceAmountDto

type RefundNotifyResourceAmountDto struct {
	Total       int64 `json:"total"`        // 订单总金额,单位为分
	Refund      int64 `json:"refund"`       // 退款金额,币种的最小单位,只能为整数,不能超过原订单支付金额,如果有使用券,后台会按比例退
	PayerTotal  int64 `json:"payer_total"`  // 用户实际支付金额,单位为分,只能为整数
	PayerRefund int64 `json:"payer_refund"` // 退款给用户的金额,不包含所有优惠券金额
}

RefundNotifyResourceAmountDto 退款通知接口,resource字段解析出来amount退款金额信息

type RefundNotifyResourceDto

type RefundNotifyResourceDto struct {
	Mchid               string                         `json:"mchid"`                 // 直连商户号
	OutTradeNo          string                         `json:"out_trade_no"`          //商户订单号
	TransactionId       string                         `json:"transaction_id"`        //微信支付订单号,正向单号
	OutRefundNo         string                         `json:"out_refund_no"`         //商户退款单号
	RefundId            string                         `json:"refund_id"`             // 微信支付退款单号
	RefundStatus        string                         `json:"refund_status"`         // 退款状态,对应常量值 RefundStatusSuccess
	SuccessTime         *time.Time                     `json:"success_time"`          // 退款成功时间
	Amount              *RefundNotifyResourceAmountDto `json:"amount"`                // 退款金额信息
	UserReceivedAccount string                         `json:"user_received_account"` //退款入账账户
}

RefundNotifyResourceDto 退款通知接口,resource字段解析出来的内容

type RefundPromotionRespV3Dto

type RefundPromotionRespV3Dto struct {
	// 券ID或者立减优惠id
	PromotionId *string `json:"promotion_id"`
	// 优惠范围,GLOBAL- 全场代金券 - SINGLE- 单品优惠
	Scope *string `json:"scope"`
	// 优惠类型,COUPON- 代金券,需要走结算资金的充值型代金券 - DISCOUNT- 优惠券,不走结算资金的免充值型优惠券
	Type *string `json:"type"`
	// 用户享受优惠的金额(优惠券面额=微信出资金额+商家出资金额+其他出资方金额 ),单位为分
	Amount *int64 `json:"amount"`
	// 优惠退款金额<=退款金额,退款金额-代金券或立减优惠退款金额为用户支付的现金,说明详见代金券或立减优惠,单位为分
	RefundAmount *int64 `json:"refund_amount"`
	// 优惠商品发生退款时返回商品信息
	GoodsDetail []RefundGoodsDetailRespV3Dto `json:"goods_detail,omitempty"`
}

RefundPromotionRespV3Dto 优惠退款信息

type RefundReqV3Dto

type RefundReqV3Dto struct {
	// 子商户的商户号,由微信支付生成并下发。服务商模式下必须传递此参数,直连模式无此参数
	SubMchid *string `json:"sub_mchid,omitempty"`
	// 原支付交易对应的微信支付订单号
	TransactionId *string `json:"transaction_id,omitempty"`
	// 原支付交易对应的商户订单号
	OutTradeNo *string `json:"out_trade_no,omitempty"`
	// 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
	OutRefundNo *string `json:"out_refund_no"`
	// 若商户传入,会在下发给用户的退款消息中体现退款原因
	Reason *string `json:"reason,omitempty"`
	// 异步接收微信支付退款结果通知的回调地址,通知url必须为外网可访问的url,不能携带参数。 如果参数中传了notify_url,则商户平台上配置的回调地址将不会生效,优先回调当前传的这个地址。
	NotifyUrl *string `json:"notify_url,omitempty"`
	// 若传递此参数则使用对应的资金账户退款,否则默认使用未结算资金退款(仅对老资金流商户适用),AVAILABLE:可用余额账户
	FundsAccount *string `json:"funds_account,omitempty"`
	// 订单金额信息
	Amount *RefundAmountReqV3Dto `json:"amount"`
	// 退款商品,指定商品退款需要传此参数,其他场景无需传递
	GoodsDetail []RefundGoodsDetailReqV3Dto `json:"goods_detail,omitempty"`
}

RefundReqV3Dto 退款入参

type RefundRespV3Dto

type RefundRespV3Dto struct {
	// 微信支付退款号
	RefundId *string `json:"refund_id"`
	// 商户退款单号,商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔
	OutRefundNo *string `json:"out_refund_no"`
	// 微信支付交易订单号
	TransactionId *string `json:"transaction_id"`
	// 原支付交易对应的商户订单号,正向单号
	OutTradeNo *string `json:"out_trade_no"`
	// 退款渠道,ORIGINAL—原路退款,BALANCE—退回到余额,OTHER_BALANCE—原账户异常退到其他余额账户,OTHER_BANKCARD—原银行卡异常退到其他银行卡
	Channel *string `json:"channel"`
	// 退款入账账户,取当前退款单的退款入账方,有以下几种情况: 1)退回银行卡:{银行名称}{卡类型}{卡尾号} 2)退回支付用户零钱:支付用户零钱 3)退还商户:商户基本账户商户结算银行账户 4)退回支付用户零钱通:支付用户零钱通
	UserReceivedAccount *string `json:"user_received_account"`
	// 退款成功时间,退款状态status为SUCCESS(退款成功)时,返回该字段。遵循rfc3339标准格式,格式为YYYY-MM-DDTHH:mm:ss+TIMEZONE,YYYY-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日13点29分35秒。
	SuccessTime *time.Time `json:"success_time,omitempty"`
	// 退款受理时间,退款创建时间
	CreateTime *time.Time `json:"create_time"`
	// 退款状态,SUCCESS—退款成功 - CLOSED—退款关闭 - PROCESSING—退款处理中 - ABNORMAL—退款异常
	Status *string `json:"status"`
	// 资金账户,UNSETTLED : 未结算资金, AVAILABLE : 可用余额,UNAVAILABLE : 不可用余额 ,OPERATION : 运营户 , BASIC : 基本账户(含可用余额和不可用余额)
	FundsAccount *string `json:"funds_account,omitempty"`
	// 金额详细信息
	Amount *RefundAmountRespV3Dto `json:"amount"`
	// 优惠退款信息
	PromotionDetail []RefundPromotionRespV3Dto `json:"promotion_detail,omitempty"`
}

RefundRespV3Dto 退款出参,适应场景1。申请退款返回,2。查询退款返回参数

type RefundStatus

type RefundStatus string

RefundStatus 退款状态

const (
	RefundStatusSuccess    RefundStatus = "SUCCESS"    //退款成功
	RefundStatusClosed     RefundStatus = "CLOSED"     //退款关闭
	RefundStatusProcessing RefundStatus = "PROCESSING" //退款处理中
	RefundStatusAbnormal   RefundStatus = "ABNORMAL"   //退款异常
)

func (RefundStatus) Ptr

func (m RefundStatus) Ptr() *RefundStatus

type SceneInfoReqV3Dto

type SceneInfoReqV3Dto struct {
	// 用户终端IP
	PayerClientIp *string `json:"payer_client_ip"`
	// 商户端设备号
	DeviceId  *string            `json:"device_id,omitempty"`
	StoreInfo *StoreInfoReqV3Dto `json:"store_info,omitempty"`
	H5Info    *H5InfoReqV3Dto    `json:"h5_info,omitempty"`
}

SceneInfoReqV3Dto 支付场景描述,入参

type SceneInfoRespV3Dto

type SceneInfoRespV3Dto struct {
	// 商户端设备号
	DeviceId *string `json:"device_id,omitempty"`
}

SceneInfoRespV3Dto 支付场景描述,出参

type SettleInfoReqV3Dto

type SettleInfoReqV3Dto struct {
	// 是否指定分账
	ProfitSharing *bool `json:"profit_sharing,omitempty"`
}

SettleInfoReqV3Dto 结算信息

type StoreInfoReqV3Dto

type StoreInfoReqV3Dto struct {
	// 商户侧门店编号
	Id *string `json:"id"`
	// 商户侧门店名称
	Name *string `json:"name,omitempty"`
	// 地区编码,详细请见微信支付提供的文档
	AreaCode *string `json:"area_code,omitempty"`
	// 详细的商户门店地址
	Address *string `json:"address,omitempty"`
}

StoreInfoReqV3Dto 商户门店信息

type TradeState

type TradeState string

TradeState 交易状态

const (
	TradeStateSuccess    TradeState = "SUCCESS"    //支付成功
	TradeStateRefund     TradeState = "REFUND"     //转入退款
	TradeStateNotpay     TradeState = "NOTPAY"     //未支付
	TradeStateClosed     TradeState = "CLOSED"     //已关闭
	TradeStateRevoked    TradeState = "REVOKED"    //已撤销(付款码支付)
	TradeStateUserpaying TradeState = "USERPAYING" //用户支付中(付款码支付)
	TradeStatePayerror   TradeState = "PAYERROR"   //"支付失败(其他原因,如银行返回失败)
)

func (TradeState) Ptr

func (m TradeState) Ptr() *TradeState

type TradeType

type TradeType string

TradeType 交易类型

const (
	TradeTypeJsapi    TradeType = "JSAPI"    //:公众号支付、小程序支付
	TradeTypeNative   TradeType = "NATIVE"   // 扫码支付
	TradeTypeApp      TradeType = "APP"      //APP支付
	TradeTypeMicropay TradeType = "MICROPAY" //付款码支付
	TradeTypeMweb     TradeType = "MWEB"     //H5支付
	TradeTypeFacepay  TradeType = "FACEPAY"  //刷脸支付
)

func (TradeType) Ptr

func (m TradeType) Ptr() *TradeType

type WechatPayHeader

type WechatPayHeader struct {
	RequestID string
	Serial    string
	Signature string
	Nonce     string
	Timestamp int64
}

WechatPayHeader 微信支付接口响应的请求头

func GetWechatPayHeaderV3

func GetWechatPayHeaderV3(allheaders map[string]string) (WechatPayHeader, error)

Jump to

Keyboard shortcuts

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