Documentation
¶
Overview ¶
Package dingtalk provide dingtalk-sdk for go
5行代码,开启微信API示例:
package main
import (
"net/http"
"github.com/esap/dingtalk" // 微信SDK包
)
func main() {
dingtalk.Debug = true
dingtalk.Set("yourToken", "yourAppID", "yourSecret", "yourEncodingAesKey")
http.HandleFunc("/", WxHandler)
http.ListenAndServe(":9090", nil)
}
func WxHandler(w http.ResponseWriter, r *http.Request) {
dingtalk.VerifyURL(w, r).NewText("客服消息1").Send().NewText("客服消息2").Send().NewText("查询结果...").Reply()
}
More info: https://github.com/esap/dingtalk
Example ¶
package main
import (
"net/http"
"github.com/esap/dingtalk"
)
// 微信SDK包
func main() {
dingtalk.Debug = true
dingtalk.Set("yourToken", "yourAppID", "yourSecret", "yourEncodingAesKey")
http.HandleFunc("/", HttpHandler)
http.ListenAndServe(":9090", nil)
}
func HttpHandler(w http.ResponseWriter, r *http.Request) {
ctx := dingtalk.VerifyURL(w, r)
switch ctx.Msg.MsgType {
case dingtalk.TypeText:
ctx.NewText(ctx.Msg.Content).Reply()
case dingtalk.TypeImage:
ctx.NewImage(ctx.Msg.MediaId).Reply()
case dingtalk.TypeVoice:
ctx.NewVoice(ctx.Msg.MediaId).Reply()
case dingtalk.TypeVideo:
ctx.NewVideo(ctx.Msg.MediaId, "video title", "video description").Reply()
case dingtalk.TypeFile:
ctx.NewFile(ctx.Msg.MediaId).Reply()
default:
ctx.NewText("其他消息类型" + ctx.Msg.MsgType).Reply()
}
}
Example (Echo) ¶
package main
import (
"github.com/esap/dingtalk"
"github.com/labstack/echo"
)
// 微信SDK包
func main() {
e := echo.New()
e.Any("/", EchoHandler)
e.Start(":9090")
}
func EchoHandler(c echo.Context) error {
ctx := dingtalk.VerifyURL(c.Response().Writer, c.Request())
switch ctx.Msg.MsgType {
case dingtalk.TypeText:
ctx.NewText(ctx.Msg.Content).Reply()
case dingtalk.TypeImage:
ctx.NewImage(ctx.Msg.MediaId).Reply()
case dingtalk.TypeVoice:
ctx.NewVoice(ctx.Msg.MediaId).Reply()
case dingtalk.TypeVideo:
ctx.NewVideo(ctx.Msg.MediaId, "video title", "video description").Reply()
case dingtalk.TypeFile:
ctx.NewFile(ctx.Msg.MediaId).Reply()
default:
ctx.NewText("其他消息类型" + ctx.Msg.MsgType).Reply()
}
return nil
}
Index ¶
- Constants
- Variables
- func GetAccessToken() string
- func GetGender(s string) string
- func GetJsMedia(filename, mediaId string) error
- func GetJsMediaBytes(mediaId string) ([]byte, error)
- func GetMedia(filename, mediaId string) error
- func GetMediaBytes(mediaId string) ([]byte, error)
- func GetOauth2Url(corpId, host string) string
- func GetRandomString(l int) string
- func GetUserAccessToken() string
- func Printf(s string, v ...interface{})
- func Println(v ...interface{})
- func Set(tk, id, sec string, key ...string) (err error)
- func SetEnt(token, appId, secret, aeskey string, agentId ...int) (err error)
- func SetLog(l io.Writer)
- func Substr(str string, start int, end int) string
- type AccessToken
- type Article
- type Button
- type CDATA
- type Context
- func (c *Context) Id() string
- func (c *Context) NewFile(mediaId string) *Context
- func (c *Context) NewImage(mediaId string) *Context
- func (c *Context) NewMpNews(mediaId string) *Context
- func (c *Context) NewMusic(mediaId, title, desc, musicUrl, hqMusicUrl string) *Context
- func (c *Context) NewNews(arts ...Article) *Context
- func (c *Context) NewText(text ...string) *Context
- func (c *Context) NewTextcard(title, description, url string) *Context
- func (c *Context) NewVideo(mediaId, title, desc string) *Context
- func (c *Context) NewVoice(mediaId string) *Context
- func (c *Context) Reply() (err error)
- func (c *Context) ReplySuccess() (err error)
- func (c *Context) Send() *Context
- func (c *Context) SendAdd() *Context
- type Department
- type DeptList
- type DkData
- type DkDataRet
- type Extattr
- type File
- type Image
- type JsConfig
- type Media
- type Menu
- type MpArticle
- type MpNews
- type MpNewsId
- type MpTemplate
- type MpUser
- type MpUserInfo
- type MpUserInfoList
- type MpUserListReq
- type Music
- type MyField
- type News
- type Server
- func (s *Server) AddMenu(m *Menu) (err error)
- func (s *Server) AddTagUsers(id int, userlist []string, partylist []int) error
- func (s *Server) AddTemplate(IdShort string) (id string, err error)
- func (s *Server) BatchGet(ul []string) (ui []MpUserInfo, err error)
- func (s *Server) BatchGetAll() (ui []MpUserInfo, err error)
- func (s *Server) CheckDeptAcl(userid, acl string) bool
- func (s *Server) CheckTagAcl(userid, acl string) bool
- func (s *Server) CheckUserAcl(userid, acl string) bool
- func (s *Server) DecryptMsg(msg string) (string, error)
- func (s *Server) DelMenu() (err error)
- func (s *Server) DelTagUsers(id int, userlist []string) error
- func (s *Server) DelTemplate(id string) (err error)
- func (s *Server) DeptAdd(dept *Department) (err error)
- func (s *Server) DeptDelete(Id int) (err error)
- func (s *Server) DeptUpdate(dept *Department) (err error)
- func (s *Server) EncryptMsg(msg []byte, timeStamp, nonce string) (re *wxRespEnc, err error)
- func (s *Server) FetchUserList()
- func (s *Server) GetAccessToken() string
- func (s *Server) GetAllCheckIn(opType, start, end int64) (dkdata []DkData, err error)
- func (s *Server) GetAllMpUserList() (ul []string, err error)
- func (s *Server) GetAllTemplate() (templist []MpTemplate, err error)
- func (s *Server) GetApproval(start, end, nextNum int64) (sdr *SpDataRet, err error)
- func (s *Server) GetCheckIn(opType, start, end int64, Namelist []string) (dkdata []DkData, err error)
- func (s *Server) GetDeptIdList() (deptIdlist []int)
- func (s *Server) GetDeptList() (dl DeptList, err error)
- func (s *Server) GetDeptName(id int) string
- func (s *Server) GetJsConfig(Url string) *JsConfig
- func (s *Server) GetJsMedia(filename, mediaId string) error
- func (s *Server) GetJsMediaBytes(mediaId string) ([]byte, error)
- func (s *Server) GetMedia(filename, mediaId string) error
- func (s *Server) GetMediaBytes(mediaId string) ([]byte, error)
- func (s *Server) GetMenu() (m *Menu, err error)
- func (s *Server) GetMpUserInfo(openid string, lang ...string) (user *MpUserInfo, err error)
- func (s *Server) GetMpUserList(openid ...string) (ul *MpUser, err error)
- func (s *Server) GetTagId(name string) int
- func (s *Server) GetTagIdList() (tagIdlist []int)
- func (s *Server) GetTagList() (l TagList, err error)
- func (s *Server) GetTagName(id int) string
- func (s *Server) GetTagUsers(id int) (tu *TagUsers, err error)
- func (s *Server) GetTicket() string
- func (s *Server) GetToParty(acl interface{}) string
- func (s *Server) GetToTag(acl interface{}) string
- func (s *Server) GetToUser(acl interface{}) string
- func (s *Server) GetUnifedOrderUrl(desc, tradeNo, fee, ip, callback, tradetype, productid string) string
- func (s *Server) GetUser(userid string) *UserInfo
- func (s *Server) GetUserAccessToken() string
- func (s *Server) GetUserIdList() (userlist []string)
- func (s *Server) GetUserInfo(userId string) (user UserInfo, err error)
- func (s *Server) GetUserList() (u userList, err error)
- func (s *Server) GetUserName(userid string) string
- func (s *Server) GetUserOauth(code string) (o UserOauth, err error)
- func (s *Server) GetUserSimpleList() (u userList, err error)
- func (s *Server) Jscode2Session(code string) (ws *WxSession, err error)
- func (s *Server) Jscode2SessionEnt(code string) (ws *WxSession, err error)
- func (s *Server) MediaUpload(mediaType string, filename string) (media Media, err error)
- func (s *Server) MsgQueueAdd(v interface{})
- func (s *Server) NewFile(to string, id int, mediaId string) File
- func (s *Server) NewImage(to string, id int, mediaId string) Image
- func (s *Server) NewMpNews(to string, id int, arts ...MpArticle) (news MpNews)
- func (s *Server) NewMpNewsId(to string, id int, mediaId string) (news MpNewsId)
- func (s *Server) NewMusic(to string, id int, mediaId, title, desc, musicUrl, qhMusicUrl string) Music
- func (s *Server) NewNews(to string, id int, arts ...Article) (news News)
- func (s *Server) NewText(to string, id int, msg ...string) Text
- func (s *Server) NewTextcard(to string, id int, title, description, url string) Textcard
- func (s *Server) NewVideo(to string, id int, mediaId, title, desc string) Video
- func (s *Server) NewVoice(to string, id int, mediaId string) Voice
- func (s *Server) NewWxCard(to string, id int, cardId string) (c WxCard)
- func (s *Server) PayOrderScan(mchId, ProductId string) string
- func (s *Server) SafeClose()
- func (s *Server) SafeOpen()
- func (s *Server) SendFile(to string, id int, mediaId string) *WxErr
- func (s *Server) SendImage(to string, id int, mediaId string) *WxErr
- func (s *Server) SendMpNews(to string, id int, arts ...MpArticle) *WxErr
- func (s *Server) SendMpNewsId(to string, id int, mediaId string) *WxErr
- func (s *Server) SendMsg(v interface{}) *WxErr
- func (s *Server) SendMusic(to string, id int, mediaId, title, desc, musicUrl, qhMusicUrl string) *WxErr
- func (s *Server) SendNews(to string, id int, arts ...Article) *WxErr
- func (s *Server) SendTemplate(to, id, url, appid, pagepath string, data interface{}) (msgid float64, err error)
- func (s *Server) SendText(to string, agentId int, msg string, safe ...int) (e *WxErr)
- func (s *Server) SendTextcard(to string, id int, title, desc, url string) *WxErr
- func (s *Server) SendVideo(to string, id int, mediaId, title, desc string) *WxErr
- func (s *Server) SendVoice(to string, id int, mediaId string) *WxErr
- func (s *Server) Set(tk, id, sec string, key ...string) (err error)
- func (s *Server) SetEnt(token, appId, secret, aeskey string, agentId ...int) (err error)
- func (s *Server) SetMchId(mchid string)
- func (s *Server) SyncDeptList() (err error)
- func (s *Server) SyncTagList() (err error)
- func (s *Server) SyncUserList() (err error)
- func (s *Server) TagAdd(Tag *Tag) (err error)
- func (s *Server) TagDelete(TagId int) (err error)
- func (s *Server) TagUpdate(Tag *Tag) (err error)
- func (s *Server) UserAdd(user *UserInfo) (err error)
- func (s *Server) UserDelete(user string) (err error)
- func (s *Server) UserUpdate(user *UserInfo) (err error)
- func (s *Server) VerifyURL(w http.ResponseWriter, r *http.Request) (ctx *Context)
- type SpDataRet
- type Tag
- type TagErr
- type TagList
- type TagUserBody
- type TagUsers
- type Text
- type Textcard
- type Ticket
- type UnifiedOrderReq
- type UnifiedOrderRet
- type UserInfo
- type UserOauth
- type Video
- type Voice
- type WxCard
- type WxErr
- func SendFile(to string, id int, mediaId string) *WxErr
- func SendImage(to string, id int, mediaId string) *WxErr
- func SendMpNews(to string, id int, arts ...MpArticle) *WxErr
- func SendMpNewsId(to string, id int, mediaId string) *WxErr
- func SendMsg(v interface{}) *WxErr
- func SendMusic(to string, id int, mediaId, title, desc, musicUrl, qhMusicUrl string) *WxErr
- func SendNews(to string, id int, arts ...Article) *WxErr
- func SendText(to string, id int, msg string, safe ...int) *WxErr
- func SendTextcard(to string, id int, title, desc, url string) *WxErr
- func SendVideo(to string, id int, mediaId, title, desc string) *WxErr
- func SendVoice(to string, id int, mediaId string) *WxErr
- type WxMsg
- type WxMsgEnc
- type WxSession
Examples ¶
Constants ¶
const ( WXAPI_ENT = "https://oapi.dingtalk.com/" WXAPI_TOKEN_ENT = WXAPI_ENT + "gettoken?appkey=%v&appsecret=%v" WXAPI_MSG_ENT = WXAPI_ENT + "message/send_to_conversation?access_token=" WXAPI_JSAPI_ENT = WXAPI_ENT + "get_jsapi_ticket?access_token=" )
WXAPI_ENT 企业号接口
const ( // WXAPIGetApproval 企业号审批数据获取接口 WXAPIGetApproval = WXAPI_ENT + "corp/getapprovaldata?access_token=" // CorpApprovalAgentID 审批AgentId CorpApprovalAgentID = 3010040 )
const ( // WXAPICheckIn 企业号打开数据获取接口 WXAPICheckIn = WXAPI_ENT + "checkin/getcheckindata?access_token=" // CorpGetCheckInAgentID 打卡AgentId CorpGetCheckInAgentID = 3010011 )
const ( WXAPI_DeptList = WXAPI_ENT + `department/list?access_token=%s` WXAPI_DeptAdd = WXAPI_ENT + `department/create?access_token=` WXAPI_DeptUpdate = WXAPI_ENT + `department/update?access_token=` WXAPI_DeptDel = WXAPI_ENT + `department/delete?access_token=` )
WXAPI 企业号部门列表接口
const ( WXAPI_TagList = WXAPI_ENT + `topapi/role/list?access_token=` WXAPI_TagUsers = WXAPI_ENT + `topapi/role/simplelist?access_token=` WXAPI_AddTagUsers = WXAPI_ENT + `topapi/role/addrolesforemps?access_token=` WXAPI_DelTagUsers = WXAPI_ENT + `topapi/role/removerolesforemps?access_token=` WXAPI_TagAdd = WXAPI_ENT + `role/add_role?access_token=` WXAPI_TagUpdate = WXAPI_ENT + `role/update_role?access_token=` WXAPI_TagDel = WXAPI_ENT + `topapi/role/deleterole?access_token=` )
WXAPI 企业号标签接口
const ( WXAPI_UserList = WXAPI_ENT + `user/listbypage?access_token=%s&department_id=1` WXAPI_UserSimpleList = WXAPI_ENT + `user/simplelist?access_token=%s&department_id=1` WXAPI_GetUser = WXAPI_ENT + "user/getuserinfo?access_token=%s&code=%s" WXAPI_GetUserInfo = WXAPI_ENT + "user/get?access_token=%s&userid=%s" WXAPI_UserAdd = WXAPI_ENT + `user/create?access_token=` WXAPI_UserUpdate = WXAPI_ENT + `user/update?access_token=` WXAPI_UserDel = WXAPI_ENT + `user/delete?access_token=` )
WXAPI 企业微信用户列表接口
const ( // WXAPI_UPLOAD 临时素材上传 WXAPI_UPLOAD = "media/upload?access_token=%s&type=%s" // WXAPI_GETMEDIA 临时素材下载 WXAPI_GETMEDIA = "media/get?access_token=%s&media_id=%s" // WXAPI_GetJssdkMedia 高清语言素材下载 WXAPI_GetJssdkMedia = "media/get/jssdk?access_token=%s&media_id=%s" )
const ( WXAPI_GetMenu = `menu/get?access_token=%s&agentid=%d` WXAPI_AddMenu = `menu/create?access_token=%s&agentid=%d` WXAPI_DelMenu = `menu/delete?access_token=%s&agentid=%d` )
WXAPI_ENT 企业号菜单接口
const ( MP_AddTemplate = WXAPI + "template/api_add_template?access_token=" MP_GetAllTemplate = WXAPI + "template/get_all_private_template?access_token=" MP_DelTemplate = WXAPI + "template/del_private_template?access_token=" MP_SendTemplateMsg = WXAPI + "message/template/send?access_token=" )
MP_Template 公众号模板消息接口
const ( MP_GetUserList = WXAPI + "user/get?access_token=%s&next_openid=%s" MP_BatchGet = WXAPI + "user/info/batchget?access_token=" MP_GetUserInfo = WXAPI + "user/info?access_token=%s&openid=%v&lang=%v" )
MP 公众号接口
const ( OAUTH2PAGE = "" /* 141-byte string literal not displayed */ Code2PAGE = "https://api.weixin.qq.com/sns/jscode2session?appid=%v&secret=%v&js_code=%v&grant_type=authorization_code" Code2PAGE_Ent = "https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session?access_token=%v&js_code=%v&grant_type=authorization_code" )
OAUTH2PAGE oauth2鉴权
const ( PayRoot = "weixin://wxpay/bizpayurl?" PayUrl = "weixin://wxpay/bizpayurl?sign=%s&appid=%s&mch_id=%s&product_id=%sX&time_stamp=%vX&nonce_str=%s" PayUnifiedOrderUrl = "https://api.mch.weixin.qq.com/pay/unifiedordefunc" )
PayRoot 支付根URL
const ( WXAPI = "https://oapi.dingtalk.com/" WXAPI_TOKEN = WXAPI + "gettoken?appkey=%v&appsecret=%v" WXAPI_MSG = WXAPI + "message/send_to_conversation?access_token=" WXAPI_JSAPI = WXAPI + "get_jsapi_ticket?access_token=" )
WXAPI 订阅号,服务号接口
const ( TypeText = "text" TypeImage = "image" TypeVoice = "voice" TypeMusic = "music" TypeVideo = "video" TypeTextcard = "textcard" // 仅企业号可用 TypeWxCard = "wxcard" // 仅服务号可用 TypeFile = "file" // 仅企业号可用 TypeNews = "news" TypeMpNews = "mpnews" // 仅企业号可用 TypeThumb = "thumb" )
Type io类型汇总
Variables ¶
var ( // Debug is a flag to Println() Debug bool = false // UserServerMap 其他实例集 UserServerMap = make(map[string]*Server) )
var FetchDelay time.Duration = 5 * time.Minute
FetchDelay 默认5分钟同步一次
Functions ¶
func GetJsMediaBytes ¶
GetJsMediaBytes 下载高清语言素材,返回body字节
Types ¶
type AccessToken ¶
type AccessToken struct {
AccessToken string `json:"access_token"`
ExpiresIn int64 `json:"expires_in"`
WxErr
}
AccessToken 回复体
type Article ¶
type Article struct {
Title CDATA `json:"title"`
Description CDATA `json:"description"`
PicUrl CDATA `json:"picurl"`
Url CDATA `json:"url"`
}
Article 文章
func NewArticle ¶
NewArticle 先创建文章,再传给NewNews()
type Button ¶
type Button struct {
Name string `json:"name"`
Type string `json:"type"`
Key string `json:"key"`
Url string `json:"url"`
AppId string `json:"appid"`
PagePath string `json:"pagepath"`
SubButton []struct {
Name string `json:"name"`
Type string `json:"type"`
Key string `json:"key"`
Url string `json:"url"`
AppId string `json:"appid"`
PagePath string `json:"pagepath"`
} `json:"sub_button"`
}
Button 按钮
type CDATA ¶
type CDATA string
CDATA 标准规范,XML编码成 `<![CDATA[消息内容]]>`
func (CDATA) MarshalXML ¶
MarshalXML 自定义xml编码接口,实现讨论: http://stackoverflow.com/q/41951345/7493327
type Context ¶
type Context struct {
*Server
Timestamp string
Nonce string
Msg *WxMsg
MsgEnc *WxMsgEnc
Resp interface{}
Writer http.ResponseWriter
Request *http.Request
// contains filtered or unexported fields
}
Context 消息上下文
func VerifyURL ¶
func VerifyURL(w http.ResponseWriter, r *http.Request) (ctx *Context)
VerifyURL 验证URL,验证成功则返回标准请求载体(Msg已解密)
func (*Context) NewTextcard ¶
NewTextcard Textcard消息
func (*Context) ReplySuccess ¶
ReplySuccess 如果不能在5秒内处理完,应该先回复success,然后通过客服消息通知用户
type Department ¶
type Department struct {
Id int `json:"id"`
Name string `json:"name"`
ParentId int `json:"parentid"`
Order1 int64 `json:"order"`
}
Department 部门
type DkData ¶
type DkData struct {
Userid string `json:"userid"` // 用户id
GroupName string `json:"groupname"` // 打卡规则名称
CheckinType string `json:"checkin_type"` // 打卡类型
ExceptionType string `json:"exception_type"` // 异常类型,如果有多个异常,以分号间隔
CheckinTime int64 `json:"checkin_time"` // 打卡时间。UTC时间戳
LocationTitle string `json:"location_title"` // 打卡地点title
LocationDetail string `json:"location_detail"` // 打卡地点详情
WifiName string `json:"wifiname"` // 打卡wifi名称
Notes string `json:"notes"` // 打卡备注
WifiMac string `json:"wifimac"` // 打卡的MAC地址/bssid
}
DkData 审批数据
type Extattr ¶
type Extattr struct {
Name string `json:"name"`
Value interface{} `json:"value"`
}
Extattr 额外属性
type File ¶
type File struct {
File media `json:"file"`
// contains filtered or unexported fields
}
File 文件消息,仅企业号支持
type Image ¶
type Image struct {
Image media `json:"image"`
// contains filtered or unexported fields
}
Image 图片消息
type JsConfig ¶
type JsConfig struct {
Beta bool `json:"beta"`
Debug bool `json:"debug"`
AppId string `json:"appId"`
Timestamp int64 `json:"timestamp"`
Nonsestr string `json:"nonceStr"`
Signature string `json:"signature"`
JsApiList []string `json:"jsApiList"`
Url string `json:"jsurl"`
App int `json:"jsapp"`
}
JsConfig Jssdk配置
type Media ¶
type Media struct {
WxErr
Type string `json:"type"`
MediaID string `json:"media_id"`
ThumbMediaId string `json:"thumb_media_id"`
CreatedAt interface{} `json:"created_at"` // 企业号是string,服务号是int,采用interface{}统一接收
}
Media 上传回复体
type Menu ¶
type Menu struct {
WxErr
Button []Button `json:"button"`
Menu struct {
Button []Button `json:"button"`
} `json:"menu,omitempty"`
}
Menu 菜单
type MpArticle ¶
type MpArticle struct {
Title string `json:"title"`
ThumbMediaId string `json:"thumb_media_id"`
Author string `json:"author"`
Url string `json:"content_source_url"`
Content string `json:"content"`
Digest string `json:"digest"`
}
MpArticle 加密文章
func NewMpArticle ¶
NewMpArticle 先创建加密文章,再传给NewMpNews()
type MpNews ¶
type MpNews struct {
MpNews struct {
Articles []MpArticle `json:"articles"`
} `json:"mpnews"`
// contains filtered or unexported fields
}
MpNews 加密新闻消息,仅企业号支持
type MpNewsId ¶
type MpNewsId struct {
MpNews struct {
MediaId CDATA `json:"media_id"`
} `json:"mpnews"`
// contains filtered or unexported fields
}
MpNewsId 加密新闻消息(通过mediaId直接发)
type MpTemplate ¶
type MpTemplate struct {
TemplateId string `json:"template_id"`
Title string `json:"title"`
PrimaryIndustry string `json:"primary_industry"`
DeputyIndustry string `json:"deputy_industry"`
Content string `json:"template_id"`
Example string `json:"example"`
}
MpTemplate 模板信息
type MpUserInfo ¶
type MpUserInfo struct {
Subscribe int
OpenId string
NickName string
Sex int
Language string
City string
Province string
Country string
HeadImgUrl string
SubscribeTime int `json:"subscribe_time"`
UnionId string
Remark string
GroupId int
TagIdList []int `json:"tagid_list"`
}
MpUserInfo 公众号用户信息
type MpUserInfoList ¶
type MpUserInfoList struct {
WxErr
MpUserInfoList []MpUserInfo `json:"user_info_list"`
}
MpUserInfoList 公众号用户信息列表
type MpUserListReq ¶
type MpUserListReq struct {
UserList interface{} `json:"user_list"`
}
MpUserListReq 公众号用户请求
type Music ¶
type Music struct {
Music music `json:"music"`
// contains filtered or unexported fields
}
Music 音乐消息,企业号不支持
type MyField ¶
type MyField struct {
Title string `json:"title"` // 类目名
Type string `json:"type"` // 类目类型【 text: "文本", textarea: "多行文本", number: "数字", date: "日期", datehour: "日期+时间", select: "选择框" 】
Value interface{} `json:"value"` // 填写的内容,Type是图片或list时,value是一个数组
DateHourValue int64 `json:"dateHourValue"` // 日期时间值
}
MyField 自定义字段
type News ¶
type News struct {
ArticleCount int
Articles struct {
Item []Article `xml:"item" json:"articles"`
} `json:"news"`
// contains filtered or unexported fields
}
News 新闻消息
type Server ¶
type Server struct {
AppId string
MchId string // 商户id,用于微信支付
AgentId int
AppKey string
AppSec string
Secret string
Token string
EncodingAESKey string
AesKey []byte // 解密的AesKey
SafeMode bool
EntMode bool
RootUrl string
MsgUrl string
TokenUrl string
JsApi string
Safe int
UserList userList
DeptList DeptList
TagList TagList
MsgQueue chan interface{}
sync.Mutex // accessToken读取锁
ExternalTokenHandler func(appId string) *AccessToken // 通过外部方法统一获取access token ,避免集群情况下token失效
// contains filtered or unexported fields
}
Server 微信服务容器
func (*Server) AddTagUsers ¶
AddTagUsers 添加标签成员
func (*Server) AddTemplate ¶
AddTemplate 获取模板
func (*Server) BatchGet ¶
func (s *Server) BatchGet(ul []string) (ui []MpUserInfo, err error)
BatchGet 批量获取公众号用户信息
func (*Server) BatchGetAll ¶
func (s *Server) BatchGetAll() (ui []MpUserInfo, err error)
BatchGetAll 获取所有公众号用户
func (*Server) CheckDeptAcl ¶
CheckDeptAcl 测试权限,对比user是否包含于acl
func (*Server) CheckTagAcl ¶
CheckTagAcl 测试权限,对比user是否包含于acl
func (*Server) CheckUserAcl ¶
CheckUserAcl 测试权限,对比user的账号,姓名是否包含于acl
func (*Server) DecryptMsg ¶
DecryptMsg 解密微信消息,密文string->base64Dec->aesDec->去除头部随机字串 AES加密的buf由16个字节的随机字符串、4个字节的msg_len(网络字节序)、msg和$AppId组成
func (*Server) DelTagUsers ¶
DelTagUsers 删除标签成员
func (*Server) DeptUpdate ¶
func (s *Server) DeptUpdate(dept *Department) (err error)
DeptUpdate 获取部门列表
func (*Server) EncryptMsg ¶
EncryptMsg 加密普通回复(AES-CBC),打包成xml格式 AES加密的buf由16个字节的随机字符串、4个字节的msg_len(网络字节序)、msg和$AppId组成
func (*Server) GetAccessToken ¶
GetAccessToken 读取AccessToken
func (*Server) GetAllCheckIn ¶
GetAllCheckIn 获取所有人的打卡数据
func (*Server) GetAllMpUserList ¶
GetAllMpUserList 获取所有用户ID
func (*Server) GetAllTemplate ¶
func (s *Server) GetAllTemplate() (templist []MpTemplate, err error)
GetAllTemplate 获取模板
func (*Server) GetApproval ¶
GetApproval 获取审批数据
func (*Server) GetCheckIn ¶
func (s *Server) GetCheckIn(opType, start, end int64, Namelist []string) (dkdata []DkData, err error)
GetCheckIn 获取打卡数据,Namelist用户列表不超过100个。若用户超过100个,请分批获取
func (*Server) GetDeptIdList ¶
GetDeptIdList 获取部门id列表
func (*Server) GetDeptList ¶
GetDeptList 获取部门列表
func (*Server) GetJsConfig ¶
GetJsConfig 获取Jssdk配置
func (*Server) GetJsMedia ¶
GetJsMedia 下载高清语言素材(通过JSSDK上传)
func (*Server) GetJsMediaBytes ¶
GetJsMediaBytes 下载高清语言素材,返回body字节
func (*Server) GetMediaBytes ¶
GetMediaBytes 下载临时素材,返回body字节
func (*Server) GetMpUserInfo ¶
func (s *Server) GetMpUserInfo(openid string, lang ...string) (user *MpUserInfo, err error)
func (*Server) GetMpUserList ¶
GetMpUserList 获取用户信息,根据openid
func (*Server) GetTagIdList ¶
GetTagIdList 获取标签id列表
func (*Server) GetTagUsers ¶
GetTagUsers 获取标签下的成员
func (*Server) GetToParty ¶
GetToParty 获取acl所包含的所有部门ID,结果形式:tagId1|tagId2|tagId3...
func (*Server) GetUnifedOrderUrl ¶
func (s *Server) GetUnifedOrderUrl(desc, tradeNo, fee, ip, callback, tradetype, productid string) string
GetUnifedOrderUrl 获取统一下单URL,用于生成付款二维码等
func (*Server) GetUserAccessToken ¶
GetUserAccessToken 获取通讯录AccessToken
func (*Server) GetUserIdList ¶
GetUserIdList 获取用户列表
func (*Server) GetUserInfo ¶
GetUserInfo 从企业号通过userId获取用户信息
func (*Server) GetUserList ¶
GetUserList 获取用户详情列表
func (*Server) GetUserName ¶
GetUserName 通过账号获取用户信息
func (*Server) GetUserOauth ¶
GetUserOauth 通过code鉴权
func (*Server) GetUserSimpleList ¶
GetUserSimpleList 获取用户列表
func (*Server) Jscode2Session ¶
Jscode2Session code换session
func (*Server) Jscode2SessionEnt ¶
Jscode2SessionEnt code换session(企业微信)
func (*Server) MediaUpload ¶
MediaUpload 临时素材上传,mediaType选项如下:
TypeImage = "image" TypeVoice = "voice" TypeVideo = "video" TypeFile = "file" // 仅企业号可用 TypeThumb = "thumb"
func (*Server) NewMpNewsId ¶
NewMpNewsId 加密新闻mpnews消息(仅企业号可用)
func (*Server) NewMusic ¶
func (s *Server) NewMusic(to string, id int, mediaId, title, desc, musicUrl, qhMusicUrl string) Music
NewMusic Music消息
func (*Server) NewTextcard ¶
NewTextcard Textcard消息
func (*Server) PayOrderScan ¶
func (*Server) SendMpNews ¶
SendMpNews 发送加密新闻mpnews消息(仅企业号可用)
func (*Server) SendMpNewsId ¶
SendMpNewsId 发送加密新闻mpnews消息(直接使用mediaId)
func (*Server) SendMusic ¶
func (s *Server) SendMusic(to string, id int, mediaId, title, desc, musicUrl, qhMusicUrl string) *WxErr
SendMusic 发送客服Music消息
func (*Server) SendTemplate ¶
func (s *Server) SendTemplate(to, id, url, appid, pagepath string, data interface{}) (msgid float64, err error)
SendTemplate 发送模板消息,data通常是map[string]struct{value string,color string}
func (*Server) SendTextcard ¶
SendTextcard 发送客服extcard消息
type SpDataRet ¶
type SpDataRet struct {
WxErr `json:"-"`
Count int64 `json:"count"`
Total int64 `json:"total"`
NextSpnum int64 `json:"next_spnum"`
Data []struct {
Spname string `json:"spname"` // 审批名称(请假,报销,自定义审批名称)
ApplyName string `json:"apply_name"` // 申请人姓名
ApplyOrg string `json:"apply_org"` // 申请人部门
ApprovalName []string `json:"approval_name"` // 审批人姓名
NotifyName []string `json:"notify_name"` // 抄送人姓名
SpStatus int64 `json:"sp_status"` // 审批状态:1审批中;2 已通过;3已驳回;4已取消
SpNum int64 `json:"sp_num"` // 审批单号
Mediaids []string `json:"mediaids"` // 审批媒体
ApplyTime int64 `json:"apply_time"` // 申请时间
ApplyUserId string `json:"apply_user_id"` // 申请人
Leave struct {
Timeunit int64 `json:"timeunit"` // 请假时间单位:0半天;1小时
LeaveType int64 `json:"leave_type"` // 请假类型:1年假;2事假;3病假;4调休假;5婚假;6产假;7陪产假;8其他
StartTime int64 `json:"start_time"` // 请假开始时间,unix时间
EndTime int64 `json:"end_time"` // 请假结束时间,unix时间
Duration int64 `json:"duration"` // 请假时长,单位小时
Reason string `json:"reason"` // 请假事由
} `json:"leave"` // 请假类型
Expense struct {
ExpenseType int64 `json:"expense_type"` // 报销类型:1差旅费;2交通费;3招待费;4其他报销
Reason string `json:"reason"` // 报销事由
Item []struct {
ExpenseitemType int64 `json:"expenseitem_type"` // 费用类型:1飞机票;2火车票;3的士费;4住宿费;5餐饮费;6礼品费;7活动费;8通讯费;9补助;10其他
Time int64 `json:"time"` // 发生时间,unix时间
Sums int64 `json:"sums"` // 费用金额,单位元
Reason string `json:"reason"` // 明细事由
} `json:"item"` // 报销明细
} `json:"expense"` // 报销类型
Comm struct {
Data string `json:"apply_data"` // 自定义审批申请的单据数据
} `json:"comm"` // 自定义类型
} `json:"data"`
}
SpDataRet 审批返回数据
type TagUserBody ¶
type TagUserBody struct {
TagId int `json:"tagid"`
UserList []string `json:"userlist"`
PartyList []int `json:"partylist"`
}
TagUserBody 标签成员(请求body格式)
type TagUsers ¶
type TagUsers struct {
WxErr
TagId int `json:"tagid"`
TagName string
UserList []UserInfo
PartyList []int
}
TagUsers 标签成员
type Textcard ¶
type Textcard struct {
Textcard textcard `json:"textcard"`
// contains filtered or unexported fields
}
Textcard 卡片消息,仅企业微信客户端有效
type UnifiedOrderReq ¶
type UnifiedOrderReq struct {
Appid string `xml:"appid"`
MchId string `xml:"mch_id"`
DeviceInfo string `xml:"device_info"`
NonceStr string `xml:"nonce_str"`
Sign string `xml:"sign"`
SignType string `xml:"sign_type"`
Body string `xml:"body"`
Detail CDATA `xml:"detail"`
Attach string `xml:"attach"`
OutTradeNo string `xml:"out_trade_no"`
FeeType string `xml:"fee_type"`
TotalFee string `xml:"total_fee"`
SpbillCreateIp string `xml:"spbill_create_ip"`
TimeStart string `xml:"time_start"`
TimeExpire string `xml:"time_expire"`
GoodsTag string `xml:"goods_tag"`
NotifyUrl string `xml:"notify_url"`
TradeType string `xml:"trade_type"`
ProductId string `xml:"product_id"`
LimitPay string `xml:"limit_pay"`
Openid string `xml:"openid"`
SceneInfo string `xml:"scene_info"`
}
UnifiedOrderReq 统一下单请求体
type UnifiedOrderRet ¶
type UnifiedOrderRet struct {
ReturnCode string `xml:"return_code"`
ReturnMsg string `xml:"return_msg"`
// 以下字段在return_code为SUCCESS的时候有返回
Appid string `xml:"appid"`
MchId string `xml:"mch_id"`
DeviceInfo string `xml:"device_info"`
NonceStr string `xml:"nonce_str"`
Sign string `xml:"sign"`
ResultCode string `xml:"result_code"`
ErrCode string `xml:"err_code"`
ErrCodeDes string `xml:"err_code_des"`
// 以下字段在return_code 和result_code都为SUCCESS的时候有返回
TradeType string `xml:"trade_type"`
PrepayId string `xml:"prepay_id"`
CodeUrl string `xml:"code_url"`
TimeExpire string `xml:"time_expire"`
GoodsTag string `xml:"goods_tag"`
NotifyUrl string `xml:"notify_url"`
ProductId string `xml:"product_id"`
LimitPay string `xml:"limit_pay"`
Openid string `xml:"openid"`
SceneInfo string `xml:"scene_info"`
}
UnifiedOrderRet 统一下单返回体
type UserInfo ¶
type UserInfo struct {
WxErr `json:"-"`
UserId string `json:"userid"`
Name string `json:"name"`
Alias string `json:"alias"`
Department []int `json:"department"`
IsLeaderInDept []int `json:"is_leader_in_dept,omitempty"`
Order []int `json:"order"`
Dept int `json:"dept"`
DeptName string `json:"deptname"`
Position string `json:"position,omitempty"`
Mobile string `json:"mobile"`
Gender string `json:"gender,omitempty"`
Email string `json:"email,omitempty"`
IsLeader int `json:"isleader,omitempty"` // old attr
AavatarMediaid string `json:"avatar_mediaid,omitempty"`
Enable int `json:"enable,omitempty"`
Telephone string `json:"telephone,omitempty"`
WeixinId string `json:"-"`
Avatar string `json:"avatar,omitempty"`
Status int `json:"-"`
ToInvite bool `json:"to_invite"`
ExtAttr struct {
Attrs []Extattr `json:"attrs"`
} `json:"extattr"`
}
UserInfo 用户信息
type Video ¶
type Video struct {
Video video `json:"video"`
// contains filtered or unexported fields
}
Video 视频消息
type Voice ¶
type Voice struct {
Voice media `json:"voice"`
// contains filtered or unexported fields
}
Voice 语音消息
type WxCard ¶
type WxCard struct {
WxCard struct {
CardId string `json:"card_id"`
} `json:"wxcard"`
// contains filtered or unexported fields
}
WxCard 卡券
type WxErr ¶
WxErr 通用错误
func SendMpNews ¶
SendMpNews 发送加密新闻mpnews消息(仅企业号可用)
func SendMpNewsId ¶
SendMpNewsId 发送加密新闻mpnews消息(直接使用mediaId)
func SendTextcard ¶
SendTextcard 发送客服extcard消息
type WxMsg ¶
type WxMsg struct {
XMLName xml.Name `xml:"xml"`
ToUserName string
FromUserName string
CreateTime int64
MsgId int64
MsgType string
Content string // text
AgentID int // corp
PicUrl string // image
MediaId string // image/voice/video/shortvideo
Format string // voice
Recognition string // voice
ThumbMediaId string // video
LocationX float32 `xml:"Latitude"` // location
LocationY float32 `xml:"Longitude"` // location
Precision float32 // LOCATION
Scale int // location
Label string // location
Title string // link
Description string // link
Url string // link
Event string // event
EventKey string // event
SessionFrom string // event|user_enter_tempsession
Ticket string
FileKey string
FileMd5 string
FileTotalLen string
ScanCodeInfo struct {
ScanType string
ScanResult string
}
AgentType string
ItemCount int
PackageId string
Item []struct {
FromUserName string
CreateTime int64
MsgType string
Event string // event
Name string
Owner string
AddUserList string
DelUserList string
ChatId string
MsgId int64
ChatInfo struct {
ChatId string
Name string
Owner string
UserList string
}
Content string // text
Receiver struct {
Type string
Id string
}
FileName string // file
PicUrl string // image/link
MediaId string // image/voice/video/shortvideo
Location_X float32 // location
Location_Y float32 // location
Scale int // location
Label string // location
Title string // link
Description string // link
Url string // link
}
}
WxMsg 混合用户消息,业务判断的主体