Documentation ¶
Index ¶
- Constants
- func AESDecryptCBC(key, data []byte) ([]byte, error)
- func AESEncryptCBC(key, data []byte) ([]byte, error)
- func HeaderEncode(h http.Header) string
- func LoadCertFromPfxFile(filename, password string) (tls.Certificate, error)
- func Nonce(size uint) string
- type APIResult
- type Action
- type ActionOption
- func WithAppAuthToken(token string) ActionOption
- func WithAuthToken(token string) ActionOption
- func WithBizContent(data X) ActionOption
- func WithEncrypt() ActionOption
- func WithKVParam(k, v string) ActionOption
- func WithNotifyURL(url string) ActionOption
- func WithOAuthCode(code string) ActionOption
- func WithRefreshToken(token string) ActionOption
- func WithReturnURL(url string) ActionOption
- func WithScene(scene string) ActionOption
- type Client
- func (c *Client) AppID() string
- func (c *Client) DecodeEncryptData(hash crypto.Hash, data, sign string) ([]byte, error)
- func (c *Client) Decrypt(encryptData string) ([]byte, error)
- func (c *Client) Do(ctx context.Context, method string, options ...ActionOption) (gjson.Result, error)
- func (c *Client) Encrypt(data string) (string, error)
- func (c *Client) PageExecute(method string, options ...ActionOption) (string, error)
- func (c *Client) Upload(ctx context.Context, method string, form UploadForm, options ...ActionOption) (gjson.Result, error)
- func (c *Client) VerifyNotify(form url.Values) (V, error)
- type ClientV3
- func (c *ClientV3) AppID() string
- func (c *ClientV3) Authorization(method, path string, query url.Values, body []byte, header http.Header) (string, error)
- func (c *ClientV3) Decrypt(encryptData string) ([]byte, error)
- func (c *ClientV3) Encrypt(data string) (string, error)
- func (c *ClientV3) GetJSON(ctx context.Context, path string, query url.Values, options ...V3HeaderOption) (*APIResult, error)
- func (c *ClientV3) PostEncrypt(ctx context.Context, path string, params X, options ...V3HeaderOption) (*APIResult, error)
- func (c *ClientV3) PostJSON(ctx context.Context, path string, params X, options ...V3HeaderOption) (*APIResult, error)
- func (c *ClientV3) Upload(ctx context.Context, path string, form UploadForm, options ...V3HeaderOption) (*APIResult, error)
- func (c *ClientV3) Verify(header http.Header, body []byte) error
- type FormFileFunc
- type GrantType
- type HTTPClient
- type HTTPOption
- type Option
- type PrivateKey
- type PublicKey
- func NewPublicKeyFromDerBlock(pemBlock []byte) (*PublicKey, error)
- func NewPublicKeyFromDerFile(pemFile string) (*PublicKey, error)
- func NewPublicKeyFromPemBlock(padding RSAPadding, pemBlock []byte) (*PublicKey, error)
- func NewPublicKeyFromPemFile(padding RSAPadding, pemFile string) (*PublicKey, error)
- type RSAPadding
- type ReqLog
- func (l *ReqLog) Do(ctx context.Context, log func(ctx context.Context, data map[string]string))
- func (l *ReqLog) Set(k, v string)
- func (l *ReqLog) SetReqBody(v string)
- func (l *ReqLog) SetReqHeader(h http.Header)
- func (l *ReqLog) SetRespBody(v string)
- func (l *ReqLog) SetRespHeader(h http.Header)
- func (l *ReqLog) SetStatusCode(code int)
- type UploadField
- type UploadForm
- type V
- type V3HeaderOption
- type V3Option
- type VEmptyMode
- type VEncOption
- type X
Constants ¶
const ( HeaderAccept = "Accept" HeaderAuthorization = "Authorization" HeaderContentType = "Content-Type" HeaderMethodOverride = "x-http-method-override" HeaderRequestID = "alipay-request-id" HeaderTraceID = "alipay-trace-id" HeaderRootCertSN = "alipay-root-cert-sn" HeaderNonce = "alipay-nonce" HeaderTimestamp = "alipay-timestamp" HeaderEncryptType = "alipay-encrypt-type" HeaderAppAuthToken = "alipay-app-auth-token" HeaderSignature = "alipay-signature" )
const ( ContentForm = "application/x-www-form-urlencoded" ContentJSON = "application/json;charset=utf-8" ContentText = "text/plain;charset=utf-8" )
const CodeOK = "10000" // API请求成功
Variables ¶
This section is empty.
Functions ¶
func AESDecryptCBC ¶ added in v1.0.3
AESDecryptCBC AES-CBC 解密
func AESEncryptCBC ¶ added in v1.0.3
AESEncryptCBC AES-CBC 加密
func HeaderEncode ¶
func LoadCertFromPfxFile ¶
func LoadCertFromPfxFile(filename, password string) (tls.Certificate, error)
LoadCertFromPfxFile 通过pfx(p12)证书文件生成TLS证书 注意:证书需采用「TripleDES-SHA1」加密方式
Types ¶
type ActionOption ¶
type ActionOption func(a *Action)
ActionOption Action选项
func WithAppAuthToken ¶
func WithAppAuthToken(token string) ActionOption
WithAppAuthToken 设置第三方应用授权Token
func WithRefreshToken ¶
func WithRefreshToken(token string) ActionOption
WithRefreshToken 设置刷新令牌(用刷新令牌来换取一个新的授权令牌)
func WithReturnURL ¶
func WithReturnURL(url string) ActionOption
WithReturnURL 设置支付成功跳转URL(HTTP/HTTPS开头字符串)
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 支付宝客户端
func NewSandbox ¶
NewSandbox 生成支付宝沙箱环境
func (*Client) DecodeEncryptData ¶
DecodeEncryptData 解析加密数据,如:授权的用户信息和手机号
func (*Client) Do ¶
func (c *Client) Do(ctx context.Context, method string, options ...ActionOption) (gjson.Result, error)
Do 向支付宝网关发送请求
func (*Client) PageExecute ¶
func (c *Client) PageExecute(method string, options ...ActionOption) (string, error)
PageExecute 致敬官方SDK
func (*Client) Upload ¶
func (c *Client) Upload(ctx context.Context, method string, form UploadForm, options ...ActionOption) (gjson.Result, error)
Upload 文件上传,参考:https://opendocs.alipay.com/apis/api_4/alipay.merchant.item.file.upload
type ClientV3 ¶
type ClientV3 struct {
// contains filtered or unexported fields
}
ClientV3 支付宝V3客户端(仅支持v3版本的接口可用)
func NewClientV3 ¶
NewClientV3 生成支付宝客户端V3
func NewSandboxV3 ¶
NewSandboxV3 生成支付宝沙箱V3
func (*ClientV3) Authorization ¶
func (c *ClientV3) Authorization(method, path string, query url.Values, body []byte, header http.Header) (string, error)
Authorization 生成签名并返回 HTTP Authorization
func (*ClientV3) GetJSON ¶
func (c *ClientV3) GetJSON(ctx context.Context, path string, query url.Values, options ...V3HeaderOption) (*APIResult, error)
GetJSON GET请求JSON数据
func (*ClientV3) PostEncrypt ¶
func (c *ClientV3) PostEncrypt(ctx context.Context, path string, params X, options ...V3HeaderOption) (*APIResult, error)
PostJSON POST加密请求
func (*ClientV3) PostJSON ¶
func (c *ClientV3) PostJSON(ctx context.Context, path string, params X, options ...V3HeaderOption) (*APIResult, error)
PostJSON POST请求JSON数据
func (*ClientV3) Upload ¶
func (c *ClientV3) Upload(ctx context.Context, path string, form UploadForm, options ...V3HeaderOption) (*APIResult, error)
Upload 文件上传,参考:https://opendocs.alipay.com/open-v3/054oog?pathHash=7834d743
type HTTPClient ¶
type HTTPClient interface { // Do 发送HTTP请求 // 注意:应该使用Context设置请求超时时间 Do(ctx context.Context, method, reqURL string, body []byte, options ...HTTPOption) (*http.Response, error) // Upload 上传文件 // 注意:应该使用Context设置请求超时时间 Upload(ctx context.Context, reqURL string, form UploadForm, 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 HeaderToHttpOption ¶
func HeaderToHttpOption(h http.Header) []HTTPOption
func WithHTTPCookies ¶
func WithHTTPCookies(cookies ...*http.Cookie) HTTPOption
WithHTTPCookies 设置HTTP请求Cookie
func WithHTTPHeader ¶
func WithHTTPHeader(key string, vals ...string) HTTPOption
WithHTTPHeader 设置HTTP请求头
type PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey RSA私钥
func NewPrivateKeyFromPemBlock ¶
func NewPrivateKeyFromPemBlock(padding RSAPadding, pemBlock []byte) (*PrivateKey, error)
NewPrivateKeyFromPemBlock 通过PEM字节生成RSA私钥
func NewPrivateKeyFromPemFile ¶
func NewPrivateKeyFromPemFile(padding 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(cipherText []byte) ([]byte, error)
Decrypt RSA私钥 PKCS#1 v1.5 解密
func (*PrivateKey) DecryptOAEP ¶
DecryptOAEP RSA私钥 PKCS#1 OAEP 解密
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey RSA公钥
func NewPublicKeyFromDerBlock ¶
NewPublicKeyFromDerBlock 通过DER字节生成RSA公钥 注意PEM格式: -----BEGIN CERTIFICATE----- | -----END CERTIFICATE----- DER转换命令: openssl x509 -inform der -in cert.cer -out cert.pem
func NewPublicKeyFromDerFile ¶
NewPublicKeyFromDerFile 通过DER证书生成RSA公钥 注意PEM格式: -----BEGIN CERTIFICATE----- | -----END CERTIFICATE----- DER转换命令: openssl x509 -inform der -in cert.cer -out cert.pem
func NewPublicKeyFromPemBlock ¶
func NewPublicKeyFromPemBlock(padding RSAPadding, pemBlock []byte) (*PublicKey, error)
NewPublicKeyFromPemBlock 通过PEM字节生成RSA公钥
func NewPublicKeyFromPemFile ¶
func NewPublicKeyFromPemFile(padding RSAPadding, pemFile string) (*PublicKey, error)
NewPublicKeyFromPemFile 通过PEM文件生成RSA公钥
func (*PublicKey) EncryptOAEP ¶
EncryptOAEP RSA公钥 PKCS#1 OAEP 加密
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`) )
func FormatPKCS1PrivateKey ¶
func FormatPKCS1PrivateKey(pemStr string) (RSAPadding, []byte)
FormatPKCS1PrivateKey 格式化支付宝应用私钥(PKCS#1)
func FormatPKCS1PublicKey ¶
func FormatPKCS1PublicKey(pemStr string) (RSAPadding, []byte)
FormatPKCS1PublicKey 格式化支付宝应用公钥(PKCS#1)
func FormatPKCS8PrivateKey ¶
func FormatPKCS8PrivateKey(pemStr string) (RSAPadding, []byte)
FormatPKCS8PrivateKey 格式化支付宝应用私钥(PKCS#8)
func FormatPKCS8PublicKey ¶
func FormatPKCS8PublicKey(pemStr string) (RSAPadding, []byte)
FormatPKCS8PublicKey 格式化支付宝应用公钥(PKCS#8)
type ReqLog ¶
type ReqLog struct {
// contains filtered or unexported fields
}
ReqLog 请求日志
type UploadField ¶
type UploadField func(form *uploadform)
UploadField 文件上传表单字段
func WithFormFile ¶
func WithFormFile(fieldname, filename string, fn FormFileFunc) UploadField
WithFormFile 设置表单文件字段
type UploadForm ¶
type UploadForm interface { // Field 返回表单普通字段 Field(name string) string // Write 将表单文件写入流 Write(w *multipart.Writer) error }
UploadForm HTTP文件上传表单
type V ¶
V 用于处理 k-v 需要格式化的场景,如:签名
type V3HeaderOption ¶
func WithV3AppAuthToken ¶
func WithV3AppAuthToken(token string) V3HeaderOption
func WithV3MethodOverride ¶
func WithV3MethodOverride(method string) V3HeaderOption
func WithV3RootCertSN ¶
func WithV3RootCertSN(sn string) V3HeaderOption
type V3Option ¶
type V3Option func(c *ClientV3)
V3Option 自定义设置项
func WithV3Logger ¶
WithV3Logger 设置日志记录
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模式