Documentation ¶
Index ¶
- func DecodeBytesToUint32(b []byte) uint32
- func EncodeUint32ToBytes(i uint32) []byte
- func FormatMap2XML(m WXML) ([]byte, error)
- func FormatMap2XMLForTest(m WXML) ([]byte, error)
- func HMacSHA256(s, key string) string
- func HTTPDo(ctx context.Context, method, reqURL string, body []byte, options ...HTTPOption) ([]byte, error)
- func HTTPGet(ctx context.Context, reqURL string, options ...HTTPOption) ([]byte, error)
- func HTTPPost(ctx context.Context, reqURL string, body []byte, options ...HTTPOption) ([]byte, error)
- func HTTPPostForm(ctx context.Context, reqURL string, data url.Values, options ...HTTPOption) ([]byte, error)
- func HTTPUpload(ctx context.Context, reqURL string, form UploadForm, options ...HTTPOption) ([]byte, error)
- func LoadCertFromPfxFile(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 uint8) string
- func PKCS5Padding(cipherText []byte, blockSize int) []byte
- func PKCS5Unpadding(plainText []byte, blockSize int) []byte
- func SHA1(s string) string
- func SHA256(s string) string
- func ZeroPadding(cipherText []byte, blockSize int) []byte
- func ZeroUnPadding(plainText []byte) []byte
- type AESCrypto
- type AESPaddingMode
- type Action
- type ActionOption
- func WithBody(f func() ([]byte, error)) ActionOption
- func WithDecode(f func(b []byte) error) ActionOption
- func WithQuery(key, value string) ActionOption
- func WithTLS() ActionOption
- func WithUpload(f func() (UploadForm, error)) ActionOption
- func WithWXML(f func(mchid, apikey, nonce string) (WXML, error)) ActionOption
- type CDATA
- type FormFileFunc
- type HTTPClient
- type HTTPOption
- type M
- type PrivateKey
- type PublicKey
- func NewPublicKeyFromDerBlock(pemBlock []byte) (*PublicKey, error)
- func NewPublicKeyFromDerFile(pemFile string) (*PublicKey, error)
- func NewPublicKeyFromPemBlock(mode RSAPaddingMode, pemBlock []byte) (*PublicKey, error)
- func NewPublicKeyFromPemFile(mode RSAPaddingMode, pemFile string) (*PublicKey, error)
- type RSAPaddingMode
- type SignType
- 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 FormatMap2XMLForTest ¶
FormatMap2XMLForTest 用于单元测试
func HMacSHA256 ¶
HMacSHA256 generates a keyed sha256 hash value.
func HTTPDo ¶
func HTTPDo(ctx context.Context, method, reqURL string, body []byte, options ...HTTPOption) ([]byte, error)
HTTPDo sends an HTTP request and returns an HTTP response
func HTTPPost ¶
func HTTPPost(ctx context.Context, reqURL string, body []byte, options ...HTTPOption) ([]byte, error)
HTTPPost issues a POST to the specified URL.
func HTTPPostForm ¶
func HTTPPostForm(ctx context.Context, reqURL string, data url.Values, options ...HTTPOption) ([]byte, 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) ([]byte, error)
HTTPUpload issues a UPLOAD to the specified URL.
func LoadCertFromPfxFile ¶
func LoadCertFromPfxFile(pfxfile, mchid string) (tls.Certificate, error)
LoadCertFromPfxFile 通过pfx(p12)证书文件生成TLS证书
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 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 AESPaddingMode) AESCrypto
NewCBCCrypto returns a new aes-cbc crypto.
func NewECBCrypto ¶
func NewECBCrypto(key []byte, mode AESPaddingMode) AESCrypto
NewECBCrypto returns a new aes-ecb crypto.
type AESPaddingMode ¶
type AESPaddingMode int
AESPaddingMode aes padding mode
const ( // AES_ZERO zero padding mode AES_ZERO AESPaddingMode = iota // AES_PKCS5 PKCS#5 padding mode AES_PKCS5 // AES_PKCS7 PKCS#7 padding mode AES_PKCS7 )
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, apikey, 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(b []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(b []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 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) ([]byte, 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) ([]byte, error) }
HTTPClient is the interface for a http client.
func NewDefaultClient ¶
func NewDefaultClient(certs ...tls.Certificate) HTTPClient
NewDefaultClient returns a default 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 PrivateKey ¶
type PrivateKey struct {
// contains filtered or unexported fields
}
PrivateKey RSA private key
func NewPrivateKeyFromPemBlock ¶
func NewPrivateKeyFromPemBlock(mode RSAPaddingMode, pemBlock []byte) (*PrivateKey, error)
NewPrivateKeyFromPemBlock returns new private key with pem block.
func NewPrivateKeyFromPemFile ¶
func NewPrivateKeyFromPemFile(mode RSAPaddingMode, pemFile string) (*PrivateKey, error)
NewPrivateKeyFromPemFile returns new private key with pem file.
func NewPrivateKeyFromPfxFile ¶
func NewPrivateKeyFromPfxFile(pfxFile, password string) (*PrivateKey, error)
NewPrivateKeyFromPfxFile returns private key with pfx(p12) file.
func (*PrivateKey) Decrypt ¶
func (pk *PrivateKey) Decrypt(cipherText []byte) ([]byte, error)
Decrypt rsa decrypt with PKCS #1 v1.5
func (*PrivateKey) DecryptOAEP ¶
DecryptOAEP rsa decrypt with PKCS #1 OAEP.
type PublicKey ¶
type PublicKey struct {
// contains filtered or unexported fields
}
PublicKey RSA public key
func NewPublicKeyFromDerBlock ¶
NewPublicKeyFromDerBlock returns public key with DER block. NOTE: PEM format with -----BEGIN CERTIFICATE----- | -----END CERTIFICATE----- CMD: openssl x509 -inform der -in cert.cer -out cert.pem
func NewPublicKeyFromDerFile ¶
NewPublicKeyFromDerFile returns public key with DER file. NOTE: PEM format with -----BEGIN CERTIFICATE----- | -----END CERTIFICATE----- CMD: openssl x509 -inform der -in cert.cer -out cert.pem
func NewPublicKeyFromPemBlock ¶
func NewPublicKeyFromPemBlock(mode RSAPaddingMode, pemBlock []byte) (*PublicKey, error)
NewPublicKeyFromPemBlock returns new public key with pem block.
func NewPublicKeyFromPemFile ¶
func NewPublicKeyFromPemFile(mode RSAPaddingMode, pemFile string) (*PublicKey, error)
NewPublicKeyFromPemFile returns new public key with pem file.
func (*PublicKey) EncryptOAEP ¶
EncryptOAEP rsa encrypt with PKCS #1 OAEP.
type RSAPaddingMode ¶
type RSAPaddingMode int
RSAPaddingMode pem block type which taken from the preamble.
const ( // RSA_PKCS1 this kind of key is commonly encoded in PEM blocks of type "RSA PRIVATE KEY" and "RSA PUBLIC KEY" RSA_PKCS1 RSAPaddingMode = iota // RSA_PKCS8 this kind of key is commonly encoded in PEM blocks of type "PRIVATE KEY" and "PUBLIC KEY" RSA_PKCS8 )
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