wxpay

package module
v0.0.0-...-68491f5 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//UnifiedOrderURL  统一下单请求api地址
	UnifiedOrderURL = "https://api.mch.weixin.qq.com/pay/unifiedorder"
	//OrderQueryURL    查询订单url
	OrderQueryURL = "https://api.mch.weixin.qq.com/pay/orderquery"
	//CloseQueryURL    关闭订单url
	CloseQueryURL = "https://api.mch.weixin.qq.com/pay/closeorder"
	//RefundURL        申请退款url
	RefundURL = "https://api.mch.weixin.qq.com/secapi/pay/refund"
	//RefundQueryURL   查询退款url
	RefundQueryURL = "https://api.mch.weixin.qq.com/pay/refundquery"
	//DownloadBillURL   下载对账单url
	DownloadBillURL = "https://api.mch.weixin.qq.com/pay/downloadbill"
	//DownloadFundflowURL   下载对账单url
	DownloadFundflowURL = "https://api.mch.weixin.qq.com/pay/downloadfundflow"
)

Variables

This section is empty.

Functions

func CalcSign

func CalcSign(Req map[string]interface{}, key string) string

CalcSign 微信支付 下单签名

func RandomNum

func RandomNum(length int) string

RandomNum 生成随机数

func RandomStr

func RandomStr(length int) string

RandomStr 生成随机字符串

func Request

func Request(reqxml interface{}, requrl string) (respBytes []byte, err error)

Request 发起请求

func StructToMap

func StructToMap(st interface{}) (m map[string]interface{})

StructToMap 结构体转map

func VerifySign

func VerifySign(needVerifyM map[string]interface{}, sign, secret string) bool

VerifySign 验证签名

Types

type CloseOrderReq

type CloseOrderReq struct {
	Appid      string `xml:"appid"`        //公众账号ID
	MchID      string `xml:"mch_id"`       //商户号
	OutTradeNo string `xml:"out_trade_no"` //商户订单号(2选1)
	NonceStr   string `xml:"nonce_str"`    //随机字符串
	Sign       string `xml:"sign"`         //签名
	SignType   string `xml:"sign_type"`    //签名类型  MD5
}

CloseOrderReq 关闭订单请求

type CloseOrderResq

type CloseOrderResq struct {
	ReturnCode         string `xml:"return_code"`          //返回状态码  SUCCESS
	ReturnMsg          string `xml:"return_msg"`           //返回信息	OK
	Appid              string `xml:"appid"`                //公众账号ID
	MchID              string `xml:"mch_id"`               //商户号
	NonceStr           string `xml:"nonce_str"`            //随机字符串
	Sign               string `xml:"sign"`                 //sign
	ResultCode         string `xml:"result_code"`          //业务结果 SUCCESS
	ErrCode            string `xml:"err_code"`             //错误代码
	ErrCodeDes         string `xml:"err_code_des"`         //错误代码描述
	DeviceInfo         string `xml:"device_info"`          //设备号
	Openid             string `xml:"openid"`               //用户标识
	IsSubscribe        string `xml:"is_subscribe"`         //是否关注公众账号
	TradeType          string `xml:"trade_type"`           //交易类型
	TradeState         string `xml:"trade_state"`          //交易状态
	BankType           string `xml:"bank_type"`            //付款银行
	TotalFee           string `xml:"total_fee"`            //标价金额
	SettlementTotalFee string `xml:"settlement_total_fee"` //应结订单金额
	FeeType            string `xml:"fee_type"`             //标价币种
	CashFee            string `xml:"cash_fee"`             //现金支付金额
	CashFeeType        string `xml:"cash_fee_type"`        //现金支付金额
	CouponFee          string `xml:"coupon_fee"`           //代金券金额
	CouponCount        string `xml:"coupon_count"`         //代金券使用数量
	CouponType0        string `xml:"coupon_type_0"`        //代金券使用数量
	CouponID0          string `xml:"coupon_id_0"`          //代金券使用数量
	CouponFee0         string `xml:"coupon_fee_0"`         //代金券使用数量
	TransactionID      string `xml:"transaction_id"`       //微信支付订单号
	OutTradeNo         string `xml:"out_trade_no"`         //商户订单号
	Attach             string `xml:"attach"`               //附加数据
	TimeEnd            string `xml:"time_end"`             //支付完成时间
	TradeStateDesc     string `xml:"trade_state_desc"`     //交易状态描述
}

CloseOrderResq 关闭订单响应

type DownloadBillReq

type DownloadBillReq struct {
	Appid    string `xml:"appid"`     //公众账号ID
	MchID    string `xml:"mch_id"`    //商户号
	NonceStr string `xml:"nonce_str"` //随机字符串
	Sign     string `xml:"sign"`      //签名
	BillDate string `xml:"bill_date"` //对账单日期
	BillType string `xml:"bill_type"` //账单类型
	TarType  string `xml:"tar_type"`  //压缩账单
}

DownloadBillReq 下载对账单请求

type DownloadBillResq

type DownloadBillResq struct {
	ReturnCode string `xml:"return_code"`  //返回状态码  SUCCESS
	ReturnMsg  string `xml:"return_msg"`   //返回信息	OK
	ResultCode string `xml:"result_code"`  //业务结果 SUCCESS
	ErrCode    string `xml:"err_code"`     //错误代码
	ErrCodeDes string `xml:"err_code_des"` //错误代码描述
}

DownloadBillResq 查询退款响应

type DownloadFundflowReq

type DownloadFundflowReq struct {
	Appid       string `xml:"appid"`        //公众账号ID
	MchID       string `xml:"mch_id"`       //商户号
	NonceStr    string `xml:"nonce_str"`    //随机字符串
	Sign        string `xml:"sign"`         //签名
	SignType    string `xml:"sign_type"`    //签名类型,目前仅支持HMAC-SHA256
	BillDate    string `xml:"bill_date"`    //对账单日期
	AccountType string `xml:"account_type"` //资金账户类型
	TarType     string `xml:"tar_type"`     //压缩账单
}

DownloadFundflowReq 下载对账单请求

type DownloadFundflowResq

type DownloadFundflowResq struct {
	ReturnCode string `xml:"return_code"`  //返回状态码  SUCCESS
	ReturnMsg  string `xml:"return_msg"`   //返回信息	OK
	ResultCode string `xml:"result_code"`  //业务结果 SUCCESS
	ErrCode    string `xml:"err_code"`     //错误代码
	ErrCodeDes string `xml:"err_code_des"` //错误代码描述
}

DownloadFundflowResq 查询退款响应

type NotifyResp

type NotifyResp struct {
	ReturnCode string `xml:"return_code"`
	ReturnMsg  string `xml:"return_msg"`
}

NotifyResp 微信支付通知微信服务器消息

type OrderQueryReq

type OrderQueryReq struct {
	Appid         string `xml:"appid"`          //公众账号ID
	MchID         string `xml:"mch_id"`         //商户号
	TransactionID string `xml:"transaction_id"` //微信订单号(2选1)
	OutTradeNo    string `xml:"out_trade_no"`   //商户订单号(2选1)
	NonceStr      string `xml:"nonce_str"`      //随机字符串
	Sign          string `xml:"sign"`           //签名
	SignType      string `xml:"sign_type"`      //签名类型  MD5
}

OrderQueryReq 统一下单请求

type OrderQueryResq

type OrderQueryResq struct {
	ReturnCode         string `xml:"return_code"`          //返回状态码  SUCCESS
	ReturnMsg          string `xml:"return_msg"`           //返回信息	OK
	Appid              string `xml:"appid"`                //公众账号ID
	MchID              string `xml:"mch_id"`               //商户号
	NonceStr           string `xml:"nonce_str"`            //随机字符串
	Sign               string `xml:"sign"`                 //sign
	ResultCode         string `xml:"result_code"`          //业务结果 SUCCESS
	ErrCode            string `xml:"err_code"`             //错误代码
	ErrCodeDes         string `xml:"err_code_des"`         //错误代码描述
	DeviceInfo         string `xml:"device_info"`          //设备号
	Openid             string `xml:"openid"`               //用户标识
	IsSubscribe        string `xml:"is_subscribe"`         //是否关注公众账号
	TradeType          string `xml:"trade_type"`           //交易类型
	TradeState         string `xml:"trade_state"`          //交易状态
	BankType           string `xml:"bank_type"`            //付款银行
	TotalFee           int    `xml:"total_fee"`            //标价金额
	SettlementTotalFee int    `xml:"settlement_total_fee"` //应结订单金额
	FeeType            string `xml:"fee_type"`             //标价币种
	CashFee            int    `xml:"cash_fee"`             //现金支付金额
	CashFeeType        string `xml:"cash_fee_type"`        //现金支付金额
	CouponFee          int    `xml:"coupon_fee"`           //代金券金额
	CouponCount        int    `xml:"coupon_count"`         //代金券使用数量
	CouponType0        string `xml:"coupon_type_0"`        //代金券使用数量
	CouponID0          string `xml:"coupon_id_0"`          //代金券使用数量
	CouponFee0         int    `xml:"coupon_fee_0"`         //代金券使用数量
	TransactionID      string `xml:"transaction_id"`       //微信支付订单号
	OutTradeNo         string `xml:"out_trade_no"`         //商户订单号
	Attach             string `xml:"attach"`               //附加数据
	TimeEnd            string `xml:"time_end"`             //支付完成时间
	TradeStateDesc     string `xml:"trade_state_desc"`     //交易状态描述
}

OrderQueryResq 统一下单请求

type Pay

type Pay struct {
	Appid     string //公众号Appid
	MiniAppid string //小程序Appid
	AppAppid  string //appAppid
	MchID     string //商户号
	Mchkey    string //商户号秘钥
	MchIDApp  string //app商户号
	MchkeyApp string //app商户号秘钥
	Cert      string //公众号支付证书位置
	Key       string //公众号支付密钥位置
	CertApp   string //公众号支付证书位置
	KeyApp    string //公众号支付密钥位置
}

Pay 支付构造参数

func NewPay

func NewPay(appid, miniappid, appappid, mchid, mchkey, mchidapp, mchkeyapp, cert, key, certapp, keyapp string) *Pay

NewPay 构造一个新的支付

func (*Pay) OrderQuery

func (p *Pay) OrderQuery(transactionID, outTradeNo, platform string) (oqrsp *OrderQueryResq)

OrderQuery 查询订单

func (*Pay) Refund

func (p *Pay) Refund(platform string, rq *RefundReq) (rrsqp *RefundResq, err error)

Refund 申请退款

func (*Pay) RefundQuery

func (p *Pay) RefundQuery(platform string, rq *RefundQueryReq) (rrsqp *RefundQueryReq, err error)

RefundQuery 退款查询

func (*Pay) SwitchPlatform

func (p *Pay) SwitchPlatform(platform string) (appid, tradetype, mchid, secret string)

SwitchPlatform 根据平台判断参数

func (*Pay) UnifiedOrder

func (p *Pay) UnifiedOrder(platform string, uor *UnifiedOrderReq) (res map[string]interface{}, err error)

UnifiedOrder 统一下单 platform 公众号:public 小程序:miniapp APP:app H5:h5

func (*Pay) UnifiedOrderCallbackVerify

func (p *Pay) UnifiedOrderCallbackVerify(r *http.Request) (mr *UnifiedOrderCallback, ok bool, err error)

UnifiedOrderCallbackVerify 统一下单回调验证

type RefunQueryResq

type RefunQueryResq struct {
	ReturnCode          string `xml:"return_code"`             //返回状态码  SUCCESS
	ReturnMsg           string `xml:"return_msg"`              //返回信息	OK
	ResultCode          string `xml:"result_code"`             //业务结果 SUCCESS
	ErrCode             string `xml:"err_code"`                //错误代码
	ErrCodeDes          string `xml:"err_code_des"`            //错误代码描述
	Appid               string `xml:"appid"`                   //公众账号ID
	MchID               string `xml:"mch_id"`                  //商户号
	NonceStr            string `xml:"nonce_str"`               //随机字符串
	Sign                string `xml:"sign"`                    //签名
	TotalRefundCount    string `xml:"total_refund_count"`      //订单总退款次数
	TransactionID       string `xml:"transaction_id"`          //微信支付订单号
	OutTradeNo          string `xml:"out_trade_no"`            //商户订单号
	TotalFee            int    `xml:"total_fee"`               //标价金额
	SettlementTotalFee  int    `xml:"settlement_total_fee"`    //应结订单金额
	FeeType             string `xml:"fee_type"`                //标价币种
	CashFee             int    `xml:"cash_fee"`                //现金支付金额
	RefundCount         int    `xml:"refund_count"`            //退款笔数
	OutRefundNo0        string `xml:"out_refund_no_0"`         //商户退款单号
	RefundID0           string `xml:"refund_id_0"`             //微信退款单号
	RefundChannel0      string `xml:"refund_channel_0"`        //退款渠道
	RefundFee0          int    `xml:"refund_fee_$n"`           //申请退款金额
	SettlementTotalFee0 int    `xml:"settlement_refund_fee_0"` //退款金额
}

RefunQueryResq 查询退款响应

type RefundQueryReq

type RefundQueryReq struct {
	Appid         string `xml:"appid"`          //公众账号ID
	MchID         string `xml:"mch_id"`         //商户号
	NonceStr      string `xml:"nonce_str"`      //随机字符串
	Sign          string `xml:"sign"`           //签名
	SignType      string `xml:"sign_type"`      //签名类型  MD5
	TransactionID string `xml:"transaction_id"` //微信订单号(4选1)
	OutTradeNo    string `xml:"out_trade_no"`   //商户订单号(4选1)
	OutRefundNo   string `xml:"out_refund_no"`  //商户退款单号(4选1)
	RefundID      string `xml:"refund_id"`      //微信退款单号(4选1)
	Offset        int    `xml:"offset"`         //偏移量
}

RefundQueryReq 查询退款请求

type RefundReq

type RefundReq struct {
	Appid         string `xml:"appid"`           //公众账号ID
	MchID         string `xml:"mch_id"`          //商户号
	NonceStr      string `xml:"nonce_str"`       //随机字符串
	Sign          string `xml:"sign"`            //签名
	SignType      string `xml:"sign_type"`       //签名类型  MD5
	TransactionID string `xml:"transaction_id"`  //微信订单号(2选1)
	OutTradeNo    string `xml:"out_trade_no"`    //商户订单号(2选1)
	OutRefundNo   string `xml:"out_refund_no"`   //商户退款单号
	TotalFee      int    `xml:"total_fee"`       //订单金额
	RefundFee     int    `xml:"refund_fee"`      //退款金额
	RefundFeeType string `xml:"refund_fee_type"` //退款货币种类
	RefundDesc    string `xml:"	refund_desc"`    //退款原因
	RefundAccount string `xml:"	refund_account"` //退款资金来源
	NotifyURL     string `xml:"	notify_url"`     //退款结果通知url
}

RefundReq 申请退款请求

type RefundResq

type RefundResq struct {
	ReturnCode          string `xml:"return_code"`           //返回状态码  SUCCESS
	ReturnMsg           string `xml:"return_msg"`            //返回信息	OK
	ResultCode          string `xml:"result_code"`           //业务结果 SUCCESS
	ErrCode             string `xml:"err_code"`              //错误代码
	ErrCodeDes          string `xml:"err_code_des"`          //错误代码描述
	Appid               string `xml:"appid"`                 //公众账号ID
	MchID               string `xml:"mch_id"`                //商户号
	NonceStr            string `xml:"nonce_str"`             //随机字符串
	Sign                string `xml:"sign"`                  //sign
	TransactionID       string `xml:"transaction_id"`        //微信支付订单号
	OutTradeNo          string `xml:"out_trade_no"`          //商户订单号
	OutRefundNo         string `xml:"out_refund_no"`         //商户退款单号
	RefundID            string `xml:"refund_id"`             //微信退款单号
	RfundFee            int    `xml:"refund_fee"`            //退款金额
	SettlementRefundFee int    `xml:"settlement_refund_fee"` //应结退款金额
	TotalFee            int    `xml:"total_fee"`             //标价金额
	SettlementTotalFee  int    `xml:"settlement_total_fee"`  //应结订单金额
	FeeType             string `xml:"fee_type"`              //标价币种
	CashFee             int    `xml:"cash_fee"`              //现金支付金额
	CashFeeType         string `xml:"cash_fee_type"`         //现金支付金额
	CashRefundFee       int    `xml:"cash_refund_fee"`       //现金退款金额
	CouponType0         string `xml:"coupon_type_0"`         //代金券类型
	CouponRefundFee     int    `xml:"coupon_refund_fee"`     //代金券退款总金额
	CouponRefundFee0    int    `xml:"coupon_refund_fee_0"`   //单个代金券退款金额
	CouponRefundCount   int    `xml:"coupon_refund_count"`   //退款代金券使用数量
	CouponRefundID0     string `xml:"coupon_refund_id_0"`    //退款代金券ID
}

RefundResq 申请退款响应

type UnifiedOrderCallback

type UnifiedOrderCallback struct {
	ReturnCode         string `xml:"return_code"`          //返回状态码  SUCCESS
	ReturnMsg          string `xml:"return_msg"`           //返回信息	OK
	Appid              string `xml:"appid"`                //公众账号ID
	MchID              string `xml:"mch_id"`               //商户号
	DeviceInfo         string `xml:"device_info"`          //设备号
	NonceStr           string `xml:"nonce_str"`            //随机字符串
	Sign               string `xml:"sign"`                 //sign
	SignType           string `xml:"sign_type"`            //sign
	ResultCode         string `xml:"result_code"`          //业务结果 SUCCESS
	ErrCode            string `xml:"err_code"`             //错误代码
	ErrCodeDes         string `xml:"err_code_des"`         //错误代码描述
	Openid             string `xml:"openid"`               //用户标识
	IsSubscribe        string `xml:"is_subscribe"`         //是否关注公众账号
	TradeType          string `xml:"trade_type"`           //交易类型
	BankType           string `xml:"bank_type"`            //付款银行
	TotalFee           int    `xml:"total_fee"`            //标价金额
	SettlementTotalFee int    `xml:"settlement_total_fee"` //应结订单金额
	FeeType            string `xml:"fee_type"`             //标价币种
	CashFee            int    `xml:"cash_fee"`             //现金支付金额
	CashFeeType        string `xml:"cash_fee_type"`        //现金支付金额
	CouponFee          int    `xml:"coupon_fee"`           //代金券金额
	CouponCount        int    `xml:"coupon_count"`         //代金券使用数量
	CouponType0        string `xml:"coupon_type_0"`        //代金券使用数量
	CouponID0          string `xml:"coupon_id_0"`          //代金券使用数量
	CouponFee0         int    `xml:"coupon_fee_0"`         //代金券使用数量
	TransactionID      string `xml:"transaction_id"`       //微信支付订单号
	OutTradeNo         string `xml:"out_trade_no"`         //商户订单号
	Attach             string `xml:"attach"`               //附加数据
	TimeEnd            string `xml:"time_end"`             //支付完成时间
}

UnifiedOrderCallback 统一下单回调

type UnifiedOrderReq

type UnifiedOrderReq struct {
	Appid          string `xml:"appid"`            //公众账号ID
	MchID          string `xml:"mch_id"`           //商户号
	DeviceInfo     string `xml:"device_info"`      //设备号
	NonceStr       string `xml:"nonce_str"`        //随机字符串
	Sign           string `xml:"sign"`             //签名
	SignType       string `xml:"sign_type"`        //签名类型  MD5
	Body           string `xml:"body"`             //商品描述
	Detail         string `xml:"detail"`           //商品详情
	Attach         string `xml:"attach"`           //附加数据
	OutTradeNo     string `xml:"out_trade_no"`     //商户订单号
	FeeType        string `xml:"fee_type"`         //标价币种  CNY
	TotalFee       int    `xml:"total_fee"`        //标价金额
	SpbillCreateIP string `xml:"spbill_create_ip"` //终端IP
	TimeStart      string `xml:"time_start"`       //交易起始时间
	TimeExpire     string `xml:"time_expire"`      //交易结束时间
	GoodsTag       string `xml:"goods_tag"`        //订单优惠标记
	NotifyURL      string `xml:"notify_url"`       //通知地址
	TradeType      string `xml:"trade_type"`       //交易类型
	ProductID      string `xml:"product_id"`       //商品ID
	LimitPay       string `xml:"limit_pay"`        //指定支付方式
	Openid         string `xml:"openid"`           //用户标识
	Receipt        string `xml:"receipt"`          //电子发票入口开放标识
	SceneInfo      string `xml:"scene_info"`       //场景信息
}

UnifiedOrderReq 统一下单请求

type UnifiedOrderResp

type UnifiedOrderResp struct {
	ReturnCode string `xml:"return_code"`  //返回状态码  SUCCESS
	ReturnMsg  string `xml:"return_msg"`   //返回信息	OK
	Appid      string `xml:"appid"`        //公众账号ID
	MchID      string `xml:"mch_id"`       //商户号
	DeviceInfo string `xml:"device_info"`  //设备号
	NonceStr   string `xml:"nonce_str"`    //随机字符串
	Sign       string `xml:"sign"`         //sign
	ResultCode string `xml:"result_code"`  //业务结果 SUCCESS
	ErrCode    string `xml:"err_code"`     //错误代码
	ErrCodeDes string `xml:"err_code_des"` //错误代码描述
	PrepayID   string `xml:"prepay_id"`    //预支付交易会话标识
	TradeType  string `xml:"trade_type"`   //交易类型
	CodeURL    string `xml:"code_url"`     //二维码链接
}

UnifiedOrderResp 统一下单响应

Jump to

Keyboard shortcuts

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