kernel

package
v2.0.2-beta06 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: MIT Imports: 33 Imported by: 2

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
	GetEndpoint    func() (string, error)
}

func NewAccessToken

func NewAccessToken(app *ApplicationInterface) (*AccessToken, error)

func (*AccessToken) ApplyToRequest

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

func (*AccessToken) GetCacheKey

func (accessToken *AccessToken) GetCacheKey() string

GetCacheKey 缓存唯一key算法说明: 1. 使用appid和secret进行字符串拼接。例如: appid=testappid secret=testsecret, 那么结果为: testappidtestsecret 2. 计算字符串的md5。"testappidtestsecret"的md5值为"edc5f6181730baffc0b88cf96658aeff" 3. 加上PowerWeChat前缀命名空间:"powerwechat.access_token.",最终结果为:"powerwechat.access_token.edc5f6181730baffc0b88cf96658aeff"

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) OverrideGetEndpoint

func (accessToken *AccessToken) OverrideGetEndpoint()

func (*AccessToken) Refresh

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

func (*AccessToken) SetToken

func (accessToken *AccessToken) SetToken(token *response2.ResponseGetToken) (tokenInterface contract.AccessTokenInterface, err error)

type ApplicationInterface

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

type BaseClient

func NewBaseClient

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

func (*BaseClient) HttpGet

func (client *BaseClient) HttpGet(url string, query *object.StringMap, 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 *object.StringMap, 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 CacheInterface

type CacheInterface cache.CacheInterface

func NewRedisClient

func NewRedisClient(options *RedisOptions) CacheInterface

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) DecryptContent

func (encryptor *Encryptor) DecryptContent(content 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 callbacks 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-callbacks?msg_signature=1495c4dfd4958d4e5faf618978ae66943a042f87&timestamp=1623292419&nonce=1623324060&echostr=o1XtmVltGmUAqoWee54yd4Q5ZBgrw4%2F9lFo5qdZoVPd1DybzarjuYCfFlR2AFbAcWHwFgmbrVBD%2Bf9910QIF6g%3D%3D"

type ExtraInfo

type ExtraInfo struct {
	Prepends *power.HashMap
	ID       string
}

func NewExtraInfo

func NewExtraInfo() (*ExtraInfo, error)

type InteractsWithCache

type InteractsWithCache struct {
	Cache CacheInterface
}

func NewInteractsWithCache

func NewInteractsWithCache(client CacheInterface) *InteractsWithCache

func (*InteractsWithCache) GetCache

func (interactCache *InteractsWithCache) GetCache() CacheInterface

func (*InteractsWithCache) SetCache

func (interactCache *InteractsWithCache) SetCache(cache CacheInterface) *InteractsWithCache

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 RedisOptions

type RedisOptions cache.RedisOptions

type ServerGuard

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

	App *ApplicationInterface

	IsSafeMode              func(request *http.Request) bool
	Validate                func(request *http.Request) (*ServerGuard, error)
	ShouldReturnRawResponse func(request *http.Request) bool

	ToCallbackType func(callbackHeader contract.EventInterface, buf []byte) (decryptMessage interface{}, err error)

	GetToken    func() string
	Resolve     func(request *http.Request) (httpRS *response.HttpResponse, err error)
	Notify      func(request *http.Request, closure func(event contract.EventInterface) interface{}) (response *response.HttpResponse, err error)
	HandleEvent func(request *http.Request, closure func(event contract.EventInterface) interface{}) (*object.HashMap, error)
	// contains filtered or unexported fields
}

func NewServerGuard

func NewServerGuard(app *ApplicationInterface) *ServerGuard

func (*ServerGuard) DecryptEvent

func (serverGuard *ServerGuard) DecryptEvent(request *http.Request, content string) (callbackHeader *models.CallbackMessageHeader, err error)

func (*ServerGuard) GetEvent

func (serverGuard *ServerGuard) GetEvent(request *http.Request) (callback *models.Callback, callbackHeader *models.CallbackMessageHeader, err error)

func (*ServerGuard) GetMessage

func (serverGuard *ServerGuard) GetMessage(request *http.Request) (callback *models.Callback, callbackHeader *models.CallbackMessageHeader, Decrypted interface{}, err error)

func (*ServerGuard) OverrideGetToken

func (serverGuard *ServerGuard) OverrideGetToken()

func (*ServerGuard) OverrideHandleEvent

func (serverGuard *ServerGuard) OverrideHandleEvent()

func (*ServerGuard) OverrideNotify

func (serverGuard *ServerGuard) OverrideNotify()

func (*ServerGuard) OverrideResolve

func (serverGuard *ServerGuard) OverrideResolve()

func (*ServerGuard) ParseMessage

func (serverGuard *ServerGuard) ParseMessage(content string) (callback *models.Callback, err error)

func (*ServerGuard) ResolveEvent

func (serverGuard *ServerGuard) ResolveEvent(request *http.Request, closure func(event contract.EventInterface) interface{}) (httpRS *response.HttpResponse, err error)

func (*ServerGuard) Serve

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

回调配置 https://developer.work.weixin.qq.com/document/path/90930

type ServiceContainer

type ServiceContainer struct {
	ID string

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

func NewServiceContainer

func NewServiceContainer(config *object.HashMap, extraInfos ...*ExtraInfo) (*ServiceContainer, error)

func (*ServiceContainer) GetConfig

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

func (*ServiceContainer) GetID

func (container *ServiceContainer) GetID() string

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