notify

package
v0.0.0-...-a9153d3 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: MIT Imports: 6 Imported by: 0

README

gateway-notify

geteway的附属notify sdk

Usage

import "https://github.com/hduhelp/api_open_sdk/notify"

func init() {
    notify.Init("appName","appSign")

    //InitOAuthApp("clientId", "clientSecret")

    //token := "12345678-236c-473a-ba32-1234567890"
    //InitPrivateApp(&token)
}

func main() {
    notice := New()
    notice.NewWeChat().
        SetTmpl("WZsoRBsLvbwRSk_2qr3oTkproxKbwbNjx4iwE7swJ6Y"). // 学校通知
        SetData("first", "通知标题", ""). // 标题
        SetData("keyword1", "通知大学", ""). // 学校
        SetData("keyword2", "通知人", ""). // 通知人
        SetData("keyword3", time.Now().Format("2006-01-02"), ""). // 通知时间
        SetData("keyword4", "通知内容", "") // 通知内容
    notice.NewDingTalk().
        MarkdownMsg(
            fmt.Sprintf("您收到一条来自%s的通知", "通知人"),
            fmt.Sprintf(
            "# %s\n\n"+
            "#### 通知人:%s\n\n"+
            "#### 通知时间:%s\n\n"+
            "通知内容:%s", "通知标题", "通知人", time.Now().Format("2006-01-02"), "通知内容"))
    notice.Receiver("接收者1的学号","接收者2的学号")
    notice.Receiver("接收者3的学号")
    _ = notice.Send()    
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(appName, appSign string)

Init 内部应用认证初始化

func InitOAuthApp

func InitOAuthApp(clientId, clientSecret string)

InitOAuthApp OAuth应用认证初始化 (发送范围仅限授权过该OAuth应用的用户)

func InitPrivateApp

func InitPrivateApp(token *string)

InitPrivateApp 个人token认证初始化 (发送范围仅限token对应用户)

Types

type DingTalkMsgLinkInput

type DingTalkMsgLinkInput struct {
	MessageUrl string `json:"messageUrl"`
	PicUrl     string `json:"picUrl"`
	Title      string `json:"title"`
	Text       string `json:"text"`
}

type DingTalkMsgMarkdownInput

type DingTalkMsgMarkdownInput struct {
	Title string `json:"title"` // 这个是点进推送列表前显示的简短的消息(进入后不可见)
	Text  string `json:"text"`  // 这个是进入后显示的详细的消息
}

type DingTalkMsgPlainTextInput

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

type DingTalkNoticeBody

type DingTalkNoticeBody struct {
	MsgType  string                     `json:"msgtype"`
	Text     *DingTalkMsgPlainTextInput `json:"text,omitempty"`
	Link     *DingTalkMsgLinkInput      `json:"link,omitempty"`
	Markdown *DingTalkMsgMarkdownInput  `json:"markdown,omitempty"`
}

func (*DingTalkNoticeBody) LinkMsg

func (t *DingTalkNoticeBody) LinkMsg(messageUrl, picUrl, title, text string)

func (*DingTalkNoticeBody) MarkdownMsg

func (t *DingTalkNoticeBody) MarkdownMsg(title, text string)

func (*DingTalkNoticeBody) PlainText

func (t *DingTalkNoticeBody) PlainText(content string)

type MiniProgram

type MiniProgram struct {
	AppId    string `json:"appid"`    // 必选; 所需跳转到的小程序appid(该小程序appid必须与发模板消息的公众号是绑定关联关系)
	PagePath string `json:"pagepath"` // 必选; 所需跳转到的小程序appid(该小程序appid必须与发模板消息的公众号是绑定关联关系)
}

type SendResult

type SendResult struct {
	Cache bool `json:"cache"`
	Data  struct {
		Failed  int `json:"failed"`
		Success int `json:"success"`
	} `json:"data"`
	Error int    `json:"error"`
	Msg   string `json:"msg"`
}

type Template

type Template struct {
	StaffID  []string            `json:"StaffID"`
	WeChat   *WeChatNoticeBody   `json:"template,omitempty"`
	DingTalk *DingTalkNoticeBody `json:"dingtalk,omitempty"`
	App      *UniNotifyInput     `json:"body,omitempty"`
	// contains filtered or unexported fields
}

func New

func New() *Template

func (*Template) NewApp

func (t *Template) NewApp(title, subtitle, content, extra string) *UniNotifyInput

func (*Template) NewDingTalk

func (t *Template) NewDingTalk() *DingTalkNoticeBody

func (*Template) NewWeChat

func (t *Template) NewWeChat() *WeChatNoticeBody

func (*Template) Receiver

func (t *Template) Receiver(staffId ...string) *Template

func (*Template) Send

func (t *Template) Send() error

func (*Template) WithContext

func (t *Template) WithContext(ctx context.Context) *Template

type TemplateDataItem

type TemplateDataItem struct {
	Value string `json:"value"`
	Color string `json:"color,omitempty"`
}

TemplateDataItem 模版内某个 .DATA 的值

type UniNotifyInput

type UniNotifyInput struct {
	Title    string
	SubTitle string
	Content  string
	Extra    string
}

type WeChatNoticeBody

type WeChatNoticeBody struct {
	Data        map[string]*TemplateDataItem `json:"data"`
	TemplateID  string                       `json:"template_id"`
	ToUser      string                       `json:"touser"`
	URL         string                       `json:"url"`
	MiniProgram *MiniProgram                 `json:"miniprogram,omitempty"`
}

func (*WeChatNoticeBody) MiniPro

func (t *WeChatNoticeBody) MiniPro(appid, pagePath string) *WeChatNoticeBody

func (*WeChatNoticeBody) SetData

func (t *WeChatNoticeBody) SetData(key, value, color string) *WeChatNoticeBody

func (*WeChatNoticeBody) SetTmpl

func (t *WeChatNoticeBody) SetTmpl(templateId string) *WeChatNoticeBody

func (*WeChatNoticeBody) Url

Jump to

Keyboard shortcuts

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