Documentation
¶
Index ¶
- Constants
- type ChatInfo
- type CtorOption
- type DeptInfo
- type HTTPHandler
- type ImageMessageExtras
- type LinkMessageExtras
- type LocationMessageExtras
- type Media
- type MediaUploadResult
- type MessageType
- type Recipient
- type RxMessage
- func (m *RxMessage) Image() (ImageMessageExtras, bool)
- func (m *RxMessage) Link() (LinkMessageExtras, bool)
- func (m *RxMessage) Location() (LocationMessageExtras, bool)
- func (m *RxMessage) String() string
- func (m *RxMessage) Text() (TextMessageExtras, bool)
- func (m *RxMessage) Video() (VideoMessageExtras, bool)
- func (m *RxMessage) Voice() (VoiceMessageExtras, bool)
- type RxMessageHandler
- type TextMessageExtras
- type UserDeptInfo
- type UserGender
- type UserID
- type UserInfo
- type UserStatus
- type VideoMessageExtras
- type VoiceMessageExtras
- type Workwx
- type WorkwxApp
- func (c *WorkwxApp) CreateAppchat(chatInfo *ChatInfo) (chatid string, err error)
- func (c *WorkwxApp) GetAppchat(chatid string) (*ChatInfo, error)
- func (c *WorkwxApp) GetUser(userid string) (*UserInfo, error)
- func (c *WorkwxApp) GetUserID(code string) (*UserID, error)
- func (c *WorkwxApp) GetUserIDByMobile(mobile string) (string, error)
- func (c *WorkwxApp) ListAllDepts() ([]*DeptInfo, error)
- func (c *WorkwxApp) ListDepts(id int64) ([]*DeptInfo, error)
- func (c *WorkwxApp) ListUsersByDeptID(deptID int64, fetchChild bool) ([]*UserInfo, error)
- func (c *WorkwxApp) SendFileMessage(recipient *Recipient, mediaID string, isSafe bool) error
- func (c *WorkwxApp) SendImageMessage(recipient *Recipient, mediaID string, isSafe bool) error
- func (c *WorkwxApp) SendMPNewsMessage(recipient *Recipient, title string, thumbMediaID string, author string, ...) error
- func (c *WorkwxApp) SendMarkdownMessage(recipient *Recipient, content string, isSafe bool) error
- func (c *WorkwxApp) SendNewsMessage(recipient *Recipient, title string, description string, url string, ...) error
- func (c *WorkwxApp) SendTextCardMessage(recipient *Recipient, title string, description string, url string, ...) error
- func (c *WorkwxApp) SendTextMessage(recipient *Recipient, content string, isSafe bool, isEnableIDTrans bool) error
- func (c *WorkwxApp) SendVideoMessage(recipient *Recipient, mediaID string, description string, title string, ...) error
- func (c *WorkwxApp) SendVoiceMessage(recipient *Recipient, mediaID string, isSafe bool) error
- func (c *WorkwxApp) SpawnAccessTokenRefresher()
- func (c *WorkwxApp) SpawnAccessTokenRefresherWithContext(ctx context.Context)
- func (c *WorkwxApp) UploadPermanentImageMedia(media *Media) (url string, err error)
- func (c *WorkwxApp) UploadTempFileMedia(media *Media) (*MediaUploadResult, error)
- func (c *WorkwxApp) UploadTempImageMedia(media *Media) (*MediaUploadResult, error)
- func (c *WorkwxApp) UploadTempVideoMedia(media *Media) (*MediaUploadResult, error)
- func (c *WorkwxApp) UploadTempVoiceMedia(media *Media) (*MediaUploadResult, error)
- type WorkwxClientError
Examples ¶
Constants ¶
const DefaultQYAPIHost = "https://qyapi.weixin.qq.com"
DefaultQYAPIHost 默认企业微信 API Host
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChatInfo ¶
type ChatInfo struct { // ChatID 群聊唯一标志 ChatID string `json:"chatid"` // Name 群聊名 Name string `json:"name"` // OwnerUserID 群主id OwnerUserID string `json:"owner"` // MemberUserIDs 群成员id列表 MemberUserIDs []string `json:"userlist"` }
ChatInfo 群聊信息
type CtorOption ¶
type CtorOption interface {
// contains filtered or unexported methods
}
CtorOption 客户端对象构造参数
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) CtorOption
WithHTTPClient 使用给定的 http.Client 作为 HTTP 客户端
type DeptInfo ¶
type DeptInfo struct { // ID 部门 ID ID int64 `json:"id"` // Name 部门名称 Name string `json:"name"` // ParentID 父亲部门id。根部门为1 ParentID int64 `json:"parentid"` // Order 在父部门中的次序值。order值大的排序靠前。值范围是[0, 2^32) Order uint32 `json:"order"` }
DeptInfo 部门信息
type HTTPHandler ¶
type HTTPHandler struct {
// contains filtered or unexported fields
}
func NewHTTPHandler ¶
func NewHTTPHandler( token string, encodingAESKey string, rxMessageHandler RxMessageHandler, ) (*HTTPHandler, error)
func (*HTTPHandler) ServeHTTP ¶
func (h *HTTPHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request)
type ImageMessageExtras ¶
type ImageMessageExtras interface { // GetPicURL 返回图片消息的图片链接 URL。 GetPicURL() string // GetMediaID 返回图片消息的图片媒体文件 ID。 // // 可以调用【获取媒体文件】接口拉取,仅三天内有效。 GetMediaID() string // contains filtered or unexported methods }
ImageMessageExtras 图片消息的参数。
type LinkMessageExtras ¶
type LinkMessageExtras interface { // GetTitle 返回链接消息的标题。 GetTitle() string // GetDescription 返回链接消息的描述。 GetDescription() string // GetURL 返回链接消息的跳转 URL。 GetURL() string // GetPicURL 返回链接消息的封面缩略图 URL。 GetPicURL() string // contains filtered or unexported methods }
LinkMessageExtras 链接消息的参数。
type LocationMessageExtras ¶
type LocationMessageExtras interface { // GetLatitude 返回位置消息的纬度(角度值;北纬为正)。 GetLatitude() float64 // GetLongitude 返回位置消息的经度(角度值;东经为正)。 GetLongitude() float64 // GetScale 返回位置消息的地图缩放大小。 GetScale() int // GetLabel 返回位置消息的地理位置信息。 GetLabel() string // contains filtered or unexported methods }
LocationMessageExtras 位置消息的参数。
type Media ¶
type Media struct {
// contains filtered or unexported fields
}
Media 欲上传的素材
NOTE: 由于 Go `mime/multipart` 包的实现细节原因, 暂时不开放 Content-Type 定制,全部传 `application/octet-stream`。 如有需求,请去 GitHub 提 issue。
func NewMediaFromBuffer ¶
NewMediaFromBuffer 从内存创建一个欲上传的素材对象
type MediaUploadResult ¶
type MediaUploadResult struct { // Type 媒体文件类型,分别有图片(image)、语音(voice)、视频(video),普通文件(file) Type string // MediaID 媒体文件上传后获取的唯一标识,3天内有效 MediaID string // CreatedAt 媒体文件上传时间戳 CreatedAt time.Time }
MediaUploadResult 临时素材上传结果
type MessageType ¶
type MessageType string
MessageType 消息类型
const MessageTypeImage MessageType = "image"
MessageTypeImage 图片消息
const MessageTypeLink MessageType = "link"
MessageTypeLink 链接消息
const MessageTypeLocation MessageType = "location"
MessageTypeLocation 位置消息
const MessageTypeText MessageType = "text"
MessageTypeText 文本消息
const MessageTypeVideo MessageType = "video"
MessageTypeVideo 视频消息
const MessageTypeVoice MessageType = "voice"
MessageTypeVoice 语音消息
type Recipient ¶
type Recipient struct { // UserIDs 成员ID列表(消息接收者),最多支持1000个 UserIDs []string // PartyIDs 部门ID列表,最多支持100个。 PartyIDs []string // TagIDs 标签ID列表,最多支持100个 TagIDs []string // ChatID 应用关联群聊ID,仅用于【发送消息到群聊会话】 ChatID string }
Recipient 消息收件人定义
type RxMessage ¶
type RxMessage struct { // FromUserID 发送者的 UserID FromUserID string // SendTime 消息发送时间 SendTime time.Time // MsgType 消息类型 MsgType MessageType // MsgID 消息 ID MsgID int64 // AgentID 企业应用 ID,可在应用的设置页面查看 AgentID int64 // contains filtered or unexported fields }
RxMessage 一条接收到的消息
func (*RxMessage) Image ¶
func (m *RxMessage) Image() (ImageMessageExtras, bool)
Image 如果消息为图片类型,则拿出相应的消息参数,否则返回 nil, false
func (*RxMessage) Link ¶
func (m *RxMessage) Link() (LinkMessageExtras, bool)
Link 如果消息为链接类型,则拿出相应的消息参数,否则返回 nil, false
func (*RxMessage) Location ¶
func (m *RxMessage) Location() (LocationMessageExtras, bool)
Location 如果消息为位置类型,则拿出相应的消息参数,否则返回 nil, false
func (*RxMessage) Text ¶
func (m *RxMessage) Text() (TextMessageExtras, bool)
Text 如果消息为文本类型,则拿出相应的消息参数,否则返回 nil, false
func (*RxMessage) Video ¶
func (m *RxMessage) Video() (VideoMessageExtras, bool)
Video 如果消息为视频类型,则拿出相应的消息参数,否则返回 nil, false
func (*RxMessage) Voice ¶
func (m *RxMessage) Voice() (VoiceMessageExtras, bool)
Voice 如果消息为语音类型,则拿出相应的消息参数,否则返回 nil, false
type RxMessageHandler ¶
type RxMessageHandler interface { // OnIncomingMessage 一条消息到来时的回调。 OnIncomingMessage(msg *RxMessage) error }
RxMessageHandler 用来接收消息的接口。
type TextMessageExtras ¶
type TextMessageExtras interface { // GetContent 返回文本消息的内容。 GetContent() string // contains filtered or unexported methods }
TextMessageExtras 文本消息的参数。
type UserDeptInfo ¶
type UserDeptInfo struct { // DeptID 部门 ID DeptID int64 // Order 部门内的排序值,默认为0,数值越大排序越前面 Order uint32 // IsLeader 在所在的部门内是否为上级 IsLeader bool }
UserDeptInfo 用户部门信息
type UserGender ¶
type UserGender int
UserGender 用户性别
const ( // UserGenderUnspecified 性别未定义 UserGenderUnspecified UserGender = 0 // UserGenderMale 男性 UserGenderMale UserGender = 1 // UserGenderFemale 女性 UserGenderFemale UserGender = 2 )
type UserID ¶
type UserID struct { // UserID 成员UserID,当用户为企业成员时返回 UserID string // OpenID 非企业成员的标识,非企业成员授权时返回 OpenID string }
UserID 访问用户身份
type UserInfo ¶
type UserInfo struct { // UserID 成员UserID // // 对应管理端的账号,企业内必须唯一。不区分大小写,长度为1~64个字节 UserID string // Name 成员名称 Name string // Position 职务信息;第三方仅通讯录应用可获取 Position string // Departments 成员所属部门信息 Departments []UserDeptInfo // Mobile 手机号码;第三方仅通讯录应用可获取 Mobile string // Gender 性别 Gender UserGender // Email 邮箱;第三方仅通讯录应用可获取 Email string // AvatarURL 头像 URL;第三方仅通讯录应用可获取 // // NOTE:如果要获取小图将url最后的”/0”改成”/100”即可。 AvatarURL string // Telephone 座机;第三方仅通讯录应用可获取 Telephone string // IsEnabled 成员的启用状态 IsEnabled bool // Alias 别名;第三方仅通讯录应用可获取 Alias string // Status 成员激活状态 Status UserStatus // QRCodeURL 员工个人二维码;第三方仅通讯录应用可获取 // // 扫描可添加为外部联系人 QRCodeURL string // 主部门 id MainDeptID int64 }
UserInfo 用户信息
type UserStatus ¶
type UserStatus int
UserStatus 用户激活信息
已激活代表已激活企业微信或已关注微工作台(原企业号)。 未激活代表既未激活企业微信又未关注微工作台(原企业号)。
const ( // UserStatusActivated 已激活 UserStatusActivated UserStatus = 1 // UserStatusDeactivated 已禁用 UserStatusDeactivated UserStatus = 2 // UserStatusUnactivated 未激活 UserStatusUnactivated UserStatus = 4 )
type VideoMessageExtras ¶
type VideoMessageExtras interface { // GetMediaID 返回视频消息的视频媒体文件 ID。 // // 可以调用【获取媒体文件】接口拉取,仅三天内有效。 GetMediaID() string // GetThumbMediaID 返回视频消息缩略图的媒体 ID。 // // 可以调用【获取媒体文件】接口拉取,仅三天内有效。 GetThumbMediaID() string // contains filtered or unexported methods }
VideoMessageExtras 视频消息的参数。
type VoiceMessageExtras ¶
type VoiceMessageExtras interface { // GetMediaID 返回语音消息的语音媒体文件 ID。 // // 可以调用【获取媒体文件】接口拉取,仅三天内有效。 GetMediaID() string // GetFormat 返回语音消息的语音格式,如 "amr"、"speex" 等。 GetFormat() string // contains filtered or unexported methods }
VoiceMessageExtras 语音消息的参数。
type Workwx ¶
type Workwx struct { // CorpID 企业 ID,必填 CorpID string // contains filtered or unexported fields }
Workwx 企业微信客户端
Example ¶
corpID := "your_corpid" corpSecret := "your_corpsecret" agentID := int64(1234567) client := workwx.New(corpID) // there're advanced options _ = workwx.New( corpID, workwx.WithQYAPIHost("http://localhost:8888"), workwx.WithHTTPClient(&http.Client{}), ) // work with individual apps app := client.WithApp(corpSecret, agentID) app.SpawnAccessTokenRefresher() // see other examples for more details
Output:
type WorkwxApp ¶
type WorkwxApp struct { *Workwx // CorpSecret 应用的凭证密钥,必填 CorpSecret string // AgentID 应用 ID,必填 AgentID int64 // contains filtered or unexported fields }
WorkwxApp 企业微信客户端(分应用)
func (*WorkwxApp) CreateAppchat ¶
CreateAppchat 创建群聊会话
func (*WorkwxApp) GetAppchat ¶
GetAppchat 获取群聊会话
func (*WorkwxApp) GetUserIDByMobile ¶
GetUserIDByMobile 通过手机号获取 userid
func (*WorkwxApp) ListAllDepts ¶
ListAllDepts 获取全量组织架构。
func (*WorkwxApp) ListUsersByDeptID ¶
ListUsersByDeptID 获取部门成员详情
func (*WorkwxApp) SendFileMessage ¶
SendFileMessage 发送文件消息
收件人参数如果仅设置了 `ChatID` 字段,则为【发送消息到群聊会话】接口调用; 否则为单纯的【发送应用消息】接口调用。
func (*WorkwxApp) SendImageMessage ¶
SendImageMessage 发送图片消息
收件人参数如果仅设置了 `ChatID` 字段,则为【发送消息到群聊会话】接口调用; 否则为单纯的【发送应用消息】接口调用。
func (*WorkwxApp) SendMPNewsMessage ¶
func (c *WorkwxApp) SendMPNewsMessage( recipient *Recipient, title string, thumbMediaID string, author string, sourceContentURL string, content string, digest string, isSafe bool, ) error
SendMPNewsMessage 发送 mpnews 类型的图文消息
收件人参数如果仅设置了 `ChatID` 字段,则为【发送消息到群聊会话】接口调用; 否则为单纯的【发送应用消息】接口调用。
func (*WorkwxApp) SendMarkdownMessage ¶
SendMarkdownMessage 发送 Markdown 消息
仅支持 Markdown 的子集,详见[官方文档](https://work.weixin.qq.com/api/doc#90002/90151/90854/%E6%94%AF%E6%8C%81%E7%9A%84markdown%E8%AF%AD%E6%B3%95)。
收件人参数如果仅设置了 `ChatID` 字段,则为【发送消息到群聊会话】接口调用; 否则为单纯的【发送应用消息】接口调用。
func (*WorkwxApp) SendNewsMessage ¶
func (c *WorkwxApp) SendNewsMessage( recipient *Recipient, title string, description string, url string, picURL string, isSafe bool, ) error
SendNewsMessage 发送图文消息
收件人参数如果仅设置了 `ChatID` 字段,则为【发送消息到群聊会话】接口调用; 否则为单纯的【发送应用消息】接口调用。
func (*WorkwxApp) SendTextCardMessage ¶
func (c *WorkwxApp) SendTextCardMessage( recipient *Recipient, title string, description string, url string, buttonText string, isSafe bool, ) error
SendTextCardMessage 发送文本卡片消息
收件人参数如果仅设置了 `ChatID` 字段,则为【发送消息到群聊会话】接口调用; 否则为单纯的【发送应用消息】接口调用。
func (*WorkwxApp) SendTextMessage ¶
func (c *WorkwxApp) SendTextMessage( recipient *Recipient, content string, isSafe bool, isEnableIDTrans bool, ) error
SendTextMessage 发送文本消息
收件人参数如果仅设置了 `ChatID` 字段,则为【发送消息到群聊会话】接口调用; 否则为单纯的【发送应用消息】接口调用。
Example ¶
corpID := "your_corpid" corpSecret := "your_corpsecret" agentID := int64(1234567) client := workwx.New(corpID) app := client.WithApp(corpSecret, agentID) // preferably do this at app initialization app.SpawnAccessTokenRefresher() // send to user(s) to1 := workwx.Recipient{ UserIDs: []string{"testuser"}, } _ = app.SendTextMessage(&to1, "send to user(s)", false) // "safe" message to2 := workwx.Recipient{ UserIDs: []string{"testuser"}, } _ = app.SendTextMessage(&to2, "safe message", true) // send to party(parties) to3 := workwx.Recipient{ PartyIDs: []string{"testdept"}, } _ = app.SendTextMessage(&to3, "send to party(parties)", false) // send to tag(s) to4 := workwx.Recipient{ TagIDs: []string{"testtag"}, } _ = app.SendTextMessage(&to4, "send to tag(s)", false) // send to chatid to5 := workwx.Recipient{ ChatID: "testchat", } _ = app.SendTextMessage(&to5, "send to chatid", false)
Output:
func (*WorkwxApp) SendVideoMessage ¶
func (c *WorkwxApp) SendVideoMessage( recipient *Recipient, mediaID string, description string, title string, isSafe bool, ) error
SendVideoMessage 发送视频消息
收件人参数如果仅设置了 `ChatID` 字段,则为【发送消息到群聊会话】接口调用; 否则为单纯的【发送应用消息】接口调用。
func (*WorkwxApp) SendVoiceMessage ¶
SendVoiceMessage 发送语音消息
收件人参数如果仅设置了 `ChatID` 字段,则为【发送消息到群聊会话】接口调用; 否则为单纯的【发送应用消息】接口调用。
func (*WorkwxApp) SpawnAccessTokenRefresher ¶
func (c *WorkwxApp) SpawnAccessTokenRefresher()
SpawnAccessTokenRefresher 启动该 app 的 access token 刷新 goroutine
NOTE: 该 goroutine 本身没有 keep-alive 逻辑,需要自助保活
func (*WorkwxApp) SpawnAccessTokenRefresherWithContext ¶
SpawnAccessTokenRefresherWithContext 启动该 app 的 access token 刷新 goroutine 可以通过 context cancellation 停止此 goroutine
NOTE: 该 goroutine 本身没有 keep-alive 逻辑,需要自助保活
func (*WorkwxApp) UploadPermanentImageMedia ¶
UploadPermanentImageMedia 上传永久图片素材
func (*WorkwxApp) UploadTempFileMedia ¶
func (c *WorkwxApp) UploadTempFileMedia(media *Media) (*MediaUploadResult, error)
UploadTempFileMedia 上传临时文件素材
func (*WorkwxApp) UploadTempImageMedia ¶
func (c *WorkwxApp) UploadTempImageMedia(media *Media) (*MediaUploadResult, error)
UploadTempImageMedia 上传临时图片素材
func (*WorkwxApp) UploadTempVideoMedia ¶
func (c *WorkwxApp) UploadTempVideoMedia(media *Media) (*MediaUploadResult, error)
UploadTempVideoMedia 上传临时视频素材
func (*WorkwxApp) UploadTempVoiceMedia ¶
func (c *WorkwxApp) UploadTempVoiceMedia(media *Media) (*MediaUploadResult, error)
UploadTempVoiceMedia 上传临时语音素材
type WorkwxClientError ¶
type WorkwxClientError struct { // Code 错误码,0表示成功,非0表示调用失败。 // // 开发者需根据errcode是否为0判断是否调用成功(errcode意义请见全局错误码)。 Code errcodes.ErrCode // Msg 错误信息,调用失败会有相关的错误信息返回。 // // 仅作参考,后续可能会有变动,因此不可作为是否调用成功的判据。 Msg string }
WorkwxClientError 企业微信客户端 SDK 的响应错误
func (*WorkwxClientError) Error ¶
func (e *WorkwxClientError) Error() string
Source Files
¶
- accesstoken.go
- apis.md.go
- appchat.go
- chat_info.md.go
- client.go
- client_options.go
- dept_info.go
- dept_info.md.go
- dummy_for_generate.go
- errors.go
- media.go
- media_api.go
- message.go
- models.go
- recipient.go
- rx.go
- rx_msg.go
- rx_msg.md.go
- rx_msg_extras.go
- traits.go
- user_info.go
- user_info.md.go
- user_info_helper.go