weixin

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2021 License: Apache-2.0 Imports: 12 Imported by: 1

README

weixin

通过企业微信群组机器人发送消息

Documentation

Index

Constants

View Source
const (
	MsgTypeFile     = "file"
	MsgTypeImage    = "image"
	MsgTypeMarkdown = "markdown"
	MsgTypeNews     = "news"
	MsgTypeText     = "text"
)
View Source
const ChannelTypeWeixin = "weixin"

Variables

View Source
var SupportedMsgtype = make(map[string]bool)

Functions

func GetMD5Hash

func GetMD5Hash(data []byte) []byte

func TruncateToValidUTF8 added in v1.0.0

func TruncateToValidUTF8(s string, byteSize int, mark string) string

func ValidMsgtype

func ValidMsgtype(msgtype string) bool

Types

type Article

type Article struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	URL         string `json:"url"`    // 点击后跳转的链接
	PicURL      string `json:"picurl"` // 图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图 1068*455,小图150*150
}

func NewArticle

func NewArticle(title string, url string) *Article

func (*Article) SetDescription

func (a *Article) SetDescription(descr string) *Article

func (*Article) SetPicURL

func (a *Article) SetPicURL(picURL string) *Article

type File

type File struct {
	MediaID string `json:"media_id"`
}

type Image

type Image struct {
	Base64 string `json:"base64"`
	MD5    string `json:"md5"`
}

type Markdown

type Markdown struct {
	Content string `json:"content"` // this should be raw markdown string, weixin bot only support a small subset syntax
}

type Msg

type Msg struct {
	MsgType  string    `json:"msgtype"`
	File     *File     `json:"file,omitempty"`
	Image    *Image    `json:"image,omitempty"`
	Markdown *Markdown `json:"markdown,omitempty"`
	News     *News     `json:"news,omitempty"`
	Text     *Text     `json:"text,omitempty"`
}

func NewMsgFile

func NewMsgFile(mediaID string) *Msg

func NewMsgFileFromPayload

func NewMsgFileFromPayload(payload *models.Payload) *Msg

func NewMsgImage

func NewMsgImage(imgByte []byte) *Msg

func NewMsgImageFromPayload

func NewMsgImageFromPayload(payload *models.Payload) *Msg

func NewMsgMarkdown

func NewMsgMarkdown(content string) *Msg

func NewMsgMarkdownFromPayload

func NewMsgMarkdownFromPayload(payload *models.Payload) *Msg

func NewMsgNews

func NewMsgNews(articles []*Article) *Msg

func NewMsgNewsFromPayload

func NewMsgNewsFromPayload(payload *models.Payload) *Msg

func NewMsgText

func NewMsgText(text *Text) *Msg

func NewMsgTextFromPayload

func NewMsgTextFromPayload(payload *models.Payload) *Msg

type News

type News struct {
	Articles []*Article `json:"articles"` // 图文消息,一个图文消息支持1到8条图文
}

type Sender

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

func NewSender

func NewSender(key string, msgType string) *Sender

func (*Sender) Send

func (s *Sender) Send(payload *models.Payload) error

type Text

type Text struct {
	Content             string   `json:"content"`
	MentionedList       []string `json:"mentioned_list"`
	MentionedMobileList []string `json:"mentioned_mobile_list"`
}

func NewText

func NewText(content string, options ...TextOption) *Text

func (*Text) WithMentionedList

func (text *Text) WithMentionedList(mentionedList []string) *Text

func (*Text) WithMentionedMobileList

func (text *Text) WithMentionedMobileList(mentionedMobileList []string) *Text

type TextOption

type TextOption func(*Text)

func TextMentionedListOpt

func TextMentionedListOpt(mentionedList []string) TextOption

func TextMentionedMobileListOpt

func TextMentionedMobileListOpt(mentionedMobileList []string) TextOption

type WeixinGroupBot

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

WexinGroupBot can send messages to weixin group ref: https://work.weixin.qq.com/api/doc/90000/90136/91770

func NewWexinGroupBot

func NewWexinGroupBot(key string) *WeixinGroupBot

func (*WeixinGroupBot) Addr

func (bot *WeixinGroupBot) Addr() string

func (*WeixinGroupBot) AddrForUpload

func (bot *WeixinGroupBot) AddrForUpload() string

func (*WeixinGroupBot) Send

func (bot *WeixinGroupBot) Send(msg *Msg) error

func (*WeixinGroupBot) SendFile

func (b *WeixinGroupBot) SendFile(filename string, fileReader io.Reader) error

func (*WeixinGroupBot) UploadFile

func (bot *WeixinGroupBot) UploadFile(filename string, fileReader io.Reader) (meidaID string, err error)

Jump to

Keyboard shortcuts

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