dingtalk

package module
v0.0.0-...-20c3085 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2019 License: MIT Imports: 20 Imported by: 0

README

dingtalk

钉钉sdk,开发调整中,请暂勿使用

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()
	}
}
Output:

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
}
Output:

Index

Examples

Constants

View Source
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 企业号接口

View Source
const (
	// WXAPIGetApproval  企业号审批数据获取接口
	WXAPIGetApproval = WXAPI_ENT + "corp/getapprovaldata?access_token="
	// CorpApprovalAgentID  审批AgentId
	CorpApprovalAgentID = 3010040
)
View Source
const (
	// WXAPICheckIn 企业号打开数据获取接口
	WXAPICheckIn = WXAPI_ENT + "checkin/getcheckindata?access_token="
	// CorpGetCheckInAgentID  打卡AgentId
	CorpGetCheckInAgentID = 3010011
)
View Source
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 企业号部门列表接口

View Source
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 企业号标签接口

View Source
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 企业微信用户列表接口

View Source
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"
)
View Source
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 企业号菜单接口

View Source
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 公众号模板消息接口

View Source
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 公众号接口

View Source
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鉴权

View Source
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

View Source
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 订阅号,服务号接口

View Source
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

View Source
var (
	// Debug is a flag to Println()
	Debug bool = false

	// UserServerMap 其他实例集
	UserServerMap = make(map[string]*Server)
)
View Source
var FetchDelay time.Duration = 5 * time.Minute

FetchDelay 默认5分钟同步一次

Functions

func GetAccessToken

func GetAccessToken() string

GetAccessToken 读取默认实例AccessToken

func GetGender

func GetGender(s string) string

GetGender 获取性别

func GetJsMedia

func GetJsMedia(filename, mediaId string) error

GetJsMedia 下载高清语言素材(通过JSSDK上传)

func GetJsMediaBytes

func GetJsMediaBytes(mediaId string) ([]byte, error)

GetJsMediaBytes 下载高清语言素材,返回body字节

func GetMedia

func GetMedia(filename, mediaId string) error

GetMedia 下载临时素材

func GetMediaBytes

func GetMediaBytes(mediaId string) ([]byte, error)

GetMediaBytes 下载媒体,返回body字节

func GetOauth2Url

func GetOauth2Url(corpId, host string) string

GetOauth2Url 获取鉴权页面

func GetRandomString

func GetRandomString(l int) string

GetRandomString 获得随机字符串

func GetUserAccessToken

func GetUserAccessToken() string

GetUserAccessToken 获取默认实例通讯录AccessToken

func Printf

func Printf(s string, v ...interface{})

Printf Debug输出

func Println

func Println(v ...interface{})

Println Debug输出

func Set

func Set(tk, id, sec string, key ...string) (err error)

Set 设置token,appId,secret

func SetEnt

func SetEnt(token, appId, secret, aeskey string, agentId ...int) (err error)

SetEnt 初始化企业号,设置token,corpid,secrat,aesKey

func SetLog

func SetLog(l io.Writer)

SetLog 设置log

func Substr

func Substr(str string, start int, end int) string

Substr 截取字符串 start 起点下标 end 终点下标(不包括)

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

func NewArticle(title, desc, picUrl, url string) Article

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

func (c CDATA) MarshalXML(e *xml.Encoder, start xml.StartElement) error

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) Id

func (c *Context) Id() string

Id 返回消息的来源与去向,可作为多应用管理时的用户组Id

func (*Context) NewFile

func (c *Context) NewFile(mediaId string) *Context

NewFile File消息

func (*Context) NewImage

func (c *Context) NewImage(mediaId string) *Context

NewImage Image消息

func (*Context) NewMpNews

func (c *Context) NewMpNews(mediaId string) *Context

NewMpNews News消息

func (*Context) NewMusic

func (c *Context) NewMusic(mediaId, title, desc, musicUrl, hqMusicUrl string) *Context

NewMusic Music消息

func (*Context) NewNews

func (c *Context) NewNews(arts ...Article) *Context

NewNews News消息

func (*Context) NewText

func (c *Context) NewText(text ...string) *Context

NewText Text消息

func (*Context) NewTextcard

func (c *Context) NewTextcard(title, description, url string) *Context

NewTextcard Textcard消息

func (*Context) NewVideo

func (c *Context) NewVideo(mediaId, title, desc string) *Context

NewVideo Video消息

func (*Context) NewVoice

func (c *Context) NewVoice(mediaId string) *Context

NewVoice Voice消息

func (*Context) Reply

func (c *Context) Reply() (err error)

Reply 被动回复消息

func (*Context) ReplySuccess

func (c *Context) ReplySuccess() (err error)

ReplySuccess 如果不能在5秒内处理完,应该先回复success,然后通过客服消息通知用户

func (*Context) Send

func (c *Context) Send() *Context

Send 主动发送消息(客服)

func (*Context) SendAdd

func (c *Context) SendAdd() *Context

SendAdd 添加主动消息队列(客服)

type Department

type Department struct {
	Id       int    `json:"id"`
	Name     string `json:"name"`
	ParentId int    `json:"parentid"`
	Order1   int64  `json:"order"`
}

Department 部门

type DeptList

type DeptList struct {
	WxErr
	Department []Department
}

DeptList 部门列表

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 DkDataRet

type DkDataRet struct {
	WxErr  `json:"-"`
	Result []DkData `json:"checkindata"`
}

DkDataRet 审批返回数据

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 文件消息,仅企业号支持

func NewFile

func NewFile(to string, id int, mediaId string) File

NewFile File消息

type Image

type Image struct {
	Image media `json:"image"`
	// contains filtered or unexported fields
}

Image 图片消息

func NewImage

func NewImage(to string, id int, mediaId string) Image

NewImage 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 上传回复体

func MediaUpload

func MediaUpload(mediaType string, filename string) (media Media, err error)

MediaUpload 临时素材上传

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

func NewMpArticle(title, mediaId, author, url, content, digest string) MpArticle

NewMpArticle 先创建加密文章,再传给NewMpNews()

type MpNews

type MpNews struct {
	MpNews struct {
		Articles []MpArticle `json:"articles"`
	} `json:"mpnews"`
	// contains filtered or unexported fields
}

MpNews 加密新闻消息,仅企业号支持

func NewMpNews

func NewMpNews(to string, id int, arts ...MpArticle) (news MpNews)

NewMpNews 加密新闻mpnews消息(仅企业号可用)

type MpNewsId

type MpNewsId struct {
	MpNews struct {
		MediaId CDATA `json:"media_id"`
	} `json:"mpnews"`
	// contains filtered or unexported fields
}

MpNewsId 加密新闻消息(通过mediaId直接发)

func NewMpNewsId

func NewMpNewsId(to string, id int, mediaId string) (news MpNewsId)

NewMpNewsId 加密新闻mpnews消息(仅企业号可用)

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 MpUser

type MpUser struct {
	WxErr
	Total int
	Count int
	Data  struct {
		OpenId []string
	}
	NextOpenId string
}

MpUser 公众号用户

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 音乐消息,企业号不支持

func NewMusic

func NewMusic(to string, id int, mediaId, title, desc, musicUrl, qhMusicUrl string) Music

NewMusic 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 新闻消息

func NewNews

func NewNews(to string, id int, arts ...Article) (news News)

NewNews 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 New

func New(token, appid, secret, key string, agentId ...int) (s *Server)

New 微信服务容器,根据agentId判断是企业号或服务号

func NewServer

func NewServer(f func(appId string) *AccessToken) *Server

NewServer 空容器

func (*Server) AddMenu

func (s *Server) AddMenu(m *Menu) (err error)

AddMenu 创建应用菜单

func (*Server) AddTagUsers

func (s *Server) AddTagUsers(id int, userlist []string, partylist []int) error

AddTagUsers 添加标签成员

func (*Server) AddTemplate

func (s *Server) AddTemplate(IdShort string) (id string, err error)

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

func (s *Server) CheckDeptAcl(userid, acl string) bool

CheckDeptAcl 测试权限,对比user是否包含于acl

func (*Server) CheckTagAcl

func (s *Server) CheckTagAcl(userid, acl string) bool

CheckTagAcl 测试权限,对比user是否包含于acl

func (*Server) CheckUserAcl

func (s *Server) CheckUserAcl(userid, acl string) bool

CheckUserAcl 测试权限,对比user的账号,姓名是否包含于acl

func (*Server) DecryptMsg

func (s *Server) DecryptMsg(msg string) (string, error)

DecryptMsg 解密微信消息,密文string->base64Dec->aesDec->去除头部随机字串 AES加密的buf由16个字节的随机字符串、4个字节的msg_len(网络字节序)、msg和$AppId组成

func (*Server) DelMenu

func (s *Server) DelMenu() (err error)

DelMenu 删除应用菜单

func (*Server) DelTagUsers

func (s *Server) DelTagUsers(id int, userlist []string) error

DelTagUsers 删除标签成员

func (*Server) DelTemplate

func (s *Server) DelTemplate(id string) (err error)

DelTemplate 删除模板

func (*Server) DeptAdd

func (s *Server) DeptAdd(dept *Department) (err error)

DeptAdd 获取部门列表

func (*Server) DeptDelete

func (s *Server) DeptDelete(Id int) (err error)

DeptDelete 删除部门

func (*Server) DeptUpdate

func (s *Server) DeptUpdate(dept *Department) (err error)

DeptUpdate 获取部门列表

func (*Server) EncryptMsg

func (s *Server) EncryptMsg(msg []byte, timeStamp, nonce string) (re *wxRespEnc, err error)

EncryptMsg 加密普通回复(AES-CBC),打包成xml格式 AES加密的buf由16个字节的随机字符串、4个字节的msg_len(网络字节序)、msg和$AppId组成

func (*Server) FetchUserList

func (s *Server) FetchUserList()

FetchUserList 定期获取AccessToken

func (*Server) GetAccessToken

func (s *Server) GetAccessToken() string

GetAccessToken 读取AccessToken

func (*Server) GetAllCheckIn

func (s *Server) GetAllCheckIn(opType, start, end int64) (dkdata []DkData, err error)

GetAllCheckIn 获取所有人的打卡数据

func (*Server) GetAllMpUserList

func (s *Server) GetAllMpUserList() (ul []string, err error)

GetAllMpUserList 获取所有用户ID

func (*Server) GetAllTemplate

func (s *Server) GetAllTemplate() (templist []MpTemplate, err error)

GetAllTemplate 获取模板

func (*Server) GetApproval

func (s *Server) GetApproval(start, end, nextNum int64) (sdr *SpDataRet, err error)

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

func (s *Server) GetDeptIdList() (deptIdlist []int)

GetDeptIdList 获取部门id列表

func (*Server) GetDeptList

func (s *Server) GetDeptList() (dl DeptList, err error)

GetDeptList 获取部门列表

func (*Server) GetDeptName

func (s *Server) GetDeptName(id int) string

GetDeptName 通过部门id获取部门名称

func (*Server) GetJsConfig

func (s *Server) GetJsConfig(Url string) *JsConfig

GetJsConfig 获取Jssdk配置

func (*Server) GetJsMedia

func (s *Server) GetJsMedia(filename, mediaId string) error

GetJsMedia 下载高清语言素材(通过JSSDK上传)

func (*Server) GetJsMediaBytes

func (s *Server) GetJsMediaBytes(mediaId string) ([]byte, error)

GetJsMediaBytes 下载高清语言素材,返回body字节

func (*Server) GetMedia

func (s *Server) GetMedia(filename, mediaId string) error

GetMedia 下载临时素材

func (*Server) GetMediaBytes

func (s *Server) GetMediaBytes(mediaId string) ([]byte, error)

GetMediaBytes 下载临时素材,返回body字节

func (*Server) GetMenu

func (s *Server) GetMenu() (m *Menu, err error)

GetMenu 获取应用菜单

func (*Server) GetMpUserInfo

func (s *Server) GetMpUserInfo(openid string, lang ...string) (user *MpUserInfo, err error)

func (*Server) GetMpUserList

func (s *Server) GetMpUserList(openid ...string) (ul *MpUser, err error)

GetMpUserList 获取用户信息,根据openid

func (*Server) GetTagId

func (s *Server) GetTagId(name string) int

GetTagId 通过标签名称获取标签名称

func (*Server) GetTagIdList

func (s *Server) GetTagIdList() (tagIdlist []int)

GetTagIdList 获取标签id列表

func (*Server) GetTagList

func (s *Server) GetTagList() (l TagList, err error)

GetTagList 获取标签列表

func (*Server) GetTagName

func (s *Server) GetTagName(id int) string

GetTagName 通过标签id获取标签名称

func (*Server) GetTagUsers

func (s *Server) GetTagUsers(id int) (tu *TagUsers, err error)

GetTagUsers 获取标签下的成员

func (*Server) GetTicket

func (s *Server) GetTicket() string

GetTicket 读取获取Ticket

func (*Server) GetToParty

func (s *Server) GetToParty(acl interface{}) string

GetToParty 获取acl所包含的所有部门ID,结果形式:tagId1|tagId2|tagId3...

func (*Server) GetToTag

func (s *Server) GetToTag(acl interface{}) string

GetToTag 获取acl所包含的所有标签ID,结果形式:tagId1|tagId2|tagId3...

func (*Server) GetToUser

func (s *Server) GetToUser(acl interface{}) string

GetToUser 获取acl所包含的所有用户ID,结果形式:userId1|userId2|userId3...

func (*Server) GetUnifedOrderUrl

func (s *Server) GetUnifedOrderUrl(desc, tradeNo, fee, ip, callback, tradetype, productid string) string

GetUnifedOrderUrl 获取统一下单URL,用于生成付款二维码等

func (*Server) GetUser

func (s *Server) GetUser(userid string) *UserInfo

GetUser 从缓存获取用户信息

func (*Server) GetUserAccessToken

func (s *Server) GetUserAccessToken() string

GetUserAccessToken 获取通讯录AccessToken

func (*Server) GetUserIdList

func (s *Server) GetUserIdList() (userlist []string)

GetUserIdList 获取用户列表

func (*Server) GetUserInfo

func (s *Server) GetUserInfo(userId string) (user UserInfo, err error)

GetUserInfo 从企业号通过userId获取用户信息

func (*Server) GetUserList

func (s *Server) GetUserList() (u userList, err error)

GetUserList 获取用户详情列表

func (*Server) GetUserName

func (s *Server) GetUserName(userid string) string

GetUserName 通过账号获取用户信息

func (*Server) GetUserOauth

func (s *Server) GetUserOauth(code string) (o UserOauth, err error)

GetUserOauth 通过code鉴权

func (*Server) GetUserSimpleList

func (s *Server) GetUserSimpleList() (u userList, err error)

GetUserSimpleList 获取用户列表

func (*Server) Jscode2Session

func (s *Server) Jscode2Session(code string) (ws *WxSession, err error)

Jscode2Session code换session

func (*Server) Jscode2SessionEnt

func (s *Server) Jscode2SessionEnt(code string) (ws *WxSession, err error)

Jscode2SessionEnt code换session(企业微信)

func (*Server) MediaUpload

func (s *Server) MediaUpload(mediaType string, filename string) (media Media, err error)

MediaUpload 临时素材上传,mediaType选项如下:

TypeImage  = "image"
TypeVoice  = "voice"
TypeVideo  = "video"
TypeFile   = "file" // 仅企业号可用
TypeThumb  = "thumb"

func (*Server) MsgQueueAdd

func (s *Server) MsgQueueAdd(v interface{})

MsgQueueAdd 添加队列消息

func (*Server) NewFile

func (s *Server) NewFile(to string, id int, mediaId string) File

NewFile File消息

func (*Server) NewImage

func (s *Server) NewImage(to string, id int, mediaId string) Image

NewImage Image 消息

func (*Server) NewMpNews

func (s *Server) NewMpNews(to string, id int, arts ...MpArticle) (news MpNews)

NewMpNews 加密新闻mpnews消息(仅企业号可用)

func (*Server) NewMpNewsId

func (s *Server) NewMpNewsId(to string, id int, mediaId string) (news MpNewsId)

NewMpNewsId 加密新闻mpnews消息(仅企业号可用)

func (*Server) NewMusic

func (s *Server) NewMusic(to string, id int, mediaId, title, desc, musicUrl, qhMusicUrl string) Music

NewMusic Music消息

func (*Server) NewNews

func (s *Server) NewNews(to string, id int, arts ...Article) (news News)

NewNews news消息

func (*Server) NewText

func (s *Server) NewText(to string, id int, msg ...string) Text

NewText Text 文本消息

func (*Server) NewTextcard

func (s *Server) NewTextcard(to string, id int, title, description, url string) Textcard

NewTextcard Textcard消息

func (*Server) NewVideo

func (s *Server) NewVideo(to string, id int, mediaId, title, desc string) Video

NewVideo Video消息

func (*Server) NewVoice

func (s *Server) NewVoice(to string, id int, mediaId string) Voice

NewVoice Voice消息

func (*Server) NewWxCard

func (s *Server) NewWxCard(to string, id int, cardId string) (c WxCard)

NewWxCard 卡券消息,服务号可用

func (*Server) PayOrderScan

func (s *Server) PayOrderScan(mchId, ProductId string) string

func (*Server) SafeClose

func (s *Server) SafeClose()

SafeClose 关闭密保模式

func (*Server) SafeOpen

func (s *Server) SafeOpen()

SafeOpen 设置密保模式

func (*Server) SendFile

func (s *Server) SendFile(to string, id int, mediaId string) *WxErr

SendFile 发送客服File消息

func (*Server) SendImage

func (s *Server) SendImage(to string, id int, mediaId string) *WxErr

SendImage 发送客服Image消息

func (*Server) SendMpNews

func (s *Server) SendMpNews(to string, id int, arts ...MpArticle) *WxErr

SendMpNews 发送加密新闻mpnews消息(仅企业号可用)

func (*Server) SendMpNewsId

func (s *Server) SendMpNewsId(to string, id int, mediaId string) *WxErr

SendMpNewsId 发送加密新闻mpnews消息(直接使用mediaId)

func (*Server) SendMsg

func (s *Server) SendMsg(v interface{}) *WxErr

SendMsg 发送消息

func (*Server) SendMusic

func (s *Server) SendMusic(to string, id int, mediaId, title, desc, musicUrl, qhMusicUrl string) *WxErr

SendMusic 发送客服Music消息

func (*Server) SendNews

func (s *Server) SendNews(to string, id int, arts ...Article) *WxErr

SendNews 发送客服news消息

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) SendText

func (s *Server) SendText(to string, agentId int, msg string, safe ...int) (e *WxErr)

SendText 发送客服text消息,过长时自动拆分

func (*Server) SendTextcard

func (s *Server) SendTextcard(to string, id int, title, desc, url string) *WxErr

SendTextcard 发送客服extcard消息

func (*Server) SendVideo

func (s *Server) SendVideo(to string, id int, mediaId, title, desc string) *WxErr

SendVideo 发送客服Video消息

func (*Server) SendVoice

func (s *Server) SendVoice(to string, id int, mediaId string) *WxErr

SendVoice 发送客服Voice消息

func (*Server) Set

func (s *Server) Set(tk, id, sec string, key ...string) (err error)

Set 设置token,appId,secret

func (*Server) SetEnt

func (s *Server) SetEnt(token, appId, secret, aeskey string, agentId ...int) (err error)

SetEnt 初始化企业号,设置token,corpid,secrat,aesKey

func (*Server) SetMchId

func (s *Server) SetMchId(mchid string)

SetMchId 设置商户ID

func (*Server) SyncDeptList

func (s *Server) SyncDeptList() (err error)

SyncDeptList 更新部门列表

func (*Server) SyncTagList

func (s *Server) SyncTagList() (err error)

SyncTagList 更新标签列表

func (*Server) SyncUserList

func (s *Server) SyncUserList() (err error)

SyncUserList 获取用户列表

func (*Server) TagAdd

func (s *Server) TagAdd(Tag *Tag) (err error)

TagAdd 获取标签列表

func (*Server) TagDelete

func (s *Server) TagDelete(TagId int) (err error)

TagDelete 删除用户

func (*Server) TagUpdate

func (s *Server) TagUpdate(Tag *Tag) (err error)

TagUpdate 获取标签列表

func (*Server) UserAdd

func (s *Server) UserAdd(user *UserInfo) (err error)

UserAdd 添加用户

func (*Server) UserDelete

func (s *Server) UserDelete(user string) (err error)

UserDelete 删除用户

func (*Server) UserUpdate

func (s *Server) UserUpdate(user *UserInfo) (err error)

UserUpdate 添加用户

func (*Server) VerifyURL

func (s *Server) VerifyURL(w http.ResponseWriter, r *http.Request) (ctx *Context)

VerifyURL 验证URL,验证成功则返回标准请求载体(Msg已解密)

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 Tag

type Tag struct {
	TagId   int    `json:"tagid"`
	TagName string `json:"tagname"`
}

Tag 标签

type TagErr

type TagErr struct {
	WxErr
	InvalidList  string
	InvalidParty []int
}

TagErr 标签获取错误

type TagList

type TagList struct {
	WxErr
	Taglist []Tag
}

TagList 标签列表

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 Text

type Text struct {
	// contains filtered or unexported fields
}

Text 文本消息

func NewText

func NewText(to string, id int, msg ...string) Text

NewText Text 文本消息

type Textcard

type Textcard struct {
	Textcard textcard `json:"textcard"`
	// contains filtered or unexported fields
}

Textcard 卡片消息,仅企业微信客户端有效

func NewTextcard

func NewTextcard(to string, id int, title, description, url string) Textcard

NewTextcard Textcard消息

type Ticket

type Ticket struct {
	Ticket    string `json:"ticket"`
	ExpiresIn int64  `json:"expires_in"`
	WxErr
}

Ticket JS-SDK

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 UserOauth

type UserOauth struct {
	WxErr
	UserId   string
	DeviceId string
	OpenId   string
}

UserOauth 用户鉴权信息

func GetUserOauth

func GetUserOauth(code string) (userOauth UserOauth, err error)

GetUserOauth 通过code鉴权

type Video

type Video struct {
	Video video `json:"video"`
	// contains filtered or unexported fields
}

Video 视频消息

func NewVideo

func NewVideo(to string, id int, mediaId, title, desc string) Video

NewVideo Video消息

type Voice

type Voice struct {
	Voice media `json:"voice"`
	// contains filtered or unexported fields
}

Voice 语音消息

func NewVoice

func NewVoice(to string, id int, mediaId string) Voice

NewVoice Voice消息

type WxCard

type WxCard struct {
	WxCard struct {
		CardId string `json:"card_id"`
	} `json:"wxcard"`
	// contains filtered or unexported fields
}

WxCard 卡券

func NewWxCard

func NewWxCard(to string, id int, cardId string) (c WxCard)

NewWxCard 卡券消息,服务号可用

type WxErr

type WxErr struct {
	ErrCode int
	ErrMsg  string
}

WxErr 通用错误

func SendFile

func SendFile(to string, id int, mediaId string) *WxErr

SendFile 发送客服File消息

func SendImage

func SendImage(to string, id int, mediaId string) *WxErr

SendImage 发送客服Image消息

func SendMpNews

func SendMpNews(to string, id int, arts ...MpArticle) *WxErr

SendMpNews 发送加密新闻mpnews消息(仅企业号可用)

func SendMpNewsId

func SendMpNewsId(to string, id int, mediaId string) *WxErr

SendMpNewsId 发送加密新闻mpnews消息(直接使用mediaId)

func SendMsg

func SendMsg(v interface{}) *WxErr

SendMsg 发送消息

func SendMusic

func SendMusic(to string, id int, mediaId, title, desc, musicUrl, qhMusicUrl string) *WxErr

SendMusic 发送客服Music消息

func SendNews

func SendNews(to string, id int, arts ...Article) *WxErr

SendNews 发送客服news消息

func SendText

func SendText(to string, id int, msg string, safe ...int) *WxErr

SendText 发送客服text消息

func SendTextcard

func SendTextcard(to string, id int, title, desc, url string) *WxErr

SendTextcard 发送客服extcard消息

func SendVideo

func SendVideo(to string, id int, mediaId, title, desc string) *WxErr

SendVideo 发送客服Video消息

func SendVoice

func SendVoice(to string, id int, mediaId string) *WxErr

SendVoice 发送客服Voice消息

func (*WxErr) Error

func (w *WxErr) Error() error

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 混合用户消息,业务判断的主体

type WxMsgEnc

type WxMsgEnc struct {
	XMLName    xml.Name `xml:"xml"`
	ToUserName string
	AgentID    int
	Encrypt    string
	AgentType  string
}

WxMsgEnc 加密的用户消息

type WxSession

type WxSession struct {
	WxErr
	SessionKey string `json:"session_key"`
	// corp
	CorpId string `json:"corpid"`
	UserId string `json:"userid"`
	// mp
	OpenId  string `json:"openid"`
	UnionId string `json:"unionid"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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