wxworkwebhook

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: GPL-3.0 Imports: 13 Imported by: 0

README

WxworkWebhook

企业微信webhook的api的封装,支持file,image,text,news,file消息类型,template_card类型稍复杂,暂时不支持

发送图片和文件需要本地路径,要自行下载网络上的文件,不处理下载逻辑

package main

import (
	"fmt"

	wxworkwebhook "github.com/guohuiyuan/WxworkWebhook"
)

func main() {
	w := wxworkwebhook.NewWebhook("693a91f6-7xxx-4bc4-97a0-0ec2sifa5aaa")
	fmt.Println(w.SendFile("example/黒金.jpg"))
	fmt.Println(w.SendImage("example/黒金.jpg"))
	fmt.Println(w.SendImage("http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png"))
	fmt.Println(w.SendText("大家要好好吃饭"))
	fmt.Println(w.SendMarkdown("# 大家要好好吃饭"))
	fmt.Println(w.SendNews("晚上好", "大家要好好吃饭", "https://b23.tv/BV1bz4y1z7uu", "http://i2.hdslb.com/bfs/archive/d04b95ba3658a39f594fc60379eaf84385126a81.png"))
}

Documentation

Index

Constants

View Source
const (
	MsgFile     = "file"
	MsgImage    = "image"
	MsgMarkdown = "markdown"
	MsgNews     = "news"
	MsgText     = "text"
)

Variables

This section is empty.

Functions

func IsNetFile

func IsNetFile(path string) bool

IsNetFile 是否为网络文件

Types

type Article

type Article struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	URL         string `json:"url"`
	PicURL      string `json:"picurl"`
}

type CommonResponse

type CommonResponse struct {
	Errcode int64  `json:"errcode"`
	Errmsg  string `json:"errmsg"`
}

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"`
}

type MsgReq

type MsgReq 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"`
}

type News

type News struct {
	Articles []Article `json:"articles"`
}

type Text

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

type UploadMediaResponse

type UploadMediaResponse struct {
	CommonResponse
	Type      string `json:"type"`
	MediaID   string `json:"media_id"`
	CreatedAt string `json:"created_at"`
}

type Webhook

type Webhook struct {
	WebhookKey string
}

func NewWebhook

func NewWebhook(key string) *Webhook

func (*Webhook) Send

func (w *Webhook) Send(msg interface{}) (response CommonResponse, err error)

func (*Webhook) SendFile

func (w *Webhook) SendFile(path string) (response CommonResponse, err error)

func (*Webhook) SendImage

func (w *Webhook) SendImage(path string) (response CommonResponse, err error)

func (*Webhook) SendMarkdown

func (w *Webhook) SendMarkdown(text string) (response CommonResponse, err error)

func (*Webhook) SendNews

func (w *Webhook) SendNews(title, description, jumpURL, picURL string) (response CommonResponse, err error)

func (*Webhook) SendText

func (w *Webhook) SendText(text string) (response CommonResponse, err error)

func (*Webhook) UploadMedia

func (w *Webhook) UploadMedia(path string) (response UploadMediaResponse, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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