core

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

企业微信微信 SDK 的核心库

Index

Constants

View Source
const (
	ErrCodeOK                 = 0
	ErrCodeInvalidCredential  = 40001 // access_token 过期错误码
	ErrCodeAccessTokenExpired = 42001 // access_token 过期错误码(maybe!!!)
)

Variables

This section is empty.

Functions

func AESDecryptData

func AESDecryptData(cipherText []byte, aesKey []byte, iv []byte) (rawData []byte, err error)

func AESDecryptMsg

func AESDecryptMsg(ciphertext []byte, aesKey []byte) (random, rawXMLMsg, received []byte, err error)

ciphertext = AES_Encrypt[random(16B) + msg_len(4B) + rawXMLMsg + received]

func AESEncryptMsg

func AESEncryptMsg(random, rawXMLMsg []byte, receiveId string, aesKey []byte) (ciphertext []byte)

ciphertext = AES_Encrypt[random(16B) + msg_len(4B) + rawXMLMsg + receiveId]

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 NewClientWithToken

func NewClientWithToken(token string, clt *http.Client) *Client

func (*Client) GetJSON

func (clt *Client) GetJSON(incompleteURL string, response interface{}) (err error)

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 Error

type Error struct {
	ErrCode int64  `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

func (*Error) Error

func (err *Error) Error() string

type MultipartFormField

type MultipartFormField struct {
	IsFile   bool
	Name     string
	FileName string
	Value    io.Reader
}

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)

Jump to

Keyboard shortcuts

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