pay

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package pay 微信支付的相关接口

Index

Constants

View Source
const (
	Success = "SUCCESS"
	Fail    = "FAIL"
)

返回状态的值

View Source
const (
	UnifiedOrderURL = "https://api.mch.weixin.qq.com/pay/unifiedorder"
	OrderQueryURL   = "https://api.mch.weixin.qq.com/pay/orderquery"
	CloseOrderURL   = "https://api.mch.weixin.qq.com/pay/closeorder"
	RefundURL       = "https://api.mch.weixin.qq.com/secapi/pay/refund"
	RefundQueryURL  = "https://api.mch.weixin.qq.com/pay/refundquery"
	DownloadBillURL = "https://api.mch.weixin.qq.com/pay/downloadbill"
	ReportURL       = "https://api.mch.weixin.qq.com/payitil/report"
)

接口地址

View Source
const (
	TradeTypeJSAPI  = "JSAPI"  // 公众号
	TradeTypeNative = "NATIVE" // 扫码
	TradeTypeApp    = "APP"
)

交易类型

View Source
const (
	SignTypeMD5        = "MD5"
	SignTypeHmacSha256 = "HMAC-SHA256"
)

签名的类型

View Source
const (
	RefundSourceRechargeFunds  = "REFUND_SOURCE_UNSETTLED_FUNDS" // 可用余额退款
	RefundSourceUnsettledFunds = "REFUND_SOURCE_UNSETTLED_FUNDS" // 未结算资金退款(默认使用未结算资金退款)
)

退款奖金来源

View Source
const (
	RefundChannelOriginal = "ORIGINAL" // 原路退款
	RefundChannelBalance  = "BALANCE"  // 退回到余额
)

退款渠道

View Source
const (
	CouponTypeCash   = "CASH"    // 充值代金券
	CouponTypeNoCash = "NO_CASH" // 非充值代金券
)

代金券类型

View Source
const DateFormat = "20060102150405"

DateFormat 日期格式

View Source
const TimeFixed time.Duration = 3600 * 8

TimeFixed 时间戳调整,东八区

Variables

View Source
var (
	ErrInvalidAppid = errors.New("返回的 appid 与当前的不匹配")
	ErrInvalidMchid = errors.New("返回的 mch_id 与当前的不匹配")
	ErrInvalidSign  = errors.New("不存在签名或是签名无法验证")
)

预定义的错误类型

Functions

func NonceString

func NonceString() string

NonceString 产生一段随机字符串

func Sign

func Sign(apikey, signType string, params map[string]string) (string, error)

Sign 微信支付签名

apikey 支付用的 apikey params 签名用的参数 fn 签名的类型,为空则为 md5

Types

type Coupon

type Coupon struct {
	ID   int    // 代金券ID
	Type string // 代金券类型,CASH--充值代金券、NO_CASH--非充值代金券
	Fee  int    // 单个代金券支付金额
}

Coupon 代金券

func GetCoupons

func GetCoupons(params map[string]string) ([]*Coupon, error)

GetCoupons 从 params 获取所有的代金券信息

type Pay

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

Pay 支付的基本配置

func New

func New(mchid, appid, apikey string, client *http.Client) *Pay

New 声明一个新的 *Pay 实例

client 若为空,则采用 http.DefaultClient

func NewTLSPay

func NewTLSPay(mchid, appid, apikey, certPath, keyPath, rootCAPath string) (*Pay, error)

NewTLSPay 声明一个带证书的支付实例

如果想要用系统的根证书,则将 rootCAPath 置为空就行。

func (*Pay) APIKey

func (p *Pay) APIKey() string

APIKey 获取 apikey

func (*Pay) AppID

func (p *Pay) AppID() string

AppID 获取 appid

func (*Pay) CloseOrder

func (p *Pay) CloseOrder(params map[string]string) (map[string]string, error)

CloseOrder 关闭订单

func (*Pay) DownloadBill

func (p *Pay) DownloadBill(params map[string]string) (map[string]string, error)

DownloadBill 下载对账单

func (*Pay) MchID

func (p *Pay) MchID() string

MchID 获取商户 ID

func (*Pay) OrderQuery

func (p *Pay) OrderQuery(params map[string]string) (map[string]string, error)

OrderQuery 订单查询

func (*Pay) Post

func (p *Pay) Post(url string, params map[string]string) (map[string]string, error)

Post 发送请求,会优先使用 params 中的相关参数。 比如:若已经指定了 appid,会不会使用 pay.AppID; 若使用了 sign,则不会再计算 sign 值。

func (*Pay) Refund

func (p *Pay) Refund(params map[string]string) (map[string]string, error)

Refund 退款

func (*Pay) RefundQuery

func (p *Pay) RefundQuery(params map[string]string) (map[string]string, error)

RefundQuery 退款查询

func (*Pay) Report

func (p *Pay) Report(params map[string]string) (map[string]string, error)

Report 主动上报接口

func (*Pay) Sign

func (p *Pay) Sign(signType string, params map[string]string) (string, error)

Sign 获取签名字符串

func (*Pay) UnifiedOrder

func (p *Pay) UnifiedOrder(params map[string]string) (map[string]string, error)

UnifiedOrder 执行统一下单

func (*Pay) ValidateAll

func (p *Pay) ValidateAll(signType string, params map[string]string) error

ValidateAll 验证 ValidateSign 和 appid 及 mchid 是否匹配

func (*Pay) ValidateResult

func (p *Pay) ValidateResult(params map[string]string) error

ValidateResult 验证从微信端返回的数据,同时验证 return_code 和 result_code

func (*Pay) ValidateReturn

func (p *Pay) ValidateReturn(params map[string]string) error

ValidateReturn 验证从微信端返回的数据,仅验证 return_code

func (*Pay) ValidateSign

func (p *Pay) ValidateSign(signType string, params map[string]string) error

ValidateSign 验证从微信端返回的数据,同时验证 ValidateResult 和 签名

Directories

Path Synopsis
Package notify 用于处理微信回调通知
Package notify 用于处理微信回调通知
Package refund 执行退款操作
Package refund 执行退款操作
Package unifiedorder 执行微信的下单操作
Package unifiedorder 执行微信的下单操作

Jump to

Keyboard shortcuts

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