kernel

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorInvalidSignature = -40001 // 签名验证错误
	ErrorParseXml         = -40002 // xml/json解析失败
	ErrorCalcSignature    = -40003 // sha加密生成签名失败
	ErrorInvalidAesKey    = -40004 // AESKey 非法
	ErrorInvalidAppId     = -40005 // ReceiveId 校验错误
	ErrorEncryptAes       = -40006 // AES 加密失败
	ErrorDecryptAes       = -40007 // AES 解密失败
	ErrorInvalidXml       = -40008 // 解密后得到的buffer非法
	ErrorBase64Encode     = -40009 // base64 编码失败
	ErrorBase64Decode     = -40010 // base64 解码失败
	ErrorXmlBuild         = -40011 // 生成xml失败
	IllegalBuffer         = -41003 // Illegal buffer

)

Wechat Docs: https://open.work.weixin.qq.com/api/doc/90000/90138/90307

View Source
const SUCCESS_EMPTY_RESPONSE = "success"

Variables

View Source
var MESSAGE_TYPE_MAPPING = map[string]int{
	"*":               messages.VOID,
	"text":            messages.TEXT,
	"image":           messages.IMAGE,
	"voice":           messages.VOICE,
	"video":           messages.VIDEO,
	"shortvideo":      messages.SHORT_VIDEO,
	"location":        messages.LOCATION,
	"link":            messages.LINK,
	"device_event":    messages.DEVICE_EVENT,
	"device_text":     messages.DEVICE_TEXT,
	"event":           messages.EVENT,
	"file":            messages.FILE,
	"miniprogrampage": messages.MINIPROGRAM_PAGE,
}

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	App *ApplicationInterface

	*request.HttpRequest
	*response.HttpResponse

	RequestMethod      string
	EndpointToGetToken string
	QueryName          string
	Token              object.HashMap
	TokenKey           string
	CachePrefix        string

	*InteractsWithCache

	GetCredentials func() *object.StringMap
}

func NewAccessToken

func NewAccessToken(app *ApplicationInterface) *AccessToken

func (*AccessToken) ApplyToRequest

func (accessToken *AccessToken) ApplyToRequest(request *http.Request, requestOptions *object.HashMap) (*http.Request, error)

func (*AccessToken) GetCacheKey

func (accessToken *AccessToken) GetCacheKey() string

func (*AccessToken) GetRefreshedToken

func (accessToken *AccessToken) GetRefreshedToken() (*response2.ResponseGetToken, error)

func (*AccessToken) GetToken

func (accessToken *AccessToken) GetToken(refresh bool) (resToken *response2.ResponseGetToken, err error)

func (*AccessToken) Refresh

func (accessToken *AccessToken) Refresh() contract.AccessTokenInterface

func (*AccessToken) SetToken

func (accessToken *AccessToken) SetToken(token string, lifeTime int) (tokenInterface contract.AccessTokenInterface, err error)

type ApplicationInterface

type ApplicationInterface interface {
	GetContainer() *ServiceContainer
	GetAccessToken() *AccessToken
	GetConfig() *Config
	GetComponent(name string) interface{}

	SetExternalRequest(r *http.Request)
	GetExternalRequest() (r *http.Request)
}

type BaseClient

func NewBaseClient

func NewBaseClient(app *ApplicationInterface, token *AccessToken) *BaseClient

func (*BaseClient) HttpGet

func (client *BaseClient) HttpGet(url string, query interface{}, outHeader interface{}, outBody interface{}) (interface{}, error)

func (*BaseClient) HttpPost

func (client *BaseClient) HttpPost(url string, data interface{}, outHeader interface{}, outBody interface{}) (interface{}, error)

func (*BaseClient) HttpPostJson

func (client *BaseClient) HttpPostJson(url string, data interface{}, query interface{}, outHeader interface{}, outBody interface{}) (interface{}, error)

func (*BaseClient) HttpUpload

func (client *BaseClient) HttpUpload(url string, files *object.HashMap, form *object.HashMap, query interface{}, outHeader interface{}, outBody interface{}) (interface{}, error)

func (*BaseClient) Request

func (client *BaseClient) Request(url string, method string, options *object.HashMap,
	returnRaw bool, outHeader interface{}, outBody interface{},
) (interface{}, error)

func (*BaseClient) RequestRaw

func (client *BaseClient) RequestRaw(url string, method string, options *object.HashMap, outHeader interface{}, outBody interface{}) (interface{}, error)

type CDATA

type CDATA struct {
	Value string `xml:",cdata"`
}

type Config

type Config struct {
	*object.Collection
}

func NewConfig

func NewConfig(items *object.HashMap) *Config

type Encryptor

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

func NewEncryptor

func NewEncryptor(appId, token, aesKey string) (*Encryptor, error)

func (*Encryptor) Decrypt

func (encryptor *Encryptor) Decrypt(content []byte, msgSignature, nonce, timestamp string) ([]byte, *support.CryptError)

Decrypt decrypt xml msg and return xml

func (*Encryptor) Encrypt

func (encryptor *Encryptor) Encrypt(msg, nonce, timestamp string) ([]byte, *support.CryptError)

Encrypt encrypt xml msg and return xml

func (*Encryptor) GetToken

func (encryptor *Encryptor) GetToken() string

GetToken Get the app token

func (*Encryptor) Signature

func (encryptor *Encryptor) Signature(token, timestamp, nonce, data string) string

func (*Encryptor) VerifyUrl

func (encryptor *Encryptor) VerifyUrl(content string, msgSignature, nonce, timestamp string) ([]byte, *support.CryptError)

VerifyUrl Parsing the official WeChat callback validation. Wechat Docs: https://work.weixin.qq.com/api/doc/90000/90135/90235 When adding URLs to the WeChat admin backend, WeChat will trigger a GET request to verify whether the server can process the encrypted information properly, and the uniformMessage needs to be decrypted and returned. 在微信管理后台添加URL的时候,微信会触发一条GET请求用于验证服务器能否正常处理加密信息,需要将消息解密出来返回。 eg: "/app-callback?msg_signature=1495c4dfd4958d4e5faf618978ae66943a042f87&timestamp=1623292419&nonce=1623324060&echostr=o1XtmVltGmUAqoWee54yd4Q5ZBgrw4%2F9lFo5qdZoVPd1DybzarjuYCfFlR2AFbAcWHwFgmbrVBD%2Bf9910QIF6g%3D%3D"

type InteractsWithCache

type InteractsWithCache struct {
	Cache cache.CacheInterface
}

func (*InteractsWithCache) GetCache

func (interactCache *InteractsWithCache) GetCache() cache.CacheInterface

type Middleware

type Middleware struct {
	contract.MiddlewareInterface
	*BaseClient
	Name string
}

----------------------------------------------------------------------

func (*Middleware) Delay

func (d *Middleware) Delay() time.Duration

func (*Middleware) GetName

func (d *Middleware) GetName() string

func (*Middleware) Retries

func (d *Middleware) Retries() int

func (*Middleware) RetryDecider

func (d *Middleware) RetryDecider(conditions *object.HashMap) bool

func (*Middleware) SetName

func (d *Middleware) SetName(name string)

type MiddlewareAccessToken

type MiddlewareAccessToken struct {
	*Middleware
}

func (*MiddlewareAccessToken) ModifyRequest

func (d *MiddlewareAccessToken) ModifyRequest(req *http2.Request) (err error)

--- MiddlewareAccessToken ---

type MiddlewareLogMiddleware

type MiddlewareLogMiddleware struct {
	*Middleware
}

func (*MiddlewareLogMiddleware) ModifyRequest

func (d *MiddlewareLogMiddleware) ModifyRequest(req *http2.Request) error

--- MiddlewareLogMiddleware ---

type MiddlewareRetry

type MiddlewareRetry struct {
	*Middleware
}

func (*MiddlewareRetry) ModifyRequest

func (d *MiddlewareRetry) ModifyRequest(req *http2.Request) error

--- MiddlewareRetry ---

func (*MiddlewareRetry) RetryDecider

func (d *MiddlewareRetry) RetryDecider(conditions *object.HashMap) bool

type ServerGuard

type ServerGuard struct {
	*support.Observable
	*support.ResponseCastable

	App *ApplicationInterface

	IsSafeMode              func() bool
	Validate                func() (*ServerGuard, error)
	ShouldReturnRawResponse func() bool

	ToCallbackType func(callbackHeader contract.EventInterface, buf []byte) (decryptMessage interface{}, err error)
	// contains filtered or unexported fields
}

func NewServerGuard

func NewServerGuard(app *ApplicationInterface) *ServerGuard

func (*ServerGuard) Serve

func (serverGuard *ServerGuard) Serve(r *http.Request) (response *response.HttpResponse, err error)

type ServiceContainer

type ServiceContainer struct {
	ID int

	DefaultConfig *object.HashMap
	UserConfig    *object.HashMap
	Config        *object.HashMap
}

func (*ServiceContainer) GetConfig

func (container *ServiceContainer) GetConfig() *object.HashMap

type WeComRecvMsg

type WeComRecvMsg struct {
	ToUserName string `xml:"ToUserName"`
	Encrypt    string `xml:"Encrypt"`
	AgentId    string `xml:"AgentID"`
}

type WeComReplyMsg

type WeComReplyMsg struct {
	XMLName   xml.Name `xml:"xml"`
	Encrypt   CDATA    `xml:"Encrypt"`
	Signature CDATA    `xml:"MsgSignature"`
	Timestamp string   `xml:"TimeStamp"`
	Nonce     CDATA    `xml:"Nonce"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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