wxpay

package
v0.0.0-...-e6aaacc Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UnifiedOrderApi 统一下单接口
	UnifiedOrderApi = "https://api.mch.weixin.qq.com/adaptor/unifiedorder"

	RefundApi = "https://api.mch.weixin.qq.com/secapi/pay/refund"
)
View Source
const (
	// TradeTypeJSAPI 公众号支付
	TradeTypeJSAPI = "JSAPI"

	// TradeTypeNative 扫码支付
	TradeTypeNative = "NATIVE"

	// TradeTypeApp App支付
	TradeTypeApp = "APP"
)

Variables

View Source
var (
	RandChar          = []byte("abcdefghijklmnopqrstuvwxyz0123456789")
	RandCharLen int32 = 36
)

Functions

This section is empty.

Types

type App

type App struct {
	AppId     string // 公众账号ID
	AppSecret string // AppSecret是APPID对应的接口密码
	MchId     string // 商户号
	NotifyUrl string // 通知地址
	TradeType string // 交易类型
}

App 微信支付

func NewApp

func NewApp(tradeType, appId, appSecret, mchId, notifyUrl string) *App

func (*App) Notify

func (a *App) Notify(data []byte) (result *NotifyResponse, err error)

Notify 支付回调

func (*App) Refund

func (a *App) Refund(req *RefundRequest) (result *RefundResponse, err error)

Refund 退款接口

func (*App) UnifiedOrder

func (a *App) UnifiedOrder(req *UnifiedOrderRequest) (result *UnifiedOrderResponse, err error)

UnifiedOrder 统一下单接口

type NotifyResponse

type NotifyResponse struct {
	Response `xml:",innerXml"`

	OpenId        string `xml:"openid"`         // 用户在商户appid下的唯一标识
	IsSubscribe   string `xml:"is_subscribe"`   // 用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效
	TradeType     string `xml:"trade_type"`     // 调用接口提交的交易类型,取值如下:JSAPI,NATIVE,APP,MICROPAY,详细说明见参数规定
	BankType      string `xml:"bank_type"`      // 银行类型,采用字符串类型的银行标识
	TotalFee      int    `xml:"total_fee"`      // 标价金额
	CashFee       int    `xml:"cash_fee"`       // 现金支付金额订单现金支付金额,详见支付金额
	TransactionId string `xml:"transaction_id"` // 微信支付订单号
	OutTradeNo    string `xml:"out_trade_no"`   // 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。
	TimeEnd       string `xml:"time_end"`       // 支付完成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。
}

NotifyResponse 回调数据

type RefundRequest

type RefundRequest struct {
	TransactionId string `xml:"transaction_id"`
	OutTradeNo    string `xml:"out_trade_no"`
	TotalFee      int    `xml:"total_fee"`
	OutRefundNo   string `xml:"out_refund_no"`
	RefundFee     int    `xml:"refund_fee"`
	NotifyUrl     string `xml:"notify_url,omitempty"`
}

RefundRequest 退款请求

func (*RefundRequest) ToParam

func (req *RefundRequest) ToParam(app *App) (param map[string]interface{}, err error)

ToParam 参数转换

type RefundResponse

type RefundResponse struct {
	Response `xml:",innerXml"`

	TransactionId string `xml:"transaction_id"`
	OutTradeNo    string `xml:"out_trade_no"`
	OutRefundNo   string `xml:"out_refund_no"`
	RefundId      string `xml:"refund_id"`
	RefundFee     int    `xml:"refund_fee"`
	TotalFee      int    `xml:"total_fee"`
	CashFee       int    `xml:"cash_fee"`
}

type Response

type Response struct {
	XMLName    xml.Name `xml:"xml"`
	ReturnCode string   `xml:"return_code"`
	ReturnMsg  string   `xml:"return_msg"`
	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"`    // 签名类型
	ResultCode string   `xml:"result_code"`  // 业务结果
	ErrCode    string   `xml:"err_code"`     // 错误码
	ErrCodeDes string   `xml:"err_code_des"` // 错误描述
}

Response 接口返回

type UnifiedOrderRequest

type UnifiedOrderRequest struct {
	Body           string `xml:"body"`             // 商品描述
	OutTradeNo     string `xml:"out_trade_no"`     // 商户订单号
	TotalFee       int    `xml:"total_fee"`        // 标价金额
	SpbillCreateIp string `xml:"spbill_create_ip"` // 终端IP
	OpenId         string `xml:"openid"`           // 用户标识,JSAPI支付此参数必传
}

UnifiedOrderRequest 支付参数

func (*UnifiedOrderRequest) ToParam

func (req *UnifiedOrderRequest) ToParam(app *App) (param map[string]interface{}, err error)

ToParam 参数转换

type UnifiedOrderResponse

type UnifiedOrderResponse struct {
	Response `xml:",innerXml"`

	TradeType string `xml:"trade_type"` // 交易类型
	PrepayId  string `xml:"prepay_id"`  // 预支付交易会话标识
	CodeURL   string `xml:"code_url"`   // 二维码链接
}

UnifiedOrderResponse 支付返回

Jump to

Keyboard shortcuts

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