Documentation ¶
Index ¶
- Constants
- func FormatPKCS1PrivateKey(pemStr string) (xcrypto.RSAPadding, []byte)
- func FormatPKCS1PublicKey(pemStr string) (xcrypto.RSAPadding, []byte)
- func FormatPKCS8PrivateKey(pemStr string) (xcrypto.RSAPadding, []byte)
- func FormatPKCS8PublicKey(pemStr string) (xcrypto.RSAPadding, []byte)
- type APIResult
- type Action
- type ActionOption
- func WithAppAuthToken(token string) ActionOption
- func WithAuthToken(token string) ActionOption
- func WithBizContent(data lib.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, fieldName, filePath string, ...) (gjson.Result, error)
- func (c *Client) UploadWithReader(ctx context.Context, method string, fieldName, fileName string, ...) (gjson.Result, error)
- func (c *Client) VerifyNotify(form url.Values) (value.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 lib.X, options ...V3HeaderOption) (*APIResult, error)
- func (c *ClientV3) PostJSON(ctx context.Context, path string, params lib.X, options ...V3HeaderOption) (*APIResult, error)
- func (c *ClientV3) Upload(ctx context.Context, reqPath, fieldName, filePath, bizData string, ...) (*APIResult, error)
- func (c *ClientV3) UploadWithReader(ctx context.Context, reqPath, fieldName, fileName string, reader io.Reader, ...) (*APIResult, error)
- func (c *ClientV3) Verify(header http.Header, body []byte) error
- type GrantType
- type Option
- type V3HeaderOption
- type V3Option
Constants ¶
const ( 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 CodeOK = "10000" // API请求成功
Variables ¶
This section is empty.
Functions ¶
func FormatPKCS1PrivateKey ¶
func FormatPKCS1PrivateKey(pemStr string) (xcrypto.RSAPadding, []byte)
FormatPKCS1PrivateKey 格式化支付宝应用私钥(PKCS#1)
func FormatPKCS1PublicKey ¶
func FormatPKCS1PublicKey(pemStr string) (xcrypto.RSAPadding, []byte)
FormatPKCS1PublicKey 格式化支付宝应用公钥(PKCS#1)
func FormatPKCS8PrivateKey ¶
func FormatPKCS8PrivateKey(pemStr string) (xcrypto.RSAPadding, []byte)
FormatPKCS8PrivateKey 格式化支付宝应用私钥(PKCS#8)
func FormatPKCS8PublicKey ¶
func FormatPKCS8PublicKey(pemStr string) (xcrypto.RSAPadding, []byte)
FormatPKCS8PublicKey 格式化支付宝应用公钥(PKCS#8)
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, fieldName, filePath string, formData map[string]string, options ...ActionOption) (gjson.Result, error)
Upload 文件上传,参考:https://opendocs.alipay.com/apis/api_4/alipay.merchant.item.file.upload
func (*Client) UploadWithReader ¶ added in v1.2.0
func (c *Client) UploadWithReader(ctx context.Context, method string, fieldName, fileName string, reader io.Reader, formData map[string]string, options ...ActionOption) (gjson.Result, error)
UploadWithReader 文件上传,参考: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 lib.X, options ...V3HeaderOption) (*APIResult, error)
PostJSON POST加密请求
func (*ClientV3) PostJSON ¶
func (c *ClientV3) PostJSON(ctx context.Context, path string, params lib.X, options ...V3HeaderOption) (*APIResult, error)
PostJSON POST请求JSON数据
func (*ClientV3) Upload ¶
func (c *ClientV3) Upload(ctx context.Context, reqPath, fieldName, filePath, bizData string, options ...V3HeaderOption) (*APIResult, error)
Upload 文件上传,参考:https://opendocs.alipay.com/open-v3/054oog?pathHash=7834d743
func (*ClientV3) UploadWithReader ¶ added in v1.2.0
func (c *ClientV3) UploadWithReader(ctx context.Context, reqPath, fieldName, fileName string, reader io.Reader, bizData string, options ...V3HeaderOption) (*APIResult, error)
UploadWithReader 文件上传,参考:https://opendocs.alipay.com/open-v3/054oog?pathHash=7834d743
type Option ¶
type Option func(c *Client)
Option 自定义设置项
func WithHttpClient ¶ added in v1.2.0
WithHttpClient 设置自定义 HTTP Client
func WithLogger ¶
WithLogger 设置日志记录
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 设置日志记录
func WithV3PrivateKey ¶
func WithV3PrivateKey(key *xcrypto.PrivateKey) V3Option
WithV3PrivateKey 设置商户RSA私钥
func WithV3PublicKey ¶
WithV3PublicKey 设置平台RSA公钥