kernel

package
v3.0.55 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT Imports: 36 Imported by: 170

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

	HttpHelper *helper.RequestHelper

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

	*InteractsWithCache

	GetCredentials func() *object.StringMap
	GetEndpoint    func() (string, error)

	SetCustomToken func(token *response2.ResponseGetToken) interface{}
	GetCustomToken func(token interface{}) object.HashMap

	GetMiddlewareOfLog func(logger contract2.LoggerInterface) contract3.RequestMiddleware
}

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) GetDefaultCacheKey added in v3.0.48

func (accessToken *AccessToken) GetDefaultCacheKey() 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) OverrideGetEndpoint

func (accessToken *AccessToken) OverrideGetEndpoint()

func (*AccessToken) OverrideGetMiddlewareOfLog added in v3.0.6

func (accessToken *AccessToken) OverrideGetMiddlewareOfLog()

func (*AccessToken) OverrideGetMiddlewares added in v3.0.6

func (accessToken *AccessToken) OverrideGetMiddlewares()

func (*AccessToken) Refresh

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

func (*AccessToken) RegisterHttpMiddlewares added in v3.0.6

func (accessToken *AccessToken) RegisterHttpMiddlewares()

func (*AccessToken) SetCacheKey added in v3.0.48

func (accessToken *AccessToken) SetCacheKey(key string)

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

type BaseClient struct {
	HttpHelper *helper.RequestHelper

	BaseURI  string
	QueryRaw bool

	*support.ResponseCastable

	Signer *support.SHA256WithRSASigner

	App   *ApplicationInterface
	Token *AccessToken

	GetMiddlewareOfAccessToken        contract.RequestMiddleware
	GetMiddlewareOfLog                func(logger contract2.LoggerInterface) contract.RequestMiddleware
	GetMiddlewareOfRefreshAccessToken func(retry int) contract.RequestMiddleware
}

func NewBaseClient

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

func (*BaseClient) CheckTokenNeedRefresh

func (client *BaseClient) CheckTokenNeedRefresh(req *http.Request, rs *http.Response, retry int) (*http.Response, error)

func (*BaseClient) HttpGet

func (client *BaseClient) HttpGet(ctx context.Context, url string, query *object.StringMap, outHeader interface{}, outBody interface{}) (interface{}, error)

func (*BaseClient) HttpPost

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

func (*BaseClient) HttpPostJson

func (client *BaseClient) HttpPostJson(ctx context.Context, url string, data interface{}, query *object.StringMap, outHeader interface{}, outBody interface{}) (interface{}, error)

func (*BaseClient) HttpPostJsonByEncode added in v3.0.38

func (client *BaseClient) HttpPostJsonByEncode(ctx context.Context, url string, data interface{}, query *object.StringMap, outHeader interface{}, outBody interface{}) (interface{}, error)

func (*BaseClient) HttpUpload

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

func (*BaseClient) OverrideGetMiddlewareOfAccessToken

func (client *BaseClient) OverrideGetMiddlewareOfAccessToken()

func (*BaseClient) OverrideGetMiddlewareOfLog

func (client *BaseClient) OverrideGetMiddlewareOfLog()

func (*BaseClient) OverrideGetMiddlewareOfRefreshAccessToken

func (client *BaseClient) OverrideGetMiddlewareOfRefreshAccessToken()

func (*BaseClient) OverrideGetMiddlewares

func (client *BaseClient) OverrideGetMiddlewares()

func (*BaseClient) RegisterHttpMiddlewares

func (client *BaseClient) RegisterHttpMiddlewares()

func (*BaseClient) Request

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

func (*BaseClient) RequestByEncodedData added in v3.0.38

func (client *BaseClient) RequestByEncodedData(ctx context.Context, url string, method string, options *object.HashMap,
	returnRaw bool, outHeader interface{}, outBody interface{},
) (*http.Response, error)

func (*BaseClient) RequestRaw

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

func (*BaseClient) RetryDecider

func (client *BaseClient) RetryDecider(conditions *object.HashMap) bool

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 RedisOptions

type RedisOptions redis.Options

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 *http.Response, err error)
	Notify      func(request *http.Request, closure func(event contract.EventInterface) interface{}) (response *http.Response, 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{}) (rs *http.Response, err error)

func (*ServerGuard) Serve

func (serverGuard *ServerGuard) Serve(request *http.Request) (response *http.Response, 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 UploadContent

type UploadContent struct {
	Name  string
	Value interface{}
}

type UploadForm

type UploadForm struct {
	FileName string
	Contents []*UploadContent
}

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