sandpay

package
v0.0.0-...-0cfe510 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const OK = "000000"

Variables

This section is empty.

Functions

func GeneratePostData

func GeneratePostData(signDataJsonString string, sign string) map[string]string

func GenerateSignString

func GenerateSignString(body interface{}, header interface{}) (str string)

func MarshalNoEscapeHTML

func MarshalNoEscapeHTML(v interface{}) ([]byte, error)

MarshalNoEscapeHTML marshal with no escape HTML

func NewSandV4Client

func NewSandV4Client(options ...SandV4Option) (*sandV4Client, error)

func NewSandV5Client

func NewSandV5Client(options ...SandV5Option) (*sandV5Client, error)

Types

type AccountInfoQueryReq

type AccountInfoQueryReq struct {
	Version         string `json:"version"`
	Mid             string `json:"mid"`
	CustomerOrderNo string `json:"customerOrderNo"`
	SignType        string `json:"signType"`
	EncryptType     string `json:"encryptType"`
	Timestamp       string `json:"timestamp,omitempty"`
	BizUserNo       string `json:"bizUserNo,omitempty"`
	EncryptKey      string `json:"encryptKey,omitempty"`
	Data            string `json:"data,omitempty"`
	Sign            string `json:"sign,omitempty"`
}

type AccountInfoQueryResponse

type AccountInfoQueryResponse struct {
	ResponseDesc      string `json:"responseDesc"`
	ResponseStatus    string `json:"responseStatus"`
	OpenAccountStatus string `json:"openAccountStatus"`
	FaceStatus        string `json:"faceStatus"`
}

type B2cPayeeReq

type B2cPayeeReq struct {
	BizUserNo string `json:"bizUserNo"`
	Name      string `json:"name"`
}

type B2cReq

type B2cReq struct {
	Version         string      `json:"version"`
	Mid             string      `json:"mid"`
	CustomerOrderNo string      `json:"customerOrderNo"`
	SignType        string      `json:"signType"`
	EncryptType     string      `json:"encryptType"`
	Timestamp       string      `json:"timestamp,omitempty"`
	EncryptKey      string      `json:"encryptKey,omitempty"`
	Data            string      `json:"data,omitempty"`
	Sign            string      `json:"sign,omitempty"`
	AccountType     string      `json:"accountType,omitempty"`
	OrderAmt        float64     `json:"orderAmt,omitempty"`
	Payee           B2cPayeeReq `json:"payee,omitempty"`
	Postscript      string      `json:"postscript,omitempty"`
	Remark          string      `json:"remark,omitempty"`
}

type B2cResponse

type B2cResponse struct {
	ResponseDesc   string `json:"responseDesc"`
	ResponseStatus string `json:"responseStatus"`
	OrderStatus    string `json:"OrderStatus"`
}

type Client

type Client interface {
	// Do 请求杉德API
	Do(ctx context.Context, reqURL string, form url.Values) (*Data, error)

	// Form 生成统一的POST表单(用于API请求或前端表单提交)
	Form(method, productID string, body X, options ...HeadOption) (url.Values, error)

	// Verify 验证并解析杉德API结果或回调通知
	Verify(form url.Values) (*Data, error)
}

Client 杉德支付客户端

func NewClient

func NewClient(cfg *Config, options ...ClientOption) (Client, error)

type ClientOption

type ClientOption func(c *client)

ClientOption 客户端配置项

func WithHTTPClient

func WithHTTPClient(cli *http.Client) ClientOption

WithHTTPClient 自定义http.Client

type CloseAccountConfirmReq

type CloseAccountConfirmReq struct {
	Version            string `json:"version"`
	Mid                string `json:"mid"`
	CustomerOrderNo    string `json:"customerOrderNo"`
	OriCustomerOrderNo string `json:"oriCustomerOrderNo"`
	SignType           string `json:"signType"`
	EncryptType        string `json:"encryptType"`
	Timestamp          string `json:"timestamp,omitempty"`
	EncryptKey         string `json:"encryptKey,omitempty"`
	Data               string `json:"data,omitempty"`
	Sign               string `json:"sign,omitempty"`
	AccountType        string `json:"accountType,omitempty"`
	BizUserNo          string `json:"bizUserNo,omitempty"`
	SmsCode            string `json:"smsCode,omitempty"`
}

type CloseAccountReq

type CloseAccountReq struct {
	Version         string  `json:"version"`
	Mid             string  `json:"mid"`
	CustomerOrderNo string  `json:"customerOrderNo"`
	SignType        string  `json:"signType"`
	EncryptType     string  `json:"encryptType"`
	Timestamp       string  `json:"timestamp,omitempty"`
	EncryptKey      string  `json:"encryptKey,omitempty"`
	Data            string  `json:"data,omitempty"`
	Sign            string  `json:"sign,omitempty"`
	AccountType     string  `json:"accountType,omitempty"`
	OrderAmt        float64 `json:"orderAmt,omitempty"`
	BizUserNo       string  `json:"bizUserNo,omitempty"`
	BizType         string  `json:"bizType,omitempty"`
	Postscript      string  `json:"postscript,omitempty"`
	Remark          string  `json:"remark,omitempty"`
	NotifyUrl       string  `json:"notifyUrl,omitempty"`
	FrontUrl        string  `json:"returnUrl,omitempty"`
}

type Config

type Config struct {
	MID      string // 商户ID
	KeyFile  string // 商户私钥(PEM格式)
	CertFile string // 杉德公钥(PEM格式)
}

Config 客户端配置

type Data

type Data struct {
	Head X `json:"head"`
	Body X `json:"body"`
}

type HeadOption

type HeadOption func(h X)

HeadOption 报文头配置项

func WithAccessType

func WithAccessType(at string) HeadOption

WithAccessType 设置接入类型:1 - 普通商户接入(默认);2 - 平台商户接入

func WithChannelType

func WithChannelType(ct string) HeadOption

WithChannelType 设置渠道类型:07 - 互联网(默认);08 - 移动端

func WithPLMid

func WithPLMid(id string) HeadOption

WithPLMid 设置平台ID:接入类型为2时必填,在担保支付模式下填写核心商户号;在杉德宝平台终端模式下填写平台商户号

func WithVersion

func WithVersion(v string) HeadOption

WithVersion 设置版本号:默认:1.0;功能产品号为微信小程序或支付宝生活号,对账单需获取营销优惠金额字段传:3.0

type Header struct {
	Version    string `json:"version"`
	Method     string `json:"method"`
	Mid        string `json:"mid"`
	AccessType string `json:"accessType"`
	//PlMid       string `json:"plMid"`
	ChannelType string `json:"channelType"`
	ReqTime     string `json:"reqTime"`
	ProductId   string `json:"productId"`
}

type OrderQueryBody

type OrderQueryBody struct {
	//商户订单号
	OrderCode string `json:"orderCode"`
	//19. 扩展域
	Extends string `json:"extends"`
}

type OrderQueryResponseBodyData

type OrderQueryResponseBodyData struct {
	OrderStatus string `json"orderStatus"`
}

type OrderQueryResponseData

type OrderQueryResponseData struct {
	Head *OrderQueryResponseHeadData `json:"head"`
	Body *OrderQueryResponseBodyData `json:"body"`
}

type OrderQueryResponseHeadData

type OrderQueryResponseHeadData struct {
	RespCode string `json"respCode"`
}

type PemBlockType

type PemBlockType string

PemBlockType pem block type which taken from the preamble.

const (
	// RSAPKCS1 private key in PKCS#1
	RSAPKCS1 PemBlockType = "RSA PRIVATE KEY"
	// RSAPKCS8 private key in PKCS#8
	RSAPKCS8 PemBlockType = "PRIVATE KEY"
)

type PostData

type PostData struct {
	Charset  string `json:"charset"`
	SignType string `json:"signType"`
	Data     string `json:"data"`
	Sign     string `json:"sign"`
}

type PrivateKey

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

PrivateKey RSA private key

func NewPrivateKeyFromPemFile

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

NewPrivateKeyFromPemFile returns new private key with pem file.

func (*PrivateKey) Decrypt

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

Decrypt rsa decrypt with PKCS #1 v1.5

func (*PrivateKey) Sign

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

Sign returns sha-with-rsa signature.

type PublicKey

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

PublicKey RSA public key

func NewPublicKeyFromDerFile

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

NewPublicKeyFromDerFile returns public key with DER file. NOTE: PEM format with -----BEGIN CERTIFICATE----- | -----END CERTIFICATE----- openssl x509 -inform der -in cert.cer -out cert.pem

func (*PublicKey) Encrypt

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

Encrypt rsa encrypt with PKCS #1 v1.5

func (*PublicKey) Verify

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

Verify verifies the sha-with-rsa signature.

type Response

type Response struct {
	Charset  string `json:"charset"`
	Data     string `json:"data"`
	SignType string `json:"signType"`
	Body     string `json:"body"`
}

type SandV4Option

type SandV4Option func(c *sandV4Client)

ClientOption 客户端配置项

func WithV4MerNo

func WithV4MerNo(merNo string) SandV4Option

merNo, prvKeyFile, pubKeyFile, notifyUrl, returnUrl string

func WithV4NotifyUrl

func WithV4NotifyUrl(file string) SandV4Option

func WithV4PrvKeyFile

func WithV4PrvKeyFile(file string) SandV4Option

func WithV4PubKeyFile

func WithV4PubKeyFile(file string) SandV4Option

func WithV4ReturnUrl

func WithV4ReturnUrl(file string) SandV4Option

func WithV4UserFlag

func WithV4UserFlag(flag string) SandV4Option

type SandV5Option

type SandV5Option func(c *sandV5Client)

ClientOption 客户端配置项

func WithMerNo

func WithMerNo(merNo string) SandV5Option

merNo, prvKeyFile, pubKeyFile, notifyUrl, returnUrl string

func WithNotifyUrl

func WithNotifyUrl(file string) SandV5Option

func WithPrvKeyFile

func WithPrvKeyFile(file string) SandV5Option

func WithPubKeyFile

func WithPubKeyFile(file string) SandV5Option

func WithReturnUrl

func WithReturnUrl(file string) SandV5Option

func WithUserFlag

func WithUserFlag(flag string) SandV5Option

type X

type X map[string]string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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