mp

package
v0.0.0-...-4162a9b Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2018 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WechatWebAuthCodeApi = `` // 用户同意授权,获取code
	/* 127-byte string literal not displayed */
	WechatWebAuthAccessTokenApi        = `https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=%s` // 通过code换取网页授权access_token
	WechatWebAuthRefreshAccessTokenApi = `https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=%s&grant_type=%s&refresh_token=%s` // 刷新access_token(如果需要)
	WechatWebAuthUserinfoApi           = `https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=%s`                   // 拉取用户信息(需scope为 snsapi_userinfo)
	WechatWebAuthCheckApi              = `https://api.weixin.qq.com/sns/auth?access_token=%s&openid=%s`                               // 检验授权凭证(access_token)是否有效
)
View Source
const (
	WechatCommentOpenApi        = `https://api.weixin.qq.com/cgi-bin/comment/open?access_token=%s`         // 打开已群发文章评论
	WechatCommentCloseApi       = `https://api.weixin.qq.com/cgi-bin/comment/close?access_token=%s`        // 关闭已群发文章评论
	WechatCommentListApi        = `https://api.weixin.qq.com/cgi-bin/comment/list?access_token=%s`         // 查看指定文章的评论数据
	WechatCommentMarkApi        = `https://api.weixin.qq.com/cgi-bin/comment/markelect?access_token=%s`    // 将评论标记精选
	WechatCommentUnmarkApi      = `https://api.weixin.qq.com/cgi-bin/comment/unmarkelect?access_token=%s`  // 将评论取消精选
	WechatCommentDeleteApi      = `https://api.weixin.qq.com/cgi-bin/comment/delete?access_token=%s`       // 删除评论
	WechatCommentReplyAddApi    = `https://api.weixin.qq.com/cgi-bin/comment/reply/add?access_token=%s`    // 回复评论
	WechatCommentReplyDeleteApi = `https://api.weixin.qq.com/cgi-bin/comment/reply/delete?access_token=%s` // 删除回复
)
View Source
const (
	WechatCommentTypeAll      = 0 // 普通评论&精选评论
	WechatCommentTypeNormal   = 1 // 普通评论
	WechatCommentTypeFeatured = 2 // 精选评论
)
View Source
const (
	WechatCustomerServiceGetkflistApi              = `https://api.weixin.qq.com/cgi-bin/customservice/getkflist?access_token=%s`                    // 获取所有客服账号
	WechatCustomerServiceGetonlinekflistApi        = `https://api.weixin.qq.com/cgi-bin/customservice/getonlinekflist?access_token=%s`              // 获取在线客服账号
	WechatCustomerServiceAddKfaccountApi           = `https://api.weixin.qq.com/customservice/kfaccount/add?access_token=%s`                        // 添加客服帐号
	WechatCustomerServiceInviteworkerKfaccountApi  = `https://api.weixin.qq.com/customservice/kfaccount/inviteworker?access_token=%s`               // 邀请绑定客服帐号
	WechatCustomerServiceUpdateKfaccountApi        = `https://api.weixin.qq.com/customservice/kfaccount/update?access_token=%s`                     // 设置客服信息
	WechatCustomerServiceUploadheadimgKfaccountApi = `http://api.weixin.qq.com/customservice/kfaccount/uploadheadimg?access_token=%s&kf_account=%s` // 上传客服头像
	WechatCustomerServiceDelKfaccountApi           = `https://api.weixin.qq.com/customservice/kfaccount/del?access_token=%s`                        // 删除客服帐号

	WechatCustomerServiceCreateKfsessionApi      = `https://api.weixin.qq.com/customservice/kfsession/create?access_token=%s`                       // 创建会话
	WechatCustomerServiceCloseKfsessionApi       = `https://api.weixin.qq.com/customservice/kfsession/close?access_token=%s`                        // 关闭会话
	WechatCustomerServiceGetKfsessionApi         = `https://api.weixin.qq.com/customservice/kfsession/getsession?access_token=%s&openid=%s`         // 获取客户会话状态
	WechatCustomerServiceGetKfsessionlistApi     = `https://api.weixin.qq.com/customservice/kfsession/getsessionlist?access_token=%s&kf_account=%s` // 获取客服会话列表
	WechatCustomerServiceGetwaitcaseKfsessionApi = `https://api.weixin.qq.com/customservice/kfsession/getwaitcase?access_token=%s`                  // 获取未接入会话列表
	WechatCustomerServiceGetmsglistMsgrecordApi  = `https://api.weixin.qq.com/customservice/msgrecord/getmsglist?access_token=%s`                   // 获取聊天记录

	WechatCustomerServiceSendMessageApi = `https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=%s` // 客服接口-发消息
)
View Source
const (
	WechatCustomerServiceMsgTypeText  = "text"
	WechatCustomerServiceMsgTypeImage = "image"
	WechatCustomerServiceMsgTypeVoice = "voice"
	WechatCustomerServiceMsgTypeVideo = "video"
)

客服消息类型

View Source
const (
	WechatMediaUploadApi        = `https://api.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s`          // 新增临时素材
	WechatMediaGetApi           = `https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s`         // 获取临时素材
	WechatMediaUploadimgApi     = `https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=%s`               // 上传图文消息内的图片获取URL
	WechatMaterialAddApi        = `https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=%s&type=%s` // 新增其他类型永久素材
	WechatMaterialGetApi        = `https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=%s`         // 获取永久素材
	WechatMaterialDeleteApi     = `https://api.weixin.qq.com/cgi-bin/material/del_material?access_token=%s`         // 删除永久素材
	WechatMaterialGetcountApi   = `https://api.weixin.qq.com/cgi-bin/material/get_materialcount?access_token=%s`    // 获取素材总数
	WechatMaterialBatchgetApi   = `https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=%s`    // 获取素材列表
	WechatMaterialAddnewsApi    = `https://api.weixin.qq.com/cgi-bin/material/add_news?access_token=%s`             // 新增永久图文素材
	WechatMaterialUpdatenewsApi = `https://api.weixin.qq.com/cgi-bin/material/update_news?access_token=%s`          // 修改永久图文素材
)
View Source
const (
	WechatArticleShowCoverPicFalse WechatArticleShowCoverPic = 0 // 不显示封面
	WechatArticleShowCoverPicTrue  WechatArticleShowCoverPic = 1 // 显示封面

	WechatArticleNeedOpenCommentNo  WechatArticleNeedOpenComment = 0 // 不打开评论
	WechatArticleNeedOpenCommentYes WechatArticleNeedOpenComment = 1 // 打开评论

	WechatArticleOnlyFansCanCommentNo  WechatArticleOnlyFansCanComment = 0 // 否,所有人都可以评论
	WechatArticleOnlyFansCanCommentYes WechatArticleOnlyFansCanComment = 1 // 是滴, 只有粉丝才能评论
)
View Source
const (
	WechatMenuCreateApi              = `https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s`         // 自定义菜单创建接口
	WechatMenuGetApi                 = `https://api.weixin.qq.com/cgi-bin/menu/get?access_token=%s`            // 自定义菜单查询接口
	WechatMenuDeleteApi              = `https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=%s`         // 自定义菜单删除接口
	WechatMenuConditionalAddApi      = `https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token=%s` // 创建个性化菜单
	WechatMenuConditionalDeleteApi   = `https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token=%s` // 删除个性化菜单
	WechatMenuConditionalTrymatchApi = `https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token=%s`       // 测试个性化菜单匹配结果
)
View Source
const (
	WechatMessageTypeText       = "text"       //文本消息
	WechatMessageTypeImage      = "image"      //图片消息
	WechatMessageTypeVoice      = "voice"      //声音消息
	WechatMessageTypeVideo      = "video"      //视频消息
	WechatMessageTypeVideoShort = "shortvideo" //短视频消息
	WechatMessageTypeLocation   = "location"   //地理位置消息
	WechatMessageTypeLink       = "link"       //链接消息
	WechatMessageTypeMusic      = "music"      //音乐消息
	WechatMessageTypeNews       = "news"       //图文消息
	WechatMessageTypeEvent      = "event"      //事件消息
)
View Source
const (
	WechatMessageEventSubscribe                  = "subscribe"                    // 关注事件
	WechatMessageEventUnsubscribe                = "unsubscribe"                  // 取消关注事件
	WechatMessageEventScan                       = "SCAN"                         // 扫码二维码事件
	WechatMessageEventLocation                   = "LOCATION"                     // 上报地理位置事件
	WechatMessageEventClick                      = "CLICK"                        // 点击自定义菜单拉取消息事件
	WechatMessageEventView                       = "VIEW"                         // 点击自定义菜单跳转链接事件
	WechatMessageEventQualificationVerifySuccess = "qualification_verify_success" // 资质认证成功通知
	WechatMessageEventQualificationVerifyFail    = "qualification_verify_fail"    // 资质认证失败通知
	WechatMessageEventNamingVerifySuccess        = "naming_verify_success"        // 名称认证成功
	WechatMessageEventNamingVerifyFail           = "naming_verify_fail"           // 名称认证失败
	WechatMessageEventAnnualRenew                = "annual_renew"                 // 年审通知
	WechatMessageEventVerifyExpired              = "verify_expired"               // 认证过期失效通知
	WechatMessageEventTemplatesendjobfinish      = "TEMPLATESENDJOBFINISH"        // 发送模板消息结果通知
)
View Source
const (
	WechatTemplateSetIndustryApi = `https://api.weixin.qq.com/cgi-bin/template/api_set_industry?access_token=%s`         // 设置所属行业
	WechatTemplateGetIndustryApi = `https://api.weixin.qq.com/cgi-bin/template/get_industry?access_token=%s`             // 获取设置的行业信息
	WechatTemplateAddApi         = `https://api.weixin.qq.com/cgi-bin/template/api_add_template?access_token=%s`         // 从模板库中添加模板信息
	WechatTemplateGetAllApi      = `https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=%s` // 获取已添加至帐号下所有模板列表
	WechatTemplateDeleteApi      = `https://api.weixin.qq.com/cgi-bin/template/del_private_template?access_token=%s`     // 删除模板
	WechatTemplateSendApi        = `https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s`             // 发送模板消息
)
View Source
const (
	WechatSubscribemsgActionApi = `` // 需要用户同意授权,获取一次给用户推送一条订阅模板消息的机会
	/* 127-byte string literal not displayed */
	WechatSubscribeTemplateApi = `https://api.weixin.qq.com/cgi-bin/message/template/subscribe?access_token=%s`
)

///////////////////////////////////////////////////////// 一次性订阅消息 //////////////////////////////////////////

View Source
const (
	WechatQrcodeCreateApi = `https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=%s` // 创建二维码API
	WechatQrcodeShowApi   = `https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=%s`           // 显示二维码API
)
View Source
const (
	WechatQrcodeScene         = "QR_SCENE"           // 二维码类型-临时的整型参数值
	WechatQrcodeStrScene      = "QR_STR_SCENE"       // 二维码类型-临时的字符串参数值
	WechatQrcodeLimitScene    = "QR_LIMIT_SCENE"     // 二维码类型-永久的整型参数值
	WechatQrcodeLimitStrScene = "QR_LIMIT_STR_SCENE" // 二维码类型-永久的字符串参数值
)
View Source
const (
	WechatUserTagsCreateApi                = `https://api.weixin.qq.com/cgi-bin/tags/create?access_token=%s`                   // 创建标签
	WechatUserTagsGetApi                   = `https://api.weixin.qq.com/cgi-bin/tags/get?access_token=%s`                      // 获取公众号已创建的标签
	WechatUserTagsUpdateApi                = `https://api.weixin.qq.com/cgi-bin/tags/update?access_token=%s`                   // 编辑标签
	WechatUserTagsDeleteApi                = `https://api.weixin.qq.com/cgi-bin/tags/delete?access_token=%s`                   // 删除标签
	WechatuserTagUsersApi                  = `https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token=%s`                  // 获取标签下粉丝列表
	WechatUserTagsMembersBatchtaggingApi   = `https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token=%s`     // 批量为用户打标签
	WechatUserTagsMembersBatchuntaggingApi = `https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token=%s`   // 批量为用户取消标签
	WechatUserTagsMembersBlacklistApi      = `https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist?access_token=%s`     // 获取公众号的黑名单列表
	WechatUserTagsMembersBatchblackApi     = `https://api.weixin.qq.com/cgi-bin/tags/members/batchblacklist?access_token=%s`   // 批量拉黑用户
	WechatUserTagsMembersBatchunblackApi   = `https://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist?access_token=%s` // 批量取消拉黑用户
	WechatUserTagsGetidlistApi             = `https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token=%s`                // 获取用户身上的标签列表

	WechatUserUpdateRemarkApi = `https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token=%s` // 设置用户备注名

	WechatUserInfoApi      = `https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s&lang=%s` // 获取用户基本信息
	WechatUserInfoBatchApi = `https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=%s`          // 批量获取用户基本信息

	WechatUserGetApi = `https://api.weixin.qq.com/cgi-bin/user/get?access_token=%s&next_openid=%s` // 获取用户列表
)
View Source
const (
	WechatRequestEchostr          = "echostr"       // 微信认证服务器请求参数:返回字符串
	WechatRequestTimestamp        = "timestamp"     // 微信服务器请求参数:时间戳
	WechatRequestNonce            = "nonce"         // 微信服务器请求参数:随机字符串
	WechatRequestSignature        = "signature"     // 微信服务器请求参数:签名字符串
	WechatRequestEncryptType      = "encrypt_type"  // 微信服务器请求参数:加密方式
	WechatRequestMessageSignature = "msg_signature" // 微信服务器请求参数:消息签名字符串

	WechatResponseStringSuccess = "success"
	WechatResponseStringFail    = "fail"
	WechatResponseStringInvalid = "invalid wechat server"

	WechatLanguageZhCn = "zh_CN" // 微信语言,简体中文
	WechatLanguageZhTw = "zh_TW" // 微信语言,繁体中文
	WechatLanguageEn   = "en"    // 微信语言,英文

	WechatEncryptType = "aes" // 微信消息加密方式
)
View Source
const (
	WechatAccessTokenApi = `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s` // 获取微信accessToken地址
)
View Source
const (
	WechatGetcallbackipApi = `https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=%s` // 获取微信服务器IP地址
)
View Source
const WechatShortUrlAction = "long2short"
View Source
const WechatShortUrlApi = `https://api.weixin.qq.com/cgi-bin/shorturl?access_token=%s`
View Source
const (
	WechatTicketGetApi = `https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=%s` // 获取微信ticket地址
)

Variables

This section is empty.

Functions

func AESDecrypt

func AESDecrypt(cipherData, aesKey []byte) ([]byte, error)

AES 解密 cipherData: 待解密信息, aesKey: 信息加密时用到的key

func AESEncrypt

func AESEncrypt(plainData, aesKey []byte) ([]byte, error)

AES 加密 plainData: 待加密信息, aesKey: 加密需要用到的key

func CheckWechatAuthSign

func CheckWechatAuthSign(wechatSignature string, wechatParams ...string) bool

验证微信消息签名是否正确 wechatSignature 微信签名信息, wechatParams 微信消息参数

func NewMsgImageResponseByte

func NewMsgImageResponseByte(ToUserName, FromUserName, MediaId string) ([]byte, error)

新建一个图片回复信息,返回字节数组格式

func NewMsgImageResponseString

func NewMsgImageResponseString(ToUserName, FromUserName, MediaId string) (string, error)

新建一个图片回复信息,返回字符串格式

func NewMsgMusicResponseByte

func NewMsgMusicResponseByte(ToUserName, FromUserName, Title, Description, ThumbMediaId, MusicUrl, HQMusicUrl string) ([]byte, error)

新建一个音乐回复信息,返回字节数组格式

func NewMsgMusicResponseString

func NewMsgMusicResponseString(ToUserName, FromUserName, Title, Description, ThumbMediaId, MusicUrl, HQMusicUrl string) (string, error)

新建一个音乐回复信息,返回字符串格式

func NewMsgNewsResponseByte

func NewMsgNewsResponseByte(ToUserName, FromUserName string, items []MsgNewsItemResponse) ([]byte, error)

新建一个图文回复信息,返回字节数组格式

func NewMsgNewsResponseString

func NewMsgNewsResponseString(ToUserName, FromUserName string, items []MsgNewsItemResponse) (string, error)

新建一个图文回复信息,返回字符串格式

func NewMsgTextResponseByte

func NewMsgTextResponseByte(ToUserName, FromUserName, Content string) ([]byte, error)

新建一个文本回复信息,返回二进制数组格式

func NewMsgTextResponseString

func NewMsgTextResponseString(ToUserName, FromUserName, Content string) (string, error)

新建一个文本回复信息,返回字符串格式

func NewMsgVideoResponseByte

func NewMsgVideoResponseByte(ToUserName, FromUserName, MediaId, Title, Description string) ([]byte, error)

新建一个视频回复信息,返回字节数组格式

func NewMsgVideoResponseString

func NewMsgVideoResponseString(ToUserName, FromUserName, MediaId, Title, Description string) (string, error)

新建一个视频回复信息,返回字符串格式

func NewMsgVoiceResponseByte

func NewMsgVoiceResponseByte(ToUserName, FromUserName, MediaId string) ([]byte, error)

新建一个语音回复信息,返回字节数组格式

func NewMsgVoiceResponseString

func NewMsgVoiceResponseString(ToUserName, FromUserName, MediaId string) (string, error)

新建一个语音回复信息,返回字符串格式

func PKCS7Padding

func PKCS7Padding(plainData []byte, blockSize int) []byte

func PKCS7UnPadding

func PKCS7UnPadding(cipherData []byte) []byte

func SignMsg

func SignMsg(wechatParams ...string) string

签名微信消息 返回加密后的字符串

func SortSha1Signature

func SortSha1Signature(sep string, params ...string) string

先排序,再用sha1加密 sep: 排序后的分隔符, params: 需要加密的字符串数组

func WechatMpDefaultAccessTokenHandlerFunc

func WechatMpDefaultAccessTokenHandlerFunc(wm *WechatMp) string

默认获取微信accessToken的方法

Types

type AccessTokenHandlerFunc

type AccessTokenHandlerFunc func(wm *WechatMp) string

type AnnualRenewHandlerFunc

type AnnualRenewHandlerFunc func(request *MsgEventAnnualRenew) string

type Article

type Article struct {
	Title              string                          `json:"title"`                           // 标题
	ThumbMediaId       string                          `json:"thumb_media_id"`                  // 图文消息的封面图片素材id(必须是永久mediaID)
	Author             string                          `json:"author,omitempty"`                // 作者
	Digest             string                          `json:"digest,omitempty"`                // 图文消息的摘要,仅有单图文消息才有摘要,多图文此处为空。如果本字段为没有填写,则默认抓取正文前64个字。
	ShowCoverPic       WechatArticleShowCoverPic       `json:"show_cover_pic"`                  // 是否显示封面,0为false,即不显示,1为true,即显示
	Content            string                          `json:"content"`                         // 图文消息的具体内容,支持HTML标签,必须少于2万字符,小于1M,且此处会去除JS,涉及图片url必须来源 "上传图文消息内的图片获取URL"接口获取。外部图片url将被过滤。
	ContentSourceUrl   string                          `json:"content_source_url"`              // 图文消息的原文地址,即点击“阅读原文”后的URL
	Url                string                          `json:"url,omitempty"`                   // 图文页的URL
	NeedOpenComment    WechatArticleNeedOpenComment    `json:"need_open_comment,omitempty"`     // 是否打开评论,0不打开,1打开
	OnlyFansCanComment WechatArticleOnlyFansCanComment `json:"only_fans_can_comment,omitempty"` // 是否粉丝才可评论,0所有人可评论,1粉丝才可评论
}

type ArticleNews

type ArticleNews struct {
	NewsItem []Article `json:"news_item"`
	common.PublicError
}

type ArticleUpdate

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

type Articles

type Articles struct {
	Articles []Article `json:"articles"`
}

type BatchMaterial

type BatchMaterial struct {
	MediaId    string `json:"media_id"`
	Name       string `json:"name"` // 文件名称
	UpdateTime int64  `json:"update_time"`
	Url        string `json:"url"`
}

type BatchMaterialNews

type BatchMaterialNews struct {
	MediaId    string      `json:"media_id"`
	Content    ArticleNews `json:"content"`
	UpdateTime int64       `json:"update_time"` // 这篇图文消息素材的最后更新时间
}

type BatchMaterialNewsResponse

type BatchMaterialNewsResponse struct {
	TotalCount int                 `json:"total_count"` // 该类型的素材的总数
	ItemCount  int                 `json:"item_count"`  // 本次调用获取的素材的数量
	Item       []BatchMaterialNews `json:"item"`
	common.PublicError
}

type BatchMaterialRequest

type BatchMaterialRequest struct {
	Type   WechatMediaType `json:"type"`   // 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
	Offset int             `json:"offset"` // 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
	Count  int             `json:"count"`  // 返回素材的数量,取值在1到20之间
}

type BatchMaterialResponse

type BatchMaterialResponse struct {
	TotalCount int                 `json:"total_count"` // 该类型的素材的总数
	ItemCount  int                 `json:"item_count"`  // 本次调用获取的素材的数量
	Item       []BatchMaterialNews `json:"item"`
	common.PublicError
}

type Button

type Button struct {
	Name      string   `json:"name"`                 // 菜单标题,不超过16个字节,子菜单不超过60个字节
	Type      string   `json:"type,omitempty"`       // 菜单的响应动作类型,view表示网页类型,click表示点击类型,miniprogram表示小程序类型
	Key       string   `json:"key,omitempty"`        // 菜单KEY值,用于消息接口推送,不超过128字节
	Url       string   `json:"url,omitempty"`        // 网页链接,用户点击菜单可打开链接,不超过1024字节。
	Appid     string   `json:"appid,omitempty"`      // 小程序的appid
	Pagepath  string   `json:"pagepath,omitempty"`   // 小程序的页面路径
	SubButton []Button `json:"sub_button,omitempty"` // 二级菜单数组,个数应为1~5个
}

type Buttons

type Buttons struct {
	Button []Button `json:"button"` // 一级菜单数组,个数应为1~3个
}

type CDATAText

type CDATAText struct {
	Text string `xml:",innerxml"`
}

防止回复消息时,出现xml格式错误

func Value2CDATA

func Value2CDATA(v string) CDATAText

处理数据结构,xml字段

type CallBackIP

type CallBackIP struct {
	IPList []string `json:"ip_list"` // 微信服务器IP地址列表
	*common.PublicError
}

type Comment

type Comment struct {
	UserCommentId string            `json:"user_comment_id"` // 用户评论id
	Openid        string            `json:"openid"`          // 用户公众号openid
	CreateTime    int64             `json:"create_time"`     // 评论时间
	Content       string            `json:"content"`         // 评论内容
	CommentType   WechatCommentType `json:"comment_type"`    // /是否精选评论,0为false即非精选,1为true,即精选
	Reply         struct {
		Content    string `json:"content"`     // 作者回复内容
		CreateTime int64  `json:"create_time"` // 作者回复时间
	} `json:"reply"`
}

type CommentRequest

type CommentRequest struct {
	MsgDataId     int               `json:"msg_data_id"`               // 群发返回的msg_data_id
	Index         int               `json:"index,omitempty"`           // 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文
	Begin         int               `json:"begin,omitempty"`           // 起始位置
	Count         int               `json:"count,omitempty"`           // 获取数目(>=50会被拒绝)
	Type          WechatCommentType `json:"type,omitempty"`            // type=0 普通评论&精选评论 type=1 普通评论 type=2 精选评论
	UserCommentId int               `json:"user_comment_id,omitempty"` // 用户评论id
	Content       string            `json:"content,omitempty"`         // 回复内容
}

type CommentResponse

type CommentResponse struct {
	Total   int       `json:"total"` // 总数,非comment的size
	Comment []Comment `json:"comment"`
	common.PublicError
}

type Conditional

type Conditional struct {
	Buttons
	Matchrule ConditionalRule `json:"matchrule"`
}

type ConditionalRule

type ConditionalRule struct {
	TagId              string        `json:"tag_id,omitempty"`                      // 用户标签的id,可通过用户标签管理接口获取
	Sex                WechatUserSex `json:"sex,string,omitempty"`                  // 性别:男(1)女(2),不填则不做匹配
	Country            string        `json:"country,omitempty"`                     // 国家信息,是用户在微信中设置的地区,具体请参考地区信息表
	Province           string        `json:"province,omitempty"`                    // 省份信息,是用户在微信中设置的地区,具体请参考地区信息表
	City               string        `json:"city,omitempty"`                        // 城市信息,是用户在微信中设置的地区,具体请参考地区信息表
	Language           string        `json:"language,omitempty"`                    // 语言信息,是用户在微信中设置的语言,具体请参考语言表: 1、简体中文 "zh_CN" 2、繁体中文TW "zh_TW" 3、繁体中文HK "zh_HK" 4、英文 "en" 5、印尼 "id" 6、马来 "ms" 7、西班牙 "es" 8、韩国 "ko" 9、意大利 "it" 10、日本 "ja" 11、波兰 "pl" 12、葡萄牙 "pt" 13、俄国 "ru" 14、泰文 "th" 15、越南 "vi" 16、阿拉伯语 "ar" 17、北印度 "hi" 18、希伯来 "he" 19、土耳其 "tr" 20、德语 "de" 21、法语 "fr"
	ClientPlatformType string        `json:"client_platform_type,string,omitempty"` // 客户端版本,当前只具体到系统型号:IOS(1), Android(2),Others(3),不填则不做匹配
}

type CustomerImageMessageRequest

type CustomerImageMessageRequest struct {
	CustomerMessageRequest
	Image struct {
		MediaId string `json:"media_id"` // 图片消息
	} `json:"image"`
}

type CustomerMessageRequest

type CustomerMessageRequest struct {
	Touser          string `json:"touser"` // 普通用户openid
	Msgtype         string `json:"msgtype"`
	Customerservice struct {
		KfAccount string `json:"kf_account"`
	} `json:"customerservice,omitempty"` // 客服账号
}

type CustomerServiceInfo

type CustomerServiceInfo struct {
	KfAccount        string `json:"kf_account"`                   // 完整客服帐号,格式为:帐号前缀@公众号微信号
	KfNick           string `json:"kf_nick"`                      // 客服昵称
	KfId             string `json:"kf_id"`                        // 客服编号
	KfHeadimgurl     string `json:"kf_headimgurl"`                // 客服头像
	KfWx             string `json:"kf_wx,omitempty"`              // 如果客服帐号已绑定了客服人员微信号,则此处显示微信号
	InviteWx         string `json:"invite_wx,omitempty"`          // 如果客服帐号尚未绑定微信号,但是已经发起了一个绑定邀请,则此处显示绑定邀请的微信号
	InviteExpireTime string `json:"invite_expire_time,omitempty"` // 如果客服帐号尚未绑定微信号,但是已经发起过一个绑定邀请,邀请的过期时间,为unix 时间戳
	InviteStatus     string `json:"invite_status,omitempty"`      // 邀请的状态,有等待确认“waiting”,被拒绝“rejected”,过期“expired”
}

type CustomerServiceInfoList

type CustomerServiceInfoList struct {
	KfList []CustomerServiceInfo `json:"kf_list,omitempty"`
	common.PublicError
}

type CustomerServiceInfoOnline

type CustomerServiceInfoOnline struct {
	KfAccount    string `json:"kf_account"`    // 完整客服帐号,格式为:帐号前缀@公众号微信号
	Status       int    `json:"status"`        // 客服在线状态,目前为:1、web 在线
	KfId         string `json:"kf_id"`         // 客服编号
	AcceptedCase int    `json:"accepted_case"` // 客服当前正在接待的会话数
}

type CustomerServiceInfoOnlineList

type CustomerServiceInfoOnlineList struct {
	KfOnlineList []CustomerServiceInfoOnline `json:"kf_online_list"`
	common.PublicError
}

type CustomerTextMessageRequest

type CustomerTextMessageRequest struct {
	CustomerMessageRequest
	Text struct {
		Content string `json:"content"` // 文本消息
	} `json:"text"`
}

type CustomerVideoMessageRequest

type CustomerVideoMessageRequest struct {
	CustomerMessageRequest
	Video struct {
		MediaId      string `json:"media_id"`
		ThumbMediaId string `json:"thumb_media_id"`
		Title        string `json:"title"`
		Description  string `json:"description"`
	} `json:"video"`
}

type CustomerVoiceMessageRequest

type CustomerVoiceMessageRequest struct {
	CustomerMessageRequest
	Voice struct {
		MediaId string `json:"media_id"` // 语音消息
	} `json:"voice"`
}

type GetMsgListParam

type GetMsgListParam struct {
	Starttime int64 `json:"starttime"` // 起始时间,unix时间戳
	Endtime   int64 `json:"endtime"`   // 结束时间,unix时间戳,每次查询时段不能超过24小时
	Msgid     int64 `json:"msgid"`     // 消息id顺序从小到大,从1开始
	Number    int64 `json:"number"`    // 每次获取条数,最多10000条
}

type GetMsgListResp

type GetMsgListResp struct {
	Worker   string `json:"worker"`   // 完整客服帐号,格式为:帐号前缀@公众号微信号
	Openid   string `json:"openid"`   // 用户标识
	Opercode int    `json:"opercode"` // 操作码,2002(客服发送信息),2003(客服接收消息)
	Text     string `json:"text"`     // 聊天记录
	Time     int64  `json:"time"`     // 操作时间,unix时间戳
	common.PublicError
}

type ImageMessage

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

type ImageMessageHandlerFunc

type ImageMessageHandlerFunc func(request *ImageMessage) string

type KfInfo

type KfInfo struct {
	KfAccount string `json:"kf_account"`          // 完整客服帐号,格式为:帐号前缀@公众号微信号,帐号前缀最多10个字符,必须是英文、数字字符或者下划线,后缀为公众号微信号,长度不超过30个字符
	Nickname  string `json:"nickname,omitempty"`  // 客服昵称,最长16个字
	Headimg   string `json:"headimg"`             // 客服头像
	InviteWx  string `json:"invite_wx,omitempty"` // 接收绑定邀请的客服微信号
}

type Kfsession

type Kfsession struct {
	KfAccount  string `json:"kf_account"`           // 完整客服帐号,格式为:帐号前缀@公众号微信号
	Openid     string `json:"openid"`               // 粉丝的openid
	Createtime int64  `json:"createtime,omitempty"` // 会话接入的时间
	LatestTime int64  `json:"latest_time"`          // 粉丝的最后一条消息的时间
	common.PublicError
}

type KfsessionList

type KfsessionList struct {
	Sessionlist []Kfsession `json:"sessionlist"`
	common.PublicError
}

type LinkMessage

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

type LinkMessageHandlerFunc

type LinkMessageHandlerFunc func(request *LinkMessage) string

type LocationHandlerFunc

type LocationHandlerFunc func(request *MsgEventLocation) string

type LocationMessage

type LocationMessage struct {
	ToUserName   string // 开发者微信号
	FromUserName string // 发送方帐号(一个OpenID)
	CreateTime   int64  // 消息创建时间 (整型)
	MsgType      string // shortvideo
	Location_X   string // 地理位置维度
	Location_Y   string // 地理位置经度
	Scale        int    // 地图缩放大小
	Label        string // 地理位置信息
	MsgId        int64  // 消息id,64位整型
}

type LocationMessageHandlerFunc

type LocationMessageHandlerFunc func(request *LocationMessage) string

type Material

type Material struct {
	MediaId string `json:"media_id"`      // 新增的图文消息素材的media_id
	Url     string `json:"url,omitempty"` // 上传图片的URL,可放置图文消息中使用。
	common.PublicError
}

type MaterialCount

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

type MaterialVideo

type MaterialVideo struct {
	Title        string `json:"title"`        // 视频素材的标题
	Introduction string `json:"introduction"` // 视频素材的描述
	DownUrl      string `json:"down_url"`     // 视频素材的地址
	common.PublicError
}

type MediaResponse

type MediaResponse struct {
	MediaType WechatMediaType `json:"type"`      // 媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb,主要用于视频与音乐格式的缩略图)
	MediaId   string          `json:"media_id"`  // 媒体文件上传后,获取标识
	CreateAt  int64           `json:"create_at"` // 媒体文件上传时间戳
	common.PublicError
}
type Menu struct {
	Menuid string  `json:"menuid,omitempty"`
	Menu   Buttons `json:"menu,omitempty"`
}
type MenuClickHandlerFunc func(request *MsgEventMenuClick) string
type MenuViewHandlerFunc func(request *MsgEventMenuView) string

type MsgEncryptRequest

type MsgEncryptRequest struct {
	XMLName    xml.Name `xml:"xml"`
	ToUserName string   // 开发者微信号
	Encrypt    string   // 加密的消息正文
}

加密后的微信消息结构

type MsgEncryptResponse

type MsgEncryptResponse struct {
	XMLName      xml.Name  `xml:"xml"`
	Encrypt      CDATAText // 加密的响应正文
	MsgSignature CDATAText // 响应正文加密的签名
	TimeStamp    int64     // 时间戳
	Nonce        CDATAText // 随机字符串
}

响应加密消息的结构

type MsgEventAnnualRenew

type MsgEventAnnualRenew struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID,此时发送方是系统帐号)
	CreateTime   int64    // 消息创建时间 (整型),时间戳
	MsgType      string   // 消息类型,event
	Event        string   // 事件类型 annual_renew,提醒公众号需要去年审了
	ExpiredTime  int64    // 有效期 (整形),指的是时间戳,将于该时间戳认证过期
}

type MsgEventLocation

type MsgEventLocation struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID)
	CreateTime   int64    // 消息创建时间 (整型)
	MsgType      string   // 消息类型,event
	Event        string   // 事件类型,LOCATION
	Latitude     string   // 地理位置纬度
	Longitude    string   // 地理位置经度
	Precision    string   // 地理位置精度
}

type MsgEventMenuClick

type MsgEventMenuClick struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID)
	CreateTime   int64    // 消息创建时间 (整型)
	MsgType      string   // 消息类型,event
	Event        string   // 事件类型,CLICK
	EventKey     string   // 事件KEY值,与自定义菜单接口中KEY值对应
}

type MsgEventMenuView

type MsgEventMenuView struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID)
	CreateTime   int64    // 消息创建时间 (整型)
	MsgType      string   // 消息类型,event
	Event        string   // 事件类型,VIEW
	EventKey     string   // 事件KEY值,设置的跳转URL
}

type MsgEventNamingVerifyFail

type MsgEventNamingVerifyFail struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID,此时发送方是系统帐号)
	CreateTime   int64    // 消息创建时间 (整型),时间戳
	MsgType      string   // 消息类型,event
	Event        string   // 事件类型 naming_verify_fail
	FailTime     string   // 失败发生时间 (整形),时间戳
	FailReason   string   // 认证失败的原因
}

type MsgEventNamingVerifySuccess

type MsgEventNamingVerifySuccess struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID,此时发送方是系统帐号)
	CreateTime   int64    // 消息创建时间 (整型),时间戳
	MsgType      string   // 消息类型,event
	Event        string   // 事件类型 naming_verify_success
	ExpiredTime  int64    // 有效期 (整形),指的是时间戳,将于该时间戳认证过期
}

type MsgEventQualificationVerifyFail

type MsgEventQualificationVerifyFail struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID,此时发送方是系统帐号)
	CreateTime   int64    // 消息创建时间 (整型),时间戳
	MsgType      string   // 消息类型,event
	Event        string   // 事件类型 qualification_verify_fail
	FailTime     string   // 失败发生时间 (整形),时间戳
	FailReason   string   // 认证失败的原因
}

type MsgEventQualificationVerifySuccess

type MsgEventQualificationVerifySuccess struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID,此时发送方是系统帐号)
	CreateTime   int64    // 消息创建时间 (整型),时间戳
	MsgType      string   // 消息类型,event
	Event        string   // 事件类型 qualification_verify_success
	ExpiredTime  int64    // 有效期 (整形),指的是时间戳,将于该时间戳认证过期
}

type MsgEventScan

type MsgEventScan struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID)
	CreateTime   int64    // 消息创建时间 (整型)
	MsgType      string   // 消息类型,event
	Event        string   // 事件类型,SCAN
	EventKey     string   // 事件KEY值,即创建二维码时的二维码scene_id,或者scene_str
	Ticket       string   // 二维码的ticket,可用来换取二维码图片
}

type MsgEventSubscribe

type MsgEventSubscribe struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID)
	CreateTime   int64    // 消息创建时间 (整型)
	MsgType      string   // 消息类型,event
	Event        string   // 事件类型,subscribe(订阅)、unsubscribe(取消订阅)
	EventKey     string   // 事件KEY值,如果有qrscene_为前缀,则表示为扫描二维码关注
	Ticket       string   // 二维码的ticket,可用来换取二维码图片
}

type MsgEventTemplateSendFinish

type MsgEventTemplateSendFinish struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 公众号微信号
	FromUserName string   // 接收模板消息的用户的openid
	CreateTime   int64    // 创建时间
	MsgType      string   // 消息类型,event
	Event        string   // 事件类型 TEMPLATESENDJOBFINISH
	MsgID        int64    // 消息ID
	Status       string   // 发送状态为成功:success, 发送状态为用户拒绝接收:failed:user block, 发送状态为发送失败(非用户拒绝):failed: system failed
}

type MsgEventVerifyExpired

type MsgEventVerifyExpired struct {
	XMLName      xml.Name `xml:"xml"`
	ToUserName   string   // 开发者微信号
	FromUserName string   // 发送方帐号(一个OpenID,此时发送方是系统帐号)
	CreateTime   int64    // 消息创建时间 (整型),时间戳
	MsgType      string   // 消息类型,event
	Event        string   // 事件类型 verify_expired
	ExpiredTime  int64    // 有效期 (整形),指的是时间戳,表示已于该时间戳认证过期,需要重新发起微信认证
}

type MsgImageResponse

type MsgImageResponse struct {
	XMLName      xml.Name  `xml:"xml"`
	ToUserName   CDATAText // 接收方帐号(收到的OpenID)
	FromUserName CDATAText // 开发者微信号
	CreateTime   int64     // 消息创建时间 (整型)
	MsgType      CDATAText // image
	Image        struct {
		MediaId CDATAText // 通过素材管理中的接口上传多媒体文件,得到的id。
	}
}

func NewMsgImageResponse

func NewMsgImageResponse(ToUserName, FromUserName, MediaId string) *MsgImageResponse

新建一个图片回复信息,返回结构格式

type MsgMusicResponse

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

func NewMsgMusicResponse

func NewMsgMusicResponse(ToUserName, FromUserName, Title, Description, ThumbMediaId, MusicUrl, HQMusicUrl string) *MsgMusicResponse

新建一个音乐回复信息,返回结构格式

type MsgNewsItemResponse

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

func NewMsgNewsItemResponse

func NewMsgNewsItemResponse(Title, Description, PicUrl, Url string) *MsgNewsItemResponse

新建一条图文消息,多个图文结构可以组成一个图文信息, 8条以内

type MsgNewsResponse

type MsgNewsResponse struct {
	XMLName      xml.Name              `xml:"xml"`
	ToUserName   CDATAText             // 接收方帐号(收到的OpenID)
	FromUserName CDATAText             // 开发者微信号
	CreateTime   int64                 // 消息创建时间 (整型)
	MsgType      CDATAText             // news
	ArticleCount int                   // 图文消息个数,限制为8条以内
	Articles     []MsgNewsItemResponse // 多条图文消息信息,默认第一个item为大图,注意,如果图文数超过8,则将会无响应
}

func NewMsgNewsResponse

func NewMsgNewsResponse(ToUserName, FromUserName string, items []MsgNewsItemResponse) *MsgNewsResponse

新建一个图文回复信息,返回结构格式,items 个数限制为8条以内

type MsgTextResponse

type MsgTextResponse struct {
	XMLName      xml.Name  `xml:"xml"`
	ToUserName   CDATAText // 接收方帐号(收到的OpenID)
	FromUserName CDATAText // 开发者微信号
	CreateTime   int64     // 消息创建时间 (整型)
	MsgType      CDATAText // text
	Content      CDATAText // 回复的消息内容(换行:在content中能够换行,微信客户端就支持换行显示)
}

func NewMsgTextResponse

func NewMsgTextResponse(ToUserName, FromUserName, Content string) *MsgTextResponse

新建一个文本回复信息,返回结构格式

type MsgVideoResponse

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

func NewMsgVideoResponse

func NewMsgVideoResponse(ToUserName, FromUserName, MediaId, Title, Description string) *MsgVideoResponse

新建一个视频回复信息,返回结构格式

type MsgVoiceResponse

type MsgVoiceResponse struct {
	XMLName      xml.Name  `xml:"xml"`
	ToUserName   CDATAText // 接收方帐号(收到的OpenID)
	FromUserName CDATAText // 开发者微信号
	CreateTime   int64     // 消息创建时间戳 (整型)
	MsgType      CDATAText // 语音,voice
	Voice        struct {
		MediaId CDATAText // 通过素材管理中的接口上传多媒体文件,得到的id
	}
}

func NewMsgVoiceResponse

func NewMsgVoiceResponse(ToUserName, FromUserName, MediaId string) *MsgVoiceResponse

新建一个语音回复信息,返回结构格式

type NamingVerifyFailHandlerFunc

type NamingVerifyFailHandlerFunc func(request *MsgEventNamingVerifyFail) string

type NamingVerifySuccessHandlerFunc

type NamingVerifySuccessHandlerFunc func(request *MsgEventNamingVerifySuccess) string

type QrcodeRequest

type QrcodeRequest struct {
	ExpireSeconds int64  `json:"expire_seconds"` // 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。
	ActionName    string `json:"action_name"`    // 二维码类型,QR_SCENE为临时的整型参数值,QR_STR_SCENE为临时的字符串参数值,QR_LIMIT_SCENE为永久的整型参数值,QR_LIMIT_STR_SCENE为永久的字符串参数值
	ActionInfo    struct {
		Scene struct {
			SceneId  int64  `json:"scene_id,omitempty"`  // 场景值ID,临时二维码时为32位非0整型,永久二维码时最大值为100000(目前参数只支持1--100000)
			SceneStr string `json:"scene_str,omitempty"` // 场景值ID(字符串形式的ID),字符串类型,长度限制为1到64
		} `json:"scene"`
	} `json:"action_info"` // 二维码详细信息
}

type QrcodeResponse

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

type QualificationVerifyFailHandlerFunc

type QualificationVerifyFailHandlerFunc func(request *MsgEventQualificationVerifyFail) string

type QualificationVerifySuccessHandlerFunc

type QualificationVerifySuccessHandlerFunc func(request *MsgEventQualificationVerifySuccess) string

type ScanHandlerFunc

type ScanHandlerFunc func(request *MsgEventScan) string

type SendTemplate

type SendTemplate struct {
	Touser      string `json:"touser"`        // 接收者openid
	TemplateId  string `json:"template_id"`   // 模板ID
	Url         string `json:"url,omitempty"` // 模板跳转链接
	Miniprogram struct {
		Appid    string `json:"appid"`    // 所需跳转到的小程序appid(该小程序appid必须与发模板消息的公众号是绑定关联关系)
		Pagepath string `json:"pagepath"` // 所需跳转到小程序的具体页面路径,支持带参数,(示例index?foo=bar)
	} `json:"miniprogram"` // 跳小程序所需数据,不需跳小程序可不用传该数据
	Data *map[string]SendTemplateData `json:"data"` // 模板数据
}

type SendTemplateData

type SendTemplateData struct {
	Value string `json:"value"` // 模板内容消息
	Color string `json:"color"` // 模板内容字体颜色,不填默认为黑色
}

type SendTemplateFinishHandlerFunc

type SendTemplateFinishHandlerFunc func(request *MsgEventTemplateSendFinish) string

type ShortUrlRequest

type ShortUrlRequest struct {
	Action  string `json:"action"`
	LongUrl string `json:"long_url"`
}

type ShortUrlResponse

type ShortUrlResponse struct {
	common.PublicError
	ShortUrl string `json:"short_url"`
}

type ShortVideoMessage

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

type ShortVideoMessageHandlerFunc

type ShortVideoMessageHandlerFunc func(request *ShortVideoMessage) string

type SubscribeHandlerFunc

type SubscribeHandlerFunc func(request *MsgEventSubscribe) string

type SubscribeTemplate

type SubscribeTemplate struct {
	Touser      string `json:"touser"`      // 填接收消息的用户openid
	TemplateId  string `json:"template_id"` // 订阅消息模板ID
	Url         string `json:"url"`         // 点击消息跳转的链接,需要有ICP备案
	Miniprogram struct {
		Appid    string `json:"appid"`    // 所需跳转到的小程序appid(该小程序appid必须与发模板消息的公众号是绑定关联关系,并且小程序要求是已发布的)
		Pagepath string `json:"pagepath"` // 所需跳转到小程序的具体页面路径,支持带参数,(示例index?foo=bar)
	} `json:"miniprogram"` // 跳小程序所需数据,不需跳小程序可不用传该数据
	Scene int                              `json:"scene,string"` // 订阅场景值
	Title string                           `json:"title"`        // 消息标题,15字以内
	Data  map[string]SubscribeTemplateData `json:"data"`         // 消息正文,value为消息内容文本(200字以内),没有固定格式,可用\n换行,color为整段消息内容的字体颜色(目前仅支持整段消息为一种颜色)
}

type SubscribeTemplateData

type SubscribeTemplateData struct {
	Value string `json:"value"` // 模板内容消息
	Color string `json:"color"` // 模板内容字体颜色,不填默认为黑色
}

type Template

type Template struct {
	TemplateId      string `json:"template_id"`                // 模板ID
	Title           string `json:"title,omitempty"`            // 模板标题
	PrimaryIndustry string `json:"primary_industry,omitempty"` // 模板所属行业的一级行业
	DeputyIndustry  string `json:"deputy_industry,omitempty"`  // 模板所属行业的二级行业
	Content         string `json:"content,omitempty"`          // 模板内容
	Example         string `json:"example,omitempty"`          // 模板示例
	common.PublicError
}

type TemplateIndustry

type TemplateIndustry struct {
	PrimaryIndustry   TemplateIndustryInfo `json:"primary_industry"`   // 帐号设置的主营行业
	SecondaryIndustry TemplateIndustryInfo `json:"secondary_industry"` // 帐号设置的副营行业
}

type TemplateIndustryInfo

type TemplateIndustryInfo struct {
	FirstClass  string `json:"first_class"`
	SecondClass string `json:"second_class"`
}

type Templates

type Templates struct {
	TemplateList []Template `json:"template_list"`
}

type TextMessage

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

type TextMessageHandlerFunc

type TextMessageHandlerFunc func(request *TextMessage) string

type Ticket

type Ticket struct {
	Ticket    string `json:"ticket"`     // 签名临时票据
	ExpiresIn string `json:"expires_in"` // 有效期,以秒为单位。在有效期内重复请求 ticket 不会被刷新
	common.PublicError
}

type TicketType

type TicketType string
const (
	WechatTicketTypeJsapi  TicketType = "jsapi"   // JSSDK获取ticket的type
	WechatTicketTypeWxcart TicketType = "wx_card" // 微信卡券
)

type UnSubscribeHandlerFunc

type UnSubscribeHandlerFunc func(request *MsgEventSubscribe) string

type VerifyExpireHandlerFunc

type VerifyExpireHandlerFunc func(request *MsgEventVerifyExpired) string

type VideoMessage

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

type VideoMessageHandlerFunc

type VideoMessageHandlerFunc func(request *VideoMessage) string

type VoiceMessage

type VoiceMessage struct {
	ToUserName   string // 开发者微信号
	FromUserName string // 发送方帐号(一个OpenID)
	CreateTime   int64  // 消息创建时间 (整型)
	MsgType      string // voice
	MediaId      string // 语音消息媒体id,可以调用多媒体文件下载接口拉取数据。
	Format       string // 语音格式,如amr,speex等
	MsgID        int64  // 消息id,64位整型
}

type VoiceMessageHandlerFunc

type VoiceMessageHandlerFunc func(request *VoiceMessage) string

type WaitcaseList

type WaitcaseList struct {
	Count        int         `json:"count"`        // 未接入会话数量
	Waitcaselist []Kfsession `json:"waitcaselist"` // 未接入会话列表,最多返回100条数据,按照来访顺序
	common.PublicError
}

type WechatAccessToken

type WechatAccessToken struct {
	AccessToken string `json:"access_token"` // 公众号获取到的凭证
	ExpiresIn   int64  `json:"expires_in"`   // 公众号凭证有效时间,单位:秒

	*common.PublicError
	// contains filtered or unexported fields
}

type WechatArticleNeedOpenComment

type WechatArticleNeedOpenComment int

图文消息,是否打开评论

type WechatArticleOnlyFansCanComment

type WechatArticleOnlyFansCanComment int

图文消息,是否只有粉丝才可以评论

type WechatArticleShowCoverPic

type WechatArticleShowCoverPic int

图文消息,是否显示封面

type WechatAuthScope

type WechatAuthScope string
const (
	WechatAuthScopeSnsapiBase     WechatAuthScope = "snsapi_base"     // 静默授权
	WechatAuthScopeSnsapiUserinfo WechatAuthScope = "snsapi_userinfo" // 弹出授权页面
)

type WechatClientPlatformType

type WechatClientPlatformType int
const (
	WechatClientPlatformTypeIOS     WechatClientPlatformType = iota + 1 // iOS 系统
	WechatClientPlatformTypeAndroid                                     // Android 系统
	WechatClientPlatformTypeOthers                                      // 其他手机系统
)

type WechatCommentType

type WechatCommentType int

评论类型

type WechatMediaType

type WechatMediaType string
const (
	WechatMediaTypeImage WechatMediaType = "image" // 素材类型:图片
	WechatMediaTypeVoice WechatMediaType = "voice" // 素材类型:语音
	WechatMediaTypeVideo WechatMediaType = "video" // 素材类型:视频
	WechatMediaTypeThumb WechatMediaType = "thumb" // 素材类型:缩略图,主要用于视频与音乐格式的缩略图
	WechatMediaTypeNews  WechatMediaType = "news"  // 素材类型:图文
)

type WechatMp

type WechatMp struct {
	Configure                         WechatMpConfig
	AccessToken                       *WechatAccessToken                    // 保存微信accessToken
	AccessTokenHandler                AccessTokenHandlerFunc                // 处理微信accessToken,如果有缓存,可以将accessToken存储到缓存中,默认存储到内存中
	SubscribeHandler                  SubscribeHandlerFunc                  // 关注微信公众号处理方法
	UnSubscribeHandler                UnSubscribeHandlerFunc                // 取消关注公众号处理方法
	ScanHandler                       ScanHandlerFunc                       // 扫描此微信公众号生成的二维码处理方法
	LocationHandler                   LocationHandlerFunc                   // 上报地理位置的处理方法
	MenuClickHandler                  MenuClickHandlerFunc                  // 自定义菜单点击的处理方法
	MenuViewHandler                   MenuViewHandlerFunc                   // 自定义菜单跳转外链的处理方法
	QualificationVerifySuccessHandler QualificationVerifySuccessHandlerFunc // 资质认证成功处理方法
	QualificationVerifyFailHandler    QualificationVerifyFailHandlerFunc    // 资质认证失败处理方法
	NamingVerifySuccessHandler        NamingVerifySuccessHandlerFunc        // 名称认证成功的处理方法
	NamingVerifyFailHandler           NamingVerifyFailHandlerFunc           // 名称认证失败的处理方法
	AnnualRenewHandler                AnnualRenewHandlerFunc                // 年审通知的处理方法
	VerifyExpiredHandler              VerifyExpireHandlerFunc               // 认证过期失效通知的处理方法
	SendTemplateFinishHandler         SendTemplateFinishHandlerFunc         // 发送模板消息结果通知
	TextMessageHandler                TextMessageHandlerFunc                // 发送文本信息的处理方法
	ImageMessageHandler               ImageMessageHandlerFunc               // 发送图片消息的处理方法
	VoiceMessageHandler               VoiceMessageHandlerFunc               // 发送语言消息的处理方法
	VideoMessageHandler               VideoMessageHandlerFunc               // 发送视频消息的处理方法
	ShortVideoMessageHandler          ShortVideoMessageHandlerFunc          // 发送短视频消息的处理方法
	LocationMessageHandler            LocationMessageHandlerFunc            // 上报地理位置的处理方法
	LinkMessageHandler                LinkMessageHandlerFunc                // 发送链接消息的处理方法
}

func New

func New(wechatMpConfig *WechatMpConfig) *WechatMp

新建一个微信公众号

func (*WechatMp) AESEncryptMessage

func (wm *WechatMp) AESEncryptMessage(plainData []byte) (*MsgEncryptResponse, error)

加密发送消息

func (*WechatMp) AccessTokenFromWechat

func (wm *WechatMp) AccessTokenFromWechat() (*WechatAccessToken, error)

获取微信通行证

func (*WechatMp) AddConditional

func (wm *WechatMp) AddConditional(accessToken string, conditional Conditional) (string, error)

创建个性化菜单

func (*WechatMp) AddKfaccount

func (wm *WechatMp) AddKfaccount(accessToken string, kfInfo *KfInfo) (*common.PublicError, error)

添加客服账号

func (*WechatMp) AddMaterial

func (wm *WechatMp) AddMaterial(accessToken string, mediaType WechatMediaType, file multipart.FileHeader, videoRequest *MaterialVideo) (*Material, error)

新增其他类型永久素材 在上传视频素材时需要POST另一个表单,id为description,包含素材的描述信息,内容格式为JSON TODO 待验证

func (*WechatMp) AddMaterialNews

func (wm *WechatMp) AddMaterialNews(accessToken string, articles *Articles) (*Material, error)

新增永久图文素材

func (*WechatMp) AddTemplate

func (wm *WechatMp) AddTemplate(accessToken, templateCode string) (*Template, error)

从模板库中添加模板 templateCode: 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式 TODO 待验证

func (*WechatMp) AuthWechatServer

func (wm *WechatMp) AuthWechatServer(r *http.Request) string

用户在设置微信公众号服务器配置,并开启后,微信会发送一次认证请求,此函数即做此验证用

func (*WechatMp) BatchBlackUsers

func (wm *WechatMp) BatchBlackUsers(accessToken string, openidList ...string) (*common.PublicError, error)

批量拉黑用户

func (*WechatMp) BatchGetMaterial

func (wm *WechatMp) BatchGetMaterial(accessToken string, request *BatchMaterialRequest) (*BatchMaterialResponse, error)

批量获取素材列表,图文素材单独获取:BatchGetNewsMaterial

func (*WechatMp) BatchGetNewsMaterial

func (wm *WechatMp) BatchGetNewsMaterial(accessToken string, request *BatchMaterialRequest) (*BatchMaterialNewsResponse, error)

批量获取图文素材列表

func (*WechatMp) BatchTagging

func (wm *WechatMp) BatchTagging(accessToken string)

批量为用户打标签

func (*WechatMp) BatchUnBlackUsers

func (wm *WechatMp) BatchUnBlackUsers(accessToken string, openidList ...string) (*common.PublicError, error)

批量取消拉黑用户

func (*WechatMp) BatchUnTagging

func (wm *WechatMp) BatchUnTagging(accessToken string)

批量为用户取消标签

func (*WechatMp) BatchUserInfos

func (wm *WechatMp) BatchUserInfos(accessToken string, userList *WechatUserList) (*WechatUserInfoList, error)

批量获取用户基本信息

func (*WechatMp) BuildSubscribeMsgURL

func (wm *WechatMp) BuildSubscribeMsgURL(scene int, templateId, redirectUrl, reserved string) string

一次性订阅消息的授权URL

func (*WechatMp) BuildWebAuthCodeURL

func (wm *WechatMp) BuildWebAuthCodeURL(redirectUrl string, scope WechatAuthScope, state string) string

网页授权,拼接获取code的URL

func (*WechatMp) CallBackFunc

func (wm *WechatMp) CallBackFunc(r *http.Request) string

微信服务推送消息接收方法

func (*WechatMp) CloseComment

func (wm *WechatMp) CloseComment(accessToken string, msgDataId int, index int) (*common.PublicError, error)

关闭已群发文章评论 msgDataId:群发返回的msg_data_id, index: 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文

func (*WechatMp) CloseKfsession

func (wm *WechatMp) CloseKfsession(accessToken string, kfsession *Kfsession) (*common.PublicError, error)

关闭会话

func (*WechatMp) CreateKfsession

func (wm *WechatMp) CreateKfsession(accessToken string, kfsession *Kfsession) (*common.PublicError, error)

创建会话

func (*WechatMp) CreateMenu

func (wm *WechatMp) CreateMenu(accessToken string, buttons Buttons) (*common.PublicError, error)

自定义菜单创建接口

func (*WechatMp) CreateTag

func (wm *WechatMp) CreateTag(accessToken string, tag *WechatUserTag) (*WechatUserTag, error)

创建标签

func (*WechatMp) DeleteComment

func (wm *WechatMp) DeleteComment(accessToken string, comment *CommentRequest) (*common.PublicError, error)

删除评论

func (*WechatMp) DeleteConditional

func (wm *WechatMp) DeleteConditional(accessToken string, menuid string) (*common.PublicError, error)

删除个性化菜单

func (*WechatMp) DeleteKfaccount

func (wm *WechatMp) DeleteKfaccount(accessToken string, kfInfo *KfInfo) (*common.PublicError, error)

删除客服账号

func (*WechatMp) DeleteMaterial

func (wm *WechatMp) DeleteMaterial(accessToken, mediaId string) (*common.PublicError, error)

删除永久素材

func (*WechatMp) DeleteMenu

func (wm *WechatMp) DeleteMenu(accessToken string) (*common.PublicError, error)

自定义菜单删除接口

func (*WechatMp) DeleteReply

func (wm *WechatMp) DeleteReply(accessToken string, comment *CommentRequest) (*common.PublicError, error)

删除回复

func (*WechatMp) DeleteTag

func (wm *WechatMp) DeleteTag(accessToken string)

删除标签

func (*WechatMp) DeleteTemplate

func (wm *WechatMp) DeleteTemplate(accessToken, templateId string) (*common.PublicError, error)

删除模板

func (*WechatMp) GetAllTemplates

func (wm *WechatMp) GetAllTemplates(accessToken string) (*Templates, error)

获取已添加至帐号下所有模板列表

func (*WechatMp) GetBlackList

func (wm *WechatMp) GetBlackList(accessToken, beginOpenId string) (*WechatUserOpenIdList, error)

获取公众号的黑名单列表

func (*WechatMp) GetCallBackIP

func (wm *WechatMp) GetCallBackIP(accessToken string) (*CallBackIP, error)

获取微信服务器IP地址

func (*WechatMp) GetKfList

func (wm *WechatMp) GetKfList(accessToken string) (*CustomerServiceInfoList, error)

获取客服基本信息

func (*WechatMp) GetKfsession

func (wm *WechatMp) GetKfsession(accessToken, openid string) (*Kfsession, error)

获取客户会话状态

func (*WechatMp) GetKfsessionList

func (wm *WechatMp) GetKfsessionList(accessToken, kfAccount string) (*KfsessionList, error)

获取客服会话列表

func (*WechatMp) GetMaterialCount

func (wm *WechatMp) GetMaterialCount(accessToken string) (*MaterialCount, error)

获取素材总数

func (*WechatMp) GetMedia

func (wm *WechatMp) GetMedia(accessToken, mediaId string) (*[]byte, *common.PublicError, error)

获取临时素材

func (*WechatMp) GetMenu

func (wm *WechatMp) GetMenu(accessToken string) (*Menu, error)

自定义菜单查询接口

func (*WechatMp) GetMsgrecordList

func (wm *WechatMp) GetMsgrecordList(accessToken string, param *GetMsgListParam) (*GetMsgListResp, error)

获取聊天记录

func (*WechatMp) GetNewsMaterial

func (wm *WechatMp) GetNewsMaterial(accessToken, mediaId string) (*ArticleNews, error)

获取永久图文素材

func (*WechatMp) GetOnlineKfList

func (wm *WechatMp) GetOnlineKfList(accessToken string) (*CustomerServiceInfoOnlineList, error)

获取客服基本信息

func (*WechatMp) GetOtherMaterial

func (wm *WechatMp) GetOtherMaterial(accessToken, mediaId string) ([]byte, error)

获取其他类型的素材,自己转换

func (*WechatMp) GetTags

func (wm *WechatMp) GetTags(accessToken string) (*WechatUserTags, error)

获取公众号已创建的标签

func (*WechatMp) GetTagsWithUser

func (wm *WechatMp) GetTagsWithUser(accessToken string)

获取用户身上的标签列表

func (*WechatMp) GetTemplateIndustries

func (wm *WechatMp) GetTemplateIndustries(accessToken string) (*TemplateIndustry, error)

获取设置的行业信息

func (*WechatMp) GetTicket

func (wm *WechatMp) GetTicket(accessToken string, ticketType TicketType) (*Ticket, error)

获取微信ticket

func (*WechatMp) GetUsers

func (wm *WechatMp) GetUsers(accessToken, nextOpenId string) (*WechatUserOpenIdList, error)

获取用户列表

func (*WechatMp) GetUsersWithTag

func (wm *WechatMp) GetUsersWithTag(accessToken string)

获取标签下粉丝列表

func (*WechatMp) GetVideoMaterial

func (wm *WechatMp) GetVideoMaterial(accessToken, mediaId string) (*MaterialVideo, error)

获取永久视频素材

func (*WechatMp) GetWaitcaseList

func (wm *WechatMp) GetWaitcaseList(accessToken string) (*WaitcaseList, error)

获取未接入会话列表

func (*WechatMp) InviteKfaccount

func (wm *WechatMp) InviteKfaccount(accessToken string, kfInfo *KfInfo) (*common.PublicError, error)

邀请绑定客服帐号

func (*WechatMp) JsapiSign

func (wm *WechatMp) JsapiSign(accessToken string, timeStamp int64, nonceStr, url string) (*string, error)

获取jsapi的签名 timeStamp: 时间戳,nonceStr: 随机字符串,url: 调用JSSDK的路径

func (*WechatMp) ListComment

func (wm *WechatMp) ListComment(accessToken string, comment *CommentRequest) (*CommentResponse, error)

查看指定文章的评论数据

func (*WechatMp) Long2Short

func (wm *WechatMp) Long2Short(accessToken, longUrl string) (*ShortUrlResponse, error)

长链接转短链接接口

func (*WechatMp) MarkComment

func (wm *WechatMp) MarkComment(accessToken string, comment *CommentRequest) (*common.PublicError, error)

将评论标记精选

func (*WechatMp) OpenComment

func (wm *WechatMp) OpenComment(accessToken string, msgDataId int, index int) (*common.PublicError, error)

打开已群发文章评论 msgDataId:群发返回的msg_data_id, index: 多图文时,用来指定第几篇图文,从0开始,不带默认操作该msg_data_id的第一篇图文

func (*WechatMp) QrcodeIntCreate

func (wm *WechatMp) QrcodeIntCreate(accessToken string, sceneId, expireSeconds int64) (*QrcodeResponse, error)

创建临时二维码,整型场景值

func (*WechatMp) QrcodeIntLimitCreate

func (wm *WechatMp) QrcodeIntLimitCreate(accessToken string, sceneId int64) (*QrcodeResponse, error)

创建永久二维码,整型场景值

func (*WechatMp) QrcodeShow

func (wm *WechatMp) QrcodeShow(ticket string) ([]byte, error)

显示二维码图片

func (*WechatMp) QrcodeStrCreate

func (wm *WechatMp) QrcodeStrCreate(accessToken string, sceneStr string, expireSeconds int64) (*QrcodeResponse, error)

创建临时二维码,字符串场景值

func (*WechatMp) QrcodeStrLimitCreate

func (wm *WechatMp) QrcodeStrLimitCreate(accessToken, sceneStr string) (*QrcodeResponse, error)

创建永久二维码,字符串场景值

func (*WechatMp) ReplyComment

func (wm *WechatMp) ReplyComment(accessToken string, comment *CommentRequest) (*common.PublicError, error)

回复评论

func (*WechatMp) SendCustomerImageMessage

func (wm *WechatMp) SendCustomerImageMessage(accessToken string, imageMessage *CustomerImageMessageRequest) (*common.PublicError, error)

客服发送图片消息

func (*WechatMp) SendCustomerMessage

func (wm *WechatMp) SendCustomerMessage(accessToken string, message interface{}) (*common.PublicError, error)

发送客服消息

func (*WechatMp) SendCustomerTextMessage

func (wm *WechatMp) SendCustomerTextMessage(accessToken string, textMessage *CustomerTextMessageRequest) (*common.PublicError, error)

客服发送文本消息

func (*WechatMp) SendCustomerVideoMessage

func (wm *WechatMp) SendCustomerVideoMessage(accessToken string, videoMessage *CustomerVideoMessageRequest) (*common.PublicError, error)

客服发送视频消息

func (*WechatMp) SendCustomerVoiceMessage

func (wm *WechatMp) SendCustomerVoiceMessage(accessToken string, voiceMessage *CustomerVoiceMessageRequest) (*common.PublicError, error)

客服发送语音消息

func (*WechatMp) SendTemplate

func (wm *WechatMp) SendTemplate(accessToken string, template *SendTemplate) (*int64, error)

发送模板消息

func (*WechatMp) SetAccessTokenHandlerFunc

func (wm *WechatMp) SetAccessTokenHandlerFunc(handlerFunc AccessTokenHandlerFunc)

设置全局获取微信accessToken的方法

func (*WechatMp) SetImageHandlerFunc

func (wm *WechatMp) SetImageHandlerFunc(handlerFunc ImageMessageHandlerFunc)

设置处理微信image消息事件方法

func (*WechatMp) SetLocationHandlerFunc

func (wm *WechatMp) SetLocationHandlerFunc(handlerFunc LocationHandlerFunc)

设置处理上报地理位置的方法

func (*WechatMp) SetMenuClickHandlerFunc

func (wm *WechatMp) SetMenuClickHandlerFunc(handlerFunc MenuClickHandlerFunc)

设置处理自定义菜单点击事件的方法

func (*WechatMp) SetMenuViewHandlerFunc

func (wm *WechatMp) SetMenuViewHandlerFunc(handlerFunc MenuViewHandlerFunc)

设置处理自定义菜单跳转外链事件的方法

func (*WechatMp) SetScanHandlerFunc

func (wm *WechatMp) SetScanHandlerFunc(handlerFunc ScanHandlerFunc)

设置处理扫描事件的方法

func (*WechatMp) SetSubscribeHandlerFunc

func (wm *WechatMp) SetSubscribeHandlerFunc(handlerFunc SubscribeHandlerFunc)

设置处理关注事件的方法

func (*WechatMp) SetTemplateIndustries

func (wm *WechatMp) SetTemplateIndustries(accessToken string, industryIds [2]int) (*common.PublicError, error)

设置所属行业

func (*WechatMp) SetTextHandlerFunc

func (wm *WechatMp) SetTextHandlerFunc(handlerFunc TextMessageHandlerFunc)

设置处理微信text消息事件方法

func (*WechatMp) SetUnSubscribeHandlerFunc

func (wm *WechatMp) SetUnSubscribeHandlerFunc(handlerFunc UnSubscribeHandlerFunc)

设置处理取消关注事件的方法

func (*WechatMp) SetVideoHandlerFunc

func (wm *WechatMp) SetVideoHandlerFunc(handlerFunc VideoMessageHandlerFunc)

设置处理微信video消息事件方法

func (*WechatMp) SetVoiceHandlerFunc

func (wm *WechatMp) SetVoiceHandlerFunc(handlerFunc VoiceMessageHandlerFunc)

设置处理微信voice消息事件方法

func (*WechatMp) SubscribeTemplate

func (wm *WechatMp) SubscribeTemplate(accessToken string, template *SubscribeTemplate) (*common.PublicError, error)

通过API推送订阅模板消息给到授权微信用户 TODO 待验证

func (*WechatMp) TrymatchConditional

func (wm *WechatMp) TrymatchConditional(accessToken, userId string) (*Buttons, error)

测试个性化菜单匹配结果

func (*WechatMp) UnMarkComment

func (wm *WechatMp) UnMarkComment(accessToken string, comment *CommentRequest) (*common.PublicError, error)

将评论取消精选

func (*WechatMp) UpdateKfaccount

func (wm *WechatMp) UpdateKfaccount(accessToken string, kfInfo *KfInfo) (*common.PublicError, error)

设置客服信息

func (*WechatMp) UpdateMaterial

func (wm *WechatMp) UpdateMaterial(accessToken string, article *ArticleUpdate) (*common.PublicError, error)

修改永久图文素材

func (*WechatMp) UpdateTag

func (wm *WechatMp) UpdateTag(accessToken string)

编辑标签

func (*WechatMp) UpdateUserRemark

func (wm *WechatMp) UpdateUserRemark(accessToken string)

设置用户备注名

func (*WechatMp) UploadMedia

func (wm *WechatMp) UploadMedia(accessToken string, mediaType WechatMediaType, file multipart.FileHeader) (*MediaResponse, error)

1、临时素材media_id是可复用的。

2、媒体文件在微信后台保存时间为3天,即3天后media_id失效。

3、上传临时素材的格式、大小限制与公众平台官网一致。

图片(image): 2M,支持PNG\JPEG\JPG\GIF格式

语音(voice):2M,播放长度不超过60s,支持AMR\MP3格式

视频(video):10MB,支持MP4格式

缩略图(thumb):64KB,支持JPG格式

4、需使用https调用本接口。

新增临时素材

func (*WechatMp) UploadMediaImg

func (wm *WechatMp) UploadMediaImg(accessToken string, file multipart.FileHeader) (*Material, error)

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

func (*WechatMp) UploadheadimgKfaccount

func (wm *WechatMp) UploadheadimgKfaccount(accessToken string, kfInfo *KfInfo) (*common.PublicError, error)

TODO 上传客服头像

func (*WechatMp) UserInfo

func (wm *WechatMp) UserInfo(accessToken, openid string) (*WechatUserInfo, error)

获取用户基本信息

func (*WechatMp) WebAuthAccessToken

func (wm *WechatMp) WebAuthAccessToken(code string) (*WechatWebAuthAccessToken, error)

通过code换取网页授权access_token

func (*WechatMp) WebAuthCheck

func (wm *WechatMp) WebAuthCheck(accessToken, openid string) (*common.PublicError, error)

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

func (*WechatMp) WebAuthRefreshAccessToken

func (wm *WechatMp) WebAuthRefreshAccessToken(refreshToken string) (*WechatWebAuthAccessToken, error)

刷新网页授权accessToken

func (*WechatMp) WebAuthUserInfo

func (wm *WechatMp) WebAuthUserInfo(accessToken, openid string) (*WechatWebAuthUserInfo, error)

网页授权,拉取用户信息(需scope为 snsapi_userinfo)

type WechatMpConfig

type WechatMpConfig struct {
	AppId          string `json:"app_id"`                     // 公众号appId
	AppSecret      string `json:"app_secret"`                 // 公众号appSecret
	Token          string `json:"token"`                      // 公众号Token
	EncodingAESKey string `json:"encoding_aes_key,omitempty"` // 公众号EncodingAESKey
}

type WechatUserInfo

type WechatUserInfo struct {
	Subscribe     int           `json:"subscribe"`      // 用户是否订阅该公众号标识,值为0时,代表此用户没有关注该公众号,拉取不到其余信息。
	Openid        string        `json:"openid"`         // 用户的标识,对当前公众号唯一
	Nickname      string        `json:"nickname"`       // 用户的昵称
	Sex           WechatUserSex `json:"sex"`            // 用户的性别,值为1时是男性,值为2时是女性,值为0时是未知
	City          string        `json:"city"`           // 用户所在城市
	Country       string        `json:"country"`        // 用户所在国家
	Province      string        `json:"province"`       // 用户所在省份
	Language      string        `json:"language"`       // 用户的语言,简体中文为zh_CN
	Headimgurl    string        `json:"headimgurl"`     // 用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空。若用户更换头像,原有头像URL将失效。
	SubscribeTime int64         `json:"subscribe_time"` // 用户关注时间,为时间戳。如果用户曾多次关注,则取最后关注时间
	Unionid       string        `json:"unionid"`        // 只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。
	Remark        string        `json:"remark"`         // 公众号运营者对粉丝的备注,公众号运营者可在微信公众平台用户管理界面对粉丝添加备注
	Groupid       int           `json:"groupid"`        // 用户所在的分组ID(兼容旧的用户分组接口)
	TagidList     []int         `json:"tagid_list"`     // 用户被打上的标签ID列表
	common.PublicError
}

type WechatUserInfoList

type WechatUserInfoList struct {
	UserInfoList []WechatUserInfo `json:"user_info_list"`
	common.PublicError
}

type WechatUserList

type WechatUserList struct {
	UserList []WechatUserInfo `json:"user_list"`
}

type WechatUserOpenIdList

type WechatUserOpenIdList struct {
	Total int `json:"total"` // 关注该公众账号的总用户数
	Count int `json:"count"` // 拉取的OPENID个数,最大值为10000
	Data  struct {
		Openid []string `json:"openid"`
	} `json:"data"` // 列表数据,OPENID的列表
	NextOpenid string `json:"next_openid"` // 拉取列表的最后一个用户的OPENID
	common.PublicError
}

type WechatUserSex

type WechatUserSex int
const (
	WechatSexUnknow WechatUserSex = iota // 未知性别
	WechatSexMale                        // 男性
	WechatSexFemale                      // 女性
)

type WechatUserTag

type WechatUserTag struct {
	Id    int    `json:"id,omitempty"`    // 标签id,由微信分配
	Name  string `json:"name"`            // 标签名,UTF8编码 (30个字符以内)
	Count int    `json:"count,omitempty"` // 此标签下粉丝数
	common.PublicError
}

type WechatUserTags

type WechatUserTags struct {
	Tags []WechatUserTag `json:"tags"`
}

type WechatWebAuthAccessToken

type WechatWebAuthAccessToken struct {
	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"`        // 用户唯一标识
	Scope        string `json:"scope"`         // 用户授权的作用域,使用逗号(,)分隔
	common.PublicError
}

微信网页授权accessToken

type WechatWebAuthUserInfo

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

微信网页授权获取用户信息

Jump to

Keyboard shortcuts

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