wxwork

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: MIT Imports: 20 Imported by: 0

README

WXWork GoDoc Go Report Card

企业微信 SDK,文档见 godoc

TODO

通讯录管理
  • 成员管理
    • 创建成员
    • 读取成员
    • 更新成员
    • 删除成员
    • 获取部门成员
    • 获取部门成员详情
    • userid与openid互换
    • 二次验证
    • 邀请成员
    • 获取加入企业二维码
  • 部门管理
    • 创建部门
    • 更新部门
    • 删除部门
    • 获取部门列表
  • 标签管理
    • 创建标签
    • 更新标签名字
    • 删除标签
    • 获取标签成员
    • 增加标签成员
    • 删除标签成员
    • 获取标签列表
  • 异步批量接口
    • 增量更新成员
    • 全量覆盖成员
    • 全量覆盖部门
    • 获取异步任务结果
  • 通讯录回调通知
    • 成员变更通知
    • 部门变更通知
    • 标签变更通知
    • 异步任务完成通知
外部联系人管理
  • 企业服务人员管理
  • 客户管理
  • 客户标签管理
  • 客户群管理
  • 消息推送
  • 离职管理
  • 统计管理
  • 变更回调
身份验证
  • 网页授权登录
    • 构造扫码登录链接
    • 获取访问用户身份
  • 扫码授权登录
    • 构造扫码登录链接
    • 获取访问用户身份
应用管理
  • 获取应用
  • 设置应用
  • 自定义菜单
    • 创建菜单
    • 获取菜单
    • 删除菜单
消息推送
  • 发送应用消息
  • 更新任务卡片消息状态
  • 接收消息
  • 发消息到群聊会话
    • 创建群聊会话
    • 修改群聊会话
    • 获取群聊会话
    • 应用推送消息
  • 互联企业消息推送
    • 发送应用消息
    • 接收消息与事件
素材管理
  • 发送应用消息
    • 上传临时素材
    • 上传图片
    • 获取临时素材
    • 获取高清语音素材
OA数据接口
  • 企业微信打卡应用
    • 获取打卡数据
    • 获取打卡规则
  • 企业微信审批应用
    • 获取审批模板详情
    • 提交审批申请
    • 审批申请状态变化回调通知
    • 批量获取审批单号
    • 获取审批申请详情
  • 企业微信公费电话
    • 获取公费电话拨打记录
日程接口
  • 创建日程
  • 更新日程
  • 取消日程
  • 获取日程
电子发票
  • 查询电子发票
  • 更新发票状态
  • 批量更新发票状态
  • 批量查询电子发票

Documentation

Index

Constants

View Source
const (
	// MSG_TYPE_TEXT 文本消息类型
	MSG_TYPE_TEXT = "text"
	// MSG_TYPE_IMAGE 图片消息类型
	MSG_TYPE_IMAGE = "image"
	// MSG_TYPE_VOICE 语音消息
	MSG_TYPE_VOICE = "voice"
	// MSG_TYPE_VIDEO 视频消息
	MSG_TYPE_VIDEO = "video"
	// MSG_TYPE_FILE 文件消息
	MSG_TYPE_FILE = "file"
	// MSG_TYPE_TEXTCARD 文本卡片消息
	MSG_TYPE_TEXTCARD = "textcard"
	// MSG_TYPE_NEWS 图文消息
	MSG_TYPE_NEWS = "news"
	// MSG_TYPE_MPNEWS 图文消息(mpnews)
	MSG_TYPE_MPNEWS = "mpnews"
	// MSG_TYPE_MARKDOWN markdown消息
	MSG_TYPE_MARKDOWN = "markdown"
	// MSG_TYPE_MINIPROGRAM_NOTICE 小程序通知消息
	MSG_TYPE_MINIPROGRAM_NOTICE = "miniprogram_notice"
	// MSG_TYPE_TASKCARD 任务卡片消息
	MSG_TYPE_TASKCARD = "taskcard"
	// MSG_TYPE_LOCATION 位置消息
	MSG_TYPE_LOCATION = "location"
	// MSG_TYPE_LINK 链接消息
	MSG_TYPE_LINK = "link"
	// MSG_TYPE_EVENT 事件消息
	MSG_TYPE_EVENT = "event"
)
View Source
const BaseURL = "https://qyapi.weixin.qq.com/cgi-bin/"

BaseURL 企业微信API接口基础网址

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	AccessToken string    `json:"access_token"`         // 获取到的凭证,最长为512字节
	ExpiresIn   int64     `json:"expires_in,omitempty"` // 凭证的有效时间(秒),通常为2小时(7200秒)
	ExpireAt    time.Time `json:"expire_at,omitempty"`  // 过期时间,超过时重新获取
	// contains filtered or unexported fields
}

AccessToken 定义了获取 access_token 时的响应

func (AccessToken) Error

func (b AccessToken) Error() error

Error 返回失败信息

func (*AccessToken) IsExpire

func (token *AccessToken) IsExpire() bool

IsExpire 验证 access_token 是否过期

func (AccessToken) Success

func (b AccessToken) Success() bool

Success 返回是否调用成功

type Agent

type Agent struct {
	// 企业ID
	CorpID string
	// AgentID 应用ID
	AgentID int
	// Secret 应用秘钥
	Secret string
	// AccessToken 应用登录凭证
	AccessToken *AccessToken
	// 是否开启Debug
	Debug bool

	Cache Cache
	// contains filtered or unexported fields
}

Agent 应用结构

func NewAgent

func NewAgent(corpid string, agentid int) *Agent

NewAgent 新建一个应用

func (*Agent) AddTagUsers

func (a *Agent) AddTagUsers(id int, users []string, parties []int) (invalidlist string, invalidparty []int, err error)

AddTagUsers 增加标签成员 文档: https://work.weixin.qq.com/api/doc/90000/90135/90214

func (*Agent) AppChatSendMessage

func (a *Agent) AppChatSendMessage(msg *AppChatMessage) error

AppChatSendMessage 应用推送消息 文档: https://work.weixin.qq.com/api/doc/90000/90135/90248

func (*Agent) BatchDeleteUsers

func (a *Agent) BatchDeleteUsers(ids ...string) error

BatchDeleteUsers 批量删除成员 文档: https://work.weixin.qq.com/api/doc/90000/90135/90199

func (*Agent) BatchInvite

func (a *Agent) BatchInvite(user []string, party, tag []int) (invaliduser []string, invalidparty, invalidtag []int, err error)

BatchInvite 邀请成员使用企业微信 文档: https://work.weixin.qq.com/api/doc/90000/90135/90975

func (*Agent) CallbackVerify

func (a *Agent) CallbackVerify(w http.ResponseWriter, r *http.Request)

CallbackVerify 回调配置验证URL有效性

func (*Agent) CreateAppChat

func (a *Agent) CreateAppChat(data map[string]interface{}) (string, error)

CreateAppChat 创建群聊会话 文档: https://work.weixin.qq.com/api/doc/90000/90135/90245

func (*Agent) CreateDepartment

func (a *Agent) CreateDepartment(dept map[string]interface{}) (int, error)

CreateDepartment 创建部门 文档: https://work.weixin.qq.com/api/doc/90000/90135/90205

func (*Agent) CreateTag

func (a *Agent) CreateTag(tagName string, tagId ...int) (int, error)

CreateTag 创建标签 文档: https://work.weixin.qq.com/api/doc/90000/90135/90210

func (*Agent) CreateUser

func (a *Agent) CreateUser(user *User) error

CreateUser 创建成员 文档地址: https://work.weixin.qq.com/api/doc/90000/90135/90195

func (*Agent) DelTagUsers

func (a *Agent) DelTagUsers(id int, users []string, parties []int) (invalidlist string, invalidparty []int, err error)

DelTagUsers 删除标签成员 文档: https://work.weixin.qq.com/api/doc/90000/90135/90215

func (*Agent) DeleteDepartment

func (a *Agent) DeleteDepartment(id int) error

DeleteDepartment 删除部门 文档: https://work.weixin.qq.com/api/doc/90000/90135/90207

func (*Agent) DeleteTag

func (a *Agent) DeleteTag(id int) error

DeleteTag 删除标签,必须为标签创建者才可删除 文档: https://work.weixin.qq.com/api/doc/90000/90135/90212

func (*Agent) DeleteUser

func (a *Agent) DeleteUser(id string) error

DeleteUser 删除成员 文档: https://work.weixin.qq.com/api/doc/90000/90135/90198

func (*Agent) Execute

func (a *Agent) Execute(method string, url string, body io.Reader, caller Caller) error

Execute 在默认的http客户端执行一个http请求

func (*Agent) ExecuteWithToken

func (a *Agent) ExecuteWithToken(method string, uri string, query url.Values, body io.Reader, caller Caller) error

ExecuteWithToken 在默认的http客户端执行一个http请求,并在请求中附带 AccessToken

func (*Agent) GetAccessToken

func (a *Agent) GetAccessToken() (string, error)

GetAccessToken 获取access_token

func (*Agent) GetAppChat

func (a *Agent) GetAppChat(chatid string) (*AppChat, error)

GetAppChat 获取群聊会话 文档: https://work.weixin.qq.com/api/doc/90000/90135/90247

func (*Agent) GetJoinQrCode

func (a *Agent) GetJoinQrCode(size string) (string, error)

GetJoinQrCode 获取加入企业二维码 文档: https://work.weixin.qq.com/api/doc/90000/90135/91714 qrcode尺寸类型,1: 171 x 171; 2: 399 x 399; 3: 741 x 741; 4: 2052 x 2052

func (*Agent) GetResultBatch

func (a *Agent) GetResultBatch(jobid string) (BatchResult, error)

GetResultBatch 获取异步任务结果 文档: https://work.weixin.qq.com/api/doc/90000/90135/90983

func (*Agent) GetTag

func (a *Agent) GetTag(id int) (*Tag, error)

GetTag 获取标签成员 文档: https://work.weixin.qq.com/api/doc/90000/90135/90213

func (*Agent) GetUser

func (a *Agent) GetUser(id string) (User, error)

GetUser 读取成员 文档: https://work.weixin.qq.com/api/doc/90000/90135/90196

func (*Agent) GetUserInfo

func (a *Agent) GetUserInfo(code string, isInterior ...bool) (id, deviceId string, err error)

GetUserInfo 获取访问用户身份 文档: https://work.weixin.qq.com/api/doc/90000/90135/91023 isInterior 是否为内部人员,true是 false不是

func (*Agent) ListDepartment

func (a *Agent) ListDepartment(id ...int) ([]Department, error)

ListDepartment 获取部门列表 文档: https://work.weixin.qq.com/api/doc/90000/90135/90208

func (*Agent) ListTags

func (a *Agent) ListTags() ([]Tag, error)

ListTags 获取标签列表 文档: https://work.weixin.qq.com/api/doc/90000/90135/90216

func (*Agent) ListUser

func (a *Agent) ListUser(deptId int, fetchChild ...bool) ([]User, error)

ListUser 获取部门成员详情 文档: https://work.weixin.qq.com/api/doc/90000/90135/90201

func (*Agent) MediaUpload

func (a *Agent) MediaUpload(file string) (*Media, error)

MediaUpload 上传临时素材并获取素材信息 参数 file 为素材位置 文档: https://work.weixin.qq.com/api/doc/90000/90135/90253

func (*Agent) OpenIDConvertToUserID

func (a *Agent) OpenIDConvertToUserID(openid string) (string, error)

OpenIDConvertToUserID openid转userid 文档: https://work.weixin.qq.com/api/doc/90000/90135/90202

func (*Agent) ParseRecvMessage

func (a *Agent) ParseRecvMessage(signature, timestamp, nonce string, data []byte) (recv RecvMessage, err error)

ParseRecvMessage 解析接收到的消息

func (*Agent) RefreshAccessToken

func (a *Agent) RefreshAccessToken() error

RefreshAccessToken 用于刷新 access_token

func (*Agent) ReplacePartyBatch

func (a *Agent) ReplacePartyBatch(bs *BatchSync) (string, error)

ReplacePartyBatch 全量覆盖部门 文档: https://work.weixin.qq.com/api/doc/90000/90135/90982

func (*Agent) ReplaceUserBatch

func (a *Agent) ReplaceUserBatch(bs *BatchSync) (string, error)

ReplaceUserBatch 全量覆盖成员 文档: https://work.weixin.qq.com/api/doc/90000/90135/90981

func (*Agent) SendMessage

func (a *Agent) SendMessage(msg *Message) (map[string][]string, error)

SendMessage 用于消息推送-发送应用消息,返回接收失败用户、组织、标签列表

func (*Agent) SetCache

func (a *Agent) SetCache(cache Cache) *Agent

SetCache 设置缓存处理器

func (*Agent) SetDebug

func (a *Agent) SetDebug(debug bool) *Agent

SetDebug 开启debug模式调用接口 注意: debug模式有使用频率限制,同一个api每分钟不能超过5次,所以在完成调试之后,请记得关掉debug。

func (*Agent) SetHttpClient

func (a *Agent) SetHttpClient(client *http.Client) *Agent

SetHttpClient 设置一个可用的 http client

func (*Agent) SetMsgCrypt

func (a *Agent) SetMsgCrypt(token, encodingAESKey string) *Agent

SetMsgCrypt 设置消息加密认证

func (*Agent) SimpleListUser

func (a *Agent) SimpleListUser(deptId int, fetchChild ...bool) ([]User, error)

SimpleListUser 获取部门成员 文档: https://work.weixin.qq.com/api/doc/90000/90135/90200

func (*Agent) SyncUserBatch

func (a *Agent) SyncUserBatch(bs *BatchSync) (string, error)

SyncUserBatch 增量更新成员 文档: https://work.weixin.qq.com/api/doc/90000/90135/90980

func (*Agent) UpdateAppChat

func (a *Agent) UpdateAppChat(data map[string]interface{}) error

UpdateAppChat 修改群聊会话 文档: https://work.weixin.qq.com/api/doc/90000/90135/90246

func (*Agent) UpdateDepartment

func (a *Agent) UpdateDepartment(dept map[string]interface{}) error

UpdateDepartment 更新部门 文档: https://work.weixin.qq.com/api/doc/90000/90135/90206

func (*Agent) UpdateTag

func (a *Agent) UpdateTag(tagName string, tagId int) error

UpdateTag 更新标签名称 文档: https://work.weixin.qq.com/api/doc/90000/90135/90211

func (*Agent) UpdateTaskcard

func (a *Agent) UpdateTaskcard(taskId, clickedKey string, userids []string) ([]string, error)

UpdateTaskcard 更新任务卡片消息状态,返回接收失败用户列表

func (*Agent) UpdateUser

func (a *Agent) UpdateUser(user *User) error

UpdateUser 更新成员 文档: https://work.weixin.qq.com/api/doc/90000/90135/90197

func (*Agent) UploadImg

func (a *Agent) UploadImg(file string) (string, error)

UploadImg 上传图片

func (*Agent) UploadImgWithType

func (a *Agent) UploadImgWithType(buf []byte, info os.FileInfo) (string, error)

UploadImgWithType 上传图片 文档: https://work.weixin.qq.com/api/doc/90000/90135/90256

func (*Agent) UploadMediaWithType

func (a *Agent) UploadMediaWithType(mediaType string, buf []byte, info os.FileInfo) (*Media, error)

UploadMediaWithType 上传临时素材

func (*Agent) UserAuthSuccess

func (a *Agent) UserAuthSuccess(code string) error

UserAuthSuccess 二次验证通过后成员加入企业 文档: https://work.weixin.qq.com/api/doc/90000/90135/90203

func (*Agent) UserIDConvertToOpenID

func (a *Agent) UserIDConvertToOpenID(userid string) (string, error)

UserIDConvertToOpenID userid转openid 文档: https://work.weixin.qq.com/api/doc/90000/90135/90202

func (*Agent) WithSecret

func (a *Agent) WithSecret(secret string) *Agent

WithSecret 返回添加了secret的应用

type AppChat

type AppChat struct {
	ChatID   string   `json:"chatid"`   // 群聊的唯一标志
	Name     string   `json:"name"`     // 群聊名称
	Owner    string   `json:"owner"`    // 群主ID
	UserList []string `json:"userlist"` // 群成员id列表
}

AppChat 群聊会话

type AppChatMessage

type AppChatMessage struct {
	// 群聊会话ID
	ChatID string `json:"chatid"`

	// 消息类型
	MsgType string `json:"msgtype,omitempty"`

	// 是否是保密消息,0表示否,1表示是,默认0
	Safe int8 `json:"safe,omitempty"`

	Text     *TextMessage     `json:"text,omitempty"`     // 文本消息
	Markdown *TextMessage     `json:"markdown,omitempty"` // markdown 消息
	Image    *MediaMessage    `json:"image,omitempty"`    // 图片消息
	Voice    *MediaMessage    `json:"voice,omitempty"`    // 语音消息
	File     *MediaMessage    `json:"file,omitempty"`     // 文件消息
	Video    *VideoMessage    `json:"video,omitempty"`    // 视频消息
	TextCard *TextCardMessage `json:"textcard,omitempty"` // 文本卡片消息
	News     *NewsMessage     `json:"news,omitempty"`     // 图文消息
	MPNews   *MPNewsMessage   `json:"mpnews,omitempty"`   // 图文消息(mpnews)
	TaskCard *TaskCardMessage `json:"taskcard,omitempty"` // 任务卡片消息
}

AppChatMessage 自建应用群聊消息

type Attrs

type Attrs struct {
	Attrs []ExternalAttr `json:"attrs"`
}

Attrs 自定义字段

type BatchResult

type BatchResult struct {

	// 任务状态,整型,1表示任务开始,2表示任务进行中,3表示任务已完成
	Status int `json:"status" xml:"status"`
	// 操作类型,字节串,目前分别有:1. sync_user(增量更新成员) 2. replace_user(全量覆盖成员)3. replace_party(全量覆盖部门)
	Type string `json:"type" xml:"type"`
	// 任务运行总条数
	Total int `json:"total" xml:"total"`
	// 目前运行百分比,当任务完成时为100
	Percentage int `json:"percentage" xml:"percentage"`
	// 详细的处理结果
	Result BatchResultDetail `json:"result" xml:"result"`
	// contains filtered or unexported fields
}

BatchResult 异步任务结果

func (BatchResult) Error

func (b BatchResult) Error() error

Error 返回失败信息

func (BatchResult) Success

func (b BatchResult) Success() bool

Success 返回是否调用成功

type BatchResultDetail

type BatchResultDetail struct {
	// 成员UserID。对应管理端的帐号
	UserID string `json:"userid,omitempty" xml:"userid,omitempty"`
	// 操作类型(按位或):1 新建部门 ,2 更改部门名称, 4 移动部门, 8 修改部门排序
	Action int `json:"action,omitempty" xml:"action,omitempty"`
	// 部门ID
	PartyID int `json:"partyid,omitempty" xml:"partyid,omitempty"`
	// contains filtered or unexported fields
}

BatchResultDetail 异步任务结果内容

func (BatchResultDetail) Error

func (b BatchResultDetail) Error() error

Error 返回失败信息

func (BatchResultDetail) Success

func (b BatchResultDetail) Success() bool

Success 返回是否调用成功

type BatchSync

type BatchSync struct {
	// 上传的csv文件的media_id
	MediaId string `json:"media_id" xml:"media_id"`
	// 是否邀请新建的成员使用企业微信(将通过微信服务通知或短信或邮件下发邀请,每天自动下发一次,最多持续3个工作日),默认值为true。
	ToInvite bool `json:"to_invite,omitempty" xml:"to_invite,omitempty"`
	// 回调信息。如填写该项则任务完成后,通过callback推送事件给企业。具体请参考应用回调模式中的相应选项
	Callback Callback `json:"callback" xml:"callback"`
}

BatchSync 异步批量处理请求结构体

type Cache

type Cache interface {
	Set(key string, value []byte) error
	Get(key string) []byte
	Remove(key string) error
}

Cache 缓存接口,自定义缓存需实现此接口

func Bolt

func Bolt() Cache

Bolt new bolt brain ...

type Callback

type Callback struct {
	// 企业应用接收企业微信推送请求的访问协议和地址,支持http或https协议
	URL string `json:"url,omitempty" xml:"url,omitempty"`
	// 用于生成签名
	Token string `json:"token" xml:"token"`
	// 用于消息体的加密,是AES密钥的Base64编码
	EncodingAESKey string `json:"encodingaeskey" xml:"encodingaeskey"`
}

Callback 应用回调,需加密

type CallbackData

type CallbackData struct {
	AgentId string `json:"agentId"`
	Content string `json:"content"`
	Ldap    string `json:"ldap"`
}

type Caller

type Caller interface {
	Success() bool
	Error() error
}

Caller 执行 http 访问时响应成功接口

type Department

type Department struct {
	// 部门id,32位整型,指定时必须大于1。若不填该参数,将自动生成id
	ID int `json:"id,omitempty" xml:"Id"`
	// 部门名称。长度限制为1~32个字符,字符不能包括\:?”<>|
	Name string `json:"name,omitempty" xml:"Name"`
	// 英文名称,需要在管理后台开启多语言支持才能生效。长度限制为1~32个字符,字符不能包括\:?”<>|
	NameEn string `json:"name_en,omitempty"`
	// 父部门id,32位整型
	ParentID int `json:"parentid,omitempty" xml:"ParentID"`
	// 在父部门中的次序值。order值大的排序靠前。有效的值范围是[0, 2^32)
	Order int `json:"order,omitempty" xml:"order"`
	// 子部门
	Department []Department `json:"department,omitempty"`
}

Department 成员部门信息 文档地址: https://work.weixin.qq.com/api/doc/90000/90135/90204

type ExternalAttr

type ExternalAttr struct {
	// 属性类型: 0-文本 1-网页 2-小程序
	Type int `json:"type,omitempty"`

	// 属性名称: 需要先确保在管理端有创建该属性,否则会忽略
	Name string `json:"name,omitempty"`

	// 文本类型的属性  type为0时必填
	Text TextAttr `json:"text,omitempty"`

	// 网页类型的属性,url和title字段要么同时为空表示清除该属性,要么同时不为空	type为1时必填
	Web WebAttr `json:"web,omitempty"`

	// 小程序类型的属性,appid和title字段要么同时为空表示清除改属性,要么同时不为空	type为2时必填
	Miniprogram MiniprogramAttr `json:"miniprogram,omitempty"`
}

ExternalAttr 自定义字段内容

type ExternalProfile

type ExternalProfile struct {

	// 企业对外简称,需从已认证的企业简称中选填。可在“我的企业”页中查看企业简称认证状态。
	CorpName string `json:"external_corp_name,omitempty"`

	// 属性列表,目前支持文本、网页、小程序三种类型
	ExternalAttr ExternalAttr `json:"external_attr,omitempty"`
}

ExternalProfile 成员对外信息 文档地址: https://work.weixin.qq.com/api/doc/90000/90135/92230

type MPNewsArticle

type MPNewsArticle struct {
	Title            string `json:"title,omitempty"`              // 图文标题
	ThumbMediaId     string `json:"thumb_media_id,omitempty"`     // 缩略图素材ID
	Author           string `json:"author,omitempty"`             // 作者
	ContentSourceUrl string `json:"content_source_url,omitempty"` // 页面链接
	Content          string `json:"content,omitempty"`            // 消息内容
	Digest           string `json:"digest,omitempty"`             // 消息描述
}

MPNewsArticle 图文消息内容(mpnews)

type MPNewsMessage

type MPNewsMessage struct {
	Articles []MPNewsArticle `json:"articles,omitempty"` // 图文消息内容,支持1-8条图文
}

MPNewsMessage 图文消息(mpnews)

type Media

type Media struct {
	Type      string `json:"type,omitempty"`       // 文件类型,image、voice、video、file
	MediaId   string `json:"media_id,omitempty"`   // 唯一标识,3天内有效
	CreatedAt string `json:"created_at,omitempty"` // 上传时间戳
	// contains filtered or unexported fields
}

Media 素材

func (Media) Error

func (b Media) Error() error

Error 返回失败信息

func (Media) Success

func (b Media) Success() bool

Success 返回是否调用成功

type MediaMessage

type MediaMessage struct {
	MediaId string `json:"media_id,omitempty"`
}

MediaMessage 素材消息

type Message

type Message struct {
	// 接收成员ID列表,“|”分隔,max:1000,全部成员:"@all"
	ToUser string `json:"touser,omitempty"`

	// 接收部门ID列表,“|”分隔,max:100
	ToParty string `json:"toparty,omitempty"`

	// 接收标签ID列表,“|”分隔,max:100
	ToTag string `json:"totag,omitempty"`

	// 消息类型
	MsgType string `json:"msgtype,omitempty"`

	// 企业应用ID
	AgentID int `json:"agentid,omitempty"`

	// 是否是保密消息,0表示否,1表示是,默认0
	Safe int8 `json:"safe,omitempty"`

	// 是否开启id转译,0表示否,1表示是,默认0
	EnableIdTrans int8 `json:"enable_id_trans,omitempty"`

	// 是否开启重复消息检查,0表示否,1表示是,默认0
	EnableDuplicateCheck int8 `json:"enable_duplicate_check,omitempty"`

	// 是否重复消息检查的时间间隔,默认1800s,最大不超过4小时
	DuplicateCheckInterval int64 `json:"duplicate_check_interval,omitempty"`

	Text        *TextMessage              `json:"text,omitempty"`               // 文本消息
	Markdown    *TextMessage              `json:"markdown,omitempty"`           // markdown 消息
	Image       *MediaMessage             `json:"image,omitempty"`              // 图片消息
	Voice       *MediaMessage             `json:"voice,omitempty"`              // 语音消息
	File        *MediaMessage             `json:"file,omitempty"`               // 文件消息
	Video       *VideoMessage             `json:"video,omitempty"`              // 视频消息
	TextCard    *TextCardMessage          `json:"textcard,omitempty"`           // 文本卡片消息
	News        *NewsMessage              `json:"news,omitempty"`               // 图文消息
	MPNews      *MPNewsMessage            `json:"mpnews,omitempty"`             // 图文消息(mpnews)
	MiniProgram *MiniprogramNoticeMessage `json:"miniprogram_notice,omitempty"` // 小程序消息
	TaskCard    *TaskCardMessage          `json:"taskcard,omitempty"`           // 任务卡片消息
}

Message 消息推送 文档地址: https://work.weixin.qq.com/api/doc/90000/90135/90235

func NewMPNewsMessage

func NewMPNewsMessage(articles []MPNewsArticle) *Message

NewMPNewsMessage 创建一条图文消息(mpnews)

func NewMarkdownMessage

func NewMarkdownMessage(content string) *Message

NewMarkdownMessage 创建一条 markdown 消息

func NewMediaMessage

func NewMediaMessage(mediaType, mediaId string) *Message

NewMediaMessage 创建一条素材消息(image、voice、file)

func NewMiniprogramNoticeMessage

func NewMiniprogramNoticeMessage(appid, page, title, desc string, efi bool, contentItem map[string]string) *Message

NewMiniprogramNoticeMessage 创建一条小程序消息

func NewNewsMessage

func NewNewsMessage(articles []NewsArticle) *Message

NewNewsMessage 创建一条图文消息,articles 最大容量为8

func NewTaskCardMessage

func NewTaskCardMessage(title, desc, url, taskId string, btn []TaskCardBtn) *Message

NewTaskCardMessage 创建一条任务卡片消息

func NewTextCardMessage

func NewTextCardMessage(title, desc, url, btntxt string) *Message

NewTextCardMessage 创建一条文本卡片消息

func NewTextMessage

func NewTextMessage(content string) *Message

NewTextMessage 创建一条文本消息

func NewVideoMessage

func NewVideoMessage(title, desc, mediaId string) *Message

NewVideoMessage 创建一条视频消息

func (*Message) SetParty

func (msg *Message) SetParty(party ...string)

SetParty 设置接收部门

func (*Message) SetTag

func (msg *Message) SetTag(tag ...string)

SetTag 设置接收标签

func (*Message) SetUser

func (msg *Message) SetUser(user ...string)

SetUser 设置接收成员

type MiniprogramAttr

type MiniprogramAttr struct {
	// 小程序appid,必须是有在本企业安装授权的小程序,否则会被忽略
	Appid int `json:"appid,omitempty"`

	// 小程序的展示标题,长度限制12个UTF8字符
	Title string `json:"title,omitempty"`

	// 小程序的页面路径
	Pagepath string `json:"pagepath,omitempty"`
}

MiniprogramAttr 小程序属性

type MiniprogramNoticeMessage

type MiniprogramNoticeMessage struct {
	Appid             string            `json:"appid,omitempty"`               // 小程序appid,必须是与当前小程序应用关联的小程序
	Page              string            `json:"page,omitempty"`                // 点击消息卡片后的小程序页面,仅限本小程序内的页面
	Title             string            `json:"title,omitempty"`               // 消息标题
	Description       string            `json:"description,omitempty"`         // 消息描述
	EmphasisFirstItem bool              `json:"emphasis_first_item,omitempty"` // 是否放大第一个content_item
	ContentItem       map[string]string `json:"content_item,omitempty"`        // 消息内容键值对,最多允许10个item
}

MiniprogramNoticeMessage 小程序消息

type NewsArticle

type NewsArticle struct {
	Title       string `json:"title,omitempty"`       // 图文标题
	Description string `json:"description,omitempty"` // 图文描述
	Url         string `json:"url,omitempty"`         // 跳转链接
	PicUrl      string `json:"picurl,omitempty"`      // 图片链接
}

NewsArticle 图文消息内容

type NewsMessage

type NewsMessage struct {
	Articles []NewsArticle `json:"articles,omitempty"` // 图文消息内容,支持1-8条图文
}

NewsMessage 图文消息

type RecvEvent

type RecvEvent struct {
	Event    string `xml:"Event"`    // 事件类型
	EventKey string `xml:"EventKey"` // 事件KEY值

	// 上报地理位置事件
	Latitude  string `xml:"Latitude"`  // 地理位置纬度
	Longitude string `xml:"Longitude"` // 地理位置经度
	Precision string `xml:"Precision"` // 地理位置精度

	// 异步任务完成事件推送
	JobID   string `xml:"JobId"`   // 异步任务id
	JobType string `xml:"JobType"` // 操作类型
	ErrCode int    `xml:"ErrCode"`
	ErrMsg  string `xml:"ErrMsg"`

	// 通讯录变更事件
	ChangeType string `xml:"ChangeType"`
}

RecvEvent 事件基础结构 - 成员关注及取消关注事件、进入应用、菜单事件直接使用

type RecvMessage

type RecvMessage struct {
	ToUsername   string `xml:"ToUserName"`   // 企业微信CorpID
	FromUsername string `xml:"FromUserName"` // 成员UserID
	CreateTime   int64  `xml:"CreateTime"`   // 消息创建时间(整型)
	MsgType      string `xml:"MsgType"`      // 消息类型
	AgentID      int    `xml:"AgentId"`      // 企业应用的id,整型
	MsgID        int64  `xml:"MsgId"`        // 消息id,64位整型

	Content string `xml:"Content"` // 文本消息

	// 多媒体消息
	MediaID      string `xml:"MediaId"`      // 媒体文件id
	PicURL       string `xml:"PicUrl"`       // 图片链接
	Format       string `xml:"Format"`       // 语音格式
	ThumbMediaID string `xml:"ThumbMediaId"` // 视频缩略图的媒体id

	// 位置消息
	LocationX float64 `xml:"Location_X"` // 地理位置纬度
	LocationY float64 `xml:"Location_Y"` // 地理位置经度
	Scale     int     `xml:"Scale"`      // 地图缩放大小
	Label     string  `xml:"Label"`      // 地理位置信息

	// 链接消息
	Title       string `xml:"Title"`       // 标题
	Description string `xml:"Description"` // 链接描述
	Url         string `xml:"Url"`         // 链接跳转的url

	RecvEvent
}

RecvMessage 消息接收基础结构

type ReplyMessage

type ReplyMessage struct {
	ToUserName   string
	FromUserName string
	CreateTime   int64
	MsgType      string

	// 文本消息
	Content string

	// 多媒体消息
	MediaId     string
	Title       string
	Description string

	ArticleCount int
	Url          string
	PicUrl       string
}

ReplyMessage 被动回复消息格式

type RespMessage

type RespMessage struct {
	InvalidUser  string `json:"invaliduser"`
	InvalidParty string `json:"invalidparty"`
	InvalidTag   string `json:"invalidtag"`
	// contains filtered or unexported fields
}

RespMessage 定义了消息会话响应

func (RespMessage) Error

func (b RespMessage) Error() error

Error 返回失败信息

func (RespMessage) Success

func (b RespMessage) Success() bool

Success 返回是否调用成功

type Tag

type Tag struct {
	TagID     int      `json:"tagid"`               // 标签id
	TagName   string   `json:"tagname"`             // 标签名称
	UserList  []string `json:"userlist,omitempty"`  // 标签成员ID列表
	PartyList []int    `json:"partylist,omitempty"` // 标签部门ID列表
}

Tag 标签结构

type TaskCardBtn

type TaskCardBtn struct {
	Key         string `json:"key,omitempty"`          // 按钮key值
	Name        string `json:"name,omitempty"`         // 按钮名称
	ReplaceName string `json:"replace_name,omitempty"` // 点击按钮后显示的名称
	Color       string `json:"color,omitempty"`        // 按钮字体颜色
	IsBold      bool   `json:"is_bold,omitempty"`      // 按钮字体是否加粗
}

TaskCardBtn 任务卡片按钮列表

func NewTaskCardBtn

func NewTaskCardBtn(key, name, rename, color string, isbold bool) TaskCardBtn

NewTaskCardBtn 创建任务卡片按键

type TaskCardMessage

type TaskCardMessage struct {
	Title       string        `json:"title,omitempty"`       // 消息标题
	Description string        `json:"description,omitempty"` // 消息描述
	Url         string        `json:"url,omitempty"`         // 跳转链接
	TaskId      string        `json:"task_id,omitempty"`     // 任务id
	Btn         []TaskCardBtn `json:"btn,omitempty"`         // 按钮列表,按钮个数为为1~2个
}

TaskCardMessage 任务卡片消息

type TextAttr

type TextAttr struct {
	// 文本属性内容,长度限制12个UTF8字符
	Value string `json:"value,omitempty"`
}

TextAttr 文本属性

type TextCardMessage

type TextCardMessage struct {
	Title       string `json:"title,omitempty"`       // 消息标题
	Description string `json:"description,omitempty"` // 消息描述
	Url         string `json:"url,omitempty"`         // 消息跳转链接
	BtnTxt      string `json:"btntxt,omitempty"`      // 按钮文字, 默认为“详情”
}

TextCardMessage 文本卡片消息

type TextMessage

type TextMessage struct {
	Content string `json:"content,omitempty"` // 消息内容,最长不超过2048个字节
}

TextMessage 文本消息

type User

type User struct {
	// 成员UserID。对应管理端的帐号,企业内必须唯一。不区分大小写,长度为1~64个字节。只能由数字、字母和“_-@.”四种字符组成,且第一个字符必须是数字或字母。
	UserID string `json:"userid,omitempty" xml:"UserID"`

	// 成员名称。长度为1~64个utf8字符
	Name string `json:"name,omitempty" xml:"Name"`

	// 成员别名。长度1~32个utf8字符
	Alias string `json:"alias,omitempty" xml:"Alias"`

	// 手机号码。企业内必须唯一,mobile/email二者不能同时为空
	Mobile string `json:"mobile,omitempty" xml:"Mobile"`

	// 成员所属部门id列表,不超过20个
	Department []int `json:"department,omitempty" xml:"Department"`

	// 部门内的排序值,默认为0,成员次序以创建时间从小到大排列。数量必须和department一致,数值越大排序越前面。有效的值范围是[0, 2^32)
	Order []int `json:"order,omitempty" xml:"Order"`

	// 职务信息。长度为0~128个字符
	Position string `json:"position,omitempty" xml:"Position"`

	// 性别。1表示男性,2表示女性
	Gender string `json:"gender,omitempty" xml:"Gender"`

	// 邮箱。长度6~64个字节,且为有效的email格式。企业内必须唯一,mobile/email二者不能同时为空
	Email string `json:"email,omitempty" xml:"Email"`

	// 座机。32字节以内,由纯数字或’-‘号组成。
	Telephone string `json:"telephone,omitempty" xml:"Telephone"`

	// 个数必须和department一致,表示在所在的部门内是否为上级。1表示为上级,0表示非上级。在审批等应用里可以用来标识上级审批人
	IsLeaderInDept []int `json:"is_leader_in_dept,omitempty" xml:"IsLeaderInDept"`

	// 成员头像的mediaid,通过素材管理接口上传图片获得的mediaid
	AvatarMediaID string `json:"avatar_mediaid,omitempty"`

	// 启用/禁用成员。1表示启用成员,0表示禁用成员
	Enable int8 `json:"enable,omitempty"`

	// 自定义字段。自定义字段需要先在WEB管理端添加,见扩展属性添加方法,否则忽略未知属性的赋值。与对外属性一致,不过只支持type=0的文本和type=1的网页类型,详细描述查看对外属性
	ExtAttr Attrs `json:"extattr,omitempty" xml:"ExtAttr"`

	// 是否邀请该成员使用企业微信(将通过微信服务通知或短信或邮件下发邀请,每天自动下发一次,最多持续3个工作日),默认值为true。
	ToInvite bool `json:"to_invite,omitempty"`

	// 成员对外属性
	ExternalProfile ExternalProfile `json:"external_profile,omitempty"`

	// 对外职务,如果设置了该值,则以此作为对外展示的职务,否则以position来展示。长度12个汉字内
	ExternalPosition string `json:"external_position,omitempty"`

	Address     string `json:"address,omitempty" xml:"Address"` // 地址。
	Avatar      string `json:"avatar,omitempty" xml:"Avatar"`   // 头像url。 第三方仅通讯录应用可获取
	ThumbAvatar string `json:"thumb_avatar,omitempty"`          // 头像缩略图url。第三方仅通讯录应用可获取
	QrCode      string `json:"qr_code,omitempty"`               // 员工二维码
	Status      int8   `json:"status,omitempty" xml:"status"`   // 激活状态: 1=已激活,2=已禁用,4=未激活。
}

User 成员信息: 文档地址: https://work.weixin.qq.com/api/doc/90000/90135/90194

type VideoMessage

type VideoMessage struct {
	Title       string `json:"title,omitempty"`       // 视频标题
	Description string `json:"description,omitempty"` // 视频介绍
	MediaMessage
}

VideoMessage 视频消息

type WebAttr

type WebAttr struct {
	// 网页的url,必须包含http或者https头
	Url string `json:"url,omitempty"`

	// 网页的展示标题,长度限制12个UTF8字符
	Title string `json:"title,omitempty"`
}

WebAttr 网页属性

Jump to

Keyboard shortcuts

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