payment

package
v0.0.0-...-15a7b9f Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MIT Imports: 35 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 Client

type Client struct {
	*ghttp.Client

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

func (*Client) RequestJson

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

RequestJson v3

func (*Client) RequestV2

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

v2 requst with cert tls

type ClientResponse

type ClientResponse struct {
	*ghttp.ClientResponse
}

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(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() (string, error)

Jsapi 下单

func (*Order) Query

func (o *Order) Query() *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(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(config ...map[string]interface{}) *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(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(billno string) *ResponseResult

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

func (*Redpack) New

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

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

func (*Redpack) Send

func (r *Redpack) Send() *ResponseResult

红包发送

func (*Redpack) Set

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

设置参数

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
}

Jump to

Keyboard shortcuts

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