wechatpayopen

package
v1.0.47 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

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

SDK 相关信息

View Source
const (
	Authorization = "Authorization"  // Header 中的 Authorization 字段
	Accept        = "Accept"         // Header 中的 Accept 字段
	ContentType   = "Content-Type"   // Header 中的 ContentType 字段
	ContentLength = "Content-Length" // Header 中的 ContentLength 字段
	UserAgent     = "User-Agent"     // Header 中的 UserAgent 字段
)

HTTP 请求报文 Header 相关常量

View Source
const (
	ApplicationJSON = "application/json"
	ImageJPG        = "image/jpg"
	ImagePNG        = "image/png"
	VideoMP4        = "video/mp4"
)

常用 ContentType

View Source
const (
	SignatureMessageFormat = "%s\n%s\n%d\n%s\n%s\n" // 数字签名原文格式
	// HeaderAuthorizationFormat 请求头中的 Authorization 拼接格式
	HeaderAuthorizationFormat = "%s mchid=\"%s\",nonce_str=\"%s\",timestamp=\"%d\",serial_no=\"%s\",signature=\"%s\""
)

请求报文签名相关常量

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

HTTP 应答报文 Header 相关常量

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

时间相关常量

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

微信支付 API 地址

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiError

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

type CertificatesResponse

type CertificatesResponse struct {
	Data []struct {
		EffectiveTime      time.Time `json:"effective_time"` // 过期时间
		EncryptCertificate struct {
			Algorithm      string `json:"algorithm"`
			AssociatedData string `json:"associated_data"`
			Ciphertext     string `json:"ciphertext"`
			Nonce          string `json:"nonce"`
		} `json:"encrypt_certificate"` // 加密证书
		ExpireTime time.Time `json:"expire_time"` // 有效时间
		SerialNo   string    `json:"serial_no"`   // 序列号
	} `json:"data"`
}

type CertificatesResult

type CertificatesResult struct {
	Result CertificatesResponse // 结果
	Body   []byte               // 内容
	Http   gorequest.Response   // 请求
	Err    error                // 错误
}

type Client

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

Client 微信支付服务

func NewClient

func NewClient(config *ConfigClient) (*Client, error)

NewClient 实例化

func (*Client) Certificates

func (c *Client) Certificates() *CertificatesResult

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

func (*Client) EcommerceFundBalance

func (c *Client) EcommerceFundBalance(accountType string) *EcommerceFundBalanceResult

EcommerceFundBalance 查询二级商户账户实时余额API accountType 账户类型 BASIC:基本账户 OPERATION:运营账户 FEES:手续费账户 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_1.shtml

func (*Client) EcommerceFundEndDayBalance

func (c *Client) EcommerceFundEndDayBalance(date string) *EcommerceFundEndDayBalanceResult

EcommerceFundEndDayBalance 查询二级商户账户日终余额API date 日期 示例值:2019-08-17 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_2.shtml

func (*Client) GetJsApi

func (c *Client) GetJsApi(param GetJsApi) (result GetJsApiResult, err error)

GetJsApi JSAPI调起支付API https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_4.shtml

func (*Client) GetSpAppid

func (c *Client) GetSpAppid() string

func (*Client) GetSpMchId

func (c *Client) GetSpMchId() string

func (*Client) GetSubAppid

func (c *Client) GetSubAppid() string

func (*Client) GetSubMchId

func (c *Client) GetSubMchId() string

func (*Client) MerchantFundBalance

func (c *Client) MerchantFundBalance(accountType string) *MerchantFundBalanceResult

MerchantFundBalance 查询电商平台账户实时余额API accountType 账户类型 BASIC:基本账户 OPERATION:运营账户 FEES:手续费账户 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_3.shtml

func (*Client) MerchantFundDayEndBalance

func (c *Client) MerchantFundDayEndBalance(accountType, date string) *MerchantFundDayEndBalanceResult

MerchantFundDayEndBalance 查询电商平台账户日终余额API accountType 账户类型 BASIC:基本账户 OPERATION:运营账户 FEES:手续费账户 date 日期 示例值:2019-08-17 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_7_4.shtml

func (*Client) PayPartnerTransactionsH5

func (c *Client) PayPartnerTransactionsH5(notMustParams ...gorequest.Params) *PayPartnerTransactionsH5Result

PayPartnerTransactionsH5 H5下单API https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_3_1.shtml

func (*Client) PayPartnerTransactionsId

func (c *Client) PayPartnerTransactionsId(transactionId string) *PayPartnerTransactionsIdResult

PayPartnerTransactionsId 微信支付订单号查询 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_5_2.shtml

func (*Client) PayPartnerTransactionsJsapi

func (c *Client) PayPartnerTransactionsJsapi(notMustParams ...gorequest.Params) *PayPartnerTransactionsJsapiResult

PayPartnerTransactionsJsapi JSAPI下单 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_5_1.shtml

func (*Client) PayPartnerTransactionsOutTradeNo

func (c *Client) PayPartnerTransactionsOutTradeNo(outTradeNo string) *PayPartnerTransactionsOutTradeNoResult

PayPartnerTransactionsOutTradeNo 商户订单号查询 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_5_2.shtml

func (*Client) PayPartnerTransactionsOutTradeNoClose

func (c *Client) PayPartnerTransactionsOutTradeNoClose(outTradeNo string) *PayPartnerTransactionsOutTradeNoCloseResult

PayPartnerTransactionsOutTradeNoClose 关闭订单API https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_5_3.shtml

func (*Client) RefundDomesticRefunds

func (c *Client) RefundDomesticRefunds(notMustParams ...gorequest.Params) *RefundDomesticRefundsResult

RefundDomesticRefunds 申请退款API https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_5_9.shtml

func (*Client) RefundDomesticRefundsOutRefundNo

func (c *Client) RefundDomesticRefundsOutRefundNo(outRefundNo string) *RefundDomesticRefundsOutRefundNoResult

RefundDomesticRefundsOutRefundNo 查询单笔退款API https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_5_9.shtml

func (*Client) SubConfig

func (c *Client) SubConfig(subAppid, subMchId string) *Client

SubConfig 子商户配置

type ConfigClient

type ConfigClient struct {
	SpAppid        string            // 服务商应用ID
	SpMchId        string            // 服务商户号
	SubAppid       string            // 子商户应用ID
	SubMchId       string            // 子商户号
	ApiV2          string            // APIv2密钥
	ApiV3          string            // APIv3密钥
	SerialNo       string            // 序列号
	MchSslSerialNo string            // pem 证书号
	MchSslCer      string            // pem 内容
	MchSslKey      string            // pem key 内容
	MongoDb        *dorm.MongoClient // 日志数据库
	PgsqlDb        *gorm.DB          // 日志数据库
	DatabaseName   string            // 库名
}

type EcommerceFundBalanceResponse

type EcommerceFundBalanceResponse struct {
	SubMchid        string `json:"sub_mchid"`        // 二级商户号
	AccountType     string `json:"account_type"`     // 账户类型
	AvailableAmount int64  `json:"available_amount"` // 可用余额
	PendingAmount   int64  `json:"pending_amount"`   // 不可用余额
}

type EcommerceFundBalanceResult

type EcommerceFundBalanceResult struct {
	Result EcommerceFundBalanceResponse // 结果
	Body   []byte                       // 内容
	Http   gorequest.Response           // 请求
	Err    error                        // 错误
}

type EcommerceFundEndDayBalanceResponse

type EcommerceFundEndDayBalanceResponse struct {
	SubMchid        string `json:"sub_mchid"`        // 二级商户号
	AvailableAmount int64  `json:"available_amount"` // 可用余额
	PendingAmount   int64  `json:"pending_amount"`   // 不可用余额
}

type EcommerceFundEndDayBalanceResult

type EcommerceFundEndDayBalanceResult struct {
	Result EcommerceFundEndDayBalanceResponse // 结果
	Body   []byte                             // 内容
	Http   gorequest.Response                 // 请求
	Err    error                              // 错误
}

type GetJsApi

type GetJsApi struct {
	Package string `json:"package"`
}

GetJsApi 入参

type GetJsApiResult

type GetJsApiResult struct {
	AppId     string `json:"app_id"`     // 应用ID
	TimeStamp string `json:"time_stamp"` // 时间戳
	NonceStr  string `json:"nonce_str"`  // 随机字符串
	Package   string `json:"package"`    // 订单详情扩展字符串
	SignType  string `json:"sign_type"`  // 签名方式
	PaySign   string `json:"pay_sign"`   // 签名
}

GetJsApiResult 返回参数

type MerchantFundBalanceResponse

type MerchantFundBalanceResponse struct {
	AvailableAmount int64 `json:"available_amount"` // 可用余额
	PendingAmount   int64 `json:"pending_amount"`   // 不可用余额
}

type MerchantFundBalanceResult

type MerchantFundBalanceResult struct {
	Result MerchantFundBalanceResponse // 结果
	Body   []byte                      // 内容
	Http   gorequest.Response          // 请求
	Err    error                       // 错误
}

type MerchantFundDayEndBalanceResponse

type MerchantFundDayEndBalanceResponse struct {
	AvailableAmount int64 `json:"available_amount"` // 可用余额
	PendingAmount   int64 `json:"pending_amount"`   // 不可用余额
}

type MerchantFundDayEndBalanceResult

type MerchantFundDayEndBalanceResult struct {
	Result MerchantFundDayEndBalanceResponse // 结果
	Body   []byte                            // 内容
	Http   gorequest.Response                // 请求
	Err    error                             // 错误
}

type PayPartnerTransactionsH5Response

type PayPartnerTransactionsH5Response struct {
	H5Url string `json:"h5_url"` // 支付跳转链接
}

type PayPartnerTransactionsH5Result

type PayPartnerTransactionsH5Result struct {
	Result   PayPartnerTransactionsH5Response // 结果
	Body     []byte                           // 内容
	Http     gorequest.Response               // 请求
	Err      error                            // 错误
	ApiError ApiError                         // 接口错误
}

type PayPartnerTransactionsIdResponse

type PayPartnerTransactionsIdResponse struct {
	Appid          string `json:"appid"`
	Mchid          string `json:"mchid"`
	OutTradeNo     string `json:"out_trade_no"`
	TransactionId  string `json:"transaction_id,omitempty"`
	TradeType      string `json:"trade_type,omitempty"`
	TradeState     string `json:"trade_state"`
	TradeStateDesc string `json:"trade_state_desc"`
	BankType       string `json:"bank_type,omitempty"`
	Attach         string `json:"attach,omitempty"`
	SuccessTime    string `json:"success_time,omitempty"`
	Payer          struct {
		Openid string `json:"openid"`
	} `json:"payer"`
	Amount struct {
		Total         int    `json:"total,omitempty"`
		PayerTotal    int    `json:"payer_total,omitempty"`
		Currency      string `json:"currency,omitempty"`
		PayerCurrency string `json:"payer_currency,omitempty"`
	} `json:"amount,omitempty"`
	SceneInfo struct {
		DeviceId string `json:"device_id,omitempty"`
	}
	PromotionDetail []struct {
		CouponId            string `json:"coupon_id"`
		Name                string `json:"name,omitempty"`
		Scope               string `json:"scope,omitempty"`
		Type                string `json:"type,omitempty"`
		Amount              int    `json:"amount"`
		StockId             string `json:"stock_id,omitempty"`
		WechatpayContribute int    `json:"wechatpay_contribute,omitempty"`
		MerchantContribute  int    `json:"merchant_contribute,omitempty"`
		OtherContribute     int    `json:"other_contribute,omitempty"`
		Currency            string `json:"currency,omitempty"`
		GoodsDetail         []struct {
			GoodsId        string `json:"goods_id"`
			Quantity       int    `json:"quantity"`
			UnitPrice      int    `json:"unit_price"`
			DiscountAmount int    `json:"discount_amount"`
			GoodsRemark    string `json:"goods_remark,omitempty"`
		} `json:"goods_detail"`
	}
}

type PayPartnerTransactionsIdResult

type PayPartnerTransactionsIdResult struct {
	Result PayPartnerTransactionsIdResponse // 结果
	Body   []byte                           // 内容
	Http   gorequest.Response               // 请求
	Err    error                            // 错误
}

type PayPartnerTransactionsJsapiResponse

type PayPartnerTransactionsJsapiResponse struct {
	PrepayId string `json:"prepay_id"`
}

type PayPartnerTransactionsJsapiResult

type PayPartnerTransactionsJsapiResult struct {
	Result   PayPartnerTransactionsJsapiResponse // 结果
	Body     []byte                              // 内容
	Http     gorequest.Response                  // 请求
	Err      error                               // 错误
	ApiError ApiError                            // 接口错误
}

type PayPartnerTransactionsOutTradeNoCloseResult

type PayPartnerTransactionsOutTradeNoCloseResult struct {
	Body []byte             // 内容
	Http gorequest.Response // 请求
	Err  error              // 错误
}

type PayPartnerTransactionsOutTradeNoResponse

type PayPartnerTransactionsOutTradeNoResponse struct {
	SpAppid        string `json:"sp_appid"`         // 服务商应用ID
	SpMchid        string `json:"sp_mchid"`         // 服务商户号
	SubAppid       string `json:"sub_appid"`        // 子商户应用ID
	SubMchid       string `json:"sub_mchid"`        // 子商户号
	OutTradeNo     string `json:"out_trade_no"`     // 商户订单号
	TransactionId  string `json:"transaction_id"`   // 微信支付订单号
	TradeType      string `json:"trade_type"`       // 交易类型
	TradeState     string `json:"trade_state"`      // 交易状态
	TradeStateDesc string `json:"trade_state_desc"` // 交易状态描述
	BankType       string `json:"bank_type"`        // 付款银行
	Attach         string `json:"attach"`           // 附加数据
	SuccessTime    string `json:"success_time"`     // 支付完成时间
	Payer          struct {
		SpOpenid  string `json:"sp_openid"`  // 用户服务标识
		SubOpenid string `json:"sub_openid"` // 用户子标识
	} `json:"payer"` // 支付者
	Amount struct {
		Total         int    `json:"total"`          // 总金额
		PayerTotal    int    `json:"payer_total"`    // 用户支付金额
		Currency      string `json:"currency"`       // 货币类型
		PayerCurrency string `json:"payer_currency"` // 用户支付币种
	} `json:"amount"` // 订单金额
	SceneInfo struct {
		DeviceId string `json:"device_id"` // 商户端设备号
	} `json:"scene_info"` // 场景信息
	PromotionDetail []struct {
		CouponId            string `json:"coupon_id"`            // 券ID
		Name                string `json:"name"`                 // 优惠名称
		Scope               string `json:"scope"`                // 优惠范围
		Type                string `json:"type"`                 // 优惠类型
		Amount              int    `json:"amount"`               // 优惠券面额
		StockId             string `json:"stock_id"`             // 活动ID
		WechatpayContribute int    `json:"wechatpay_contribute"` // 微信出资
		MerchantContribute  int    `json:"merchant_contribute"`  // 商户出资
		OtherContribute     int    `json:"other_contribute"`     // 其他出资
		Currency            string `json:"currency"`             // 优惠币种
		GoodsDetail         []struct {
			GoodsId        string `json:"goods_id"`        // 商品编码
			Quantity       int    `json:"quantity"`        // 商品数量
			UnitPrice      int    `json:"unit_price"`      // 商品单价
			DiscountAmount int    `json:"discount_amount"` // 商品优惠金额
			GoodsRemark    string `json:"goods_remark"`    // 商品备注
		} `json:"goods_detail"` // 单品列表
	} `json:"promotion_detail"` // 优惠功能
}

type PayPartnerTransactionsOutTradeNoResult

type PayPartnerTransactionsOutTradeNoResult struct {
	Result   PayPartnerTransactionsOutTradeNoResponse // 结果
	Body     []byte                                   // 内容
	Http     gorequest.Response                       // 请求
	Err      error                                    // 错误
	ApiError ApiError                                 // 接口错误
}

type RefundDomesticRefundsOutRefundNoResponse

type RefundDomesticRefundsOutRefundNoResponse struct {
	RefundId            string    `json:"refund_id"`
	OutRefundNo         string    `json:"out_refund_no"`
	TransactionId       string    `json:"transaction_id"`
	OutTradeNo          string    `json:"out_trade_no"`
	Channel             string    `json:"channel"`
	UserReceivedAccount string    `json:"user_received_account"`
	SuccessTime         string    `json:"success_time"`
	CreateTime          time.Time `json:"create_time"`
	Status              string    `json:"status"`
	FundsAccount        string    `json:"funds_account"`
	Amount              struct {
		Total  int `json:"total"`
		Refund int `json:"refund"`
		From   []struct {
			Account string `json:"account"`
			Amount  int    `json:"amount"`
		} `json:"from"`
		PayerTotal       int    `json:"payer_total"`
		PayerRefund      int    `json:"payer_refund"`
		SettlementRefund int    `json:"settlement_refund"`
		SettlementTotal  int    `json:"settlement_total"`
		DiscountRefund   int    `json:"discount_refund"`
		Currency         string `json:"currency"`
	} `json:"amount"`
	PromotionDetail []struct {
		PromotionId  string `json:"promotion_id"`
		Scope        string `json:"scope"`
		Type         string `json:"type"`
		Amount       int    `json:"amount"`
		RefundAmount int    `json:"refund_amount"`
		GoodsDetail  struct {
			MerchantGoodsId  string `json:"merchant_goods_id"`
			WechatpayGoodsId string `json:"wechatpay_goods_id"`
			GoodsName        string `json:"goods_name"`
			UnitPrice        int    `json:"unit_price"`
			RefundAmount     int    `json:"refund_amount"`
			RefundQuantity   int    `json:"refund_quantity"`
		} `json:"goods_detail"`
	} `json:"promotion_detail"`
}

type RefundDomesticRefundsOutRefundNoResult

type RefundDomesticRefundsOutRefundNoResult struct {
	Result RefundDomesticRefundsOutRefundNoResponse // 结果
	Body   []byte                                   // 内容
	Http   gorequest.Response                       // 请求
	Err    error                                    // 错误
}

type RefundDomesticRefundsResponse

type RefundDomesticRefundsResponse struct {
	RefundId            string    `json:"refund_id"`
	OutRefundNo         string    `json:"out_refund_no"`
	TransactionId       string    `json:"transaction_id"`
	OutTradeNo          string    `json:"out_trade_no"`
	Channel             string    `json:"channel"`
	UserReceivedAccount string    `json:"user_received_account"`
	SuccessTime         time.Time `json:"success_time"`
	CreateTime          time.Time `json:"create_time"`
	Status              string    `json:"status"`
	FundsAccount        string    `json:"funds_account"`
	Amount              struct {
		Total  int `json:"total"`
		Refund int `json:"refund"`
		From   []struct {
			Account string `json:"account"`
			Amount  int    `json:"amount"`
		} `json:"from"`
		PayerTotal       int    `json:"payer_total"`
		PayerRefund      int    `json:"payer_refund"`
		SettlementRefund int    `json:"settlement_refund"`
		SettlementTotal  int    `json:"settlement_total"`
		DiscountRefund   int    `json:"discount_refund"`
		Currency         string `json:"currency"`
	} `json:"amount"`
	PromotionDetail []struct {
		PromotionId  string `json:"promotion_id"`
		Scope        string `json:"scope"`
		Type         string `json:"type"`
		Amount       int    `json:"amount"`
		RefundAmount int    `json:"refund_amount"`
		GoodsDetail  struct {
			MerchantGoodsId  string `json:"merchant_goods_id"`
			WechatpayGoodsId string `json:"wechatpay_goods_id"`
			GoodsName        string `json:"goods_name"`
			UnitPrice        int    `json:"unit_price"`
			RefundAmount     int    `json:"refund_amount"`
			RefundQuantity   int    `json:"refund_quantity"`
		} `json:"goods_detail"`
	} `json:"promotion_detail"`
}

type RefundDomesticRefundsResult

type RefundDomesticRefundsResult struct {
	Result RefundDomesticRefundsResponse // 结果
	Body   []byte                        // 内容
	Http   gorequest.Response            // 请求
	Err    error                         // 错误
}

Jump to

Keyboard shortcuts

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