weixinapp

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: Apache-2.0 Imports: 8 Imported by: 1

README

weixinapp

通过企业微信的应用发送消息。

只有企业管理员账号才有权限创建应用。

Documentation

Index

Constants

View Source
const (
	MsgTypeText              = "text"
	MsgTypeFile              = "file"
	MsgTypeImage             = "image"
	MsgTypeVoice             = "voice"
	MsgTypeVideo             = "video"
	MsgTypeNews              = "news"
	MsgTypeMPNews            = "mpnews"
	MsgTypeTextCard          = "textcard"
	MsgTypeMarkdown          = "markdown"
	MsgTypeMiniprogramNotice = "miniprogram_notice"
	MsgTypeInteractiveCard   = "interactive_card"
)
View Source
const ChannelTypeWeixin = "weixinapp"

Variables

View Source
var ErrCodeAboutTokens = []int{
	40014,
	42001,
}

ErrCodeAboutTokens contains weixinapp https://work.weixin.qq.com/api/doc/90000/90139/90313

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

Functions

func SanitizeMarkdown

func SanitizeMarkdown(content 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 ArticleForMPNews

type ArticleForMPNews struct {
	Title            string `json:"title"`
	ThumbMediaID     string `json:"thumb_media_id"`
	Author           string `json:"author,omitempty"`
	ContentSourceURL string `json:"content_source_url,omitempty"`
	Content          string `json:"content,omitempty"`
	Digest           string `json:"digest,omitempty"`
}

type Btn

type Btn struct {
	Key    string `json:"key"`
	Name   string `json:"name"`
	Color  string `json:"color,omitempty"`
	IsBold bool   `json:"bool,omitempty"`
}

type File

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

type Image

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

type InteractiveTaskcard

type InteractiveTaskcard struct {
	Title  string `json:"title"`
	TaskID string `json:"task_id"`
	Btns   []*Btn `json:"btn"`

	Description string `json:"description,omitempty"`
	URL         string `json:"url,omitempty"`
}

type KV

type KV struct {
	Key   string `json:"key"`
	Value string `json:"string"`
}

type MPNews

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

type Markdown

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

type MiniprogramNotice

type MiniprogramNotice struct {
	AppID             string `json:"appid"`
	Page              string `json:"page"`
	Title             string `json:"title"`
	Description       string `json:"description"`
	EmphasisFirstItem string `json:"emphasis_first_item"`
	ContentItem       []KV   `json:"content_item"`
}

type Msg

type Msg struct {
	MsgType string `json:"msgtype"`
	AgentID int    `json:"agentid"`

	// touser、toparty、totag不能同时为空
	ToUser  string `json:"touser,omitempty"`
	ToParty string `json:"toparty,omitempty"`
	ToTag   string `json:"totag,omitempty"`

	Text                *Text                `json:"text,omitempty"`
	Image               *Image               `json:"image,omitempty"`
	Voice               *Voice               `json:"voice,omitempty"`
	File                *File                `json:"file,omitempty"`
	TextCard            *TextCard            `json:"textcard,omitempty"`
	News                *News                `json:"news,omitempty"`
	MPNews              *MPNews              `json:"mpnews,omitempty"`
	Markdown            *Markdown            `json:"markdown,omitempty"`
	MiniprogramNotice   *MiniprogramNotice   `json:"miniprogram_notice,omitempty"`
	InteractiveTaskcard *InteractiveTaskcard `json:"interactive_taskcard,omitempty"`

	Safe                   int `json:"safe,omitempty"`
	EnableIDTrans          int `json:"enable_id_trans,omitempty"`
	DuplicateCheckInterval int `json:"duplicate_check_interval,omitempty"`
}

func NewMsgFile

func NewMsgFile(file *File) *Msg

func NewMsgFileFromPayload

func NewMsgFileFromPayload(payload *models.Payload) *Msg

func NewMsgImage

func NewMsgImage(mediaID string) *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(content string) *Msg

func NewMsgTextFromPayload

func NewMsgTextFromPayload(payload *models.Payload) *Msg

func (*Msg) Valid

func (msg *Msg) Valid() bool

type News

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

type Notifier

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

func NewNotifer

func NewNotifer(corpID string, agentID int, agentSecret string) *Notifier

func (*Notifier) Addr

func (n *Notifier) Addr() string

func (*Notifier) AddrForGetToken

func (n *Notifier) AddrForGetToken() string

func (*Notifier) GetToken

func (n *Notifier) GetToken() error

func (*Notifier) Send

func (n *Notifier) Send(msg *Msg) error

func (*Notifier) ShouldGetToken

func (n *Notifier) ShouldGetToken() bool

type Sender

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

func NewSender

func NewSender(corpID string, agentID int, agentSecret string, msgType string) *Sender

func (*Sender) Send

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

type Text

type Text struct {
	Content string `json:"content"`
}

type TextCard

type TextCard struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	URL         string `json:"url"`
	BtnText     string `json:"btntext"`
}

type Video

type Video struct {
	MediaID     string `json:"media_id"`
	Title       string `json:"title"`
	Description string `json:"description"`
}

type Voice

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

Jump to

Keyboard shortcuts

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