Documentation
¶
Index ¶
- Constants
- func DecodeBytesToUint32(b []byte) uint32
- func EncodeUint32ToBytes(i uint32) []byte
- type AESCBCCrypto
- type AESPaddingMode
- type AccessToken
- type Action
- func BatchBlackList(openids []string) Action
- func BatchGetSubscriberInfo(openids []string, receiver *[]SubscriberInfo) Action
- func BatchUnBlackList(openids []string) Action
- func CheckAuthToken(openid string) Action
- func CreateConditionalMenu(matchRule *MenuMatchRule, buttons ...Button) Action
- func CreateMenu(buttons ...Button) Action
- func DeleteConditionalMenu(menuID string) Action
- func DeleteMenu() Action
- func GetAuthUser(openid string, receiver *AuthUser) Action
- func GetBlackList(beginOpenID string, receiver *SubscriberList) Action
- func GetJSAPITicket(receiver *JSAPITicket) Action
- func GetMenuList(receiver *MenuList) Action
- func GetSubscriberInfo(openid string, receiver *SubscriberInfo) Action
- func GetSubscriberList(nextOpenID string, receiver *SubscriberList) Action
- func SendTemplateMessage(msg *TemplateMessage) Action
- func SetUserRemark(openid, remark string) Action
- func UploadMaterialImage(filename string, receiver *MaterialUploadResult) Action
- func UploadMaterialNews(articles []*MaterialArticle, receiver *MaterialUploadResult) Action
- func UploadMedia(mediaType MediaType, filename string, receiver *MediaUploadResult) Action
- type Article
- type AuthToken
- type AuthUser
- type BatchSubscriberInfo
- type Button
- func ClickButton(name, key string) Button
- func GroupButton(name string, buttons ...Button) Button
- func LocationSelectButton(name, key string) Button
- func MPButton(name, appid, pagePath, url string) Button
- func MediaButton(name, mediaID string) Button
- func PicPhotoOrAlbumButton(name, key string) Button
- func PicSysphotoButton(name, key string) Button
- func PicWeixinButton(name, key string) Button
- func ScancodePushButton(name, key string) Button
- func ScancodeWaitMsgButton(name, key string) Button
- func ViewButton(name, url string) Button
- func ViewLimitedButton(name, mediaID string) Button
- type CDATA
- type ConditionalMenu
- type DefaultMenu
- type EventMessage
- type HTTPBody
- type HTTPClient
- type HTTPOption
- type ImageReply
- type JSAPITicket
- type MaterialArticle
- type MaterialUploadResult
- type MediaType
- type MediaUploadResult
- type MenuButton
- type MenuList
- type MenuMatchRule
- type MessageBody
- type MusicReply
- type NewsReply
- type PostBody
- type Reply
- func NewArticleReply(count int, articles ...Article) Reply
- func NewImageReply(mediaID string) Reply
- func NewMusicReply(mediaID, title, desc, url, HQUrl string) Reply
- func NewTextReply(content string) Reply
- func NewTransfer2KFReply(kfAccount ...string) Reply
- func NewVideoReply(mediaID, title, desc string) Reply
- func NewVoiceReply(mediaID string) Reply
- type ReplyHeader
- type ReplyMessage
- type SubscriberInfo
- type SubscriberList
- type SubscriberListData
- type TemplateMessage
- type TextReply
- type TransInfo
- type Transfer2KFReply
- type VideoReply
- type VoiceReply
- type WXClient
- type WechatAPI
- type WechatOA
- func (w *WechatOA) AccessToken(options ...HTTPOption) (*AccessToken, error)
- func (w *WechatOA) Code2AuthToken(code string, options ...HTTPOption) (*AuthToken, error)
- func (w *WechatOA) DecryptEvent(cipherText string) (*EventMessage, error)
- func (w *WechatOA) Do(accessToken string, action Action, options ...HTTPOption) error
- func (w *WechatOA) EncryptReply(from, to string, reply Reply) (*ReplyMessage, error)
- func (w *WechatOA) RefreshAuthToken(refreshToken string, options ...HTTPOption) (*AuthToken, error)
- func (w *WechatOA) SetEncodingAESKey(aesKey string)
- func (w *WechatOA) SetSignToken(token string)
- type X
Constants ¶
const ( CgiBinAccessTokenURL = "https://api.weixin.qq.com/cgi-bin/token" CgiBinTicketURL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket" )
cgi-bin
const ( MenuCreateURL = "https://api.weixin.qq.com/cgi-bin/menu/create" MenuAddConditionalURL = "https://api.weixin.qq.com/cgi-bin/menu/addconditional" MenuListURL = "https://api.weixin.qq.com/cgi-bin/menu/get" MenuDeleteURL = "https://api.weixin.qq.com/cgi-bin/menu/delete" MenuDeleteConditionalURL = "https://api.weixin.qq.com/cgi-bin/menu/delconditional" )
menu
const ( SnsCode2TokenURL = "https://api.weixin.qq.com/sns/oauth2/access_token" SnsCheckAccessTokenURL = "https://api.weixin.qq.com/sns/auth" SnsRefreshAccessTokenURL = "https://api.weixin.qq.com/sns/oauth2/refresh_token" SnsUserInfoURL = "https://api.weixin.qq.com/sns/userinfo" )
sns
const ( SubscriberGetURL = "https://api.weixin.qq.com/cgi-bin/user/info" SubscriberBatchGetURL = "https://api.weixin.qq.com/cgi-bin/user/info/batchget" SubscriberListURL = "https://api.weixin.qq.com/cgi-bin/user/get" BlackListGetURL = "https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist" BatchBlackListURL = "https://api.weixin.qq.com/cgi-bin/tags/members/batchblacklist" BatchUnBlackListURL = "https://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist" UserRemarkSetURL = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark" )
subscriber
const ( MediaUploadURL = "https://api.weixin.qq.com/cgi-bin/media/upload" MediaGetURL = "https://api.weixin.qq.com/cgi-bin/media/get" MaterialNewsUploadURL = "https://api.weixin.qq.com/cgi-bin/material/add_news" MaterialImageUploadURL = "https://api.weixin.qq.com/cgi-bin/media/uploadimg" )
media
const DefaultReply = "success"
DefaultReply 公众号默认回复
const MaxSubscriberListCount = 10000
MaxSubscriberListCount 公众号订阅者列表的最大数目
const (
TemplateMessageSendURL = "https://api.weixin.qq.com/cgi-bin/message/template/send"
)
message
Variables ¶
This section is empty.
Functions ¶
func DecodeBytesToUint32 ¶
DecodeBytesToUint32 从 4 字节的网络字节序里解析出整数 uint32
func EncodeUint32ToBytes ¶
EncodeUint32ToBytes 把整数 uint32 格式化成 4 字节的网络字节序
Types ¶
type AESCBCCrypto ¶
type AESCBCCrypto struct {
// contains filtered or unexported fields
}
AESCBCCrypto aes-cbc crypto
func NewAESCBCCrypto ¶
func NewAESCBCCrypto(key, iv []byte) *AESCBCCrypto
NewAESCBCCrypto returns new aes-cbc crypto
func (*AESCBCCrypto) Decrypt ¶
func (c *AESCBCCrypto) Decrypt(cipherText []byte, mode AESPaddingMode) ([]byte, error)
Decrypt aes-cbc decrypt with PKCS#7 padding
func (*AESCBCCrypto) Encrypt ¶
func (c *AESCBCCrypto) Encrypt(plainText []byte, mode AESPaddingMode) ([]byte, error)
Encrypt aes-cbc encrypt with PKCS#7 padding
type AESPaddingMode ¶
type AESPaddingMode string
AESPaddingMode aes padding mode
const ( // PKCS5 PKCS#5 padding mode PKCS5 AESPaddingMode = "PKCS#5" // PKCS7 PKCS#7 padding mode PKCS7 AESPaddingMode = "PKCS#7" )
type AccessToken ¶
AccessToken 公众号普通AccessToken
type Action ¶
type Action interface {
Body() HTTPBody
URL() func(accessToken string) string
Decode() func(resp []byte) error
}
Action defines action
func BatchGetSubscriberInfo ¶
func BatchGetSubscriberInfo(openids []string, receiver *[]SubscriberInfo) Action
BatchGetSubscriberInfo 批量获取微信公众号订阅者信息
func CheckAuthToken ¶
CheckAuthToken 校验网页授权AccessToken是否有效
func CreateConditionalMenu ¶
func CreateConditionalMenu(matchRule *MenuMatchRule, buttons ...Button) Action
CreateConditionalMenu 个性化菜单
func DeleteConditionalMenu ¶
DeleteConditional 删除个性化菜单
func GetAuthUser ¶
GetAuthUser 获取授权微信用户信息(注意:使用网页授权的access_token)
func GetBlackList ¶
func GetBlackList(beginOpenID string, receiver *SubscriberList) Action
GetBlackList 获取用户黑名单列表
func GetJSAPITicket ¶
func GetJSAPITicket(receiver *JSAPITicket) Action
GetJSAPITicket 获取 jsapi ticket (注意:使用普通access_token)
func GetSubscriberInfo ¶
func GetSubscriberInfo(openid string, receiver *SubscriberInfo) Action
GetSubscriberInfo 获取微信公众号订阅者信息
func GetSubscriberList ¶
func GetSubscriberList(nextOpenID string, receiver *SubscriberList) Action
GetSubscriberList 获取微信公众号订阅者列表
func SendTemplateMessage ¶
func SendTemplateMessage(msg *TemplateMessage) Action
SendTemplateMessage 发送模板消息
func SetUserRemark ¶
SetUserRemark 设置用户备注名(该接口暂时开放给微信认证的服务号)
func UploadMaterialImage ¶
func UploadMaterialImage(filename string, receiver *MaterialUploadResult) Action
UploadMaterialImage 上传图文消息内的图片(不受公众号的素材库中图片数量的100000个的限制)
func UploadMaterialNews ¶
func UploadMaterialNews(articles []*MaterialArticle, receiver *MaterialUploadResult) Action
UploadMaterialNews 上传永久图文素材(公众号的素材库保存总数量有上限:图文消息素材、图片素材上限为100000,其他类型为1000)
func UploadMedia ¶
func UploadMedia(mediaType MediaType, filename string, receiver *MediaUploadResult) Action
UploadMedia 上传临时素材到微信服务器
type Article ¶
type Article struct {
Title CDATA `xml:"Title"` // 图文消息标题
Description CDATA `xml:"Description"` // 图文消息描述
PicURL CDATA `xml:"PicUrl"` // 图片链接, 支持JPG, PNG格式, 较好的效果为大图360*200, 小图200*200
URL CDATA `xml:"Url"` // 点击图文消息跳转链接
}
Article 公众号图文
type AuthToken ¶
type AuthToken struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int64 `json:"expires_in"`
OpenID string `json:"openid"`
Scope string `json:"scope"`
}
AuthToken 公众号网页授权Token
type AuthUser ¶
type AuthUser struct {
OpenID string `json:"openid"`
UnionID string `json:"unionid"`
Nickname string `json:"nickname"`
Gender int `json:"sex"`
Province string `json:"province"`
City string `json:"city"`
Country string `json:"country"`
Avatar string `json:"headimgurl"`
Privilege []string `json:"privilege"`
}
AuthUser 授权微信用户信息
type BatchSubscriberInfo ¶
type BatchSubscriberInfo struct {
UserInfoList []*SubscriberInfo `json:"user_info_list"`
}
BatchSubscriberInfo 微信公众号批量订阅者信息
type Button ¶
type Button map[string]interface{}
Button 菜单按钮
func LocationSelectButton ¶
LocationSelectButton 发送位置按钮
func PicPhotoOrAlbumButton ¶
PicPhotoOrAlbum 拍照或者相册发图按钮
func ScancodePushButton ¶
ScancodePushButton 扫码推事件按钮
func ScancodeWaitMsgButton ¶
ScancodeWaitMsgButton 扫码带提示按钮
func ViewLimitedButton ¶
ViewLimitedButton 图文消息按钮
type CDATA ¶
type CDATA string
CDATA XML CDATA section which is defined as blocks of text that are not parsed by the parser, but are otherwise recognized as markup.
func (CDATA) MarshalXML ¶
MarshalXML encodes the receiver as zero or more XML elements.
type ConditionalMenu ¶
type ConditionalMenu struct {
Button []*MenuButton `json:"button"`
MenuID int64 `json:"menuid"`
MatchRule *MenuMatchRule `json:"matchrule"`
}
ConditionalMenu 个性化菜单
type DefaultMenu ¶
type DefaultMenu struct {
Button []*MenuButton `json:"button"`
MenuID int64 `json:"menuid"`
}
DefaultMenu 默认菜单
type EventMessage ¶
type EventMessage struct {
ToUserName string `xml:"ToUserName"`
FromUserName string `xml:"FromUserName"`
CreateTime int64 `xml:"CreateTime"`
MsgType string `xml:"MsgType"`
MsgID int64 `xml:"MsgId"`
Content string `xml:"Content"`
PicURL string `xml:"PicUrl"`
MediaID string `xml:"MediaId"`
Format string `xml:"Format"`
Recognition string `xml:"Recognition"`
ThumbMediaID string `xml:"ThumbMediaId"`
LocationX float64 `xml:"Location_X"`
LocationY float64 `xml:"Location_Y"`
Scale int `xml:"Scale"`
Label string `xml:"Label"`
Title string `xml:"Title"`
Description string `xml:"Description"`
URL string `xml:"Url"`
Event string `xml:"Event"`
EventKey string `xml:"EventKey"`
Ticket string `xml:"Ticket"`
Latitude float64 `xml:"Latitude"`
Longitude float64 `xml:"Longitude"`
Precision float64 `xml:"Precision"`
}
EventMessage 微信公众号事件推送消息
type HTTPClient ¶
type HTTPClient interface {
Get(reqURL string, options ...HTTPOption) ([]byte, error)
Post(reqURL string, body []byte, options ...HTTPOption) ([]byte, error)
}
func NewHTTPClient ¶
func NewHTTPClient(tlsCfg ...*tls.Config) HTTPClient
NewHTTPClient returns a new http client
type HTTPOption ¶
type HTTPOption interface {
// contains filtered or unexported methods
}
HTTPOption configures how we set up the http request
func WithHTTPClose ¶
func WithHTTPClose() HTTPOption
WithHTTPClose specifies close the connection after replying to this request (for servers) or after sending this request and reading its response (for clients).
func WithHTTPCookies ¶
func WithHTTPCookies(cookies ...*http.Cookie) HTTPOption
WithHTTPCookies specifies the cookies to http request.
func WithHTTPHeader ¶
func WithHTTPHeader(key, value string) HTTPOption
WithHTTPHeader specifies the headers to http request.
func WithHTTPTimeout ¶
func WithHTTPTimeout(d time.Duration) HTTPOption
WithHTTPTimeout specifies the timeout to http request.
type ImageReply ¶
type ImageReply struct {
XMLName xml.Name `xml:"xml"`
ReplyHeader
Image struct {
MediaID CDATA `xml:"MediaId"` // 通过素材管理接口上传多媒体文件得到 MediaId
} `xml:"Image"`
}
ImageReply 公众号图片回复消息
type JSAPITicket ¶
JSAPITicket 公众号 jsapi ticket
type MaterialArticle ¶
type MaterialArticle struct {
Title string `json:"title"`
ThumbMediaID string `json:"thumb_media_id"`
Author string `json:"author"`
Digest string `json:"digest"`
ShowCoverPic string `json:"show_cover_pic"`
Content string `json:"content"`
ContentSourceURL string `json:"content_source_url"`
NeedOpenComment int `json:"need_open_comment"`
OnlyFansCanComment int `json:"only_fans_can_comment"`
}
MaterialArticle 文章素材
type MaterialUploadResult ¶
MaterialUploadResult 永久素材上传结果
type MediaUploadResult ¶
type MediaUploadResult struct {
Type string `json:"type"`
MediaID string `json:"media_id"`
CreatedAt int64 `json:"created_at"`
}
MediaUploadResult 临时素材上传结果
type MenuButton ¶
type MenuButton struct {
Type string `json:"type"`
Name string `json:"name"`
Key string `json:"key,omitempty"`
URL string `json:"url,omitempty"`
AppID string `json:"appid,omitempty"`
PagePath string `json:"page_path,omitempty"`
MediaID string `json:"media_id,omitempty"`
SubButton []*MenuButton `json:"sub_button,omitempty"`
}
MenuButton 菜单按钮
type MenuList ¶
type MenuList struct {
DefaultMenu *DefaultMenu `json:"menu"`
ConditionalMenu []*ConditionalMenu `json:"conditionalmenu"`
}
MenuList 菜单列表
type MenuMatchRule ¶
type MenuMatchRule struct {
TagID int64 `json:"tag_id"`
Sex int `json:"sex"`
Country string `json:"country"`
Province string `json:"province"`
City string `json:"city"`
ClientPlatformType int `json:"client_platform_type"`
}
MenuMatchRule 菜单匹配规则
type MusicReply ¶
type MusicReply struct {
XMLName xml.Name `xml:"xml"`
ReplyHeader
Music struct {
Title CDATA `xml:"Title,omitempty"` // 音乐标题
Description CDATA `xml:"Description,omitempty"` // 音乐描述
MusicURL CDATA `xml:"MusicUrl,omitempty"` // 音乐链接
HQMusicURL CDATA `xml:"HQMusicUrl,omitempty"` // 高质量音乐链接, WIFI环境优先使用该链接播放音乐
ThumbMediaID CDATA `xml:"ThumbMediaId"` // 通过素材管理接口上传多媒体文件得到 ThumbMediaId
} `xml:"Music"`
}
MusicReply 公众号音乐回复
type NewsReply ¶
type NewsReply struct {
XMLName xml.Name `xml:"xml"`
ReplyHeader
ArticleCount int `xml:"ArticleCount"` // 图文消息个数, 限制为10条以内
Articles []Article `xml:"Articles>item"` // 多条图文消息信息, 默认第一个item为大图, 注意, 如果图文数超过10, 则将会无响应
}
NewsReply 公众号图文回复
type PostBody ¶
type PostBody struct {
// contains filtered or unexported fields
}
PostBody implements http body
type Reply ¶
func NewArticleReply ¶
NewArticleReply returns article reply
func NewMusicReply ¶
NewMusicReply returns music reply
func NewTransfer2KFReply ¶
NewTransfer2KFReply returns transfer to kf reply
func NewVideoReply ¶
NewVideoReply returns video reply
type ReplyHeader ¶
type ReplyHeader struct {
FromUserName CDATA `xml:"FromUserName"`
ToUserName CDATA `xml:"ToUserName"`
CreateTime int64 `xml:"CreateTime"`
MsgType CDATA `xml:"MsgType"`
}
ReplyHeader 公众号消息回复公共头
type ReplyMessage ¶
type ReplyMessage struct {
XMLName xml.Name `xml:"xml"`
Encrypt CDATA `xml:"Encrypt"`
MsgSignature CDATA `xml:"MsgSignature"`
TimeStamp int64 `xml:"TimeStamp"`
Nonce CDATA `xml:"Nonce"`
}
ReplyMessage 公众号回复
type SubscriberInfo ¶
type SubscriberInfo struct {
Subscribe int `json:"subscribe"`
OpenID string `json:"openid"`
NickName string `json:"nickname"`
Sex int `json:"sex"`
Language string `json:"language"`
City string `json:"city"`
Province string `json:"province"`
Country string `json:"country"`
AvatarURL string `json:"headimgurl"`
SubscribeTime int64 `json:"subscribe_time"`
UnionID string `json:"unionid"`
Remark string `json:"remark"`
GroupID int64 `json:"groupid"`
TagidList []int64 `json:"tagid_list"`
SubscribeScene string `json:"subscribe_scene"`
QRScene int64 `json:"qr_scene"`
QRSceneStr string `json:"qr_scene_str"`
}
SubscriberInfo 微信公众号订阅者信息
type SubscriberList ¶
type SubscriberList struct {
Total int `json:"total"`
Count int `json:"count"`
Data *SubscriberListData `json:"data"`
NextOpenID string `json:"next_openid"`
}
SubscriberList 微信公众号订阅者列表
type SubscriberListData ¶
type SubscriberListData struct {
OpenID []string `json:"openid"`
}
SubscriberListData 微信公众号订阅者列表数据
type TemplateMessage ¶
type TemplateMessage struct {
OpenID string // 接收者(用户)的 openid
TemplateID string // 模板ID
RedirectURL string // 模板跳转链接(海外帐号没有跳转能力)
MPAppID string // 所需跳转到的小程序appid(该小程序appid必须与发模板消息的公众号是绑定关联关系,暂不支持小游戏)
MPPagePath string // 所需跳转到小程序的具体页面路径,支持带参数,(示例index?foo=bar),要求该小程序已发布,暂不支持小游戏
Data MessageBody // 模板内容,格式形如:{"key1": {"value": any}, "key2": {"value": any}}
Color string // 模板内容字体颜色,不填默认为黑色
}
TemplateMessage 公众号模板消息
type TextReply ¶
type TextReply struct {
XMLName xml.Name `xml:"xml"`
ReplyHeader
Content CDATA `xml:"Content"`
}
TextReply 公众号文本回复
type Transfer2KFReply ¶
type Transfer2KFReply struct {
XMLName xml.Name `xml:"xml"`
ReplyHeader
TransInfo *TransInfo `xml:"TransInfo,omitempty"`
}
Transfer2KFReply 公众号消息转客服
type VideoReply ¶
type VideoReply struct {
XMLName xml.Name `xml:"xml"`
ReplyHeader
Video struct {
MediaID CDATA `xml:"MediaId"` // 通过素材管理接口上传多媒体文件得到 MediaId
Title CDATA `xml:"Title,omitempty"` // 视频消息的标题, 可以为空
Description CDATA `xml:"Description,omitempty"` // 视频消息的描述, 可以为空
} `xml:"Video" json:"Video"`
}
VideoReply 公众号视频回复
type VoiceReply ¶
type VoiceReply struct {
XMLName xml.Name `xml:"xml"`
ReplyHeader
Voice struct {
MediaID CDATA `xml:"MediaId"` // 通过素材管理接口上传多媒体文件得到 MediaId
} `xml:"Voice"`
}
VoiceReply 公众号语音回复
type WechatAPI ¶
type WechatAPI struct {
// contains filtered or unexported fields
}
WechatAPI implements action
type WechatOA ¶
type WechatOA struct {
// contains filtered or unexported fields
}
WechatOA 微信公众号
func (*WechatOA) AccessToken ¶
func (w *WechatOA) AccessToken(options ...HTTPOption) (*AccessToken, error)
AccessToken 获取普通AccessToken
func (*WechatOA) Code2AuthToken ¶
func (w *WechatOA) Code2AuthToken(code string, options ...HTTPOption) (*AuthToken, error)
Code2AuthToken 获取公众号网页授权AccessToken
func (*WechatOA) DecryptEvent ¶
func (w *WechatOA) DecryptEvent(cipherText string) (*EventMessage, error)
DecryptEvent 事件推送解密
func (*WechatOA) Do ¶
func (w *WechatOA) Do(accessToken string, action Action, options ...HTTPOption) error
Do exec action
func (*WechatOA) EncryptReply ¶
func (w *WechatOA) EncryptReply(from, to string, reply Reply) (*ReplyMessage, error)
EncryptReply 消息回复加密
func (*WechatOA) RefreshAuthToken ¶
func (w *WechatOA) RefreshAuthToken(refreshToken string, options ...HTTPOption) (*AuthToken, error)
RefreshAuthToken 刷新网页授权AccessToken
func (*WechatOA) SetEncodingAESKey ¶
SetEncodingAESKey 服务器配置EncodingAESKey
func (*WechatOA) SetSignToken ¶
SetSignToken 服务器配置Token