Documentation ¶
Overview ¶
Package wechat provide wechat-sdk for go
5行代码,开启微信API示例:
package main
import (
"net/http" "gitee.com/fbbi/go-wechat" // 微信SDK包
)
func main() { wechat.Debug = true cfg := &wechat.WxConfig{ Token: "yourToken", AppId: "yourAppID", Secret: "yourSecret", EncodingAESKey: "yourEncodingAesKey", } app := wechat.New(cfg) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { app.VerifyURL(w, r).NewText("客服消息1").Send().NewText("客服消息2").Send().NewText("查询OK").Reply() }) http.ListenAndServe(":9090", nil) }
More info: https://gitee.com/fbbi/go-wechat
Package wechat TODO:微信支付接口
Example ¶
wechat.Debug = true cfg := &wechat.WxConfig{ Token: "yourToken", AppId: "yourAppID", Secret: "yourSecret", EncodingAESKey: "yourEncodingAesKey", } app := wechat.New(cfg) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { ctx := app.VerifyURL(w, r) // 根据消息类型主动回复 switch ctx.Msg.MsgType { case wechat.TypeText: ctx.NewText(ctx.Msg.Content).Reply() // 回复文字 case wechat.TypeImage: ctx.NewImage(ctx.Msg.MediaId).Reply() // 回复图片 case wechat.TypeVoice: ctx.NewVoice(ctx.Msg.MediaId).Reply() // 回复语音 case wechat.TypeVideo: ctx.NewVideo(ctx.Msg.MediaId, "video title", "video description").Reply() //回复视频 case wechat.TypeFile: ctx.NewFile(ctx.Msg.MediaId).Reply() // 回复文件,仅企业微信可用 default: ctx.NewText("其他消息类型" + ctx.Msg.MsgType).Reply() // 回复模板消息 } }) http.ListenAndServe(":9090", nil)
Output:
Index ¶
- Constants
- Variables
- func GetGender(s string) string
- func GetOauth2Url(corpId, host string) string
- func Printf(s string, v ...interface{})
- func Println(v ...interface{})
- func SetLog(l io.Writer)
- 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) Send() *Context
- type Department
- type DeptList
- type DkData
- type DkDataRet
- type Extattr
- type File
- type Image
- type JsConfig
- type MarkDown
- 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 QrcodeParamsReq
- type QrcodeParamsResp
- type Server
- func (s *Server) AddMenu(m *Menu) (err error)
- func (s *Server) AddMsg(v interface{})
- 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) CreateQrcodeParams(v QrcodeParamsReq) (m QrcodeParamsResp, err error)
- 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) NewFile(to, mediaId string) File
- func (s *Server) NewImage(to, mediaId string) Image
- func (s *Server) NewMarkDown(to, content string) (md MarkDown)
- func (s *Server) NewMpNews(to string, arts ...MpArticle) (news MpNews)
- func (s *Server) NewMpNewsId(to string, mediaId string) (news MpNewsId)
- func (s *Server) NewMusic(to, mediaId, title, desc, musicUrl, qhMusicUrl string) Music
- func (s *Server) NewNews(to string, arts ...Article) (news News)
- func (s *Server) NewTaskCard(to, Title, Desc, Url, TaskId, Btn string) (tc TaskCard)
- func (s *Server) NewText(to string, msg ...string) Text
- func (s *Server) NewTextcard(to, title, description, url string) Textcard
- func (s *Server) NewVideo(to, mediaId, title, desc string) Video
- func (s *Server) NewVoice(to, mediaId string) Voice
- func (s *Server) NewWxCard(to, 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, mediaId string) *WxErr
- func (s *Server) SendImage(to string, mediaId string) *WxErr
- func (s *Server) SendMarkDown(to string, content string) *WxErr
- func (s *Server) SendMpNews(to string, arts ...MpArticle) *WxErr
- func (s *Server) SendMpNewsId(to string, mediaId string) *WxErr
- func (s *Server) SendMsg(v interface{}) *WxErr
- func (s *Server) SendMusic(to string, mediaId, title, desc, musicUrl, qhMusicUrl string) *WxErr
- func (s *Server) SendNews(to string, arts ...Article) *WxErr
- func (s *Server) SendTaskCard(to string, Title, Desc, Url, TaskId, Btn string) *WxErr
- func (s *Server) SendTemplate(to, id, url, appid, pagepath string, data interface{}) *WxErr
- func (s *Server) SendText(to, msg string) (e *WxErr)
- func (s *Server) SendTextcard(to string, title, desc, url string) *WxErr
- func (s *Server) SendVideo(to string, mediaId, title, desc string) *WxErr
- func (s *Server) SendVoice(to string, mediaId string) *WxErr
- 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 TaskCard
- type Text
- type Textcard
- type Ticket
- type UnifiedOrderReq
- type UnifiedOrderRet
- type UserInfo
- type UserOauth
- type Video
- type Voice
- type WxCard
- type WxConfig
- type WxErr
- type WxMsg
- type WxMsgEnc
- type WxSession
Examples ¶
Constants ¶
const ( // CorpAPIGetApproval 企业微信审批数据获取接口 CorpAPIGetApproval = CorpAPI + "corp/getapprovaldata?access_token=" // CorpApprovalAgentID 审批AgentId CorpApprovalAgentID = 3010040 )
const ( // CorpAPICheckInGet 企业微信打开数据获取接口 CorpAPICheckInGet = CorpAPI + "checkin/getcheckindata?access_token=" // CorpCheckInAgentID 打卡AgentId CorpCheckInAgentID = 3010011 )
const ( CorpAPIDeptList = CorpAPI + `department/list?access_token=%s` CorpAPIDeptAdd = CorpAPI + `department/create?access_token=` CorpAPIDeptUpdate = CorpAPI + `department/update?access_token=` CorpAPIDeptDel = CorpAPI + `department/delete?access_token=` )
CorpAPIDeptList 企业微信部门列表接口
const ( CorpAPITagList = CorpAPI + `tag/list?access_token=` CorpAPITagAdd = CorpAPI + `tag/create?access_token=` CorpAPITagUpdate = CorpAPI + `tag/update?access_token=` CorpAPITagDel = CorpAPI + `tag/delete?access_token=` // CorpAPITagUsers 企业微信标签用户接口 CorpAPITagUsers = CorpAPI + `tag/get?access_token=` CorpAPIAddTagUsers = CorpAPI + `tag/addtagusers?access_token=` CorpAPIDelTagUsers = CorpAPI + `tag/deltagusers?access_token=` )
CorpAPITagList 企业微信标签接口
const ( // CorpAPIGetUserOauth 企业微信用户oauth2认证接口 CorpAPIGetUserOauth = CorpAPI + "user/getuserinfo?access_token=%s&code=%s" // CorpAPIUserList 企业微信用户列表 CorpAPIUserList = CorpAPI + `user/list?access_token=%s&department_id=1&fetch_child=1` CorpAPIUserSimpleList = CorpAPI + `user/simplelist?access_token=%s&department_id=1&fetch_child=1` // CorpAPIUserGet 企业微信用户接口 CorpAPIUserGet = CorpAPI + "user/get?access_token=%s&userid=%s" CorpAPIUserAdd = CorpAPI + `user/create?access_token=` CorpAPIUserUpdate = CorpAPI + `user/update?access_token=` CorpAPIUserDel = CorpAPI + `user/delete?access_token=` )
const ( // WXAPIMediaUpload 临时素材上传 WXAPIMediaUpload = "media/upload?access_token=%s&type=%s" // WXAPIMediaGet 临时素材下载 WXAPIMediaGet = "media/get?access_token=%s&media_id=%s" // WXAPIMediaGetJssdk 高清语言素材下载 WXAPIMediaGetJssdk = "media/get/jssdk?access_token=%s&media_id=%s" )
const ( WXAPIMenuGet = `menu/get?access_token=%s&agentid=%d` WXAPIMenuAdd = `menu/create?access_token=%s&agentid=%d` WXAPIMenuDel = `menu/delete?access_token=%s&agentid=%d` )
WXAPIMenuGet 微信菜单接口,兼容企业微信和服务号
const ( MPTemplateGetAll = WXAPI + "template/get_all_private_template?access_token=" MPTemplateAdd = WXAPI + "template/api_add_template?access_token=" MPTemplateDel = WXAPI + "template/del_private_template?access_token=" MPTemplateSendMsg = WXAPI + "message/template/send?access_token=" )
MPTemplateGetAll 服务号模板消息接口
const ( MPUserGetList = WXAPI + "user/get?access_token=%s&next_openid=%s" MPUserBatchGet = WXAPI + "user/info/batchget?access_token=" MPUserInfo = WXAPI + "user/info?access_token=%s&openid=%v&lang=%v" )
MPUserGetList 公众号用户接口
const ( WXAPIOauth2 = "" /* 139-byte string literal not displayed */ WXAPIJscode2session = "https://api.weixin.qq.com/sns/jscode2session?appid=%v&secret=%v&js_code=%v&grant_type=authorization_code" CorpAPIJscode2session = "https://qyapi.weixin.qq.com/cgi-bin/miniprogram/jscode2session?access_token=%v&js_code=%v&grant_type=authorization_code" )
WXAPIOauth2 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://api.weixin.qq.com/cgi-bin/" WXAPIToken = WXAPI + "token?grant_type=client_credential&appid=%s&secret=%s" WXAPIMsg = WXAPI + "message/custom/send?access_token=" WXAPIJsapi = WXAPI + "ticket/getticket?type=jsapi&access_token=" )
WXAPI 订阅号,服务号,小程序接口,相关接口常量统一以此开头
const ( CorpAPI = "https://qyapi.weixin.qq.com/cgi-bin/" CorpAPIToken = CorpAPI + "gettoken?corpid=%s&corpsecret=%s" CorpAPIMsg = CorpAPI + "message/send?access_token=" CorpAPIJsapi = CorpAPI + "get_jsapi_ticket?access_token=" )
CorpAPI 企业微信接口,相关接口常量统一以此开头
const ( TypeText = "text" TypeImage = "image" TypeVoice = "voice" TypeMusic = "music" TypeVideo = "video" TypeTextcard = "textcard" // 仅企业微信可用 TypeWxCard = "wxcard" // 仅服务号可用 TypeMarkDown = "markdown" // 仅企业微信可用 TypeTaskCard = "taskcard" // 仅企业微信可用 TypeFile = "file" // 仅企业微信可用 TypeNews = "news" TypeMpNews = "mpnews" // 仅企业微信可用 )
Type io类型汇总
const (
ParamsQrcode = "qrcode/create?access_token=%s" // 二维码
)
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 ¶
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 Resp interface{} Writer http.ResponseWriter Request *http.Request // contains filtered or unexported fields }
Context 消息上下文
func (*Context) NewTextcard ¶
NewTextcard Textcard消息
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 MarkDown ¶
type MarkDown struct { MarkDown struct { Content string `json:"content"` } `json:"markdown"` // contains filtered or unexported fields }
MarkDown markdown消息,仅企业微信支持,上限2048字节,utf-8编码
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:"content"` 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 QrcodeParamsReq ¶
type QrcodeParamsReq struct { ExpireSeconds int `json:"expireSeconds"` //该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 ActionName string `json:"actionName"` // 二维码类型,QR_SCENE为临时的整型参数值,QR_STR_SCENE为临时的字符串参数值,QR_LIMIT_SCENE为永久的整型参数值,QR_LIMIT_STR_SCENE为永久的字符串参数值 ActionInfo string `json:"actionInfo"` //二维码详细信息 SceneId string `json:"sceneId"` // 场景值ID,临时二维码时为32位非0整型,永久二维码时最大值为100000(目前参数只支持1--100000) SceneStr string `json:"sceneStr"` // 场景值ID(字符串形式的ID),字符串类型,长度限制为1到64 }
type QrcodeParamsResp ¶
type Server ¶
type Server struct { AppId string MchId string // 商户id,用于微信支付 AgentId int Secret string Token string EncodingAESKey string AppName string // 唯一标识,主要用于企业微信多应用区分 AppType int // 0-公众号,小程序; 1-企业微信 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, appName ...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) CreateQrcodeParams ¶
func (s *Server) CreateQrcodeParams(v QrcodeParamsReq) (m QrcodeParamsResp, err error)
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)
GetMpUserInfo 获取用户详情
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" // 仅企业微信可用
func (*Server) NewMarkDown ¶
NewMarkDown markdown消息,企业微信可用
func (*Server) NewMpNewsId ¶
NewMpNewsId 加密新闻mpnews消息(仅企业微信可用)
func (*Server) NewTaskCard ¶
NewTaskCard 任务卡片消息,企业微信可用
func (*Server) NewTextcard ¶
NewTextcard Textcard消息
func (*Server) PayOrderScan ¶
PayOrderScan 扫码付
func (*Server) SendMarkDown ¶
SendMarkDown 发送加密新闻mpnews消息(直接使用mediaId)
func (*Server) SendMpNews ¶
SendMpNews 发送加密新闻mpnews消息(仅企业号可用)
func (*Server) SendMpNewsId ¶
SendMpNewsId 发送加密新闻mpnews消息(直接使用mediaId)
func (*Server) SendTaskCard ¶
SendTaskCard 发送任务卡片taskcard消息
func (*Server) SendTemplate ¶
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 TaskCard ¶
type TaskCard struct { TaskCard struct { Title string `json:"title"` Description string `json:"description"` Url string `json:"url"` TaskId string `json:"task_id"` Btn []map[string]interface{} `json:"btn"` } `json:"taskcard"` // contains filtered or unexported fields }
TaskCard 任务卡片消息,仅企业微信支持,支持一到两个按钮设置
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 WxConfig ¶
type WxConfig struct { AppId string Token string Secret string EncodingAESKey string AgentId int MchId string AppName string AppType int // 0-公众号,小程序; 1-企业微信 ExternalTokenHandler func(string, ...string) *AccessToken // 外部token获取函数 }
WxConfig 配置,用于New()
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 TaskId string ScanCodeInfo struct { ScanType string ScanResult string } }
WxMsg 混合用户消息,业务判断的主体