BaseWeixinPayPay

package
v5.1.37 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

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

Variables

This section is empty.

Functions

func HandlePaidNotify

func HandlePaidNotify(res http.ResponseWriter, req *http.Request, fuck func(PaidNotify) (bool, string)) error

HandlePaidNotify 处理支付结果通知

func HandleRefundedNotify

func HandleRefundedNotify(res http.ResponseWriter, req *http.Request, key string, fuck func(RefundedNotify) (bool, string)) error

HandleRefundedNotify 处理退款结果通知 key: 微信支付 KEY

func MerchantChange

func MerchantChange(args *ArgsMerchantChange) ([]byte, error)

MerchantChange 商户能力支持

func PayRefund

func PayRefund(args *ArgsPayRefund) (Refunder, RefundedResponse, error)

PayRefund 向微信服务器发出退款申请

Types

type ArgsMerchantChange

type ArgsMerchantChange struct {
	//商户ID
	// 可以留空,则走平台微信小程序主体
	OrgID int64
	//支付key
	PayKey string
	//用户微信OpenID
	UserOpenID string
	//用户昵称
	UserName string
	//支付描述
	PayDes string
	//支付金额
	Price int
}

ArgsMerchantChange 商户能力支持参数

type ArgsPayCreate

type ArgsPayCreate struct {
	//商户ID
	// 可以留空,则走平台微信小程序主体
	OrgID int64
	//支付金额
	Price int
	//用户微信OpenID
	UserOpenID string
	//描述
	Des string
	//支付key
	PayKey string
	//IP
	IP string
	//过期时间
	ExpireTime time.Time
}

ArgsPayCreate 支付请求模块参数

type ArgsPayRefund

type ArgsPayRefund struct {
	//商户ID
	// 可以留空,则走平台微信小程序主体
	OrgID int64
	//总金额
	Price int
	//退款金额
	RefundPrice int
	//支付key
	PayKey string
}

ArgsPayRefund 向微信服务器发出退款申请参数

type Order

type Order struct {
	// 必填 ...
	AppID      string `xml:"appid"`        // 小程序ID
	MchID      string `xml:"mch_id"`       // 商户号
	TotalFee   int    `xml:"total_fee"`    // 标价金额
	NotifyURL  string `xml:"notify_url"`   // 异步接收微信支付结果通知的回调地址,通知url必须为外网可访问的url,不能携带参数。
	OpenID     string `xml:"openid"`       // 下单用户ID
	Body       string `xml:"body"`         // 商品描述
	OutTradeNo string `xml:"out_trade_no"` // 商户订单号

	// 选填 ...
	IP        string    `xml:"spbill_create_ip,omitempty"` // 终端IP
	NoCredit  bool      `xml:"-"`                          // 上传此参数 no_credit 可限制用户不能使用信用卡支付
	StartedAt time.Time `xml:"-"`                          // 交易起始时间 格式为yyyyMMddHHmmss
	ExpiredAt time.Time `xml:"-"`                          // 交易结束时间 订单失效时间 格式为yyyyMMddHHmmss
	Tag       string    `xml:"goods_tag,omitempty"`        // 订单优惠标记,使用代金券或立减优惠功能时需要的参数,
	Detail    string    `xml:"detail,omitempty"`           // 商品详情
	Attach    string    `xml:"attach,omitempty"`           // 附加数据
}

Order 商户统一订单

func (Order) Unify

func (o Order) Unify(client *BaseWeixinPayClient.ClientType) (pres PaidResponse, err error)

Unify 统一下单

@key payment secret key

type OrderResponse

type OrderResponse struct {
	DeviceInfo         string `xml:"device_info"`          // 设备号	微信支付分配的终端设备号,
	OpenId             string `xml:"openid"`               //用户标识	用户在商户appid下的唯一标识
	IsSubscribe        string `xml:"is_subscribe"`         //是否关注公众账号	用户是否关注公众账号,Y-关注,N-未关注
	TradeType          string `xml:"trade_type"`           //交易类型 	JSAPI	调用接口提交的交易类型,取值如下:JSAPI,NATIVE,APP,MICROPAY,详细说明见参数规定
	TradeState         string `xml:"trade_state"`          //交易状态 SUCCESS—支付成功 REFUND—转入退款 NOTPAY—未支付 CLOSED—已关闭  REVOKED—已撤销(刷卡支付) USERPAYING--用户支付中 PAYERROR--支付失败(其他原因,如银行返回失败)
	BankType           string `xml:"bank_type"`            //付款银行 CMC	银行类型,采用字符串类型的银行标识
	TotalFee           int    `xml:"total_fee"`            //标价金额 订单总金额,单位为分
	SettlementTotalFee int    `xml:"settlement_total_fee"` //应结订单金额 当订单使用了免充值型优惠券后返回该参数,应结订单金额=订单金额-免充值优惠券金额。
	FeeType            string `xml:"fee_type"`             //标价币种	CNY	货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
	TransactionId      string `xml:"transaction_id"`       //微信支付订单号
	OutTradeNo         string `xml:"out_trade_no"`         //商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
	Attach             string `xml:"attach"`               //附加数据,原样返回
	TimeEnd            string `xml:"time_end"`             //支付完成时间是 yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
	CashFee            int    `xml:"cash_fee"`             //现金支付金额订单现金支付金额
	TradeStateDesc     string `xml:"trade_state_desc"`     //交易状态描述	支付失败,请重新下单支付	对当前查询订单状态的描述和下一步操作的指引
}

type PaidNotify

type PaidNotify struct {
	AppID         string  `xml:"appid"`               // 小程序ID
	MchID         string  `xml:"mch_id"`              // 商户号
	TotalFee      int     `xml:"total_fee"`           // 标价金额
	NonceStr      string  `xml:"nonce_str"`           // 随机字符串
	Sign          string  `xml:"sign"`                // 签名
	SignType      string  `xml:"sign_type,omitempty"` // 签名类型: 目前支持HMAC-SHA256和MD5,默认为MD5
	OpenID        string  `xml:"openid"`
	TradeType     string  `xml:"trade_type"`                     // 交易类型 JSAPI
	Bank          string  `xml:"bank_type"`                      // 银行类型,采用字符串类型的银行标识
	Settlement    float64 `xml:"settlement_total_fee,omitempty"` // 应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
	FeeType       string  `xml:"fee_type,omitempty"`             // 货币种类: 符合ISO4217标准的三位字母代码,默认人民币: CNY
	CashFee       float64 `xml:"cash_fee"`                       // 现金支付金额订单的现金支付金额
	CashFeeType   string  `xml:"cash_fee_type,omitempty"`        // 现金支付货币类型: 符合ISO4217标准的三位字母代码,默认人民币: CNY
	CouponFee     float64 `xml:"coupon_fee,omitempty"`           // 总代金券金额: 代金券金额<=订单金额,订单金额-代金券金额=现金支付金额
	CouponCount   int     `xml:"coupon_count,omitempty"`         // 代金券使用数量
	TransactionID string  `xml:"transaction_id"`                 // 微信支付订单号
	Attach        string  `xml:"attach,omitempty"`               // 商家数据包,原样返回
	// 商户系统内部订单号: 要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
	OutTradeNo string `xml:"out_trade_no"`
	// 支付完成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010
	Timeend string `xml:"time_end"`
}

PaidNotify 支付结果返回数据

type PaidResponse

type PaidResponse struct {
	AppID    string `xml:"appid"` // 小程序ID
	MchID    string `xml:"mch_id"`
	PrePayID string `xml:"prepay_id"`
	Sign     string `xml:"sign"`
	NonceStr string `xml:"nonce_str"`
}

PaidResponse 支付返回面向用户的集合

type Params

type Params struct {
	Timestamp string `json:"timeStamp"`
	NonceStr  string `json:"nonceStr"`
	SignType  string `json:"signType"`
	PaySign   string `json:"paySign"`
	Package   string `json:"package"`
}

Params 前端调用支付必须的参数 注意返回后得大小写格式不能变动

func GetParams

func GetParams(client *BaseWeixinPayClient.ClientType, nonceStr, prepayID string) (p Params, err error)

GetParams 获取支付参数

@appID 小程序 APPID @key 微信支付密钥 @nonceStr 统一下单得到的 nonceStr @prepayID 统一下单得到的 prepayID

func PayCreate

func PayCreate(args *ArgsPayCreate) (params Params, err error)

PayCreate 支付请求模块 二次封装支付类请求,避免接口变化

type Query

type Query struct {
	AppID         string `xml:"appid"`                    // 小程序ID
	MchID         string `xml:"mch_id"`                   // 商户号
	OutTradeNo    string `xml:"out_trade_no,omitempty"`   // 商户订单号
	TransactionID string `xml:"transaction_id,omitempty"` // 微信支付订单号
	SignType      string `xml:"sign_type,omitempty"`      // 签名类型: 目前支持HMAC-SHA256和MD5,默认为MD5
	NonceStr      string `xml:"nonce_str"`                // 随机字符串
	Sign          string `xml:"sign"`                     // 签名
}

func (Query) Query

func (q Query) Query(client *BaseWeixinPayClient.ClientType) (resp OrderResponse, err error)

type RefundedNotify

type RefundedNotify struct {
	AppID         string // 小程序ID
	MchID         string // 商户号
	NonceStr      string // 随机字符串
	TransactionID string `xml:"transaction_id"` // 微信支付订单号
	// 商户系统内部订单号: 要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
	OutTradeNo  string  `xml:"out_trade_no"`
	RefundID    string  `xml:"refund_id"`     // 微信退款单号
	OutRefundNo string  `xml:"out_refund_no"` // 商户退款单号
	TotalFee    float64 `xml:"total_fee"`     // 标价金额
	// 当该订单有使用非充值券时,返回此字段。
	// 应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
	Settlement float64 `xml:"settlement_total_fee,omitempty"`
	RefundFee  float64 `xml:"refund_fee"` // 退款总金额,单位为分
	// 退款金额
	// 退款金额=申请退款金额-非充值代金券退款金额,退款金额<=申请退款金额
	SettlementRefund float64 `xml:"settlement_refund_fee"`
	// 退款状态
	// SUCCESS 退款成功 | CHANGE 退款异常 | REFUNDCLOSE 退款关闭
	RefundStatus string `xml:"refund_status"`
	// 退款成功时间
	// 资金退款至用户帐号的时间,格式2017-12-15 09:46:01
	SuccessTime string `xml:"success_time,omitempty"`
	// 退款入账账户:取当前退款单的退款入账方
	// 1)退回银行卡:  {银行名称}{卡类型}{卡尾号}
	// 2)退回支付用户零钱: 支付用户零钱
	// 3)退还商户: 商户基本账户 商户结算银行账户
	// 4)退回支付用户零钱通: 支付用户零钱通
	ReceiveAccount string `xml:"refund_recv_accout"`
	// 退款资金来源
	// REFUND_SOURCE_RECHARGE_FUNDS 可用余额退款/基本账户
	// REFUND_SOURCE_UNSETTLED_FUNDS 未结算资金退款
	RefundAccount string `xml:"refund_account"`
	// 退款发起来源
	// API接口
	// VENDOR_PLATFORM商户平台
	Source string `xml:"refund_request_source"`
}

RefundedNotify 解密后的退款通知消息体

type RefundedResponse

type RefundedResponse struct {
	AppID         string `xml:"appid"`
	MchID         string `xml:"mch_id"`
	TransactionID string `xml:"transaction_id"` // 微信订单号: 微信生成的订单号,在支付通知中有返回。和商户订单号二选一
	OutTradeNo    string `xml:"out_trade_no"`   // 商户订单号: 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。 和微信订单号二选一
	OutRefundNo   string `xml:"out_refund_no"`  // 商户退款单号: 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。
	// 微信退款单号
	RefundID string `xml:"refund_id"`
	// 退款总金额,单位为分,可以做部分退款
	RefundFee int `xml:"refund_fee"`
	// 应结退款金额
	// 去掉非充值代金券退款金额后的退款金额,退款金额=申请退款金额-非充值代金券退款金额,退款金额<=申请退款金额
	SettlementRefundFee int `xml:"settlement_refund_fee"`
	// 标价金额
	// 订单总金额,单位为分,只能为整数
	TotalFee int `xml:"total_fee"`
	// 应结订单金额
	// 去掉非充值代金券金额后的订单总金额,应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额。
	SettlementTotalFee int `xml:"settlement_total_fee"`
	// 标价币种
	// FeeType            int `xml:"fee_type"`
	// 现金支付金额
	CashFee       int    `xml:"cash_fee"`
	CashRefundFee int    `xml:"cash_refund_fee"`
	Sign          string `xml:"sign"`
	NonceStr      string `xml:"nonce_str"`
}

RefundedResponse 请求退款返回数据

type Refunder

type Refunder struct {
	// 必填 ...
	AppID         string `xml:"appid"`  // 小程序ID
	MchID         string `xml:"mch_id"` // 商户号
	TotalFee      int    `xml:"total_fee"`
	RefundFee     int    `xml:"refund_fee"`               // 退款金额: 退款总金额,订单总金额,单位为分,只能为整数
	TransactionID string `xml:"transaction_id,omitempty"` // 微信订单号: 微信生成的订单号,在支付通知中有返回。和商户订单号二选一
	OutTradeNo    string `xml:"out_trade_no,omitempty"`   // 商户订单号: 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。 和微信订单号二选一
	OutRefundNo   string `xml:"out_refund_no"`            // 商户退款单号: 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。

	// 选填 ...
	// RefundFeeType string `xml:"refund_fee_type,omitempty"` // 货币种类: 货币类型,符合ISO 4217标准的三位字母代码,默认人民币: CNY
	RefundDesc string `xml:"refund_desc,omitempty"` // 退款原因: 若商户传入,会在下发给用户的退款消息中体现退款原因

	// 退款结果通知url: 异步接收微信支付退款结果通知的回调地址
	// 通知 URL 必须为外网可访问且不允许带参数
	// 如果参数中传了notify_url,则商户平台上配置的回调地址将不会生效。
	NotifyURL string `xml:"notify_url,omitempty"`
}

Refunder 退款表单数据

func (Refunder) Refund

func (r Refunder) Refund(client *BaseWeixinPayClient.ClientType) (rres RefundedResponse, err error)

Refund 发起退款请求

type TransferResponse

type TransferResponse struct {
	Datetime time.Time
	// contains filtered or unexported fields
}

TransferResponse 转账返回数据

type Transferer

type Transferer struct {
	// required
	AppID      string `xml:"mch_appid"`
	MchID      string `xml:"mchid"`            // 商户号
	OutTradeNo string `xml:"partner_trade_no"` // 商户订单号
	ToUser     string `xml:"openid"`
	Amount     int    `xml:"amount"`
	// 企业付款描述信息
	Desc string `xml:"desc"`

	// optional
	IP string `xml:"spbill_create_ip,omitempty"`
	// 校验用户姓名选项
	CheckName bool   `xml:"-"`
	Device    string `xml:"device_info,omitempty"`
	// 收款用户真实姓名
	// 如果check_name设置为FORCE_CHECK,则必填用户真实姓名
	RealName string `xml:"re_user_name,omitempty"`
}

Transferer transfer params

func (Transferer) Transfer

func (t Transferer) Transfer(client *BaseWeixinPayClient.ClientType) (res TransferResponse, err error)

Transfer 转账到微信用户零钱

Jump to

Keyboard shortcuts

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