ysepay

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

README

ysepay-go

golang GitHub release pkg.go.dev Apache 2.0 license

银盛支付 Go SDK

go get -u github.com/shenghui0779/ysepay-go

Documentation

Index

Constants

View Source
const (
	SysOK        = "SYS000" // 网关受理成功响应码
	SysAccepting = "SYS001" // 网关受理中响应码

	ComOK         = "COM000" // 业务受理成功
	ComProcessing = "COM004" // 业务处理中
)

Variables

View Source
var ErrSysAccepting = errors.New("SYS001 | 网关受理中")

ErrSysAccepting 网关受理中

Functions

func DESDecryptECB added in v1.0.3

func DESDecryptECB(key, data []byte) ([]byte, error)

DESDecryptECB DES-ECB 解密

func DESEncryptECB added in v1.0.3

func DESEncryptECB(key, data []byte) ([]byte, error)

DESEncryptECB DES-ECB 加密

func HeaderEncode

func HeaderEncode(h http.Header) string

func LoadCertFromPfxFile

func LoadCertFromPfxFile(filename, password string) (tls.Certificate, error)

LoadCertFromPfxFile 通过pfx(p12)证书文件生成TLS证书 注意:证书需采用「TripleDES-SHA1」加密方式

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.

Types

type Client

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

Client 银盛支付客户端

func NewClient

func NewClient(mchNO, desKey string, options ...Option) *Client

NewClient 生成银盛支付客户端

func (*Client) Decrypt

func (c *Client) Decrypt(cipher string) (string, error)

Decrypt 敏感数据DES解密

func (*Client) Encrypt

func (c *Client) Encrypt(plain string) (string, error)

Encrypt 敏感数据DES加密

func (*Client) MchNO

func (c *Client) MchNO() string

MchNO 返回商户号

func (*Client) MustEncrypt

func (c *Client) MustEncrypt(plain string) string

MustEncrypt 敏感数据DES加密;若发生错误,则Panic

func (*Client) PostForm

func (c *Client) PostForm(ctx context.Context, api, serviceNO string, bizData V) (gjson.Result, error)

PostForm 发送POST表单请求

func (*Client) VerifyNotify

func (c *Client) VerifyNotify(form url.Values) (gjson.Result, error)

VerifyNotify 解析并验证异步回调通知,返回BizJSON数据

type HTTPClient

type HTTPClient interface {
	// Do 发送HTTP请求
	// 注意:应该使用Context设置请求超时时间
	Do(ctx context.Context, method, reqURL string, body []byte, options ...HTTPOption) (*http.Response, error)
}

HTTPClient HTTP客户端

func NewDefaultHTTPClient

func NewDefaultHTTPClient() HTTPClient

NewDefaultHTTPClient 生成一个默认的HTTP客户端

func NewHTTPClient

func NewHTTPClient(cli *http.Client) HTTPClient

NewHTTPClient 通过官方 `http.Client` 生成一个HTTP客户端

type HTTPOption

type HTTPOption func(o *httpOptions)

HTTPOption HTTP请求选项

func WithHTTPClose

func WithHTTPClose() HTTPOption

WithHTTPClose 请求结束后关闭请求

func WithHTTPCookies

func WithHTTPCookies(cookies ...*http.Cookie) HTTPOption

WithHTTPCookies 设置HTTP请求Cookie

func WithHTTPHeader

func WithHTTPHeader(key string, vals ...string) HTTPOption

WithHTTPHeader 设置HTTP请求头

type Option

type Option func(c *Client)

Option 自定义设置项

func WithHttpCli

func WithHttpCli(cli *http.Client) Option

WithHttpCli 设置自定义 HTTP Client

func WithLogger

func WithLogger(f func(ctx context.Context, data map[string]string)) Option

WithLogger 设置日志记录

func WithPrivateKey

func WithPrivateKey(key *PrivateKey) Option

WithPrivateKey 设置商户RSA私钥

func WithPublicKey

func WithPublicKey(key *PublicKey) Option

WithPublicKey 设置平台RSA公钥

type PrivateKey

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

PrivateKey RSA私钥

func NewPrivateKeyFromPemBlock

func NewPrivateKeyFromPemBlock(mode RSAPadding, pemBlock []byte) (*PrivateKey, error)

NewPrivateKeyFromPemBlock 通过PEM字节生成RSA私钥

func NewPrivateKeyFromPemFile

func NewPrivateKeyFromPemFile(mode RSAPadding, pemFile string) (*PrivateKey, error)

NewPrivateKeyFromPemFile 通过PEM文件生成RSA私钥

func NewPrivateKeyFromPfxFile

func NewPrivateKeyFromPfxFile(pfxFile, password string) (*PrivateKey, error)

NewPrivateKeyFromPfxFile 通过pfx(p12)证书生成RSA私钥 注意:证书需采用「TripleDES-SHA1」加密方式

func (*PrivateKey) Decrypt

func (pk *PrivateKey) Decrypt(data []byte) ([]byte, error)

Decrypt RSA私钥 PKCS#1 v1.5 解密

func (*PrivateKey) DecryptOAEP

func (pk *PrivateKey) DecryptOAEP(hash crypto.Hash, data []byte) ([]byte, error)

DecryptOAEP RSA私钥 PKCS#1 OAEP 解密

func (*PrivateKey) Sign

func (pk *PrivateKey) Sign(hash crypto.Hash, data []byte) ([]byte, error)

Sign RSA私钥签名

type PublicKey

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

PublicKey RSA公钥

func NewPublicKeyFromDerBlock

func NewPublicKeyFromDerBlock(pemBlock []byte) (*PublicKey, error)

NewPublicKeyFromDerBlock 通过DER字节生成RSA公钥 注意PEM格式: -----BEGIN CERTIFICATE----- | -----END CERTIFICATE----- DER转换命令: openssl x509 -inform der -in cert.cer -out cert.pem

func NewPublicKeyFromDerFile

func NewPublicKeyFromDerFile(pemFile string) (*PublicKey, error)

NewPublicKeyFromDerFile 通过DER证书生成RSA公钥 注意PEM格式: -----BEGIN CERTIFICATE----- | -----END CERTIFICATE----- DER转换命令: openssl x509 -inform der -in cert.cer -out cert.pem

func NewPublicKeyFromPemBlock

func NewPublicKeyFromPemBlock(mode RSAPadding, pemBlock []byte) (*PublicKey, error)

NewPublicKeyFromPemBlock 通过PEM字节生成RSA公钥

func NewPublicKeyFromPemFile

func NewPublicKeyFromPemFile(mode RSAPadding, pemFile string) (*PublicKey, error)

NewPublicKeyFromPemFile 通过PEM文件生成RSA公钥

func (*PublicKey) Encrypt

func (pk *PublicKey) Encrypt(plainText []byte) ([]byte, error)

Encrypt RSA公钥 PKCS#1 v1.5 加密

func (*PublicKey) EncryptOAEP

func (pk *PublicKey) EncryptOAEP(hash crypto.Hash, plainText []byte) ([]byte, error)

EncryptOAEP RSA公钥 PKCS#1 OAEP 加密

func (*PublicKey) Verify

func (pk *PublicKey) Verify(hash crypto.Hash, data, signature []byte) error

Verify RSA公钥验签

type RSAPadding added in v1.0.2

type RSAPadding int

RSAPadding RSA PEM 填充模式

const (
	RSA_PKCS1 RSAPadding = 1 // PKCS#1 (格式:`RSA PRIVATE KEY` 和 `RSA PUBLIC KEY`)
	RSA_PKCS8 RSAPadding = 8 // PKCS#8 (格式:`PRIVATE KEY` 和 `PUBLIC KEY`)
)

type ReqLog

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

ReqLog 请求日志

func NewReqLog

func NewReqLog(method, reqURL string) *ReqLog

NewReqLog 生成请求日志

func (*ReqLog) Do

func (l *ReqLog) Do(ctx context.Context, log func(ctx context.Context, data map[string]string))

Do 日志记录

func (*ReqLog) Set

func (l *ReqLog) Set(k, v string)

Set 设置日志K-V

func (*ReqLog) SetReqBody

func (l *ReqLog) SetReqBody(v string)

SetBody 设置请求Body

func (*ReqLog) SetReqHeader

func (l *ReqLog) SetReqHeader(h http.Header)

SetReqHeader 设置请求头

func (*ReqLog) SetRespBody

func (l *ReqLog) SetRespBody(v string)

SetResp 设置返回报文

func (*ReqLog) SetRespHeader

func (l *ReqLog) SetRespHeader(h http.Header)

SetRespHeader 设置返回头

func (*ReqLog) SetStatusCode

func (l *ReqLog) SetStatusCode(code int)

SetStatusCode 设置HTTP状态码

type V

type V map[string]string

V 用于处理 k-v 需要格式化的场景,如:签名

func (V) Del

func (v V) Del(key string)

Del 删除Key

func (V) Encode

func (v V) Encode(sym, sep string, options ...VEncOption) string

Encode 通过自定义的符号和分隔符按照key的ASCII码升序格式化为字符串。 例如:("=", "&") ---> bar=baz&foo=quux; 例如:(":", "#") ---> bar:baz#foo:quux;

func (V) Get

func (v V) Get(key string) string

Get 获取值

func (V) Has

func (v V) Has(key string) bool

Has 判断Key是否存在

func (V) Set

func (v V) Set(key, value string)

Set 设置 k-v

type VEmptyMode added in v1.0.4

type VEmptyMode int

VEmptyMode 值为空时的Encode模式

const (
	EmptyDefault VEmptyMode = iota // 默认:bar=baz&foo=
	EmptyIgnore                    // 忽略:bar=baz
	EmptyOnlyKey                   // 仅保留Key:bar=baz&foo
)

type VEncOption

type VEncOption func(o *vEncOptions)

VEncOption V Encode 选项

func WithEmptyMode added in v1.0.4

func WithEmptyMode(mode VEmptyMode) VEncOption

WithEmptyMode 设置值为空时的Encode模式

func WithIgnoreKeys

func WithIgnoreKeys(keys ...string) VEncOption

WithIgnoreKeys 设置Encode时忽略的key

func WithKVEscape

func WithKVEscape() VEncOption

WithKVEscape 设置K-V是否需要QueryEscape

Jump to

Keyboard shortcuts

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