payment

package
v0.0.0-...-77647f8 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KEY_LENGTH_BYTE      = 32
	AUTH_TAG_LENGTH_BYTE = 16
)
View Source
const (
	MessageEventType = "TRANSACTION.SUCCESS" //支付通知状态
	MessageResCode   = "SUCCESS"             //成功返回到code值
	PaySuccess       = "SUCCESS"             //支付成功
	PayRefund        = "REFUND"              //转入退款
	PayNotPay        = "NOTPAY"              //未支付
	PayClosed        = "CLOSED"              //已关闭
	Paying           = "USERPAYING"          //正在支付中(付款码)
	PayRevoked       = "REVOKED"             //已撤销(付款码)
	PayError         = "PAYERROR"            //支付失败
)
View Source
const (
	AUTH_TYPE = "WECHATPAY2-SHA256-RSA2048"
)
View Source
const (
	BASE_API_URI = "https://api.mch.weixin.qq.com"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bill

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

Bill 账单管理

func (*Bill) DownloadBill

func (b *Bill) DownloadBill(ctx context.Context, downloadURL string) *BillResponse

DownloadBill 下载账单文件

func (*Bill) GetFundBill

func (b *Bill) GetFundBill(ctx context.Context, req BillRequest) *BillResponse

GetFundBill 获取资金账单

func (*Bill) GetTradeBill

func (b *Bill) GetTradeBill(ctx context.Context, req BillRequest) *BillResponse

GetTradeBill 获取交易账单

type BillRequest

type BillRequest struct {
	BillDate string `json:"bill_date"`           // 账单日期
	BillType string `json:"bill_type,omitempty"` // 账单类型
	SubMchID string `json:"sub_mchid,omitempty"` // 子商户号
	TarType  string `json:"tar_type,omitempty"`  // 压缩账单类型
}

BillRequest 账单请求参数

type BillResponse

type BillResponse struct {
	*gjson.Json
}

BillResponse 账单响应

func (*BillResponse) BillURL

func (b *BillResponse) BillURL() string

BillURL 获取账单下载地址

func (*BillResponse) ErrCode

func (b *BillResponse) ErrCode() int

ErrCode 错误码

func (*BillResponse) ErrMsg

func (b *BillResponse) ErrMsg() string

ErrMsg 错误信息

func (*BillResponse) HashType

func (b *BillResponse) HashType() string

HashType 哈希类型

func (*BillResponse) HashValue

func (b *BillResponse) HashValue() string

HashValue 哈希值

func (*BillResponse) Success

func (b *BillResponse) Success() bool

Success 是否成功

type Client

type Client struct {
	*gclient.Client

	UrlValues url.Values
	// Logger  *log.Logger
	BaseUri string
	// contains filtered or unexported fields
}

func (*Client) RequestJson

func (c *Client) RequestJson(ctx context.Context, method string, endpoint string, data ...interface{}) *Response

RequestJson v3

func (*Client) RequestV2

func (c *Client) RequestV2(ctx context.Context, method string, endpoint string, data ...interface{}) *Response

v2 requst with cert tls

type ClientResponse

type ClientResponse struct {
	*gclient.Response
}

type Config

type Config struct {
	AppID string `json:"app_id"` //公众号
	MchID string `json:"mch_id"` //商户号
	//v2接口
	Key      string `json:"key"`       //API 秘钥
	CertPath string `json:"cert_path"` //API 证书路径 绝对路径!!!
	KeyPath  string `json:"key_path"`  //绝对路径!!!
	Sandbox  bool   `json:"sandbox"`   //沙盒模式
	//v3接口
	SerialNo    string            `json:"serial_no"`         //商户证书编号
	PriCertPath string            `json:"private_cert_path"` //私钥证书路径 绝对路径!!!
	PubCertPath string            `json:"public_cert_Path"`  //公钥证书路径 绝对路径!!!
	PublicCer   *x509.Certificate //商户证书公钥
	PrivateCer  interface{}       //商户证书私钥

	PFSerialNo     string            //平台证书编号
	PFPublicCer    *x509.Certificate //平台证书公钥
	PFCertSavePath string            //平台证书保存路径 绝对路径!!!
	PFCertPrefix   string            //平台证书保存前缀
	ApiV3Key       string            //apiv3 秘钥

	//公用
	NotifyUrl string `json:"notify_url"` //默认回调地址

	//服务商参数
	SubMchID string `json:"sub_mch_id"`
	SubAppID string `json:"sub_appid"`
	//others
	Logger  *log.Logger
	LogPath string
}

Config

type Jssdk

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

type Marketing

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

营销

func (*Marketing) Redpack

func (m *Marketing) Redpack() *Redpack

红包

type Notify

type Notify struct {
	Request  *ehttp.Request
	Response *ehttp.Response

	Message *NotifyMessage // 消息数据包含原始数据
	// contains filtered or unexported fields
}

支付通知

func (*Notify) HandlePaid

func (n *Notify) HandlePaid(ctx context.Context, f func(message *NotifyMessage) (bool, error))

支付通知处理

type NotifyMessage

type NotifyMessage struct {
	Raw         *gjson.Json //原始数据,未解密 获取消息id,通知时间等用原始数据获取
	*gjson.Json             //解密后的数据 这里面不包含原始数据,只包含解密后的resource
}

type NotifyRes

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

type Order

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

func (*Order) H5

func (o *Order) H5()

H5下单

func (*Order) Jsapi

func (o *Order) Jsapi(ctx context.Context, prepay jsapi.PrepayRequest) (p jsapi.PrepayRes, err error)

Jsapi 下单

func (*Order) Query

func (o *Order) Query(ctx context.Context) *QueryOrder

Query 订单查询

func (*Order) Set

func (o *Order) Set(pattern string, value interface{})

Set

type OrderConfig

type OrderConfig struct {
	AppID string `json:"appid"`
	MchID string `json:"mchid"`
}

订单

type Payment

type Payment struct {
	Logger *log.Logger
	Cache  *gcache.Cache
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, config Config, compatible ...bool) *Payment

New

func (*Payment) Certificates

func (p *Payment) Certificates()

func (*Payment) GCMDecryte

func (p *Payment) GCMDecryte(associateData, cipherText, nonce string) ([]byte, error)

aes-256-gcm

func (*Payment) Jssdk

func (p *Payment) Jssdk(prepayId string) *Jssdk

Jssdk

func (*Payment) Marketing

func (p *Payment) Marketing() *Marketing

Markting

func (*Payment) Notify

func (p *Payment) Notify(r *http.Request, w http.ResponseWriter) *Notify

获取支付通知

func (*Payment) Order

func (p *Payment) Order() *Order

Order

func (*Payment) V2MD5

func (p *Payment) V2MD5(m map[string]interface{}) string

v2 md5签名

func (*Payment) V2Signature

func (p *Payment) V2Signature(str string) string

v2加密

func (*Payment) V2SortKey

func (p *Payment) V2SortKey(text map[string]interface{}) string

v2排序

func (*Payment) VerifySignature

func (p *Payment) VerifySignature(ctx context.Context, header http.Header, body []byte) error

应答及回调验签

type QueryOrder

type QueryOrder struct {
	Code int
	*gjson.Json
}

QueryOrder @see https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_2.shtml 返回参数

type Redpack

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

营销红包 v2 @see https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3

func (*Redpack) GetInfo

func (r *Redpack) GetInfo(ctx context.Context, billno string) *ResponseResult

查询红包发送情况,根据商户订单号

func (*Redpack) New

func (r *Redpack) New(config map[string]interface{}) *Redpack

配置 传入需要参数 校验参数

func (*Redpack) Send

func (r *Redpack) Send(ctx context.Context) *ResponseResult

红包发送

func (*Redpack) Set

func (r *Redpack) Set(pattern string, value interface{})

设置参数

type Refund

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

Refund 退款管理

func (*Refund) QueryRefund

func (r *Refund) QueryRefund(ctx context.Context, outRefundNo string) *RefundResponse

QueryRefund 查询退款

func (*Refund) Refund

func (r *Refund) Refund(ctx context.Context, req RefundRequest) *RefundResponse

Refund 申请退款

type RefundAmount

type RefundAmount struct {
	Total       int      `json:"total"`                  // 订单金额
	Refund      int      `json:"refund"`                 // 退款金额
	From        []string `json:"from,omitempty"`         // 退款出资账户
	TotalFee    int      `json:"total_fee,omitempty"`    // 应结订单金额
	RefundFee   int      `json:"refund_fee,omitempty"`   // 退款金额
	RefundTotal int      `json:"refund_total,omitempty"` // 退款总出资
}

RefundAmount 退款金额信息

type RefundGoodsDetail

type RefundGoodsDetail struct {
	MerchantGoodsID  string `json:"merchant_goods_id"`            // 商户商品编码
	WechatpayGoodsID string `json:"wechatpay_goods_id,omitempty"` // 微信商品编码
	GoodsName        string `json:"goods_name,omitempty"`         // 商品名称
	UnitPrice        int    `json:"unit_price"`                   // 商品单价
	RefundAmount     int    `json:"refund_amount"`                // 商品退款金额
	RefundQuantity   int    `json:"refund_quantity"`              // 商品退款数量
}

RefundGoodsDetail 退款商品详情

type RefundRequest

type RefundRequest struct {
	TransactionID string              `json:"transaction_id,omitempty"` // 微信支付订单号
	OutTradeNo    string              `json:"out_trade_no,omitempty"`   // 商户订单号
	OutRefundNo   string              `json:"out_refund_no"`            // 商户退款单号
	Reason        string              `json:"reason,omitempty"`         // 退款原因
	NotifyURL     string              `json:"notify_url,omitempty"`     // 退款结果通知 url
	FundsAccount  string              `json:"funds_account,omitempty"`  // 退款资金来源
	Amount        RefundAmount        `json:"amount"`                   // 金额信息
	GoodsDetail   []RefundGoodsDetail `json:"goods_detail,omitempty"`   // 订单商品列表
}

RefundRequest 退款请求参数

type RefundResponse

type RefundResponse struct {
	*gjson.Json
}

RefundResponse 退款响应

func (*RefundResponse) ErrCode

func (r *RefundResponse) ErrCode() int

ErrCode 错误码

func (*RefundResponse) ErrMsg

func (r *RefundResponse) ErrMsg() string

ErrMsg 错误信息

func (*RefundResponse) RefundID

func (r *RefundResponse) RefundID() string

RefundID 退款单号

func (*RefundResponse) Status

func (r *RefundResponse) Status() string

Status 退款状态

func (*RefundResponse) Success

func (r *RefundResponse) Success() bool

Success 是否成功

type Response

type Response struct {
	Status     string
	StatusCode int
	Header     http.Header
	Body       []byte
}

func (*Response) ReadAll

func (r *Response) ReadAll() []byte

ReadAll

func (*Response) ReadAllString

func (r *Response) ReadAllString() string

ReadAllString

type ResponseResult

type ResponseResult struct {
	*gjson.Json
}

Directories

Path Synopsis
model

Jump to

Keyboard shortcuts

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