wechat

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2021 License: MIT Imports: 16 Imported by: 0

README

WeChat SDK

Build Status Go Report Card GoDoc

微信SDK的golang实现,短小精悍,同时兼容【企业微信/服务号/订阅号/小程序】

快速开始

5行代码,链式消息,快速开启微信API示例:

package main

import (
	"net/http"

	"github.com/esap/wechat" // 微信SDK包
)

func main() {
	wechat.Debug = true
	
	cfg := &wechat.WxConfig{
		Token:          "yourToken",
		AppId:          "yourAppID",
		Secret:         "yourSecret",
		EncodingAESKey: "yourEncodingAesKey",
	}

	app := wechat.New(cfg)
	app.SendText("@all", "Hello,World!")
	
	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)
}

配置方式

	// 创建公众号实例(服务号/订阅号/小程序) 不带aesKey则为明文模式
	cfg := &wechat.WxConfig{
		Token:          "yourToken",
		AppId:          "yourAppID",
		Secret:         "yourSecret",
	}

	// 创建公众号实例(服务号/订阅号/小程序)
	cfg := &wechat.WxConfig{
		Token:          "yourToken",
		AppId:          "yourAppID",
		Secret:         "yourSecret",
		EncodingAESKey: "yourEncodingAesKey",
	}

	// 创建企业微信实例
	cfg := &wechat.WxConfig{
		Token:          "yourToken",
		AppId:          "yourCorpID",
		AgentId:        "yourAgentId",
		Secret:         "yourSecret",
		EncodingAESKey: "yourEncodingAesKey",
		AppType:        1,
	}

主动推送消息

用户关注后,企业微信可以主动推送消息,服务号需要用户48小时内进入过。

	app.SendText(to, msg)
	app.SendImage(to, mediaId)
	app.SendVoice(to, mediaId)
	app.SendFile(to, mediaId)
	app.SendVideo(to, mediaId, title, desc)
	app.SendTextcard(to, title, desc, url)
	app.SendMusic(to, mediaId, title, desc, musicUrl, qhMusicUrl)
	app.SendNews(to, arts...)
	app.SendMpNews(to, arts...)
	app.SendMpNewsId(to, mediaId)
	app.SendMarkDown(to, content)

消息回调

  • 通常将app.VerifyURL(http.ResponseWriter, *http.Request)嵌入http handler

该函数返回*wechat.Context基本对象,其中的Msg为用户消息:

	// 混合用户消息,业务判断的主体
	WxMsg struct {
		XMLName      xml.Name `xml:"xml"`
		ToUserName  
		FromUserName
		CreateTime  64
		MsgId       64
		MsgType     
		Content       // text
		AgentID          // corp
		PicUrl        // image
		MediaId       // image/voice/video/shortvideo
		Format        // voice
		Recognition   // voice
		ThumbMediaId  // video
		LocationX    float32 `xml:"Latitude"`  // location
		LocationY    float32 `xml:"Longitude"` // location
		Precision    float32 // LOCATION
		Scale            // location
		Label         // location
		Title         // link
		Description   // link
		Url           // link
		Event         // event
		EventKey      // event
		SessionFrom   // event|user_enter_tempsession
		Ticket      
		FileKey     
		FileMd5     
		FileTotalLen

		ScanCodeInfo struct {
			ScanType  
			ScanResult
		}
	}

  • 如果使用其他web框架,例如echo/gin/beego等,则把VerifyURL()放入controller或handler
// echo示例 公众号回调接口
func wxApiPost(c echo.Context) error {
	ctx := app.VerifyURL(c.Response().Writer, c.Request())
	
	// TODO: 这里是其他业务操作

	return nil
}
回调回复消息

回调回复消息有两种方式:

  • 被动回复,采用XML格式编码返回(Reply);

  • 客服消息,采用json格式编码返回(Send);

  • 两种方式都可先调用*wechat.Context对象的New方法创建消息,然后调用Reply()或Send()。

  • 支持链式调用,但Reply()只有第一次有效。

	ctx.NewText("正在查询中...").Reply()
	ctx.NewText("客服消息1").Send().NewText("客服消息2").Send()
  • 被动回复可直接调用Reply(),表示已收到,然后调用客服消息。
文本消息
	ctx.NewText("content")
图片/语言/文件消息
	// mediaID 可通过素材管理-上上传多媒体文件获得
	ctx.NewImage("mediaID")
	ctx.NewVoice("mediaID")
	
	// 仅企业号支持
	ctx.NewFile("mediaID")
视频消息
	ctx.NewVideo("mediaID", "title", "description")
音乐消息
	ctx.NewMusic("thumbMediaID","title", "description", "musicURL", "hqMusicURL")
图文消息
	// 先创建三个文章
	art1 := wechat.NewArticle("拥抱AI,享受工作",
		"来自村长的ESAP系统最新技术分享",
		"http://ylin.wang/img/esap18-1.png",
		"http://ylin.wang/2017/07/13/esap18/")
	art2 := wechat.NewArticle("用企业微信代替pda实现扫描入库",
		"来自村长的ESAP系统最新技术分享",
		"http://ylin.wang/img/esap17-2.png",
		"http://ylin.wang/2017/06/23/esap17/")
	art3 := wechat.NewArticle("大道至简的哲学",
		"来自村长的工作日志",
		"http://ylin.wang/img/golang.jpg",
		"http://ylin.wang/2017/01/29/log7/")
	// 打包成新闻
	ctx.NewNews(art1, art2, art3)
模板消息

相关issue

	tlpdata := map[string]struct {
		Value `json:"value"`
		Color `json:"color"`
	}{
		"first": {Value: "我是渣渣涛", Color: "#173177"},
		"keyword1": {Value: "这是一个你从没有玩过的全新游戏", Color: "#173177"},
		"keyword2": {Value: "只要你跟着我一起试玩一下", Color: "#173177"},
		"keyword3": {Value: "你就会爱上这款游戏", Color: "#4B1515"},
		"remark":   {Value: "是兄弟就来砍我", Color: "#071D42"},
	}
	ctx.SendTemplate(
		ctx.Msg.FromUserName,
		"tempid", // 模板ID
		c.Request.Host, // 跳转url
		ctx.AppId, // 跳转小程序,比url优先
		"", // 小程序页面
		tlpdata,
	)

License

MIT

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

Examples

Constants

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

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

View Source
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=`
)
View Source
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"
)
View Source
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 微信菜单接口,兼容企业微信和服务号

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

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

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

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://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 订阅号,服务号,小程序接口,相关接口常量统一以此开头

View Source
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 企业微信接口,相关接口常量统一以此开头

View Source
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类型汇总

View Source
const (
	ParamsQrcode = "qrcode/create?access_token=%s" // 二维码
)

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 GetGender

func GetGender(s string) string

GetGender 获取性别

func GetOauth2Url

func GetOauth2Url(corpId, host string) string

GetOauth2Url 获取鉴权页面

func Printf

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

Printf Debug输出

func Println

func Println(v ...interface{})

Println Debug输出

func SetLog

func SetLog(l io.Writer)

SetLog 设置log

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
	Resp      interface{}
	Writer    http.ResponseWriter
	Request   *http.Request
	// contains filtered or unexported fields
}

Context 消息上下文

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

func (c *Context) Send() *Context

Send 主动发送消息(客服)

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

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 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 加密新闻消息,仅企业微信支持

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

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 QrcodeParamsResp struct {
	Ticket        string `json:"ticket"`
	ExpireSeconds int    `json:"expireSeconds"`
	Url           string `json:"url"`
}

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 New

func New(wc *WxConfig) *Server

New 微信服务容器

func Set

func Set(wc *WxConfig) *Server

func (*Server) AddMenu

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

AddMenu 创建应用菜单

func (*Server) AddMsg

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

AddMsg 添加队列消息

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

func (s *Server) CreateQrcodeParams(v QrcodeParamsReq) (m QrcodeParamsResp, err error)

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)

GetMpUserInfo 获取用户详情

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" // 仅企业微信可用

func (*Server) NewFile

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

NewFile File消息

func (*Server) NewImage

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

NewImage Image 消息

func (*Server) NewMarkDown

func (s *Server) NewMarkDown(to, content string) (md MarkDown)

NewMarkDown markdown消息,企业微信可用

func (*Server) NewMpNews

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

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

func (*Server) NewMpNewsId

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

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

func (*Server) NewMusic

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

NewMusic Music消息

func (*Server) NewNews

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

NewNews news消息

func (*Server) NewTaskCard

func (s *Server) NewTaskCard(to, Title, Desc, Url, TaskId, Btn string) (tc TaskCard)

NewTaskCard 任务卡片消息,企业微信可用

func (*Server) NewText

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

NewText Text 文本消息

func (*Server) NewTextcard

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

NewTextcard Textcard消息

func (*Server) NewVideo

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

NewVideo Video消息

func (*Server) NewVoice

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

NewVoice Voice消息

func (*Server) NewWxCard

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

NewWxCard 卡券消息,服务号可用

func (*Server) PayOrderScan

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

PayOrderScan 扫码付

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, mediaId string) *WxErr

SendFile 发送客服File消息

func (*Server) SendImage

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

SendImage 发送客服Image消息

func (*Server) SendMarkDown

func (s *Server) SendMarkDown(to string, content string) *WxErr

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

func (*Server) SendMpNews

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

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

func (*Server) SendMpNewsId

func (s *Server) SendMpNewsId(to string, 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, mediaId, title, desc, musicUrl, qhMusicUrl string) *WxErr

SendMusic 发送客服Music消息

func (*Server) SendNews

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

SendNews 发送客服news消息

func (*Server) SendTaskCard

func (s *Server) SendTaskCard(to string, Title, Desc, Url, TaskId, Btn string) *WxErr

SendTaskCard 发送任务卡片taskcard消息

func (*Server) SendTemplate

func (s *Server) SendTemplate(to, id, url, appid, pagepath string, data interface{}) *WxErr

SendTemplate 发送模板消息,data通常是map[string]struct{value string,color string}

func (*Server) SendText

func (s *Server) SendText(to, msg string) (e *WxErr)

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

func (*Server) SendTextcard

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

SendTextcard 发送客服extcard消息

func (*Server) SendVideo

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

SendVideo 发送客服Video消息

func (*Server) SendVoice

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

SendVoice 发送客服Voice消息

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 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 Text

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

Text 文本消息

type Textcard

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

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 用户鉴权信息

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 WxErr

type WxErr struct {
	ErrCode int
	ErrMsg  string
}

WxErr 通用错误

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
	TaskId       string

	ScanCodeInfo struct {
		ScanType   string
		ScanResult string
	}
}

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"`
}

WxSession 兼容企业微信和服务号

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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