Documentation ¶
Index ¶
- Constants
- Variables
- type AccessToken
- func (accessToken *AccessToken) ApplyToRequest(request *http.Request, requestOptions *object.HashMap) (*http.Request, error)
- func (accessToken *AccessToken) GetCacheKey() string
- func (accessToken *AccessToken) GetRefreshedToken() (*response2.ResponseGetToken, error)
- func (accessToken *AccessToken) GetToken(refresh bool) (resToken *response2.ResponseGetToken, err error)
- func (accessToken *AccessToken) OverrideGetEndpoint()
- func (accessToken *AccessToken) OverrideGetMiddlewareOfLog()
- func (accessToken *AccessToken) OverrideGetMiddlewares()
- func (accessToken *AccessToken) Refresh() contract.AccessTokenInterface
- func (accessToken *AccessToken) RegisterHttpMiddlewares()
- func (accessToken *AccessToken) SetToken(token *response2.ResponseGetToken) (tokenInterface contract.AccessTokenInterface, err error)
- type ApplicationInterface
- type BaseClient
- func (client *BaseClient) CheckTokenNeedRefresh(req *http.Request, rs *http.Response, retry int) (*http.Response, error)
- func (client *BaseClient) HttpGet(ctx context.Context, url string, query *object.StringMap, ...) (interface{}, error)
- func (client *BaseClient) HttpPost(ctx context.Context, url string, data interface{}, outHeader interface{}, ...) (interface{}, error)
- func (client *BaseClient) HttpPostJson(ctx context.Context, url string, data interface{}, query *object.StringMap, ...) (interface{}, error)
- func (client *BaseClient) HttpUpload(ctx context.Context, url string, files *object.HashMap, form *UploadForm, ...) (interface{}, error)
- func (client *BaseClient) OverrideGetMiddlewareOfAccessToken()
- func (client *BaseClient) OverrideGetMiddlewareOfLog()
- func (client *BaseClient) OverrideGetMiddlewareOfRefreshAccessToken()
- func (client *BaseClient) OverrideGetMiddlewares()
- func (client *BaseClient) RegisterHttpMiddlewares()
- func (client *BaseClient) Request(ctx context.Context, url string, method string, options *object.HashMap, ...) (*http.Response, error)
- func (client *BaseClient) RequestRaw(ctx context.Context, url string, method string, options *object.HashMap, ...) (*http.Response, error)
- func (client *BaseClient) RetryDecider(conditions *object.HashMap) bool
- type CDATA
- type CacheInterface
- type Config
- type Encryptor
- func (encryptor *Encryptor) Decrypt(content []byte, msgSignature, nonce, timestamp string) ([]byte, *support.CryptError)
- func (encryptor *Encryptor) DecryptContent(content string) ([]byte, *support.CryptError)
- func (encryptor *Encryptor) Encrypt(msg, nonce, timestamp string) ([]byte, *support.CryptError)
- func (encryptor *Encryptor) GetToken() string
- func (encryptor *Encryptor) Signature(token, timestamp, nonce, data string) string
- func (encryptor *Encryptor) VerifyUrl(content string, msgSignature, nonce, timestamp string) ([]byte, *support.CryptError)
- type ExtraInfo
- type InteractsWithCache
- type RedisOptions
- type ServerGuard
- func (serverGuard *ServerGuard) DecryptEvent(request *http.Request, content string) (callbackHeader *models.CallbackMessageHeader, err error)
- func (serverGuard *ServerGuard) GetEvent(request *http.Request) (callback *models.Callback, callbackHeader *models.CallbackMessageHeader, ...)
- func (serverGuard *ServerGuard) GetMessage(request *http.Request) (callback *models.Callback, callbackHeader *models.CallbackMessageHeader, ...)
- func (serverGuard *ServerGuard) OverrideGetToken()
- func (serverGuard *ServerGuard) OverrideHandleEvent()
- func (serverGuard *ServerGuard) OverrideNotify()
- func (serverGuard *ServerGuard) OverrideResolve()
- func (serverGuard *ServerGuard) ParseMessage(content string) (callback *models.Callback, err error)
- func (serverGuard *ServerGuard) ResolveEvent(request *http.Request, closure func(event contract.EventInterface) interface{}) (rs *http.Response, err error)
- func (serverGuard *ServerGuard) Serve(request *http.Request) (response *http.Response, err error)
- type ServiceContainer
- type UploadContent
- type UploadForm
- type WeComRecvMsg
- type WeComReplyMsg
Constants ¶
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
const SUCCESS_EMPTY_RESPONSE = "success"
Variables ¶
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 CachePrefix string *InteractsWithCache GetCredentials func() *object.StringMap GetEndpoint func() (string, error) GetMiddlewareOfLog func(logger contract2.LoggerInterface) contract3.RequestMiddleware }
func NewAccessToken ¶
func NewAccessToken(app *ApplicationInterface) (*AccessToken, error)
func (*AccessToken) ApplyToRequest ¶
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) 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) 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 (*BaseClient) HttpPost ¶
func (client *BaseClient) HttpPost(ctx context.Context, url string, data interface{}, outHeader interface{}, outBody interface{}) (interface{}, error)
func (*BaseClient) HttpPostJson ¶
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) RequestRaw ¶
func (*BaseClient) RetryDecider ¶
func (client *BaseClient) RetryDecider(conditions *object.HashMap) bool
type CacheInterface ¶
type CacheInterface cache.CacheInterface
func NewRedisClient ¶
func NewRedisClient(options *RedisOptions) CacheInterface
type Config ¶
type Config struct {
*object.Collection
}
type Encryptor ¶
type Encryptor struct {
// contains filtered or unexported fields
}
func NewEncryptor ¶
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) 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×tamp=1623292419&nonce=1623324060&echostr=o1XtmVltGmUAqoWee54yd4Q5ZBgrw4%2F9lFo5qdZoVPd1DybzarjuYCfFlR2AFbAcWHwFgmbrVBD%2Bf9910QIF6g%3D%3D"
type ExtraInfo ¶
func NewExtraInfo ¶
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 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 *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 ¶
回调配置 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 }