Documentation
¶
Index ¶
- func DecodeBytesToUint32(b []byte) uint32
- func EncodeUint32ToBytes(i uint32) []byte
- func FormatMap2XML(m WXML) ([]byte, error)
- func HMacSHA256(s, key string) string
- func HTTPDo(ctx context.Context, method, reqURL string, body []byte, options ...HTTPOption) (*http.Response, error)
- func HTTPGet(ctx context.Context, reqURL string, options ...HTTPOption) (*http.Response, error)
- func HTTPPost(ctx context.Context, reqURL string, body []byte, options ...HTTPOption) (*http.Response, error)
- func HTTPPostForm(ctx context.Context, reqURL string, data url.Values, options ...HTTPOption) (*http.Response, error)
- func HTTPUpload(ctx context.Context, reqURL string, form UploadForm, options ...HTTPOption) (*http.Response, error)
- func LoadP12Cert(pfxfile, mchid string) (tls.Certificate, error)
- func MD5(s string) string
- func MarshalNoEscapeHTML(v interface{}) ([]byte, error)
- func NewECBDecrypter(b cipher.Block) cipher.BlockMode
- func NewECBEncrypter(b cipher.Block) cipher.BlockMode
- func Nonce(size uint) string
- func PKCS5Padding(cipherText []byte, blockSize int) []byte
- func PKCS5Unpadding(plainText []byte, blockSize int) []byte
- func RSADecryptOEAP(cipherText, privateKey []byte) ([]byte, error)
- func RSAEncryptOEAP(plainText, publicKey []byte) ([]byte, error)
- func SHA256(s string) string
- func ZeroPadding(cipherText []byte, blockSize int) []byte
- func ZeroUnPadding(plainText []byte) []byte
- type AESCrypto
- type Action
- type ActionOption
- func WithBody(f func() ([]byte, error)) ActionOption
- func WithDecode(f func(resp []byte) error) ActionOption
- func WithQuery(key, value string) ActionOption
- func WithTLS() ActionOption
- func WithUpload(f func() (UploadForm, error)) ActionOption
- func WithWXML(f func(mchid, nonce string) (WXML, error)) ActionOption
- type CDATA
- type Client
- type ClientOption
- type FormFileFunc
- type HTTPClient
- type HTTPOption
- type LogData
- type Logger
- type M
- type PaddingMode
- type PemBlockType
- type UploadField
- type UploadForm
- type WXML
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeBytesToUint32 ¶
DecodeBytesToUint32 从 4 字节的网络字节序里解析出整数 uint32
func EncodeUint32ToBytes ¶
EncodeUint32ToBytes 把整数 uint32 格式化成 4 字节的网络字节序
func HMacSHA256 ¶
HMacSHA256 generates a keyed sha256 hash value.
func HTTPDo ¶
func HTTPDo(ctx context.Context, method, reqURL string, body []byte, options ...HTTPOption) (*http.Response, error)
HTTPDo sends an HTTP request and returns an HTTP response
func HTTPPost ¶
func HTTPPost(ctx context.Context, reqURL string, body []byte, options ...HTTPOption) (*http.Response, error)
HTTPPost issues a POST to the specified URL.
func HTTPPostForm ¶
func HTTPPostForm(ctx context.Context, reqURL string, data url.Values, options ...HTTPOption) (*http.Response, error)
HTTPPostForm issues a POST to the specified URL, with data's keys and values URL-encoded as the request body.
func HTTPUpload ¶
func HTTPUpload(ctx context.Context, reqURL string, form UploadForm, options ...HTTPOption) (*http.Response, error)
HTTPUpload issues a UPLOAD to the specified URL.
func LoadP12Cert ¶
func LoadP12Cert(pfxfile, mchid string) (tls.Certificate, error)
LoadP12Cert 通过p12(pfx)证书文件生成Pem证书
func MarshalNoEscapeHTML ¶
MarshalNoEscapeHTML marshal with no escape HTML
func NewECBDecrypter ¶
NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.
func NewECBEncrypter ¶
NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.
func PKCS5Padding ¶
func PKCS5Unpadding ¶
func RSADecryptOEAP ¶
RSADecryptOEAP rsa decrypt with PKCS #1 OEAP.
func RSAEncryptOEAP ¶
RSAEncryptOEAP rsa encrypt with PKCS #1 OEAP.
func ZeroPadding ¶
func ZeroUnPadding ¶
Types ¶
type AESCrypto ¶
type AESCrypto interface { // Encrypt encrypts the plain text. Encrypt(plainText []byte) ([]byte, error) // Decrypt decrypts the cipher text. Decrypt(cipherText []byte) ([]byte, error) }
AESCrypto is the interface for aes crypto.
func NewCBCCrypto ¶
func NewCBCCrypto(key, iv []byte, mode PaddingMode) AESCrypto
NewCBCCrypto returns a new aes-cbc crypto.
func NewECBCrypto ¶
func NewECBCrypto(key []byte, mode PaddingMode) AESCrypto
NewECBCrypto returns a new aes-ecb crypto.
type Action ¶
type Action interface { // Method returns action method Method() string // URL returns request url URL(accessToken ...string) string // WXML returns body for xml request WXML(mchid, nonce string) (WXML, error) // Body returns body for post request Body() ([]byte, error) // UploadForm returns form for uploading media UploadForm() (UploadForm, error) // Decode decodes response Decode(resp []byte) error // IsUpload specifies the request does upload IsUpload() bool // TLS specifies the request with certificate IsTLS() bool }
Action is the interface that handle wechat api
func NewAction ¶
func NewAction(method string, reqURL string, options ...ActionOption) Action
NewAction returns a new action
func NewGetAction ¶
func NewGetAction(reqURL string, options ...ActionOption) Action
NewGetAction returns a new action with GET method
func NewPostAction ¶
func NewPostAction(reqURL string, options ...ActionOption) Action
NewPostAction returns a new action with POST method
type ActionOption ¶
type ActionOption func(a *action)
ActionOption configures how we set up the action
func WithBody ¶
func WithBody(f func() ([]byte, error)) ActionOption
WithBody sets post body for action.
func WithDecode ¶
func WithDecode(f func(resp []byte) error) ActionOption
WithDecode sets response decode for action.
func WithQuery ¶
func WithQuery(key, value string) ActionOption
WithQuery sets query params for action.
func WithUpload ¶
func WithUpload(f func() (UploadForm, error)) ActionOption
WithUpload sets uploadform for action.
type CDATA ¶
type CDATA string
CDATA XML CDATA section which is defined as blocks of text that are not parsed by the parser, but are otherwise recognized as markup.
func (CDATA) MarshalXML ¶
MarshalXML encodes the receiver as zero or more XML elements.
type Client ¶
type Client interface { // Post sends an HTTP post request Do(ctx context.Context, method, reqURL string, body []byte, options ...HTTPOption) ([]byte, error) // Upload sends an HTTP post request for uploading media Upload(ctx context.Context, reqURL string, form UploadForm, options ...HTTPOption) ([]byte, error) // Set sets options for client Set(options ...ClientOption) }
Client is the interface that do http request
func DefaultClient ¶
func DefaultClient(certs ...tls.Certificate) Client
DefaultClient returns a new default wechat client
type ClientOption ¶
type ClientOption func(c *wxclient)
ClientOption configures how we set up the wechat client.
func WithHTTPClient ¶
func WithHTTPClient(client HTTPClient) ClientOption
WithHTTPClient sets http client for wechat client.
func WithLogger ¶
func WithLogger(logger Logger) ClientOption
WithLogger sets logger for wechat client.
type FormFileFunc ¶
FormFileFunc writes file content to multipart writer.
type HTTPClient ¶
type HTTPClient interface { // Do sends an HTTP request and returns an HTTP response. // Should use context to specify the timeout for request. Do(ctx context.Context, method, reqURL string, body []byte, options ...HTTPOption) (*http.Response, error) // Upload issues a UPLOAD to the specified URL. // Should use context to specify the timeout for request. Upload(ctx context.Context, reqURL string, form UploadForm, options ...HTTPOption) (*http.Response, error) }
HTTPClient is the interface for a http client.
func NewHTTPClient ¶
func NewHTTPClient(client *http.Client) HTTPClient
NewHTTPClient returns a new http client
type HTTPOption ¶
type HTTPOption func(s *httpSetting)
HTTPOption configures how we set up the http request.
func WithHTTPClose ¶
func WithHTTPClose() HTTPOption
WithHTTPClose specifies close the connection after replying to this request (for servers) or after sending this request and reading its response (for clients).
func WithHTTPCookies ¶
func WithHTTPCookies(cookies ...*http.Cookie) HTTPOption
WithHTTPCookies specifies the cookies to http request.
func WithHTTPHeader ¶
func WithHTTPHeader(key, value string) HTTPOption
WithHTTPHeader specifies the header to http request.
type PaddingMode ¶
type PaddingMode string
PaddingMode aes padding mode
const ( // ZERO zero padding mode ZERO PaddingMode = "ZERO" // PKCS5 PKCS#5 padding mode PKCS5 PaddingMode = "PKCS#5" // PKCS7 PKCS#7 padding mode PKCS7 PaddingMode = "PKCS#7" )
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 UploadField ¶
type UploadField func(f *uploadform)
UploadField configures how we set up the upload from.
func WithFormField ¶
func WithFormField(fieldname, fieldvalue string) UploadField
WithFormField specifies the form field to upload from.
func WithFormFile ¶
func WithFormFile(fieldname, filename string, fn FormFileFunc) UploadField
WithFormFile specifies the file field to upload from.
type UploadForm ¶
type UploadForm interface { // Write writes fields to multipart writer Write(w *multipart.Writer) error }
UploadForm is the interface for http upload.
func NewUploadForm ¶
func NewUploadForm(fields ...UploadField) UploadForm
NewUploadForm returns an upload form