wemessage

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2021 License: MIT Imports: 20 Imported by: 0

README

WeMessage

企业微信消息推送部分,主要包括

  • 发送应用消息
  • 接收消息和事件 // 暂未完成

从而利用企业微信来完成 ios 上类似app bark 的功能。

Usage

SendMessage
client := wemessage.NewClient(corpID, corpSecret)

textMsg := wemessage.TextMessage{
    ToUser:  "user",
    ToParty: "",
    ToTag:   "",
    MsgType: "text",
    AgentID: 100001,
    Text: struct {
        Content string `json:"content"`
    }{
        Content: "wemessage test message",
    },
    Safe:                   0,
    EnableIdTrans:          0,
    EnableDuplicateCheck:   0,
    DuplicateCheckInterval: 0,
}

_, err := wemessage.SendMessage(client, textMsg)

Documentation

Index

Constants

View Source
const (
	IMAGE        = "image"
	VOICE        = "voice"
	VIDEO        = "video"
	FILE         = "file"
	MinFileSize  = 5
	MaxImageSize = 2 * 1024 * 1024
	MaxVoiceSize = 2 * 1024 * 1024
	MaxVideoSize = 10 * 1024 * 1024
	MaxFileSize  = 20 * 1024 * 1024
)
View Source
const (
	ValidateSignatureError int = -40001
	ParseXmlError          int = -40002
	ComputeSignatureError  int = -40003
	IllegalAesKey          int = -40004
	ValidateCorpidError    int = -40005
	EncryptAESError        int = -40006
	DecryptAESError        int = -40007
	IllegalBuffer          int = -40008
	EncodeBase64Error      int = -40009
	DecodeBase64Error      int = -40010
	GenXmlError            int = -40010
	ParseJsonError         int = -40012
	GenJsonError           int = -40013
	IllegalProtocolType    int = -40014
)

Variables

View Source
var ErrSizeLimit = errors.New("exceed the file size limit")

Functions

func GetSendURL

func GetSendURL(c *Client) (string, error)

func GetTemporaryMediaURL

func GetTemporaryMediaURL(c *Client, mediaType string) (string, error)

func UploadTemporaryMedia

func UploadTemporaryMedia(c *Client, mediaType string, name string) (string, error)

Types

type CDATA

type CDATA struct {
	Value string `xml:",cdata"`
}

type Client

type Client struct {
	CorpID     string
	CorpSecret string

	BaseURL    string
	HttpClient *http.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(corpID, corpSecret string) *Client

func (*Client) AccessToken

func (c *Client) AccessToken() (string, error)

func (*Client) Get

func (c *Client) Get(url string, body io.Reader) (resp *http.Response, err error)

func (*Client) Post

func (c *Client) Post(url, contentType string, body io.Reader) (resp *http.Response, err error)

func (*Client) RenewAccessToken

func (c *Client) RenewAccessToken() error

func (Client) TokenExpired

func (c Client) TokenExpired() bool

type CryptError

type CryptError struct {
	ErrCode int
	ErrMsg  string
}

func NewCryptError

func NewCryptError(err_code int, err_msg string) *CryptError

type FileMessage

type FileMessage struct {
	ToUser  string `json:"touser"`
	ToParty string `json:"toparty"`
	ToTag   string `json:"totag"`
	MsgType string `json:"msgtype"`
	AgentID int    `json:"agentid"`
	File    struct {
		MediaID string `json:"media_id"`
	} `json:"file"`
	Safe                   int `json:"safe"`
	EnableDuplicateCheck   int `json:"enable_duplicate_check"`
	DuplicateCheckInterval int `json:"duplicate_check_interval"`
}

func (FileMessage) ToJSON

func (m FileMessage) ToJSON() ([]byte, error)

type ImageMessage

type ImageMessage struct {
	ToUser  string `json:"touser"`
	ToParty string `json:"toparty"`
	ToTag   string `json:"totag"`
	MsgType string `json:"msgtype"`
	AgentID int    `json:"agentid"`
	Image   struct {
		MediaID string `json:"media_id"`
	} `json:"image"`
	Safe                   int `json:"safe"`
	EnableDuplicateCheck   int `json:"enable_duplicate_check"`
	DuplicateCheckInterval int `json:"duplicate_check_interval"`
}

func (ImageMessage) ToJSON

func (m ImageMessage) ToJSON() ([]byte, error)

type MarkdownMessage

type MarkdownMessage struct {
	ToUser   string `json:"touser"`
	ToParty  string `json:"toparty"`
	ToTag    string `json:"totag"`
	MsgType  string `json:"msgtype"`
	AgentID  int    `json:"agentid"`
	Markdown struct {
		Content string `json:"content"`
	} `json:"markdown"`
	EnableDuplicateCheck   int `json:"enable_duplicate_check"`
	DuplicateCheckInterval int `json:"duplicate_check_interval"`
}

func (MarkdownMessage) ToJSON

func (m MarkdownMessage) ToJSON() ([]byte, error)

type Message

type Message interface {
	ToJSON() ([]byte, error)
}

type MessageResponse

type MessageResponse struct {
	ErrCode      int    `json:"errcode"`
	ErrMsg       string `json:"errmsg"`
	InvalidUser  string `json:"invaliduser"`
	InvalidParty string `json:"invalidparty"`
	InvalidTag   string `json:"invalidtag"`
	MsgID        string `json:"msgid"`
	ResponseCode string `json:"response_code"`
}

func SendMessage

func SendMessage(c *Client, m Message) (*MessageResponse, error)

func (*MessageResponse) UnMarshalFromJSON

func (r *MessageResponse) UnMarshalFromJSON(p []byte) error

type NewsMessage

type NewsMessage struct {
	ToUser  string `json:"touser"`
	ToParty string `json:"toparty"`
	ToTag   string `json:"totag"`
	MsgType string `json:"msgtype"`
	AgentID int    `json:"agentid"`
	News    struct {
		Articles []struct {
			Title       string `json:"title"`
			Description string `json:"description"`
			URL         string `json:"url"`
			PicURL      string `json:"picurl"`
			Appid       string `json:"appid"`
			PagePath    string `json:"pagepath"`
		} `json:"articles"`
	} `json:"news"`
	EnableIDTrans          int `json:"enable_id_trans"`
	EnableDuplicateCheck   int `json:"enable_duplicate_check"`
	DuplicateCheckInterval int `json:"duplicate_check_interval"`
}

func (NewsMessage) ToJSON

func (m NewsMessage) ToJSON() ([]byte, error)

type ProtocolProcessor

type ProtocolProcessor interface {
	// contains filtered or unexported methods
}

type ProtocolType

type ProtocolType int
const (
	XmlType ProtocolType = 1
)

type Response

type Response interface {
	UnMarshalFromJSON([]byte) error
}

type TemporaryMediaResponse

type TemporaryMediaResponse struct {
	ErrCode   int    `json:"errcode"`
	ErrMsg    string `json:"errmsg"`
	Type      string `json:"type"`
	MediaId   string `json:"media_id"`
	CreatedAt string `json:"created_at"`
}

func (*TemporaryMediaResponse) UnMarshalFromJSON

func (r *TemporaryMediaResponse) UnMarshalFromJSON(p []byte) error

type TextCardMessage

type TextCardMessage struct {
	ToUser   string `json:"touser"`
	ToParty  string `json:"toparty"`
	ToTag    string `json:"totag"`
	MsgType  string `json:"msgtype"`
	AgentID  int    `json:"agentid"`
	TextCard struct {
		Title       string `json:"title"`
		Description string `json:"description"`
		Url         string `json:"url"`
		BtnText     string `json:"btntxt"`
	} `json:"textcard"`
	EnableIDTrans          int `json:"enable_id_trans"`
	EnableDuplicateCheck   int `json:"enable_duplicate_check"`
	DuplicateCheckInterval int `json:"duplicate_check_interval"`
}

func (TextCardMessage) ToJSON

func (m TextCardMessage) ToJSON() ([]byte, error)

type TextMessage

type TextMessage struct {
	ToUser  string `json:"touser"`
	ToParty string `json:"toparty"`
	ToTag   string `json:"totag"`
	MsgType string `json:"msgtype"` //Must be text
	AgentID int    `json:"agentid"`
	Text    struct {
		Content string `json:"content"`
	} `json:"text"`
	Safe                   int `json:"safe"`
	EnableIdTrans          int `json:"enable_id_trans"`
	EnableDuplicateCheck   int `json:"enable_duplicate_check"`
	DuplicateCheckInterval int `json:"duplicate_check_interval"`
}

func (TextMessage) ToJSON

func (m TextMessage) ToJSON() ([]byte, error)

type TokenResponse

type TokenResponse struct {
	ErrCode     int    `json:"errcode"`
	ErrMsg      string `json:"errmsg"`
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
}

func (*TokenResponse) UnMarshalFromJSON

func (r *TokenResponse) UnMarshalFromJSON(p []byte) error

type VideoMessage

type VideoMessage struct {
	ToUser  string `json:"touser"`
	ToParty string `json:"toparty"`
	ToTag   string `json:"totag"`
	MsgType string `json:"msgtype"`
	AgentID int    `json:"agentid"`
	Video   struct {
		MediaID     string `json:"media_id"`
		Title       string `json:"title"`
		Description string `json:"description"`
	} `json:"video"`
	Safe                   int `json:"safe"`
	EnableDuplicateCheck   int `json:"enable_duplicate_check"`
	DuplicateCheckInterval int `json:"duplicate_check_interval"`
}

func (VideoMessage) ToJSON

func (m VideoMessage) ToJSON() ([]byte, error)

type VoiceMessage

type VoiceMessage struct {
	ToUser  string `json:"touser"`
	ToParty string `json:"toparty"`
	ToTag   string `json:"totag"`
	MsgType string `json:"msgtype"`
	AgentID int    `json:"agentid"`
	Voice   struct {
		MediaID string `json:"media_id"`
	} `json:"voice"`
	EnableDuplicateCheck   int `json:"enable_duplicate_check"`
	DuplicateCheckInterval int `json:"duplicate_check_interval"`
}

func (VoiceMessage) ToJSON

func (m VoiceMessage) ToJSON() ([]byte, error)

type WXBizMsg4Recv

type WXBizMsg4Recv struct {
	Tousername string `xml:"ToUserName"`
	Encrypt    string `xml:"Encrypt"`
	Agentid    string `xml:"AgentID"`
}

type WXBizMsg4Send

type WXBizMsg4Send struct {
	XMLName   xml.Name `xml:"xml"`
	Encrypt   CDATA    `xml:"Encrypt"`
	Signature CDATA    `xml:"MsgSignature"`
	Timestamp string   `xml:"TimeStamp"`
	Nonce     CDATA    `xml:"Nonce"`
}

func NewWXBizMsg4Send

func NewWXBizMsg4Send(encrypt, signature, timestamp, nonce string) *WXBizMsg4Send

type WXBizMsgCrypt

type WXBizMsgCrypt struct {
	// contains filtered or unexported fields
}

func NewWXBizMsgCrypt

func NewWXBizMsgCrypt(token, encoding_aeskey, receiver_id string, protocol_type ProtocolType) *WXBizMsgCrypt

func (*WXBizMsgCrypt) DecryptMsg

func (self *WXBizMsgCrypt) DecryptMsg(msg_signature, timestamp, nonce string, post_data []byte) ([]byte, *CryptError)

func (*WXBizMsgCrypt) EncryptMsg

func (self *WXBizMsgCrypt) EncryptMsg(reply_msg, timestamp, nonce string) ([]byte, *CryptError)

func (*WXBizMsgCrypt) ParsePlainText

func (self *WXBizMsgCrypt) ParsePlainText(plaintext []byte) ([]byte, uint32, []byte, []byte, *CryptError)

func (*WXBizMsgCrypt) VerifyURL

func (self *WXBizMsgCrypt) VerifyURL(msg_signature, timestamp, nonce, echostr string) ([]byte, *CryptError)

type XmlProcessor

type XmlProcessor struct {
}

Jump to

Keyboard shortcuts

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