weixin

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2015 License: MIT Imports: 24 Imported by: 0

README

weixin

Golang 实现的微信公众号接口

测试公众号

扫码关注如下公众号

测试号二维码

Documentation

Index

Constants

View Source
const (
	CustomAddURL    = "https://api.weixin.qq.com/customservice/kfaccount/add?access_token=%s"
	CustomUpdateURL = "https://api.weixin.qq.com/customservice/kfaccount/update?access_token=%s"
	CustomDeleteURL = "https://api.weixin.qq.com/customservice/kfaccount/del?access_token=%s"
	// 设置客服帐号的头像
	CustomHeadingURL = "http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=%s&kf_account=%s"
	CustomListURL    = "https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token=%s"
	CustomMsgURL     = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=%s"
)

客服消息接口

View Source
const (
	WeixinErrCodeSystemBusy = -1
	WeixinErrCodeSuccess    = 0
)

微信错误消息

View Source
const (
	MaterialUploadTemporaryURL = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s"
	MaterialGetTemporaryURL    = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s"
	MaterialAddNewsURL         = "https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=%s"
	MaterialUploadImg          = "https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=%s"
	MaterialUploadNewsURL      = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=%s&type=%s"
	MaterialGetNewsURL         = "https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=%s"
	MaterialDeleteNewsURL      = "https://api.weixin.qq.com/cgi-bin/material/del_material?access_token=%s"
	MaterialUpdateNewsURL      = "https://api.weixin.qq.com/cgi-bin/material/update_news?access_token=%s"
	MaterialCountURL           = "https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=%s"
	MaterialBatchGetNewsURL    = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=%s"
)

素材管理

View Source
const (
	MenuCreateURL = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s"
	MenuGetURL    = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=%s"
	MenuDeleteURL = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=%s"
	MenuInfoURL   = "https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token=%s"
)

自定义菜单

View Source
const (
	MenuTypeClick           = "click"              // 点击推事件
	MenuTypeView            = "view"               // 点击推事件
	MenuTypeScancodePush    = "scancode_push"      // 扫码推事件
	MenuTypeScancodeWaitmsg = "scancode_waitmsg"   // 扫码推事件且弹出“消息接收中”提示框
	MenuTypePicSysphoto     = "pic_sysphoto"       // 弹出系统拍照发图
	MenuTypePicPhotoOrAlbum = "pic_photo_or_album" // 弹出拍照或者相册发图
	MenuTypePicWeixin       = "pic_weixin"         // 弹出微信相册发图器
	MenuTypeLocationSelect  = "location_select"    // 弹出地理位置选择器
	MenuTypeMediaId         = "media_id"           // 下发消息(除文本消息)
	MenuTypeViewLimited     = "view_limited"       // 跳转图文消息URL

)

各种菜单类型

View Source
const (
	MenuCreateConditionalURL       = "https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=%s"
	MenuTryMatchConditionalMenuURL = "https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token=%s"
	MenuDeleteConditionalURL       = "https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=%s"
)

个性化菜单

View Source
const (
	AccountCreateQRCodeURL     = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s"
	AccountGetQRCodeImgAddrURL = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s"
)

二维码

View Source
const (
	TamplateSetIndustryURL     = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=%s"
	TemplateAddTemplateURL     = "https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=%s"
	TemplateSendTemplateMsgURL = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s"
)

模板消息接口

View Source
const (
	UserGroupCreateURL                 = "https://api.weixin.qq.com/cgi-bin/groups/create?access_token=%s"
	UserGroupUpdateURL                 = "https://api.weixin.qq.com/cgi-bin/groups/update?access_token=%s"
	UserGroupDeleteURL                 = "https://api.weixin.qq.com/cgi-bin/groups/delete?access_token=%s"
	UserGroupGetAllURL                 = "https://api.weixin.qq.com/cgi-bin/groups/get?access_token=%s"
	UserGroupGetGroupIdURL             = "https://api.weixin.qq.com/cgi-bin/groups/getid?access_token=%s"
	UserGroupUpdateMemberGroupURL      = "https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=%s"
	UserGroupBatchUpdateMemberGroupURL = "https://api.weixin.qq.com/cgi-bin/groups/members/batchupdate?access_token=%s"
)

用户分组管理

View Source
const (
	UserInfoUpdateRemarkURL     = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=%s"
	UserInfoGetUserInfoURL      = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s&lang=%s"
	UserInfoBatchGetUserInfoURL = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=%s"
	UserInfoGetUserListURL      = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=%s&next_openid=%s"
)

用户基本信息

View Source
const (
	LangZHCN = "zh_CN" // 简体
	LangZHTW = "zh_TW" // 繁体
	LangEN   = "en"    // 英语
)

微信支持的语言

View Source
const (
	UserWebRedirectURL       = "" /* 129-byte string literal not displayed */
	UserWebWebTokenURL       = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code"
	UserWebRefreshTokenURL   = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s"
	UserWebGetWebUserInfoURL = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=%s"
	UserWebCheckWebTokenURL  = "https://api.weixin.qq.com/sns/auth?access_token=%s&openid=%s"
)

网页授权获取用户基本信息

View Source
const (
	// 不弹出授权页面,直接跳转,只能获取用户openid
	ScopeSNSAPIBase = "snsapi_base"
	// 弹出授权页面,可通过openid拿到昵称、性别、所在地。并且,即使在未关注的情况下,只要用户授权,也能获取其信息
	ScopeSNSAPIUserInfo = "snsapi_userinfo"
)

应用授权作用域

View Source
const (
	ShortURLLongURL2ShortURL = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=%s"
)

链接转换

Variables

View Source
var (
	RecvTextHandler       func(*RecvText) ReplyMsg
	RecvImageHandler      func(*RecvImage) ReplyMsg
	RecvVoiceHandler      func(*RecvVoice) ReplyMsg
	RecvVideoHandler      func(*RecvVideo) ReplyMsg
	RecvShortVideoHandler func(*RecvVideo) ReplyMsg
	RecvLocationHandler   func(*RecvLocation) ReplyMsg
	RecvLinkHandler       func(*RecvLink) ReplyMsg
)

各类消息处理器

View Source
var (
	EventSubscribeHandler             func(*EventSubscribe) ReplyMsg
	EventUnsubscribeHandler           func(*EventSubscribe) ReplyMsg
	EventLocationHandler              func(*EventLocation) ReplyMsg
	EventClickHandler                 func(*EventClick) ReplyMsg
	EventViewHandler                  func(*EventView) ReplyMsg
	EventTemplateSendJobFinishHandler func(*EventTemplateSendJobFinish) ReplyMsg

	EventScancodePushHandler    func(*EventScancodePush) ReplyMsg
	EventScancodeWaitmsgHandler func(*EventScancodeWaitmsg) ReplyMsg
	EventPicSysphotoHandler     func(*EventPicSysphoto) ReplyMsg
	EventPicPhotoOrAlbumHandler func(*EventPicPhotoOrAlbum) ReplyMsg
	EventPicWeixinHandler       func(*EventPicWeixin) ReplyMsg
	EventLocationSelectHandler  func(*EventLocationSelect) ReplyMsg

	EventQualificationVerifySuccessHandler func(*EventQualificationVerifySuccess) ReplyMsg // 资质认证成功
	EventQualificationVerifyFailHandler    func(*EventQualificationVerifyFail) ReplyMsg    // 资质认证失败
	EventNamingVerifySuccessHandler        func(*EventNamingVerifySuccess) ReplyMsg        // 名称认证成功(即命名成功)
	EventNamingVerifyFailHandler           func(*EventNamingVerifyFail) ReplyMsg           // 名称认证失败
	EventAnnualRenewHandler                func(*EventAnnualRenew) ReplyMsg                // 年审通知
	EventVerifyExpiredHandler              func(*EventVerifyExpired) ReplyMsg              // 认证过期失效通知
)

各类事件处理器

View Source
var (
	OriginId       string // 原始ID
	AppId          string // 应用ID
	AppSecret      string // 应用密钥
	Token          string // 令牌
	EncodingAESKey []byte // 消息加解密密钥
)

TConfig 配置

View Source
var AccessToken func() string

AccessToken 取最新的 access_token,必须使用这个接口取,内部已经加锁

View Source
var EventDefaultHandler = func(msg *Message) (reply ReplyMsg) {
	log.Debugf("unregistered receive event handler %s, use EventDefaultHandler", msg.Event)
	return nil
}

EventDefaultHandler 如果没有注册某类事件处理器,那么收到这类事件时,使用这个默认处理器

View Source
var RecvDefaultHandler = func(msg *Message) (reply ReplyMsg) {
	log.Debugf("unregistered receive message handler %s, use RecvDefaultHandler", msg.MsgType)
	return nil
}

RecvDefaultHandler 如果没有注册某类消息处理器,那么收到这类消息时,使用这个默认处理器

Functions

func AESCBCDecrypt

func AESCBCDecrypt(enc, key, iv []byte) (src []byte, err error)

AESCBCDecrypt 采用 CBC 模式的 AES 解密

func AESCBCEncrypt

func AESCBCEncrypt(src, key, iv []byte) (enc []byte, err error)

AESCBCEncrypt 采用 CBC 模式的 AES 加密

func AddCustom

func AddCustom(account, nickname, password string) (err error)

AddCustom 添加客服帐号

func AddCustomStruct

func AddCustomStruct(cust *Custom) (err error)

AddCustomStruct 添加客服帐号

func AddNews

func AddNews(as []Article) (mediaId string, err error)

AddNews 新增永久图文素材

func AddTemplate

func AddTemplate(shortId string) (templateId string, err error)

AddTemplate 添加模板,获得模板ID

func BatchUpdateMemberGroup

func BatchUpdateMemberGroup(openIds []string, toGroupId int) (err error)

BatchUpdateMemberGroup 批量移动用户分组

func CheckSignature

func CheckSignature(token, timestamp, nonce, encrypt, sign string) bool

CheckSignature 验证加密的报文的签名

func CheckWebToken

func CheckWebToken(webToken, openId string) (err error)

CheckWebToken 检验网页授权凭证(access_token)是否有效

func CreateConditionalMenu

func CreateConditionalMenu(cm *ConditionalMenu) (menuId string, err error)

CreateConditionalMenu 创建个性化菜单

func CreateMenu

func CreateMenu(buttons []Button) (err error)

CreateMenu 创建菜单

func DecryptMsg

func DecryptMsg(b64Enc string, aesKey []byte, appId string) (msg []byte, err error)

DecryptMsg 解密报文

func DeleteConditionalMenu

func DeleteConditionalMenu(menuId int) (err error)

DeleteConditionalMenu 删除个性化菜单,menuId 为菜单 id,可以通过自定义菜单查询接口获取

func DeleteCustom

func DeleteCustom(account, nickname, password string) (err error)

DeleteCustom 删除客服帐号

func DeleteCustomStruct

func DeleteCustomStruct(cust *Custom) (err error)

DeleteCustomStruct 删除客服帐号

func DeleteMenu

func DeleteMenu() (err error)

DeleteMenu 删除菜单

func DeleteNews

func DeleteNews(mediaId string) (err error)

DeleteNews 删除永久素材

func DeleteUserGroup

func DeleteUserGroup(groupId int) (err error)

DeleteUserGroup 修改用户分组名

func EncryptMsg

func EncryptMsg(msg []byte, aesKey []byte, appId string) (b64Enc string, err error)

EncryptMsg 加密报文

func GenRedirectURL

func GenRedirectURL(redirectURL string, scope ScopeSNSAPI, state ...string) string

GenRedirectURL 生成跳转链接 state 非必填,默认当前时间 重定向后会带上state参数,开发者可以填写a-zA-Z0-9的参数值,最多128字节

func GetGroupIdByOpenId

func GetGroupIdByOpenId(openId string) (groupId int, err error)

GetGroupIdByOpenId 查询用户所在分组

func GetQRCodeImg

func GetQRCodeImg(ticket string) string

GetQRCodeImg 通过ticket换取二维码

func GetTemporaryMaterial

func GetTemporaryMaterial(mediaId string) (filename string, body []byte, err error)

GetTemporaryMaterial 新增临时素材

func GetUnmarshal

func GetUnmarshal(url string, ret interface{}) (err error)

GetUnmarshal 工具类, Get 并解析返回的报文,返回 error

func GetUserList

func GetUserList(fromOpenId ...string) (openIds []string, total, count int, nextOpenId string, err error)

GetUserList 获取用户列表。第一个拉取的OPENID,nextOpenId 不填默认从头开始拉取

func HandleAccess

func HandleAccess(w http.ResponseWriter, r *http.Request)

HandleAccess 接入微信公众平台开发,并接口来自微信服务器的消息

func Initialize

func Initialize(originId, appId, appSecret, token, encodingAESKey string)

Initialize 配置并初始化

func LongURL2Short

func LongURL2Short(longURL string) (shortURL string, err error)

LongURL2Short 长链接转短链接接口

func PKCS7Padding

func PKCS7Padding(src []byte, k int) (padded []byte)

PKCS7Padding PKCS#7填充,Buf需要被填充为K的整数倍, 在buf的尾部填充(K-N%K)个字节,每个字节的内容是(K- N%K)

func PKCS7UnPadding

func PKCS7UnPadding(src []byte) (padded []byte)

PKCS7UnPadding 去掉PKCS#7填充,Buf需要被填充为K的整数倍, 在buf的尾部填充(K-N%K)个字节,每个字节的内容是(K- N%K)

func ParseFullMsg

func ParseFullMsg(fullMsg []byte) (randBytes []byte, msgLen int, msg []byte, appId string)

ParseFullMsg 从完整报文中解析出消息内容, AES加密的buf由16个字节的随机字符串、4个字节的msg_len(网络字节序)、msg和$AppId组成, 其中msg_len为msg的长度,$AppId为公众帐号的AppId

func Post

func Post(url string, js []byte) (err error)

Post 工具类, POST json 并返回 error

func PostMarshal

func PostMarshal(url string, v interface{}) (err error)

PostMarshal 工具类, POST 编组并返回 error

func PostMarshalUnmarshal

func PostMarshalUnmarshal(url string, v interface{}, ret interface{}) (err error)

PostMarshalUnmarshal 工具类, POST 编组并解析返回的报文,返回 error

func PostUnmarshal

func PostUnmarshal(url string, js []byte, ret interface{}) (err error)

PostUnmarshal 工具类, POST json 并解析返回的报文,返回 error

func RandBytes

func RandBytes(size int) (r []byte)

RandBytes 产生 size 个长度的随机字节

func RefreshAccessToken

func RefreshAccessToken(appId, appSecret string)

RefreshAccessToken 定时刷新 access_token

func SendCustomMsg

func SendCustomMsg(openId string, msg CustMsg) (err error)

SendCustomMsg 客服接口-发消息

func SendTemplateMsg

func SendTemplateMsg(m *TemplateMsg) (msgId int, err error)

SendTemplateMsg 发送模板消息,返回消息 Id

func SetIndustry

func SetIndustry(primary, secondary int) error

SetIndustry 设置所属行业

行业代码查询

主行业 副行业 代码 IT科技 互联网/电子商务 1 IT科技 IT软件与服务 2 IT科技 IT硬件与设备 3 IT科技 电子技术 4 IT科技 通信与运营商 5 IT科技 网络游戏 6 金融业 银行 7 金融业 基金|理财|信托 8 金融业 保险 9 餐饮 餐饮 10 酒店旅游 酒店 11 酒店旅游 旅游 12 运输与仓储 快递 13 运输与仓储 物流 14 运输与仓储 仓储 15 教育 培训 16 教育 院校 17 政府与公共事业 学术科研 18 政府与公共事业 交警 19 政府与公共事业 博物馆 20 政府与公共事业 公共事业|非盈利机构 21 医药护理 医药医疗 22 医药护理 护理美容 23 医药护理 保健与卫生 24 交通工具 汽车相关 25 交通工具 摩托车相关 26 交通工具 火车相关 27 交通工具 飞机相关 28 房地产 建筑 29 房地产 物业 30 消费品 消费品 31 商业服务 法律 32 商业服务 会展 33 商业服务 中介服务 34 商业服务 认证 35 商业服务 审计 36 文体娱乐 传媒 37 文体娱乐 体育 38 文体娱乐 娱乐休闲 39 印刷 印刷 40 其它 其它 41

func Signature

func Signature(token, timestamp, nonce, encrypt string) string

Signature 对加密的报文计算签名

func SpliceFullMsg

func SpliceFullMsg(msg []byte, appId string) (fullMsg []byte)

SpliceFullMsg 拼接完整报文, AES加密的buf由16个字节的随机字符串、4个字节的msg_len(网络字节序)、msg和$AppId组成, 其中msg_len为msg的长度,$AppId为公众帐号的AppId

func UpdateCustom

func UpdateCustom(account, nickname, password string) (err error)

UpdateCustom 修改客服帐号

func UpdateCustomStruct

func UpdateCustomStruct(cust *Custom) (err error)

UpdateCustomStruct 修改客服帐号

func UpdateMemberGroup

func UpdateMemberGroup(openId string, toGroupId int) (err error)

UpdateMemberGroup 移动用户分组

func UpdateNews

func UpdateNews(news *UpdateNewsReq) (err error)

UpdateNews 修改永久图文素材

func UpdateUserRemark

func UpdateUserRemark(openId, remark string) (err error)

UpdateUserRemark 设置用户备注名

func Upload

func Upload(url, fieldName string, file *os.File, ret interface{}, desc ...string) (err error)

Upload 工具类, 上传文件

func UploadHeading

func UploadHeading(account string, file *os.File) (err error)

UploadHeading 设置客服帐号的头像

func UploadImg

func UploadImg(file *os.File) (u string, err error)

UploadImg 上传图文消息内的图片获取URL

func UploadNews

func UploadNews(mtype MediaType, file *os.File) (mediaId, u string, err error)

UploadNews 新增其他类型永久素材

func UploadTemporaryMaterial

func UploadTemporaryMaterial(mtype MediaType, file *os.File) (mediaId string, createAt int, err error)

UploadTemporaryMaterial 新增临时素材

func UploadVideo

func UploadVideo(mtype MediaType, title, desc string, file *os.File) (mediaId, u string, err error)

UploadVideo 新增视频类型永久素材

func ValidateURL

func ValidateURL(token, timestamp, nonce, signature string) bool

ValidateURL 验证 URL 以判断来源是否合法

Types

type Account

type Account struct {
	Account    string `json:"kf_account"`
	NickName   string `json:"kf_nick"`
	AccountId  string `json:"kf_id"`
	HeadImgURL string `json:"kf_headimgurl"`
}

Account 客服账号

func GetCustomList

func GetCustomList() (accs []Account, err error)

GetCustomList 获取所有客服账号

type AllMenu

type AllMenu struct {
	WeixinError
	Menu struct {
		Button []Button `json:"button"`
		MenuId int      `json:"menuid"` // 菜单 id
	} `json:"menu"`
	ConditionalMenu struct {
		Button    []Button  `json:"button"`
		MenuId    int       `json:"menuid"`    // 菜单 id
		MatchRule MatchRule `json:"matchrule"` // 菜单匹配规则
	} `json:"conditionalmenu"`
}

AllMenu 自定义菜单

func GetMenu

func GetMenu() (all *AllMenu, err error)

GetMenu 查询菜单

type Article

type Article struct {
	Title            string `json:"title"`              // 标题
	ThumbMediaId     string `json:"thumb_media_id"`     // 图文消息的封面图片素材id(必须是永久mediaID)
	Author           string `json:"author"`             // 作者
	Digest           string `json:"digest"`             // 图文消息的摘要,仅有单图文消息才有摘要,多图文此处为空
	ShowCoverPic     int    `json:"show_cover_pic"`     // 是否显示封面,0为false,即不显示,1为true,即显示
	Content          string `json:"content"`            // 图文消息的具体内容,支持HTML标签,必须少于2万字符,小于1M,且此处会去除JS
	URL              string `json:"url"`                // 图文页的URL
	ContentSourceURL string `json:"content_source_url"` // 图文消息的原文地址,即点击“阅读原文”后的URL
}

Article 永久图文素材

type Button

type Button struct {
	Name      string   `json:"name"`
	Type      MenuType `json:"type,omitempty"`
	Key       string   `json:"key,omitempty"`
	URL       string   `json:"url,omitempty"`
	SubButton []Button `json:"sub_button,omitempty"`
}

Button 菜单上的按钮

func TryMatchConditionalMenu

func TryMatchConditionalMenu(userId string) (buttons []Button, err error)

TryMatchConditionalMenu 测试个性化菜单匹配结果,userId 可以是粉丝的 OpenID,也可以是粉丝的微信号

type ConditionalMenu

type ConditionalMenu struct {
	Button    []Button  `json:"button"`    // 一级菜单数组,个数应为1~3个
	MatchRule MatchRule `json:"matchrule"` // 菜单匹配规则
}

ConditionalMenu 个性化菜单

type CustImage

type CustImage struct {
	MediaId string `json:"media_id"` //	发送的图片/语音/视频的媒体ID
}

CustImage 客服接口发送图片消息

type CustMsg

type CustMsg interface{}

CustMsg 客服消息接口

type CustMusic

type CustMusic struct {
	Title        string `json:"title"`          //	图文消息/视频消息/音乐消息的标题
	Description  string `json:"description"`    //	图文消息/视频消息/音乐消息的描述
	MusicURL     string `json:"musicurl"`       //	音乐链接
	HQMusicURL   string `json:"hqmusicurl"`     //	高品质音乐链接,wifi环境优先使用该链接播放音乐
	ThumbMediaId string `json:"thumb_media_id"` //	缩略图的媒体ID
}

CustMusic 客服接口发送音乐消息

type CustNewsArticle

type CustNewsArticle struct {
	Title       string `json:"title"`       //	图文消息/视频消息/音乐消息的标题
	Description string `json:"description"` //	图文消息/视频消息/音乐消息的描述
	URL         string `json:"url"`         //	图文消息被点击后跳转的链接
	PicURL      string `json:"picurl"`      //	图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80
}

CustNewsArticle 客服接口发送图文消息。图文消息条数限制在10条以内,注意,如果图文数超过10,则将会无响应

type CustText

type CustText struct {
	Content string `json:"content"` //	文本消息内容
}

CustText 客服接口发送文本消息

type CustVideo

type CustVideo struct {
	MediaId      string `json:"media_id"`       //	发送的图片/语音/视频的媒体ID
	ThumbMediaId string `json:"thumb_media_id"` //	缩略图的媒体ID
	Title        string `json:"title"`          //	图文消息/视频消息/音乐消息的标题
	Description  string `json:"description"`    //	图文消息/视频消息/音乐消息的描述
}

CustVideo 客服接口发送视频消息

type CustVoice

type CustVoice struct {
	MediaId string `json:"media_id"` //	发送的图片/语音/视频的媒体ID
}

CustVoice 客服接口发送语音消息

type CustWXCard

type CustWXCard struct {
	CardId  string `json:"card_id"`
	CardExt string `json:"card_ext"`
}

CustWXCard 客服接口发送卡券

type Custom

type Custom struct {
	Account  string `json:"kf_account"`
	NickName string `json:"nickname"`
	Password string `json:"password"`
}

Custom 客服帐号

type CustomList

type CustomList struct {
	WeixinError
	List []Account `json:"kf_list"`
}

CustomList 客服列表

type EncMessage

type EncMessage struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   `xml:"-"` // 开发者微信号
	Encrypt      string   // 加密的消息报文
	MsgSignature string   // 报文签名
	TimeStamp    string   // 时间戳
	Nonce        string   // 随机数
}

EncMessage 加密消息体

type EventAnnualRenew

type EventAnnualRenew struct {
	EventBase       // 事件类型 annual_renew
	ExpiredTime int // 有效期 (整形),指的是时间戳,将于该时间戳认证过期,需尽快年审
}

EventAnnualRenew 年审通知

func NewEventAnnualRenew

func NewEventAnnualRenew(m *Message) *EventAnnualRenew

NewEventAnnualRenew 把通用 struct 转化成相应类型的 struct

type EventBase

type EventBase struct {
	RecvMsg
	ToUserName   string    // 开发者微信号
	FromUserName string    // 发送方帐号(一个OpenID)
	CreateTime   string    // 消息创建时间(整型)
	MsgType      MsgType   // 消息类型,event
	Event        EventType // 事件类型
}

EventBase 事件基础类

type EventClick

type EventClick struct {
	EventBase        // 事件类型 CLICK
	EventKey  string // 事件KEY值,与自定义菜单接口中KEY值对应
}

EventClick 点击菜单拉取消息时的事件推送

func NewEventClick

func NewEventClick(m *Message) *EventClick

NewEventClick 把通用 struct 转化成相应类型的 struct

type EventLocation

type EventLocation struct {
	EventBase         // 事件类型 LOCATION
	Latitude  float64 // 地理位置纬度
	Longitude float64 // 地理位置经度
	Precision float64 // 地理位置精度
}

EventLocation 上报地理位置事件

func NewEventLocation

func NewEventLocation(m *Message) *EventLocation

NewEventLocation 把通用 struct 转化成相应类型的 struct

type EventLocationSelect

type EventLocationSelect struct {
	EventBase         // 事件类型 pic_sysphoto
	EventKey  string  // 事件KEY值,由开发者在创建菜单时设定
	LocationX float64 // 地理位置维度
	LocationY float64 // 地理位置经度
	Scale     int     // 精度,可理解为精度或者比例尺、越精细的话 scale越高
	Label     string  // 地理位置的字符串信息
	Poiname   string  // 朋友圈POI的名字,可能为空
}

EventLocationSelect 弹出地理位置选择器的事件推送

func NewEventLocationSelect

func NewEventLocationSelect(m *Message) *EventLocationSelect

NewEventLocationSelect 把通用 struct 转化成相应类型的 struct

type EventNamingVerifyFail

type EventNamingVerifyFail struct {
	EventBase         // 事件类型 naming_verify_fail
	FailTime   int    // 失败发生时间 (整形),时间戳
	FailReason string // 认证失败的原因
}

EventNamingVerifyFail 名称认证失败(这时虽然客户端不打勾,但仍有接口权限)

func NewEventNamingVerifyFail

func NewEventNamingVerifyFail(m *Message) *EventNamingVerifyFail

NewEventNamingVerifyFail 把通用 struct 转化成相应类型的 struct

type EventNamingVerifySuccess

type EventNamingVerifySuccess struct {
	EventBase       // 事件类型 naming_verify_success
	ExpiredTime int // 有效期 (整形),指的是时间戳,将于该时间戳认证过期
}

EventNamingVerifySuccess 名称认证成功(即命名成功)

func NewEventNamingVerifySuccess

func NewEventNamingVerifySuccess(m *Message) *EventNamingVerifySuccess

NewEventNamingVerifySuccess 把通用 struct 转化成相应类型的 struct

type EventPicPhotoOrAlbum

type EventPicPhotoOrAlbum struct {
	EventBase           // 事件类型 pic_sysphoto
	EventKey   string   // 事件KEY值,由开发者在创建菜单时设定
	Count      int      // 发送的图片数量
	PicMd5Sums []string // 图片的MD5值,开发者若需要,可用于验证接收到图片
}

EventPicPhotoOrAlbum 弹出拍照或者相册发图的事件推送

func NewEventPicPhotoOrAlbum

func NewEventPicPhotoOrAlbum(m *Message) *EventPicPhotoOrAlbum

NewEventPicPhotoOrAlbum 把通用 struct 转化成相应类型的 struct

type EventPicSysphoto

type EventPicSysphoto struct {
	EventBase           // 事件类型 pic_sysphoto
	EventKey   string   // 事件KEY值,由开发者在创建菜单时设定
	Count      int      // 发送的图片数量
	PicMd5Sums []string // 图片的MD5值,开发者若需要,可用于验证接收到图片
}

EventPicSysphoto 弹出系统拍照发图的事件推送

func NewEventPicSysphoto

func NewEventPicSysphoto(m *Message) *EventPicSysphoto

NewEventPicSysphoto 把通用 struct 转化成相应类型的 struct

type EventPicWeixin

type EventPicWeixin struct {
	EventBase           // 事件类型 pic_weixin
	EventKey   string   // 事件KEY值,由开发者在创建菜单时设定
	Count      int      // 发送的图片数量
	PicMd5Sums []string // 图片的MD5值,开发者若需要,可用于验证接收到图片
}

EventPicWeixin 弹出微信相册发图器的事件推送

func NewEventPicWeixin

func NewEventPicWeixin(m *Message) *EventPicWeixin

NewEventPicWeixin 把通用 struct 转化成相应类型的 struct

type EventQualificationVerifyFail

type EventQualificationVerifyFail struct {
	EventBase         // 事件类型 qualification_verify_fail
	FailTime   int    // 失败发生时间 (整形),时间戳
	FailReason string // 认证失败的原因
}

EventQualificationVerifyFail 资质认证失败

func NewEventQualificationVerifyFail

func NewEventQualificationVerifyFail(m *Message) *EventQualificationVerifyFail

NewEventQualificationVerifyFail 把通用 struct 转化成相应类型的 struct

type EventQualificationVerifySuccess

type EventQualificationVerifySuccess struct {
	EventBase       // 事件类型 qualification_verify_success
	ExpiredTime int // 有效期 (整形),指的是时间戳,将于该时间戳认证过期
}

EventQualificationVerifySuccess 资质认证成功(此时立即获得接口权限)

func NewEventQualificationVerifySuccess

func NewEventQualificationVerifySuccess(m *Message) *EventQualificationVerifySuccess

NewEventQualificationVerifySuccess 把通用 struct 转化成相应类型的 struct

type EventScancodePush

type EventScancodePush struct {
	EventBase         // 事件类型 scancode_push
	EventKey   string // 事件KEY值,由开发者在创建菜单时设定
	ScanType   string // 扫描类型,一般是qrcode
	ScanResult string // 扫描结果,即二维码对应的字符串信息
}

EventScancodePush 扫码推事件的事件推送

func NewEventScancodePush

func NewEventScancodePush(m *Message) *EventScancodePush

NewEventScancodePush 把通用 struct 转化成相应类型的 struct

type EventScancodeWaitmsg

type EventScancodeWaitmsg struct {
	EventBase         // 事件类型 scancode_waitmsg
	EventKey   string // 事件KEY值,由开发者在创建菜单时设定
	ScanType   string // 扫描类型,一般是qrcode
	ScanResult string // 扫描结果,即二维码对应的字符串信息
}

EventScancodeWaitmsg 扫码推事件且弹出“消息接收中”提示框的事件推送

func NewEventScancodeWaitmsg

func NewEventScancodeWaitmsg(m *Message) *EventScancodeWaitmsg

NewEventScancodeWaitmsg 把通用 struct 转化成相应类型的 struct

type EventSubscribe

type EventSubscribe struct {
	EventBase
	// 事件类型 subscribe(订阅)、unsubscribe(取消订阅)
	// 用户扫描带场景值二维码时,可能推送以下两种事件:
	// 1. 如果用户还未关注公众号,则用户可以关注公众号,关注后微信会将带场景值关注事件推送给开发者。
	//    EventKey	事件KEY值,qrscene_为前缀,后面为二维码的参数值
	// 2. 如果用户已经关注公众号,则微信会将带场景值扫描事件推送给开发者。
	//    EventKey	事件KEY值,是一个32位无符号整数,即创建二维码时的二维码scene_id
	EventKey string
	Ticket   string // 二维码的ticket,可用来换取二维码图片

}

EventSubscribe 关注/取消关注事件

func NewEventSubscribe

func NewEventSubscribe(m *Message) *EventSubscribe

NewEventSubscribe 把通用 struct 转化成相应类型的 struct

type EventTemplateSendJobFinish

type EventTemplateSendJobFinish struct {
	EventBase        // 事件类型 VIEW
	MsgID     int    // 消息id
	Status    string // 发送状态为成功
}

EventTemplateSendJobFinish 模版消息发送结果通知事件

func NewEventTemplateSendJobFinish

func NewEventTemplateSendJobFinish(m *Message) *EventTemplateSendJobFinish

NewEventTemplateSendJobFinish 把通用 struct 转化成相应类型的 struct

type EventType

type EventType string

EventType 事件类型

const (
	EventTypeSubscribe             EventType = "subscribe"
	EventTypeUnsubscribe           EventType = "unsubscribe"
	EventTypeLocation              EventType = "LOCATION"
	EventTypeClick                 EventType = "CLICK"
	EventTypeView                  EventType = "VIEW"
	EventTypeTemplateSendJobFinish EventType = "TEMPLATESENDJOBFINISH" // 模版消息发送结果通知事件
)

微信支持的事件类型

const (
	EventTypeQualificationVerifySuccess EventType = "qualification_verify_success" // 资质认证成功
	EventTypeQualificationVerifyFail    EventType = "qualification_verify_fail"    // 资质认证失败
	EventTypeNamingVerifySuccess        EventType = "naming_verify_success"        // 名称认证成功(即命名成功)
	EventTypeNamingVerifyFail           EventType = "naming_verify_fail"           // 名称认证失败
	EventTypeAnnualRenew                EventType = "annual_renew"                 // 年审通知
	EventTypeVerifyExpired              EventType = "verify_expired"               // 认证过期失效通知
)

微信支持的事件类型

const (
	EventTypeScancodePush    EventType = "scancode_push"      // 扫码推事件的事件推送
	EventTypeScancodeWaitmsg EventType = "scancode_waitmsg"   // 扫码推事件且弹出“消息接收中”提示框的事件推送
	EventTypePicSysphoto     EventType = "pic_sysphoto"       // 弹出系统拍照发图的事件推送
	EventTypePicPhotoOrAlbum EventType = "pic_photo_or_album" // 弹出拍照或者相册发图的事件推送
	EventTypePicWeixin       EventType = "pic_weixin"         // 弹出微信相册发图器的事件推送
	EventTypeLocationSelect  EventType = "location_select"    // 弹出地理位置选择器的事件推送
)

微信支持的事件类型

type EventVerifyExpired

type EventVerifyExpired struct {
	EventBase       // 事件类型 verify_expired
	ExpiredTime int // 有效期 (整形),指的是时间戳,表示已于该时间戳认证过期,需要重新发起微信认证
}

EventVerifyExpired 认证过期失效通知

func NewEventVerifyExpired

func NewEventVerifyExpired(m *Message) *EventVerifyExpired

NewEventVerifyExpired 把通用 struct 转化成相应类型的 struct

type EventView

type EventView struct {
	EventBase        // 事件类型 VIEW
	EventKey  string // 事件KEY值,设置的跳转URL
}

EventView 点击菜单跳转链接时的事件推送

func NewEventView

func NewEventView(m *Message) *EventView

NewEventView 把通用 struct 转化成相应类型的 struct

type Group

type Group struct {
	Id    int    `json:"id,omitempty"`
	Name  string `json:"name"`
	Count int    `json:"count,omitempty"`
}

Group 用户分组

func CreateUserGroup

func CreateUserGroup(name string) (g *Group, err error)

CreateUserGroup 创建用户分组

func GetAllUserGroups

func GetAllUserGroups() (gs []Group, err error)

GetAllUserGroups 查询所有分组

func UpdateUserGroup

func UpdateUserGroup(id int, name string) (g *Group, err error)

UpdateUserGroup 修改用户分组名

type GroupIdWapper

type GroupIdWapper struct {
	GroupId int `json:"groupid"`
}

GroupIdWapper 用户所在分组包装器

type GroupWapper

type GroupWapper struct {
	WeixinError
	Group Group `json:"group"`
}

GroupWapper 用户分组包装器

type GroupsWapper

type GroupsWapper struct {
	WeixinError
	Groups []Group `json:"groups"`
}

GroupsWapper 所有用户分组包装器

type KeywordPair

type KeywordPair struct {
	Value string `json:"value"`
	Color string `json:"color,omitempty"`
}

KeywordPair 模板消息内容值

type Lang

type Lang string

Lang 国家地区语言版本

type MatchRule

type MatchRule struct {
	GroupId int `json:"group_id,omitempty"` // 用户分组id,可通过用户分组管理接口获取
	Sex     int `json:"sex,omitempty"`      // 性别:男(1)女(2),不填则不做匹配
	// 客户端版本,当前只具体到系统型号:IOS(1), Android(2),Others(3),不填则不做匹配
	ClientPlatformType int `json:"client_platform_type,omitempty"`
	// country、province、city组成地区信息,将按照country、province、city的顺序进行验证,
	// 要符合地区信息表的内容。地区信息从大到小验证,小的可以不填,即若填写了省份信息,则国家信
	// 息也必填并且匹配,城市信息可以不填。 例如 “中国 广东省 广州市”、“中国 广东省”都是合法
	// 的地域信息,而“中国 广州市”则不合法,因为填写了城市信息但没有填写省份信息。
	// 地区信息表:http://mp.weixin.qq.com/wiki/static/assets/870a3c2a14e97b3e74fde5e88fa47717.zip
	Country  string `json:"country,omitempty"`  // 国家信息,是用户在微信中设置的地区,具体请参考地区信息表
	Province string `json:"province,omitempty"` // 省份信息,是用户在微信中设置的地区,具体请参考地区信息表
	City     string `json:"city,omitempty"`     // 城市信息,是用户在微信中设置的地区,具体请参考地区信息表
}

MatchRule 菜单匹配规则,六个字段,均可为空,但不能全部为空,至少要有一个匹配信息是不为空的,

type MaterialCount

type MaterialCount struct {
	WeixinError
	VoiceCount int `json:"voice_count"` // 语音总数量
	VideoCount int `json:"video_count"` // 视频总数量
	ImageCount int `json:"image_count"` // 图片总数量
	NewsCount  int `json:"news_count"`  // 图文总数量
}

MaterialCount 素材总数

func GetMaterialCount

func GetMaterialCount() (mc *MaterialCount, err error)

GetMaterialCount 获取素材总数

type MediaType

type MediaType string

MediaType 媒体文件类型

const (
	MediaTypeImage MediaType = "image"
	MediaTypeVoice MediaType = "voice"
	MediaTypeVideo MediaType = "video"
	MediaTypeThumb MediaType = "thumb"
)

微信支持的媒体文件类型

type MenuInfo struct {
	IsMenuOpen   int `json:"is_menu_open"` // 菜单是否开启,0代表未开启,1代表开启
	SelfmenuInfo struct {
		Button []struct {
			// 菜单的类型,公众平台官网上能够设置的菜单类型有view(跳转网页)、text(返回文本,下同)、
			// img、photo、video、voice。使用API设置的则有8种,详见《自定义菜单创建接口》
			Type MenuType `json:"type"`
			Name string   `json:"name"` // 菜单名称
			// 对于不同的菜单类型,value的值意义不同。官网上设置的自定义菜单:
			// Text:保存文字到value; Img、voice:保存mediaID到value; Video:保存视频下载链接到value;
			//  News:保存图文消息到news_info,同时保存mediaID到value; View:保存链接到url。
			// 使用API设置的自定义菜单: click、scancode_push、scancode_waitmsg、pic_sysphoto、
			// pic_photo_or_album、	pic_weixin、location_select:保存值到key;view:保存链接到url
			Key       string `json:"key"`
			URL       string `json:"url"`
			Value     string `json:"value"`
			SubButton struct {
				List []struct {
					Name     string   `json:"name"`
					Type     MenuType `json:"type"`
					Key      string   `json:"key"`
					URL      string   `json:"url"`
					Value    string   `json:"value"`
					NewsInfo struct {
						List []struct {
							Title      string `json:"title"`       // 图文消息的标题
							Author     string `json:"author"`      // 作者
							Digest     string `json:"digest"`      // 摘要
							ShowCover  string `json:"show_cover"`  // 是否显示封面,0为不显示,1为显示
							CoverURL   string `json:"cover_url"`   // 封面图片的URL
							ContentURL string `json:"content_url"` // 正文的URL
							SourceURL  string `json:"source_url"`  // 原文的URL,若置空则无查看原文入口
						}
					} `json:"news_info"` // news_info	图文消息的信息
				} `json:"list"`
			} `json:"sub_button"` // 菜单按钮
		} `json:"button"` // 菜单按钮
	} `json:"selfmenu_info"` // 菜单信息
}

MenuInfo 自定义菜单配置

func GetMenuInfo

func GetMenuInfo() (mi *MenuInfo, err error)

GetMenuInfo 获取自定义菜单配置

type MenuType string

MenuType 菜单类型

请注意:

1、自定义菜单最多包括3个一级菜单,每个一级菜单最多包含5个二级菜单。
2、一级菜单最多4个汉字,二级菜单最多7个汉字,多出来的部分将会以“...”代替。
3、创建自定义菜单后,由于微信客户端缓存,需要24小时微信客户端才会展现出来。测试时可以尝试取消关注公众账号后再次关注,则可以看到创建后的效果。
自定义菜单接口可实现多种类型按钮,如下:

1、click:点击推事件

用户点击click类型按钮后,微信服务器会通过消息接口推送消息类型为event	的结构给开发者(参考消息接口指南),并且带上按钮中开发者填写的key值,开发者可以通过自定义的key值与用户进行交互;

2、view:跳转URL

用户点击view类型按钮后,微信客户端将会打开开发者在按钮中填写的网页URL,可与网页授权获取用户基本信息接口结合,获得用户基本信息。

3、scancode_push:扫码推事件

用户点击按钮后,微信客户端将调起扫一扫工具,完成扫码操作后显示扫描结果(如果是URL,将进入URL),且会将扫码的结果传给开发者,开发者可以下发消息。

4、scancode_waitmsg:扫码推事件且弹出“消息接收中”提示框

用户点击按钮后,微信客户端将调起扫一扫工具,完成扫码操作后,将扫码的结果传给开发者,同时收起扫一扫工具,然后弹出“消息接收中”提示框,随后可能会收到开发者下发的消息。

5、pic_sysphoto:弹出系统拍照发图

用户点击按钮后,微信客户端将调起系统相机,完成拍照操作后,会将拍摄的相片发送给开发者,并推送事件给开发者,同时收起系统相机,随后可能会收到开发者下发的消息。

6、pic_photo_or_album:弹出拍照或者相册发图

用户点击按钮后,微信客户端将弹出选择器供用户选择“拍照”或者“从手机相册选择”。用户选择后即走其他两种流程。

7、pic_weixin:弹出微信相册发图器

用户点击按钮后,微信客户端将调起微信相册,完成选择操作后,将选择的相片发送给开发者的服务器,并推送事件给开发者,同时收起相册,随后可能会收到开发者下发的消息。

8、location_select:弹出地理位置选择器

用户点击按钮后,微信客户端将调起地理位置选择工具,完成选择操作后,将选择的地理位置发送给开发者的服务器,同时收起位置选择工具,随后可能会收到开发者下发的消息。

9、media_id:下发消息(除文本消息)

用户点击media_id类型按钮后,微信服务器会将开发者填写的永久素材id对应的素材下发给用户,永久素材类型可以是图片、音频、视频、图文消息。请注意:永久素材id必须是在“素材管理/新增永久素材”接口上传后获得的合法id。

10、view_limited:跳转图文消息URL

用户点击view_limited类型按钮后,微信客户端将打开开发者在按钮中填写的永久素材id对应的图文消息URL,永久素材类型只支持图文消息。请注意:永久素材id必须是在“素材管理/新增永久素材”接口上传后获得的合法id。

请注意,3到8的所有事件,仅支持微信iPhone5.4.1以上版本,和Android5.4以上版本的微信用户,旧版本微信用户点击后将没有回应,开发者也不能正常接收到事件推送。9和10,是专门给第三方平台旗下未微信认证(具体而言,是资质认证未通过)的订阅号准备的事件类型,它们是没有事件推送的,能力相对受限,其他类型的公众号不必使用。

type Message

type Message struct {
	Encrypt string

	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID)
	CreateTime   string   // 消息创建时间(整型)
	MsgId        int      // 消息id,64位整型

	// text-文本消息,image-图片消息,voice-语音消息,
	// video-视频消息,shortvideo-小视频消息,
	// location-地理位置消息,link-链接消息,
	// music-音乐,news-图文消息
	MsgType MsgType

	// text-文本消息
	Content string `xml:",omitempty"` // 文本消息内容

	// image-图片消息
	PicUrl  string `xml:",omitempty"` // 图片链接
	MediaId string `xml:",omitempty"` // 图片消息媒体id,可以调用多媒体文件下载接口拉取数据

	// voice-语音消息
	// MediaId string  `xml:",omitempty"`// 语音消息媒体id,可以调用多媒体文件下载接口拉取数据
	Format       string `xml:",omitempty"` // 语音格式,如amr,speex等
	Recongnition string `xml:",omitempty"` // 语音识别结果,使用UTF8编码

	// video-视频消息,shortvideo-小视频消息
	// MediaId string `xml:",omitempty"` // 视频消息媒体id,可以调用多媒体文件下载接口拉取数据
	ThumbMediaId string `xml:",omitempty"` // 视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据

	// location-地理位置消息
	LocationX float64 `xml:"Location_X,omitempty"` // 地理位置维度
	LocationY float64 `xml:"Location_Y,omitempty"` // 地理位置经度
	Scale     int     `xml:",omitempty"`           // 地图缩放大小
	Label     string  `xml:",omitempty"`           // 地理位置信息

	// link-链接消息
	Title       string `xml:",omitempty"` // 消息标题
	Description string `xml:",omitempty"` // 消息描述
	Url         string `xml:",omitempty"` // 消息链接

	// 关注/取消关注事件
	Event EventType // 事件类型,subscribe(订阅)、unsubscribe(取消订阅)

	// 扫描带参数二维码事件
	// Event	EventType // 事件类型,subscribe
	// 用户扫描带场景值二维码时,可能推送以下两种事件:
	// 1. 如果用户还未关注公众号,则用户可以关注公众号,关注后微信会将带场景值关注事件推送给开发者。
	//    EventKey	事件KEY值,qrscene_为前缀,后面为二维码的参数值
	// 2. 如果用户已经关注公众号,则微信会将带场景值扫描事件推送给开发者。
	//    EventKey	事件KEY值,是一个32位无符号整数,即创建二维码时的二维码scene_id
	EventKey string // 事件KEY值,qrscene_为前缀,后面为二维码的参数值
	Ticket   string // 二维码的ticket,可用来换取二维码图片

	// 上报地理位置事件
	// Event EventType	// 事件类型,LOCATION
	Latitude  float64 // 地理位置纬度
	Longitude float64 // 地理位置经度
	Precision float64 // 地理位置精度

	// 模版消息发送任务完成后,微信服务器会将是否送达成功作为通知
	// Event         EventType // 事件类型,TEMPLATESENDJOBFINISH
	TplMsgId int    // 消息id
	Status   string // 发送状态为成功

	// 事件类型,scancode_push/scancode_waitmsg
	// Event        EventType // 事件类型,scancode_push
	// EventKey     string    // 事件KEY值,由开发者在创建菜单时设定
	ScanType   string `json:"ScanCodeInfo>ScanType"`   // 扫描类型,一般是qrcode
	ScanResult string `json:"ScanCodeInfo>ScanResult"` // 扫描结果,即二维码对应的字符串信息

	// 事件类型,pic_sysphoto
	// Event      EventType // 事件类型,pic_sysphoto
	// EventKey   string    // 事件KEY值,由开发者在创建菜单时设定
	Count      int      `json:"SendPicsInfo>Count"`                  // 发送的图片数量
	PicMd5Sums []string `json:"SendPicsInfo>PicList>item>PicMd5Sum"` // 图片的MD5值,开发者若需要,可用于验证接收到图片

	LocationX2 float64 `xml:"SendLocationInfo>Location_X,omitempty"` // 地理位置维度
	LocationY2 float64 `xml:"SendLocationInfo>Location_Y,omitempty"` // 地理位置经度
	Scale2     int     `xml:"SendLocationInfo>Scale,omitempty"`      // 精度,可理解为精度或者比例尺、越精细的话 scale越高
	Label2     string  `xml:"SendLocationInfo>Label,omitempty"`      // 地理位置的字符串信息
	Poiname    string  `xml:"SendLocationInfo>Poiname,omitempty"`    // 朋友圈POI的名字,可能为空

	// 事件类型 qualification_verify_success,naming_verify_success,annual_renew,verify_expired
	ExpiredTime int // 有效期 (整形),指的是时间戳,将于该时间戳认证过期

	// 事件类型,qualification_verify_fail,naming_verify_fail
	FailTime   int    // 失败发生时间 (整形),时间戳
	FailReason string // 认证失败的原因
}

Message 通用类,接收微信各类消息

type MsgType

type MsgType string

MsgType 消息类型

const (
	MsgTypeText       MsgType = "text"       // 文本消息
	MsgTypeImage      MsgType = "image"      // 图片消息
	MsgTypeVoice      MsgType = "voice"      // 语音消息
	MsgTypeVideo      MsgType = "video"      // 视频消息
	MsgTypeShortVideo MsgType = "shortvideo" // 小视频消息
	MsgTypeLocation   MsgType = "location"   // 地理位置消息
	MsgTypeLink       MsgType = "link"       // 链接消息
	MsgTypeMusic      MsgType = "music"      // 音乐消息
	MsgTypeNews       MsgType = "news"       // 图文消息
	MsgTypeWXCard     MsgType = "wxcard"     // 卡券,客服消息时使用
	MsgTypeEvent      MsgType = "event"      // 事件推送
)

微信支持的消息类型

type News

type News struct {
	Title       string    `json:"title"` // 图文消息的标题
	Description string    `json:"description"`
	DownURL     string    `json:"down_url"`
	NewsItem    []Article `json:"news_item"`
}

News 永久素材

func GetNews

func GetNews(mediaId string) (ret *News, err error)

GetNews 获取临时素材

type NewsList

type NewsList struct {
	WeixinError
	TotalCount string `json:"total_count"` // 该类型的素材的总数
	ItemCount  string `json:"item_count"`  // 本次调用获取的素材的数量
	Item       []struct {
		MediaId    string `json:"media_id"`
		UpdateTime string `json:"update_time"` // 这篇图文消息素材的最后更新时间
		Name       string `json:"name"`        // 文件名称
		URL        string `json:"url"`         // 图文页的URL,或者,当获取的列表是图片素材列表时,该字段是图片的URL
		Content    struct {
			NewsItem []Article `json:"news_item"`
		} `json:"content"` // 本次调用获取的素材的数量
	} `json:"item"` // 多图文消息会在此处有多篇文章
}

NewsList 素材列表

func BatchGetNews

func BatchGetNews(mtype MediaType, offset int, count int) (ret *NewsList, err error)

BatchGetNews 获取素材列表

type QRCodeTicket

type QRCodeTicket struct {
	Ticket        string `json:"ticket"`         // 获取的二维码ticket,凭借此ticket可以在有效时间内换取二维码。
	ExpireSeconds int    `json:"expire_seconds"` // 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天)。
	URL           string `json:"url"`            // 二维码图片解析后的地址,开发者可根据该地址自行生成需要的二维码图片
}

QRCodeTicket 二维码ticket

func CreatePermanentQRCodeTicket

func CreatePermanentQRCodeTicket(sceneId int) (ticket *QRCodeTicket, err error)

CreatePermanentQRCodeTicket 创建永久二维码

func CreatePermanentQRCodeTicketString

func CreatePermanentQRCodeTicketString(sceneId string) (ticket *QRCodeTicket, err error)

CreatePermanentQRCodeTicketString 创建字符串形式的二维码

func CreateTemporaryQRCodeTicket

func CreateTemporaryQRCodeTicket(sceneId int, expireSeconds ...int) (ticket *QRCodeTicket, err error)

CreateTemporaryQRCodeTicket 创建临时二维码

type RecvEvent

type RecvEvent interface {
	RecvMsg
}

RecvEvent 事件消息

func NewRecvEvent

func NewRecvEvent(msg *Message) RecvEvent

NewRecvEvent 把通用 struct 转化成相应类型的 struct

type RecvImage

type RecvImage struct {
	RecvMsg
	ToUserName   string  // 开发者微信号
	FromUserName string  // 发送方帐号(一个OpenID)
	CreateTime   string  // 消息创建时间(整型)
	MsgType      MsgType // image
	PicUrl       string  // 图片链接
	MediaId      string  // 图片消息媒体id,可以调用多媒体文件下载接口拉取数据
	MsgId        int     // 消息id,64位整型
}

RecvImage 接收图片消息

func NewRecvImage

func NewRecvImage(m *Message) *RecvImage

NewRecvImage 把通用 struct 转化成相应类型的 struct

type RecvLink struct {
	RecvMsg
	ToUserName   string  // 开发者微信号
	FromUserName string  // 发送方帐号(一个OpenID)
	CreateTime   string  // 消息创建时间(整型)
	MsgType      MsgType // location
	Title        string  // 消息标题
	Description  string  // 消息描述
	Url          string  // 消息链接
	MsgId        int     // 消息id,64位整型
}

RecvLink 接收链接消息

func NewRecvLink(m *Message) *RecvLink

NewRecvLink 把通用 struct 转化成相应类型的 struct

type RecvLocation

type RecvLocation struct {
	RecvMsg
	ToUserName   string  // 开发者微信号
	FromUserName string  // 发送方帐号(一个OpenID)
	CreateTime   string  // 消息创建时间(整型)
	MsgType      MsgType // location
	LocationX    float64 `xml:"Location_X,omitempty"` // 地理位置维度
	LocationY    float64 `xml:"Location_Y,omitempty"` // 地理位置经度
	Scale        int     // 地图缩放大小
	Label        string  // 地理位置信息
	MsgId        int     // 消息id,64位整型
}

RecvLocation 接收地理位置消息

func NewRecvLocation

func NewRecvLocation(m *Message) *RecvLocation

NewRecvLocation 把通用 struct 转化成相应类型的 struct

type RecvMsg

type RecvMsg interface{}

RecvMsg 用户消息

func NewRecvMsg

func NewRecvMsg(msg *Message) RecvMsg

NewRecvMsg 把通用 struct 转化成相应类型的 struct

type RecvText

type RecvText struct {
	RecvMsg
	ToUserName   string  // 开发者微信号
	FromUserName string  // 发送方帐号(一个OpenID)
	CreateTime   string  // 消息创建时间(整型)
	MsgType      MsgType // text
	Content      string  // 文本消息内容
	MsgId        int     // 消息id,64位整型
}

RecvText 接收文本消息

func NewRecvText

func NewRecvText(m *Message) *RecvText

NewRecvText 把通用 struct 转化成相应类型的 struct

type RecvVideo

type RecvVideo struct {
	RecvMsg
	ToUserName   string  // 开发者微信号
	FromUserName string  // 发送方帐号(一个OpenID)
	CreateTime   string  // 消息创建时间(整型)
	MsgType      MsgType // video
	MediaId      string  // 视频消息媒体id,可以调用多媒体文件下载接口拉取数据
	ThumbMediaId string  // 视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据
	MsgId        int     // 消息id,64位整型
}

RecvVideo 接收图片消息

func NewRecvVideo

func NewRecvVideo(m *Message) *RecvVideo

NewRecvVideo 把通用 struct 转化成相应类型的 struct

type RecvVoice

type RecvVoice struct {
	RecvMsg
	ToUserName   string  // 开发者微信号
	FromUserName string  // 发送方帐号(一个OpenID)
	CreateTime   string  // 消息创建时间(整型)
	MsgType      MsgType // voice
	MediaId      string  // 语音消息媒体id,可以调用多媒体文件下载接口拉取数据
	Format       string  // 语音格式,如amr,speex等
	Recongnition string  // 语音识别结果,使用UTF8编码
	MsgId        int     // 消息id,64位整型
}

RecvVoice 接收视频/小视频消息

func NewRecvVoice

func NewRecvVoice(m *Message) *RecvVoice

NewRecvVoice 把通用 struct 转化成相应类型的 struct

type ReplyArticle

type ReplyArticle struct {
	Title       string `xml:",omitempty"` // 	图文消息标题
	Description string `xml:",omitempty"` // 	图文消息描述
	PicUrl      string `xml:",omitempty"` // 	图片链接,支持JPG、PNG格式,较好的效果为大图360*200,小图200*200
	Url         string `xml:",omitempty"` // 	点击图文消息跳转链接
}

ReplyArticle 图文消息

type ReplyBase

type ReplyBase struct {
	MsgType MsgType
}

ReplyBase 被动回复用户消息基础类

func (*ReplyBase) SetMsgType

func (b *ReplyBase) SetMsgType(msgType MsgType)

SetMsgType 设置消息类型

type ReplyImage

type ReplyImage struct {
	ReplyBase
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID)
	CreateTime   string   // 消息创建时间(整型)
	PicUrl       string   // 图片链接
	MediaId      string   `xml:"Image>MediaId"` // 图片消息媒体id,可以调用多媒体文件下载接口拉取数据
}

ReplyImage 回复图片消息

type ReplyMsg

type ReplyMsg interface {
	SetMsgType(msgType MsgType)
}

ReplyMsg 被动回复用户消息接口

func HandleEvent

func HandleEvent(msg *Message) (reply ReplyMsg)

HandleEvent 处理各类事件

func HandleMessage

func HandleMessage(msg *Message) (ret ReplyMsg)

HandleMessage 处理各类消息

type ReplyMusic

type ReplyMusic struct {
	ReplyBase
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID)
	CreateTime   string   // 消息创建时间(整型)
	Title        string   `xml:"Music>Title,omitempty"`        // 音乐标题
	Description  string   `xml:"Music>Description,omitempty"`  // 音乐描述
	MusicURL     string   `xml:"Music>MusicURL,omitempty"`     // 	音乐链接
	HQMusicUrl   string   `xml:"Music>HQMusicUrl,omitempty"`   // 	高质量音乐链接,WIFI环境优先使用该链接播放音乐
	ThumbMediaId string   `xml:"Music>ThumbMediaId,omitempty"` // 	缩略图的媒体id,通过素材管理接口上传多媒体文件,得到的id
}

ReplyMusic 回复音乐消息

type ReplyNews

type ReplyNews struct {
	ReplyBase
	XMLName      xml.Name       `xml:"xml"`
	ToUserName   string         // 开发者微信号
	FromUserName string         // 发送方帐号(一个OpenID)
	CreateTime   string         // 消息创建时间(整型)
	ArticleCount int            // 图文消息个数,限制为10条以内
	Articles     []ReplyArticle `xml:"Articles>item"` // 多条图文消息信息,默认第一个item为大图,注意,如果图文数超过10,则将会无响应
}

ReplyNews 回复图文消息

type ReplyText

type ReplyText struct {
	ReplyBase
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID)
	CreateTime   string   // 消息创建时间(整型)
	Content      string   // 文本消息内容
}

ReplyText 回复文本消息

type ReplyVideo

type ReplyVideo struct {
	ReplyBase
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID)
	CreateTime   string   // 消息创建时间(整型)
	MediaId      string   `xml:"Video>MediaId"`               // 通过素材管理接口上传多媒体文件,得到的id
	Title        string   `xml:"Video>Title,omitempty"`       // 视频消息的标题
	Description  string   `xml:"Video>Description,omitempty"` // 视频消息的描述
}

ReplyVideo 回复视频消息

type ReplyVoice

type ReplyVoice struct {
	ReplyBase
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID)
	CreateTime   string   // 消息创建时间(整型)
	MediaId      string   `xml:"Voice>MediaId"` // 通过素材管理接口上传多媒体文件,得到的id
}

ReplyVoice 回复语音消息

type ScopeSNSAPI

type ScopeSNSAPI string

ScopeSNSAPI 应用授权作用域类型

type TemplateData

type TemplateData struct {
	First    KeywordPair `json:"first"`
	Keyword1 KeywordPair `json:"keyword1"`
	Keyword2 KeywordPair `json:"keyword2,omitempty"`
	Keyword3 KeywordPair `json:"keyword3,omitempty"`
	Keyword4 KeywordPair `json:"keyword4,omitempty"`
	Keyword5 KeywordPair `json:"keyword5,omitempty"`
	Remark   KeywordPair `json:"value"`
}

TemplateData 模板消息内容

type TemplateId

type TemplateId struct {
	WeixinError
	TemplateId string `json:"template_id"`
}

TemplateId 模板ID with Error

type TemplateMsg

type TemplateMsg struct {
	ToUser     string       `json:"touser"`
	TemplateId string       `json:"template_id"`
	URL        string       `json:"url,omitempty"`
	Data       TemplateData `json:"data"`
}

TemplateMsg 模板消息

type TempplateMsgId

type TempplateMsgId struct {
	WeixinError
	MsgId int `json:"msgid"`
}

TempplateMsgId 模版消息 Id

type UpdateNewsReq

type UpdateNewsReq struct {
	MediaId  string    `json:"media_id"` // 要修改的图文消息的id
	Index    string    `json:"index"`    // 要更新的文章在图文消息中的位置(多图文消息时,此字段才有意义),第一篇为0
	Articles []Article `json:"articles"` // 要修改的图文消息的id
}

UpdateNewsReq 修改永久图文素材

type UserInfo

type UserInfo struct {
	WeixinError
	Subscribe     int    `json:"subscribe"`
	OpenId        string `json:"openid"`
	NickName      string `json:"nickname"`
	Sex           int    `json:"sex"`
	Language      Lang   `json:"language"`
	City          string `json:"city"`
	Province      string `json:"province"`
	Country       string `json:"country"`
	HeadImgURL    string `json:"headimgurl"`
	SubscribeTime int    `json:"subscribe_time"`
	UnionId       string `json:"unionid"`
	Remark        string `json:"remark"`
	GroupId       int    `json:"groupid"`
}

UserInfo 用户基本信息

func BatchGetUserInfo

func BatchGetUserInfo(openIds []string, lang ...Lang) (infos []UserInfo, err error)

BatchGetUserInfo 获取用户基本信息(包括UnionID机制)

func GetUserInfo

func GetUserInfo(openId string, lang ...Lang) (info *UserInfo, err error)

GetUserInfo 获取用户基本信息(包括UnionID机制)

type WebToken

type WebToken struct {
	WeixinError
	AccessToken  string `json:"access_token"`      // 网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同
	ExpiresIn    int    `json:"expires_in"`        // access_token接口调用凭证超时时间,单位(秒)
	RefreshToken string `json:"refresh_token"`     // 用户刷新access_token
	OpenId       string `json:"openid"`            // 用户唯一标识,请注意,在未关注公众号时,用户访问公众号的网页,也会产生一个用户和公众号唯一的OpenID
	Scope        string `json:"scope"`             // 用户授权的作用域,使用逗号(,)分隔
	UnionId      string `json:"unionid,omitempty"` // 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。详见:获取用户个人信息(UnionID机制)
}

WebToken 网页授权access_token

func GetWebToken

func GetWebToken(code string) (token *WebToken, err error)

GetWebToken 获取网页授权 access_token

func RefreshWebToken

func RefreshWebToken(refreshToken string) (token *WebToken, err error)

RefreshWebToken 刷新网页授权 access_token

type WebUserInfo

type WebUserInfo struct {
	WeixinError
	OpenId   string `json:"openid"`   // 用户的唯一标识
	NickName string `json:"nickname"` // 用户昵称
	Sex      int    `json:"sex"`      // 用户的性别,值为1时是男性,值为2时是女性,值为0时是未知
	Province string `json:"province"` // 用户个人资料填写的省份
	City     string `json:"city"`     // 普通用户个人资料填写的城市
	Country  string `json:"country"`  // 国家,如中国为CN
	// 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,
	// 0代表640*640正方形头像),用户没有头像时该项为空。若用户更换头像,原有头像URL将失效。
	HeadImgURL string   `json:"headimgurl"`
	Privilege  []string `json:"privilege"` // 用户特权信息,json 数组,如微信沃卡用户为(chinaunicom)
	// 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。详见:获取用户个人信息(UnionID机制)
	UnionId string `json:"unionid"`
}

WebUserInfo 网页授权获取用户基本信息

func GetWebUserInfo

func GetWebUserInfo(webToken, openId string, lang ...Lang) (info *WebUserInfo, err error)

GetWebUserInfo 刷新网页授权 access_token

type WeixinError

type WeixinError struct {
	ErrCode int    `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

WeixinError 微信错误

func (*WeixinError) Error

func (e *WeixinError) Error() string

func (*WeixinError) GetWeixinError

func (e *WeixinError) GetWeixinError() *WeixinError

GetWeixinError 返回微信错误消息

type WeixinErrorer

type WeixinErrorer interface {
	// GetErrCode() int
	// GetErrMsg() string
	GetWeixinError() *WeixinError
}

WeixinErrorer 微信错误消息接口

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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