Documentation ¶
Overview ¶
企业微信微信 SDK 的核心库
Index ¶
- Constants
- func AESDecryptData(cipherText []byte, aesKey []byte, iv []byte) (rawData []byte, err error)
- func AESDecryptMsg(ciphertext []byte, aesKey []byte) (random, rawXMLMsg, received []byte, err error)
- func AESEncryptMsg(random, rawXMLMsg []byte, receiveId string, aesKey []byte) (ciphertext []byte)
- type AccessTokenServer
- type Client
- func (clt *Client) GetJSON(incompleteURL string, response interface{}) (err error)
- func (clt *Client) PostJSON(incompleteURL string, request interface{}, response interface{}) (err error)
- func (clt *Client) PostMultipartForm(incompleteURL string, fields []MultipartFormField, response interface{}) (err error)
- type DefaultAccessTokenServer
- func (srv *DefaultAccessTokenServer) Debug() bool
- func (srv *DefaultAccessTokenServer) IID01332E16DF5011E5A9D5A4DB30FED8E1()
- func (srv *DefaultAccessTokenServer) RefreshToken(currentToken string) (token string, err error)
- func (srv *DefaultAccessTokenServer) RefreshTokenWithExpires(currentToken string) (token string, expiresIn int64, err error)
- func (srv *DefaultAccessTokenServer) SetDebug(debug bool)
- func (srv *DefaultAccessTokenServer) SetSecret(corpId string, corpSecret string)
- func (srv *DefaultAccessTokenServer) Token() (token string, err error)
- type Error
- type MultipartFormField
- type SimpleAccessTokenServer
- func (srv *SimpleAccessTokenServer) Debug() bool
- func (srv *SimpleAccessTokenServer) IID01332E16DF5011E5A9D5A4DB30FED8E1()
- func (srv *SimpleAccessTokenServer) RefreshToken(currentToken string) (token string, err error)
- func (srv *SimpleAccessTokenServer) RefreshTokenWithExpires(currentToken string) (token string, expiresIn int64, err error)
- func (srv *SimpleAccessTokenServer) SetDebug(debug bool)
- func (srv *SimpleAccessTokenServer) SetSecret(corpId string, corpSecret string)
- func (srv *SimpleAccessTokenServer) Token() (token string, err error)
Constants ¶
View Source
const ( ErrCodeOK = 0 ErrCodeInvalidCredential = 40001 // access_token 过期错误码 ErrCodeAccessTokenExpired = 42001 // access_token 过期错误码(maybe!!!) )
Variables ¶
This section is empty.
Functions ¶
func AESDecryptData ¶
Types ¶
type AccessTokenServer ¶
type AccessTokenServer interface { Token() (token string, err error) // 请求中控服务器返回缓存的 access_token SetDebug(bool) Debug() bool RefreshToken(currentToken string) (token string, err error) // 请求中控服务器刷新 access_token SetSecret(corpId string, corpSecret string) RefreshTokenWithExpires(currentToken string) (token string, expiresIn int64, err error) // 请求中控服务器刷新 access_token IID01332E16DF5011E5A9D5A4DB30FED8E1() // 接口标识, 没有实际意义 }
access_token 中控服务器接口.
type Client ¶
type Client struct { AccessTokenServer HttpClient *http.Client }
func NewClient ¶
func NewClient(srv AccessTokenServer, clt *http.Client) *Client
NewClient 创建一个新的 Client.
如果 clt == nil 则默认用 util.DefaultHttpClient
func (*Client) GetJSON ¶
GetJSON HTTP GET 微信资源, 然后将微信服务器返回的 JSON 用 encoding/json 解析到 response.
NOTE: 1. 一般不需要调用这个方法, 请直接调用高层次的封装函数; 2. 最终的 URL == incompleteURL + access_token; 3. response 格式有要求, 要么是 *Error, 要么是下面结构体的指针(注意 Error 必须是第一个 Field): struct { Error ... }
func (*Client) PostJSON ¶
func (clt *Client) PostJSON(incompleteURL string, request interface{}, response interface{}) (err error)
PostJSON 用 encoding/json 把 request marshal 为 JSON, HTTP POST 到微信服务器, 然后将微信服务器返回的 JSON 用 encoding/json 解析到 response.
NOTE: 1. 一般不需要调用这个方法, 请直接调用高层次的封装函数; 2. 最终的 URL == incompleteURL + access_token; 3. response 格式有要求, 要么是 *Error, 要么是下面结构体的指针(注意 Error 必须是第一个 Field): struct { Error ... }
func (*Client) PostMultipartForm ¶
func (clt *Client) PostMultipartForm(incompleteURL string, fields []MultipartFormField, response interface{}) (err error)
PostMultipartForm 通用上传接口.
--BOUNDARY Content-Disposition: form-data; name="FIELDNAME"; filename="FILENAME" Content-Type: application/octet-stream FILE-CONTENT --BOUNDARY Content-Disposition: form-data; name="FIELDNAME" JSON-DESCRIPTION --BOUNDARY-- NOTE: 1. 一般不需要调用这个方法, 请直接调用高层次的封装函数; 2. 最终的 URL == incompleteURL + access_token; 3. response 格式有要求, 要么是 *Error, 要么是下面结构体的指针(注意 Error 必须是第一个 Field): struct { Error ... }
type DefaultAccessTokenServer ¶
type DefaultAccessTokenServer struct {
// contains filtered or unexported fields
}
DefaultAccessTokenServer 实现了 AccessTokenServer 接口.
NOTE: 1. 用于单进程环境. 2. 因为 DefaultAccessTokenServer 同时也是一个简单的中控服务器, 而不是仅仅实现 AccessTokenServer 接口, 所以整个系统只能存在一个 DefaultAccessTokenServer 实例!
func NewDefaultAccessTokenServer ¶
func NewDefaultAccessTokenServer(corpId, corpSecret string, httpClient *http.Client) (srv *DefaultAccessTokenServer)
NewDefaultAccessTokenServer 创建一个新的 DefaultAccessTokenServer, 如果 httpClient == nil 则默认使用 util.DefaultHttpClient.
func (*DefaultAccessTokenServer) Debug ¶
func (srv *DefaultAccessTokenServer) Debug() bool
func (*DefaultAccessTokenServer) IID01332E16DF5011E5A9D5A4DB30FED8E1 ¶
func (srv *DefaultAccessTokenServer) IID01332E16DF5011E5A9D5A4DB30FED8E1()
func (*DefaultAccessTokenServer) RefreshToken ¶
func (srv *DefaultAccessTokenServer) RefreshToken(currentToken string) (token string, err error)
func (*DefaultAccessTokenServer) RefreshTokenWithExpires ¶
func (srv *DefaultAccessTokenServer) RefreshTokenWithExpires(currentToken string) (token string, expiresIn int64, err error)
func (*DefaultAccessTokenServer) SetDebug ¶
func (srv *DefaultAccessTokenServer) SetDebug(debug bool)
func (*DefaultAccessTokenServer) SetSecret ¶
func (srv *DefaultAccessTokenServer) SetSecret(corpId string, corpSecret string)
func (*DefaultAccessTokenServer) Token ¶
func (srv *DefaultAccessTokenServer) Token() (token string, err error)
type MultipartFormField ¶
type SimpleAccessTokenServer ¶
type SimpleAccessTokenServer struct {
// contains filtered or unexported fields
}
func NewSimpleAccessTokenServer ¶
func NewSimpleAccessTokenServer(token string, httpClient *http.Client) (srv *SimpleAccessTokenServer)
func (*SimpleAccessTokenServer) Debug ¶
func (srv *SimpleAccessTokenServer) Debug() bool
func (*SimpleAccessTokenServer) IID01332E16DF5011E5A9D5A4DB30FED8E1 ¶
func (srv *SimpleAccessTokenServer) IID01332E16DF5011E5A9D5A4DB30FED8E1()
func (*SimpleAccessTokenServer) RefreshToken ¶
func (srv *SimpleAccessTokenServer) RefreshToken(currentToken string) (token string, err error)
func (*SimpleAccessTokenServer) RefreshTokenWithExpires ¶
func (srv *SimpleAccessTokenServer) RefreshTokenWithExpires(currentToken string) (token string, expiresIn int64, err error)
func (*SimpleAccessTokenServer) SetDebug ¶
func (srv *SimpleAccessTokenServer) SetDebug(debug bool)
func (*SimpleAccessTokenServer) SetSecret ¶
func (srv *SimpleAccessTokenServer) SetSecret(corpId string, corpSecret string)
func (*SimpleAccessTokenServer) Token ¶
func (srv *SimpleAccessTokenServer) Token() (token string, err error)
Click to show internal directories.
Click to hide internal directories.