api

package
v0.0.0-...-fb94b6f Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2015 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SyncUserTask          = "sync_user"
	ReplaceUserTask       = "replace_user"
	InviteUserTask        = "invite_user"
	ReplaceDepartmentTask = "replace_party"
)

异步任务操作类型

View Source
const (
	ImageMedia mediaType = "image"
	VoiceMedia mediaType = "voice"
	VideoMedia mediaType = "video"
	FileMedia  mediaType = "file"
)

媒体文件类型

View Source
const (
	MenuButtonTypeClick           = "click"
	MenuButtonTypeView            = "view"
	MenuButtonTypeScanCodePush    = "scancode_push"
	MenuButtonTypeScanCodeWaitMsg = "scancode_waitmsg"
	MenuButtonTypePicSysPhoto     = "pic_sysphoto"
	MenuButtonTypePicPhotoOrAlbum = "pic_photo_or_album"
	MenuButtonTypePicWeixin       = "pic_weixin"
	MenuButtonTypeLocationSelect  = "location_select"
)

自定义菜单按钮类型

View Source
const (
	SubscribeEvent       = "subscribe"
	UnsubscribeEvent     = "unsubscribe"
	LocationEvent        = "LOCATION"
	MenuClickEvent       = "CLICK"
	MenuViewEvent        = "VIEW"
	ScanCodePushEvent    = "scancode_push"
	ScanCodeWaitMsgEvent = "scancode_waitmsg"
	PicSysPhotoEvent     = "pic_sysphoto"
	PicPhotoOrAlbumEvent = "pic_photo_or_album"
	PicWeiXinEvent       = "pic_weixin"
	LocationSelectEvent  = "location_select"
	EnterAgentEvent      = "enter_agent"
	BatchJobResultEvent  = "batch_job_result"
)

接收事件类型

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	CorpID     string
	MsgCrypter crypter.MessageCrypter
	Client     *base.Client
	Tokener    *base.Tokener
	// contains filtered or unexported fields
}

API 封装了企业号相关的接口操作

func New

func New(corpID, corpSecret, token, encodingAESKey string) *API

New 方法创建 API 实例

func (*API) BatchDeleteUser

func (a *API) BatchDeleteUser(userIds []string) error

BatchDeleteUser 方法用于批量删除用户

func (*API) CreateChat

func (a *API) CreateChat(chat *Chat) error

CreateChat 方法用于创建微信聊天

func (*API) CreateDepartment

func (a *API) CreateDepartment(department *Department) error

CreateDepartment 方法用于创建部门

func (*API) CreateMenu

func (a *API) CreateMenu(agentID int64, menu Menu) error

CreateMenu 方法用于创建某个应用的菜单

func (*API) CreateUser

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

CreateUser 方法用于创建用户

func (*API) DeleteDepartment

func (a *API) DeleteDepartment(id int64) error

DeleteDepartment 方法用于删除部门

func (*API) DeleteMenu

func (a *API) DeleteMenu(agentID int64) error

DeleteMenu 方法用于删除某个应用的菜单

func (*API) DeleteUser

func (a *API) DeleteUser(userID string) error

DeleteUser 方法用于删除某个用户

func (*API) DownloadMedia

func (a *API) DownloadMedia(mediaID string, writer io.Writer) (string, error)

DownloadMedia 方法用于从微信服务器获取媒体文件,文件流将写入 writer 中,并返回 filename 或者 error 信息

func (*API) FetchToken

func (a *API) FetchToken() (token string, expiresIn int64, err error)

FetchToken 方法使用企业管理组的密钥向 API 服务器获取企业号的令牌信息

func (*API) GetJSSDKSignature

func (a *API) GetJSSDKSignature(uri, timestamp, noncestr string) (string, error)

GetJSSDKSignature 方法用于获取 JSSDK 的签名

func (*API) GetMenu

func (a *API) GetMenu(agentID int64) (Menu, error)

GetMenu 方法用于获取某个应用的菜单

func (*API) GetOAuth2AuthorizeURI

func (a *API) GetOAuth2AuthorizeURI(redirectURI, state string) string

GetOAuth2AuthorizeURI 方法用于构建 OAuth2 中企业获取 code 的 URL 地址

func (*API) GetOAuth2User

func (a *API) GetOAuth2User(agentID int64, code string) (OAuth2UserInfo, error)

GetOAuth2User 方法用于获取 OAuth2 方式验证登录后的用户信息

func (*API) GetTaskResult

func (a *API) GetTaskResult(taskID string) (AsyncTaskResultInfo, error)

GetTaskResult 方法用于获取异步任务的完成结果

func (*API) GetUser

func (a *API) GetUser(userID string) (*User, error)

GetUser 方法用于获取某个用户的信息

func (*API) InviteUser

func (a *API) InviteUser(userID, inviteTips string) (inviteType int, err error)

InviteUser 方法用于邀请成员关注

func (*API) ListDepartment

func (a *API) ListDepartment(id int64) ([]*Department, error)

ListDepartment 方法用于获取部门列表,获取根部门时 id 为 1

func (*API) ListSimpleUser

func (a *API) ListSimpleUser(departmentID int64, fetchChild *int, status *int) ([]*User, error)

ListSimpleUser 方法用于获取部门成员列表(成员仅有简单信息)

func (*API) ListUser

func (a *API) ListUser(departmentID int64, fetchChild *int, status *int) ([]*User, error)

ListUser 方法用于获取部门成员列表(成员带有详情信息)

func (*API) NewRecvMsgHandler

func (a *API) NewRecvMsgHandler() *recvMsgHandler

NewRecvMsgHandler 方法用于创建消息接收处理器的实例

func (*API) PerformInviteUsersTask

func (a *API) PerformInviteUsersTask(task InviteTask) (string, error)

PerformInviteUsersTask 方法执行邀请成员关注的任务

func (*API) PerformReplaceDepartmentTask

func (a *API) PerformReplaceDepartmentTask(task UpdateContactTask) (string, error)

PerformReplaceDepartmentTask 方法执行全量更新部门的任务

func (*API) PerformReplaceUsersTask

func (a *API) PerformReplaceUsersTask(task UpdateContactTask) (string, error)

PerformReplaceUsersTask 方法执行全量更新成员的任务

func (*API) PerformUpdateUsersTask

func (a *API) PerformUpdateUsersTask(task UpdateContactTask) (string, error)

PerformUpdateUsersTask 方法执行增量更新成员的任务

func (*API) Retriable

func (a *API) Retriable(reqURL string, body []byte) (bool, string, error)

Retriable 方法实现了 API 在发起请求遇到 token 错误时,先刷新 token 然后再次发起请求的逻辑

func (*API) SendMessage

func (a *API) SendMessage(message interface{}) error

SendMessage 方法用于主动发送消息给企业成员

func (*API) SendTextMessage

func (a *API) SendTextMessage(chatTextMessage *ChatTextMessage) error

func (*API) UpdateDepartment

func (a *API) UpdateDepartment(department *Department) error

UpdateDepartment 方法用于更新部门信息

func (*API) UpdateUser

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

UpdateUser 方法用于更新用户信息

func (*API) UploadMedia

func (a *API) UploadMedia(mediaType mediaType, filename string, reader io.Reader) (UploadedMedia, error)

UploadMedia 方法用于将媒体文件上传至微信服务器

type Article

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

Article 为普通图文消息的文章内容

type Articles

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

Articles 为普通图文消息的文章列表

type AsyncTaskCallback

type AsyncTaskCallback struct {
	URL            string `json:"url"`
	Token          string `json:"token"`
	EncodingAESKey string `json:"encodingaeskey"`
}

AsyncTaskCallback 异步任务的回调信息

type AsyncTaskResultInfo

type AsyncTaskResultInfo struct {
	Status     int         `json:"status"`
	Type       string      `json:"type"`
	Total      int         `json:"total"`
	Percentage float64     `json:"percentage"`
	RemainTime float64     `json:"remaintime"`
	Result     interface{} `json:"result"`
}

AsyncTaskResultInfo 为异步任务完成结果信息

type Chat

type Chat struct {
	ChatId   string   `json:"chatid"`
	Name     string   `json:"name"`
	Owner    string   `json:"owner,omitempty"`
	UserList []string `json:"userlist,omitempty"`
}

type ChatReceiver

type ChatReceiver struct {
	Type string `json:"type"`
	Id   string `json:"id"`
}

type ChatText

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

type ChatTextMessage

type ChatTextMessage struct {
	Receiver *ChatReceiver `json:"receiver"`
	Sender   string        `json:"sender,omitempty"`
	Msgtype  string        `json:"msgtype"`
	Text     *ChatText     `json:"text"`
}

type Department

type Department struct {
	ID       int64  `json:"id,omitempty"`
	Name     string `json:"name,omitempty"`
	Order    int64  `json:"order,omitempty"`
	ParentID int64  `json:"parentid,omitempty"`
}

Department 表示部门信息

type FileMessage

type FileMessage struct {
	ToUser  string      `json:"touser,omitempty"`
	ToParty string      `json:"toparty,omitempty"`
	ToTag   string      `json:"totag,omitempty"`
	MsgType MessageType `json:"msgtype"`
	AgentID int64       `json:"agentid"`
	File    Media       `json:"file"`
	Safe    int         `json:"safe"`
}

FileMessage 为发送的文件类型消息

type ImageMessage

type ImageMessage struct {
	ToUser  string      `json:"touser,omitempty"`
	ToParty string      `json:"toparty,omitempty"`
	ToTag   string      `json:"totag,omitempty"`
	MsgType MessageType `json:"msgtype"`
	AgentID int64       `json:"agentid"`
	Image   Media       `json:"image"`
	Safe    int         `json:"safe"`
}

ImageMessage 为发送的图片类型消息

type InviteTask

type InviteTask struct {
	ToUser     string            `json:"touser,omitempty"`
	ToParty    string            `json:"toparty,omitempty"`
	ToTag      string            `json:"totag,omitempty"`
	InviteTips string            `json:"invite_tips,omitempty"`
	Callback   AsyncTaskCallback `json:"callback"`
}

InviteTask 批量邀请成员关注企业号的异步任务信息

type InviteUserTaskResult

type InviteUserTaskResult struct {
	base.Error
	UserID     string `json:"userid"`
	InviteType int    `json:"invitetype"`
}

InviteUserTaskResult 邀请成员关注任务的执行结构信息

type JobResultInfo

type JobResultInfo struct {
	JobID   string `xml:"JobId"`
	JobType string
	ErrCode int
	ErrMsg  string
}

JobResultInfo 描述异步任务完成事件中任务完成情况信息

type Media

type Media struct {
	ID string `json:"media_id"`
}

Media 为发送消息的媒体文件内容

type Menu struct {
	Buttons []MenuButton `json:"button"`
}

Menu 中最多包含 3 个菜单按钮(一级菜单)

type MenuButton struct {
	Type       string       `json:"type"`
	Name       string       `json:"name"`
	Key        string       `json:"key,omitempty"`
	URL        string       `json:"url,omitempty"`
	SubButtons []MenuButton `json:"sub_button,omitempty"`
}

MenuButton 中最多包含 5 个子菜单(二级菜单)

type MessageType

type MessageType string

MessageType 消息类型定义

const (
	TextMsg  MessageType = "text"
	ImageMsg MessageType = "image"
	VoiceMsg MessageType = "voice"
	VideoMsg MessageType = "video"

	FileMsg   MessageType = "file"
	NewsMsg   MessageType = "news"
	MpNewsMsg MessageType = "mpnews"

	LocationMsg MessageType = "location"
	EventMsg    MessageType = "event"
)

各种消息类型值

type MpArticle

type MpArticle 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"`
	Digest           string `json:"digest,omitempty"`
	ShowCoverPic     *int   `json:"show_cover_pic,omitempty"`
}

MpArticle 为特殊图文消息的文章内容

type MpArticles

type MpArticles struct {
	Articles []MpArticle `json:"articles"`
}

MpArticles 为特殊图文消息的文章列表

type MpNewsMessage

type MpNewsMessage struct {
	ToUser  string      `json:"touser,omitempty"`
	ToParty string      `json:"toparty,omitempty"`
	ToTag   string      `json:"totag,omitempty"`
	MsgType MessageType `json:"msgtype"`
	AgentID int64       `json:"agentid"`
	MpNews  MpArticles  `json:"mpnews"`
	Safe    int         `json:"safe"`
}

MpNewsMessage 为发送的特殊图文类型消息

type NewsMessage

type NewsMessage struct {
	ToUser  string      `json:"touser,omitempty"`
	ToParty string      `json:"toparty,omitempty"`
	ToTag   string      `json:"totag,omitempty"`
	MsgType MessageType `json:"msgtype"`
	AgentID int64       `json:"agentid"`
	News    Articles    `json:"news"`
}

NewsMessage 为发送的普通图文类型消息

type OAuth2UserInfo

type OAuth2UserInfo struct {
	UserID   string `json:"UserId"`
	DeviceID string `json:"DeviceId"`
}

OAuth2UserInfo 为用户 OAuth2 验证登录后的简单信息

type RecvBaseData

type RecvBaseData struct {
	ToUserName   string
	FromUserName string
	CreateTime   int
	MsgType      MessageType
	AgentID      int64
}

RecvBaseData 描述接收到的各类消息或事件的公共结构

type RecvBatchJobResultEvent

type RecvBatchJobResultEvent struct {
	RecvBaseData
	Event    string
	BatchJob JobResultInfo
}

RecvBatchJobResultEvent 描述异步任务完成事件的结构

type RecvEnterAgentEvent

type RecvEnterAgentEvent struct {
	RecvBaseData
	Event    string
	EventKey string
}

RecvEnterAgentEvent 描述成员进入应用事件的结构

type RecvImageMessage

type RecvImageMessage struct {
	RecvBaseData
	MsgID   uint64 `xml:"MsgId"`
	PicURL  string `xml:"PicUrl"`
	MediaID string `xml:"MediaId"`
}

RecvImageMessage 描述接收到的图片类型消息结构

type RecvLocationEvent

type RecvLocationEvent struct {
	RecvBaseData
	Event     string
	Latitude  float64
	Longitude float64
	Precision float64
}

RecvLocationEvent 描述上报地理位置事件的结构

type RecvLocationMessage

type RecvLocationMessage struct {
	RecvBaseData
	MsgID     uint64  `xml:"MsgId"`
	LocationX float64 `xml:"Location_X"`
	LocationY float64 `xml:"Location_Y"`
	Scale     int
	Label     string
}

RecvLocationMessage 描述接收到的地理位置类型消息结构

type RecvLocationSelectEvent

type RecvLocationSelectEvent struct {
	RecvBaseData
	Event            string
	EventKey         string
	SendLocationInfo SendLocationInfo
}

RecvLocationSelectEvent 描述弹出地理位置选择器事件的结构

type RecvMenuEvent

type RecvMenuEvent struct {
	RecvBaseData
	Event    string
	EventKey string
}

RecvMenuEvent 描述菜单事件的结构

type RecvPicEvent

type RecvPicEvent struct {
	RecvBaseData
	Event        string
	EventKey     string
	SendPicsInfo SendPicsInfo
}

RecvPicEvent 描述发图事件的结构

type RecvScanCodeEvent

type RecvScanCodeEvent struct {
	RecvBaseData
	Event        string
	EventKey     string
	ScanCodeInfo ScanCodeInfo
}

RecvScanCodeEvent 描述扫码推/扫码推事件且弹出“消息接收中”提示框类型事件的结构

type RecvSubscribeEvent

type RecvSubscribeEvent struct {
	RecvBaseData
	Event string
}

RecvSubscribeEvent 描述成员关注/取消关注事件的结构

type RecvTextMessage

type RecvTextMessage struct {
	RecvBaseData
	MsgID   uint64 `xml:"MsgId"`
	Content string
}

RecvTextMessage 描述接收到的文本类型消息结构

type RecvVideoMessage

type RecvVideoMessage struct {
	RecvBaseData
	MsgID        uint64 `xml:"MsgId"`
	MediaID      string `xml:"MediaId"`
	ThumbMediaID string `xml:"ThumbMediaId"`
}

RecvVideoMessage 描述接收到的视频类型消息结构

type RecvVoiceMessage

type RecvVoiceMessage struct {
	RecvBaseData
	MsgID   uint64 `xml:"MsgId"`
	MediaID string `xml:"MediaId"`
	Format  string
}

RecvVoiceMessage 描述接收到的语音类型消息结构

type RespArticle

type RespArticle struct {
	Title       base.CDATAText
	Description base.CDATAText
	PicURL      base.CDATAText `xml:"PicUrl"`
	URL         base.CDATAText `xml:"Url"`
}

RespArticle 描述被动响应的图文消息结构

type RespArticleItem

type RespArticleItem struct {
	Item RespArticle `xml:"item"`
}

RespArticleItem 描述被动响应的图文消息结构的包裹

type RespBaseData

type RespBaseData struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   base.CDATAText
	FromUserName base.CDATAText
	CreateTime   int
	MsgType      base.CDATAText
}

RespBaseData 描述被动响应消息的公共结构

type RespImageMessage

type RespImageMessage struct {
	RespBaseData
	Image RespMedia
}

RespImageMessage 描述被动相应的图片消息结构

type RespMedia

type RespMedia struct {
	MediaID base.CDATAText `xml:"MediaId"`
}

RespMedia 描述被动响应的媒体内容结构

type RespNewsMessage

type RespNewsMessage struct {
	RespBaseData
	ArticleCount int
	Articles     []RespArticleItem
}

RespNewsMessage 描述被动相应的图文消息结构

type RespTextMessage

type RespTextMessage struct {
	RespBaseData
	Content base.CDATAText
}

RespTextMessage 描述被动响应的文本消息的结构

type RespVideoMedia

type RespVideoMedia struct {
	MediaID     base.CDATAText `xml:"MediaId"`
	Title       base.CDATAText
	Description base.CDATAText
}

RespVideoMedia 描述被动相应的视频媒体内容结构

type RespVideoMessage

type RespVideoMessage struct {
	RespBaseData
	Video RespVideoMedia
}

RespVideoMessage 描述被动相应的语音消息结构

type RespVoiceMessage

type RespVoiceMessage struct {
	RespBaseData
	Voice RespMedia
}

RespVoiceMessage 描述被动相应的语音消息结构

type ScanCodeInfo

type ScanCodeInfo struct {
	ScanType   string
	ScanResult string
}

ScanCodeInfo 描述扫码事件的相关内容结构

type SendLocationInfo

type SendLocationInfo struct {
	LocationX float64 `xml:"Location_X"`
	LocationY float64 `xml:"Location_Y"`
	Scale     int
	Label     string
	PoiName   string `xml:"Poiname"`
}

SendLocationInfo 描述弹出地理位置选择器事件中地理位置信息结构

type SendPicItem

type SendPicItem struct {
	Item SendPicMD5Sum `xml:"item"`
}

SendPicItem 描述发图事件中单个图片信息结构

type SendPicMD5Sum

type SendPicMD5Sum struct {
	PicMd5Sum string
}

SendPicMD5Sum 描述发图事件中单个图片的 MD5 信息

type SendPicsInfo

type SendPicsInfo struct {
	Count   int64
	PicList []SendPicItem
}

SendPicsInfo 描述发图事件的图片信息结构

type TextContent

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

TextContent 为文本类型消息的文本内容

type TextMessage

type TextMessage struct {
	ToUser  string      `json:"touser,omitempty"`
	ToParty string      `json:"toparty,omitempty"`
	ToTag   string      `json:"totag,omitempty"`
	MsgType MessageType `json:"msgtype"`
	AgentID int64       `json:"agentid"`
	Text    TextContent `json:"text"`
	Safe    int         `json:"safe"`
}

TextMessage 为发送的文本类型消息

type UpdateContactTask

type UpdateContactTask struct {
	MediaID  string            `json:"media_id"`
	Callback AsyncTaskCallback `json:"callback"`
}

UpdateContactTask 增量更新企业成员、全量更新成员或部门的异步任务信息

type UpdateDepartmentTaskResult

type UpdateDepartmentTaskResult struct {
	base.Error
	Action       int   `json:"action"`
	DepartmentID int64 `json:"partyid"`
}

UpdateDepartmentTaskResult 全量更新部门任务的执行结果信息

type UpdateUserTaskResult

type UpdateUserTaskResult struct {
	base.Error
	Action int    `json:"action"`
	UserID string `json:"userid"`
}

UpdateUserTaskResult 增量、全量更新成员任务的执行结果信息

type UploadedMedia

type UploadedMedia struct {
	Type      string `json:"type"`
	MediaID   string `json:"media_id"`
	CreatedAt int64  `json:"created_at"`
}

UploadedMedia 上传成功的媒体文件信息

type User

type User struct {
	UserID        string         `json:"userid"`
	Name          string         `json:"name,omitempty"`
	DepartmentIds []int64        `json:"department,omitempty"`
	Position      string         `json:"position,omitempty"`
	Mobile        string         `json:"mobile,omitempty"`
	Email         string         `json:"email,omitempty"`
	WeixinID      string         `json:"weixinid,omitempty"`
	Enable        *int           `json:"enable,omitempty"`
	Avatar        string         `json:"avatar,omitempty"`
	Status        *int           `json:"status,omitempty"`
	ExtAttr       UserAttributes `json:"extattr,omitempty"`
}

User struct 为企业用户信息

type UserAttribute

type UserAttribute struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

UserAttribute struct 为用户扩展信息

type UserAttributes

type UserAttributes struct {
	Attrs []*UserAttribute `json:"attrs,omitempty"`
}

UserAttributes struct 为用户扩展信息列表

type VideoContent

type VideoContent struct {
	ID          string `json:"media_id"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
}

VideoContent 为视频类型消息的内容

type VideoMessage

type VideoMessage struct {
	ToUser  string       `json:"touser,omitempty"`
	ToParty string       `json:"toparty,omitempty"`
	ToTag   string       `json:"totag,omitempty"`
	MsgType MessageType  `json:"msgtype"`
	AgentID int64        `json:"agentid"`
	Video   VideoContent `json:"video"`
	Safe    int          `json:"safe"`
}

VideoMessage 为发送的视频类型消息

type VoiceMessage

type VoiceMessage struct {
	ToUser  string      `json:"touser,omitempty"`
	ToParty string      `json:"toparty,omitempty"`
	ToTag   string      `json:"totag,omitempty"`
	MsgType MessageType `json:"msgtype"`
	AgentID int64       `json:"agentid"`
	Voice   Media       `json:"voice"`
	Safe    int         `json:"safe"`
}

VoiceMessage 为发送的声音类型消息

Jump to

Keyboard shortcuts

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