wxwork

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2019 License: BSD-3-Clause Imports: 10 Imported by: 1

README

企业微信消息接口

简单的企业微信消息接口api,目前实现功能个:

  1. 以文本格式,发送应用消息
  2. 以Markdown格式发送应用消息

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	BaseURL = "https://qyapi.weixin.qq.com"

	Methods = map[string]HTTPAction{
		"GetAccessToken": HTTPAction{
			Method: "GET",
			URL:    "/cgi-bin/gettoken?corpid={{.CropID}}&corpsecret={{.Secret}}",
		},
		"MessageSend": HTTPAction{
			Method: "POST",
			URL:    "/cgi-bin/message/send?access_token={{.Token}}",
		},
	}
)

Functions

This section is empty.

Types

type API

type API struct {
	Secret  string
	AgentID int
	CropID  string
	Token   string
	// contains filtered or unexported fields
}

func GetAPI

func GetAPI() (a *API, err error)

func GetAPIFromFile

func GetAPIFromFile(configFile string) (a *API, err error)

func NewAPI

func NewAPI(cropID string, agentID int, secret string) *API

func (*API) GetToken

func (a *API) GetToken() (token string, err error)

func (*API) Send

func (a *API) Send(msg interface{}) (err error)

func (*API) SendMarkdownToUser

func (a *API) SendMarkdownToUser(content string, users ...string) (err error)

func (*API) SendTextToUser

func (a *API) SendTextToUser(content string, users ...string) (err error)

type Config

type Config struct {
	CropID string `json:"cropid"`
	Agent  int    `json:"agentid"`
	Secret string `json:"secret"`
}

Config wxwork config

type HTTPAction

type HTTPAction struct {
	Method string
	URL    string
}

type ImageMsg

type ImageMsg struct {
	MsgBase
	Image struct {
		MediaID string `json:"media_id"`
	} `json:"image"`
	Safe          int `json:"safe"`
	EnableIDTrans int `json:"enable_id_trans"`
}

ImageMsg image msg

type MarkdownMsg

type MarkdownMsg struct {
	MsgBase
	Markdown struct {
		Content string `json:"content"`
	} `json:"markdown"`
}

MarkdownMsg markdown msg

func NewMarkdownMsg

func NewMarkdownMsg(content string) *MarkdownMsg

type MsgBase

type MsgBase struct {
	ToUser  string `json:"touser"`
	ToParty string `json:"toparty"`
	ToTag   string `json:"totag"`
	MsgType string `json:"msgtype"`
	AgentID int    `json:"agentid"`
}

MsgBase msg base struct

type MsgResp

type MsgResp struct {
	RespBase
	InvalidUser  string `json:"invaliduser"`
	InvalidParty string `json:"invalidparty"`
	InvalidTag   string `json:"invalidtag"`
}

type RespBase

type RespBase struct {
	ErrCode int    `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

func (*RespBase) Error

func (r *RespBase) Error() error

type TextMsg

type TextMsg struct {
	MsgBase
	Text struct {
		Content string `json:"content"`
	} `json:"text"`
	Safe          int `json:"safe"`
	EnableIDTrans int `json:"enable_id_trans"`
}

TextMsg text msg

func NewTextMsg

func NewTextMsg(content string) *TextMsg

type TokenResp

type TokenResp struct {
	RespBase
	AccessToken string `json:"access_token"`
	ExpireIn    int    `json:"expires_in"`
}

Jump to

Keyboard shortcuts

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