README ¶
微信公众平台库 – Go语言版本
简介
这是一个使用Go语言对微信公众平台的封装。参考了微信公众平台API文档
入门
安装
通过执行下列语句就可以完成安装
go get github.com/wizjin/weixin
注册微信公众平台
注册微信公众平台,填写验证微信公众平台的Token
示例
package main
import (
"github.com/wizjin/weixin"
"net/http"
)
// 文本消息的处理函数
func Echo(w weixin.ResponseWriter, r *weixin.Request) {
txt := r.Content // 获取用户发送的消息
w.ReplyText(txt) // 回复一条文本消息
w.PostText("Post:" + txt) // 发送一条文本消息
}
// 关注事件的处理函数
func Subscribe(w weixin.ResponseWriter, r *weixin.Request) {
w.ReplyText("欢迎关注") // 有新人关注,返回欢迎消息
}
func main() {
// my-token 验证微信公众平台的Token
// app-id, app-secret用于高级API调用。
// 如果仅使用接收/回复消息,则可以不填写,使用下面语句
// mux := weixin.New("my-token", "", "")
mux := weixin.New("my-token", "app-id", "app-secret")
// 设置AES密钥,如果不使用AES可以省略这行代码
mux.SetEncodingAESKey("encoding-AES-key")
// 注册文本消息的处理函数
mux.HandleFunc(weixin.MsgTypeText, Echo)
// 注册关注事件的处理函数
mux.HandleFunc(weixin.MsgTypeEventSubscribe, Subscribe)
http.Handle("/", mux) // 注册接收微信服务器数据的接口URI
http.ListenAndServe(":80", nil) // 启动接收微信数据服务器
}
微信公众平台要求在收到消息后5秒内回复消息(Reply接口) 如果时间操作很长,则可以使用Post接口发送消息 如果只使用Post接口发送消息,则需要先调用ReplyOK来告知微信不用等待回复。
处理函数
处理函数的定义可以使用下面的形式
func Func(w weixin.ResponseWriter, r *weixin.Request) {
...
}
可以注册的处理函数类型有以下几种
weixin.MsgTypeText接收文本消息weixin.MsgTypeImage接收图片消息weixin.MsgTypeVoice接收语音消息weixin.MsgTypeVideo接收视频消息weixin.MsgTypeShortVideo接收小视频消息weixin.MsgTypeLocation接收地理位置消息weixin.MsgTypeLink接收链接消息weixin.MsgTypeEventSubscribe接收关注事件weixin.MsgTypeEventUnsubscribe接收取消关注事件weixin.MsgTypeEventScan接收扫描二维码事件weixin.MsgTypeEventView接收点击菜单跳转链接时的事件weixin.MsgTypeEventClick接收自定义菜单事件weixin.MsgTypeEventLocation接收上报地理位置事件weixin.MsgTypeEventTemplateSent接收模版消息发送结果
发送被动响应消息
需要发送被动响应消息,可通过weixin.ResponseWriter的下列方法完成
ReplyOK()无同步消息回复ReplyText(text)回复文本消息ReplyImage(mediaId)回复图片消息ReplyVoice(mediaId)回复语音消息ReplyVideo(mediaId, title, description)回复视频消息ReplyMusic(music)回复音乐消息ReplyNews(articles)回复图文消息
发送客服消息
PostText(text)发送文本消息PostImage(mediaId)发送图片消息PostVoice(mediaId)发送语音消息PostVideo(mediaId, title, description)发送视频消息PostMusic(music)发送音乐消息PostNews(articles)发送图文消息
发送模版消息
如需要发送模版消息,需要先获取模版ID,之后再根据ID发送。
func GetTemplateId(wx *weixin.Weixin) {
tid, err := wx.AddTemplate("TM00015")
if err != nil {
fmt.Println(err)
} else {
fmt.Println(ips) // 模版ID
}
}
随后可以发送模版消息了。
func SendTemplateMessage(w weixin.ResponseWriter, r *weixin.Request) {
templateId := ...
url := ...
msgid, err := w.PostTemplateMessage(templateId, url,
weixin.TmplData{ "first": weixin.TmplItem{"Hello World!", "#173177"}})
if err != nil {
fmt.Println(err)
} else {
fmt.Println(msgid)
}
}
在模版消息发送成功后,还会通过类型为MsgTypeEventTemplateSent的消息推送获得发送结果。
TemplateSentStatusSuccess发送成功TemplateSentStatusUserBlock发送失败,用户拒绝接收TemplateSentStatusSystemFailed发送失败,系统原因
上传/下载多媒体文件
使用如下函数可以用来上传多媒体文件:
UploadMediaFromFile(mediaType string, filepath string)
示例 (用一张本地图片来返回图片消息):
func ReciveMessage(w weixin.ResponseWriter, r *weixin.Request) {
// 上传本地文件并获取MediaID
mediaId, err := w.UploadMediaFromFile(weixin.MediaTypeImage, "/my-file-path")
if err != nil {
w.ReplyText("上传图片失败")
} else {
w.ReplyImage(mediaId) // 利用获取的MediaId来返回图片消息
}
}
使用如下函数可以用来下载多媒体文件:
DownloadMediaToFile(mediaId string, filepath string)
示例 (收到一条图片消息,然后保存图片到本地文件):
func ReciveImageMessage(w weixin.ResponseWriter, r *weixin.Request) {
// 下载文件并保存到本地
err := w.DownloadMediaToFile(r.MediaId, "/my-file-path")
if err != nil {
w.ReplyText("保存图片失败")
} else {
w.ReplyText("保存图片成功")
}
}
获取微信服务器IP地址
示例,获取微信服务器IP地址列表
func GetIpList(wx *weixin.Weixin) {
ips, err := wx.GetIpList()
if err != nil {
fmt.Println(err)
} else {
fmt.Println(ips) // Ip地址列表
}
}
获取AccessToken
示例,获取AccessToken
func GetAccessToken(wx *weixin.Weixin) {
a := wx.GetAccessToken
if time.Until(token.Expires).Seconds() > 0 {
fmt.Println(a.Token) // AccessToken
} else {
fmt.Println("Timeout") // 超时
}
}
创建/换取二维码
示例,创建临时二维码
func CreateQRScene(wx *weixin.Weixin) {
// 二维码ID - 1000
// 过期时间 - 1800秒
qr, err := wx.CreateQRScene(1000, 1800)
if err != nil {
fmt.Println(err)
} else {
url := qr.ToURL() // 获取二维码的URL
fmt.Println(url)
}
}
示例,创建永久二维码
func CreateQRScene(wx *weixin.Weixin) {
// 二维码ID - 1001
qr, err := wx.CreateQRLimitScene(1001)
if err != nil {
fmt.Println(err)
} else {
url := qr.ToURL() // 获取二维码的URL
fmt.Println(url)
}
}
长链接转短链接接口
func ShortURL(wx *weixin.Weixin) {
// 长链接转短链接
url, err := wx.ShortURL("http://mp.weixin.qq.com/wiki/10/165c9b15eddcfbd8699ac12b0bd89ae6.html")
if err != nil {
fmt.Println(err)
} else {
fmt.Println(url)
}
}
自定义菜单
示例,创建自定义菜单
func CreateMenu(wx *weixin.Weixin) {
menu := &weixin.Menu{make([]weixin.MenuButton, 2)}
menu.Buttons[0].Name = "我的菜单"
menu.Buttons[0].Type = weixin.MenuButtonTypeUrl
menu.Buttons[0].Url = "https://mp.weixin.qq.com"
menu.Buttons[1].Name = "我的子菜单"
menu.Buttons[1].SubButtons = make([]weixin.MenuButton, 1)
menu.Buttons[1].SubButtons[0].Name = "测试"
menu.Buttons[1].SubButtons[0].Type = weixin.MenuButtonTypeKey
menu.Buttons[1].SubButtons[0].Key = "MyKey001"
err := wx.CreateMenu(menu)
if err != nil {
fmt.Println(err)
}
}
自定义菜单的类型有如下几种
weixin.MenuButtonTypeKey点击推事件weixin.MenuButtonTypeUrl跳转URLweixin.MenuButtonTypeScancodePush扫码推事件weixin.MenuButtonTypeScancodeWaitmsg扫码推事件且弹出"消息接收中"提示框weixin.MenuButtonTypePicSysphoto弹出系统拍照发图weixin.MenuButtonTypePicPhotoOrAlbum弹出拍照或者相册发图weixin.MenuButtonTypePicWeixin弹出微信相册发图器weixin.MenuButtonTypeLocationSelect弹出地理位置选择器weixin.MenuButtonTypeMediaId下发消息(除文本消息)weixin.MenuButtonTypeViewLimited跳转图文消息URL
示例,获取自定义菜单
func DeleteMenu(wx *weixin.Weixin) {
menu, err := wx.GetMenu()
if err != nil {
fmt.Println(err)
} else {
fmt.Println(menu)
}
}
示例,删除自定义菜单
func DeleteMenu(wx *weixin.Weixin) {
err := wx.DeleteMenu()
if err != nil {
fmt.Println(err)
}
}
JSSDK签名
示例,生成JSSDK签名
func SignJSSDK(wx *weixin.Weixin, url string) {
timestamp := time.Now().Unix()
noncestr := fmt.Sprintf("%d", c.randreader.Int())
sign, err := wx.JsSignature(url, timestamp, noncestr)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(sign)
}
}
重定向URL生成
示例,生成重定向URL
func CreateRedirect(wx *weixin.Weixin, url string) {
redirect := wx.CreateRedirectURL(url, weixin.RedirectURLScopeBasic, "")
}
URL的类型有如下几种:
RedirectURLScopeBasic基本授权,仅用来获取OpenId或UnionIdRedirectURLScopeUserInfo高级授权,可以用于获取用户基本信息,需要用户同意
用户OpenId和UnionId获取
示例,获取用户OpenId和UnionId
func GetUserId(wx *weixin.Weixin, code string) {
user, err := wx.GetUserAccessToken(code)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(user.OpenId)
fmt.Println(user.UnionId)
}
}
用户信息获取
示例,获取用户信息
func GetUserInfo(wx *weixin.Weixin, openid string) {
user, err := wx.GetUserInfo(openid)
if err != nil {
fmt.Println(err)
} else {
fmt.Println(user.Nickname)
fmt.Println(user.Sex)
fmt.Println(user.City)
fmt.Println(user.Country)
fmt.Println(user.Province)
fmt.Println(user.HeadImageUrl)
fmt.Println(user.SubscribeTime)
fmt.Println(user.Remark)
}
}
参考连接
版权声明
This project is licensed under the MIT license, see LICENSE.
更新日志
Version 0.5.4 - upcoming
- 用户管理
- 支持AES
Version 0.5.3 - 2016年01月05日
- 添加模版消息送
Version 0.5.2 - 2015年12月05日
- 添加JSSDK签名生成
- 添加重定向URL生成
- 添加获取用户OpenId和UnionId
- 添加获取授权用户信息
Version 0.5.1 - 2015年06月26日
- 获取微信服务器IP地址
- 接收小视频消息
Version 0.5.0 - 2015年06月25日
- 自定义菜单
- 长链接转短链接
Version 0.4.1 - 2014年09月07日
- 添加将消息转发到多客服功能
Version 0.4.0 - 2014年02月07日
- 创建/换取二维码
Version 0.3.0 - 2014年01月07日
- 多媒体文件处理:上传/下载多媒体文件
Version 0.2.0 - 2013年12月19日
- 发送客服消息:文本消息,图片消息,语音消息,视频消息,音乐消息,图文消息
Version 0.1.0 – 2013年12月17日
- Token验证URL有效性
- 接收普通消息:文本消息,图片消息,语音消息,视频消息,地理位置消息,链接消息
- 接收事件推送:关注/取消关注,扫描二维码事件,上报地理位置,自定义菜单
- 发送被动响应消息:文本消息,图片消息,语音消息,视频消息,音乐消息,图文消息
Documentation ¶
Overview ¶
Package weixin MP SDK (Golang)
Index ¶
- Constants
- type AccessToken
- type Article
- type HandlerFunc
- type Material
- type Materials
- type Menu
- type MenuButton
- type MessageHeader
- type Music
- type QRScene
- type Request
- type ResponseWriter
- type TmplData
- type TmplItem
- type TmplMiniProgram
- type TmplMsg
- type UserAccessToken
- type UserInfo
- type Weixin
- func (wx *Weixin) AddTemplate(shortid string) (string, error)
- func (wx *Weixin) BatchGetMaterial(materialType string, offset int, count int) (*Materials, error)
- func (wx *Weixin) CreateHandlerFunc(w http.ResponseWriter, r *http.Request) http.HandlerFunc
- func (wx *Weixin) CreateMenu(menu *Menu) error
- func (wx *Weixin) CreateQRLimitScene(sceneID int) (*QRScene, error)
- func (wx *Weixin) CreateQRLimitSceneByString(sceneStr string) (*QRScene, error)
- func (wx *Weixin) CreateQRScene(sceneID int, expires int) (*QRScene, error)
- func (wx *Weixin) CreateQRSceneByString(sceneStr string, expires int) (*QRScene, error)
- func (wx *Weixin) CreateRedirectURL(urlStr string, scope string, state string) string
- func (wx *Weixin) DeleteMenu() error
- func (wx *Weixin) DownloadMedia(mediaID string, writer io.Writer) error
- func (wx *Weixin) DownloadMediaToFile(mediaID string, fp string) error
- func (wx *Weixin) GetAccessToken() AccessToken
- func (wx *Weixin) GetAppId() string
- func (wx *Weixin) GetAppSecret() string
- func (wx *Weixin) GetIpList() ([]string, error)
- func (wx *Weixin) GetJsAPITicket() (string, error)
- func (wx *Weixin) GetMenu() (*Menu, error)
- func (wx *Weixin) GetUserAccessToken(code string) (*UserAccessToken, error)
- func (wx *Weixin) GetUserInfo(openid string) (*UserInfo, error)
- func (wx *Weixin) HandleFunc(pattern string, handler HandlerFunc)
- func (wx *Weixin) JsSignature(url string, timestamp int64, noncestr string) (string, error)
- func (wx *Weixin) PostImage(touser string, mediaID string) error
- func (wx *Weixin) PostMusic(touser string, music *Music) error
- func (wx *Weixin) PostNews(touser string, articles []Article) error
- func (wx *Weixin) PostTemplateMessage(touser string, templateid string, url string, data TmplData) (int32, error)
- func (wx *Weixin) PostTemplateMessageMiniProgram(msg *TmplMsg) (int64, error)
- func (wx *Weixin) PostText(touser string, text string) error
- func (wx *Weixin) PostVideo(touser string, m string, t string, d string) error
- func (wx *Weixin) PostVoice(touser string, mediaID string) error
- func (wx *Weixin) RefreshAccessToken()
- func (wx *Weixin) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (wx *Weixin) SetEncodingAESKey(key string) error
- func (wx *Weixin) SetTemplateIndustry(id1 string, id2 string) error
- func (wx *Weixin) ShortURL(url string) (string, error)
- func (wx *Weixin) UploadMedia(mediaType string, filename string, reader io.Reader) (string, error)
- func (wx *Weixin) UploadMediaFromFile(mediaType string, fp string) (string, error)
Constants ¶
const ( EventSubscribe = "subscribe" EventUnsubscribe = "unsubscribe" EventScan = "SCAN" EventView = "VIEW" EventClick = "CLICK" EventLocation = "LOCATION" EventTemplateSent = "TEMPLATESENDJOBFINISH" // Message type MsgTypeDefault = ".*" MsgTypeText = "text" MsgTypeImage = "image" MsgTypeVoice = "voice" MsgTypeVideo = "video" MsgTypeShortVideo = "shortvideo" MsgTypeLocation = "location" MsgTypeLink = "link" MsgTypeEvent = msgEvent + ".*" MsgTypeEventSubscribe = msgEvent + "\\." + EventSubscribe MsgTypeEventUnsubscribe = msgEvent + "\\." + EventUnsubscribe MsgTypeEventScan = msgEvent + "\\." + EventScan MsgTypeEventView = msgEvent + "\\." + EventView MsgTypeEventClick = msgEvent + "\\." + EventClick MsgTypeEventLocation = msgEvent + "\\." + EventLocation MsgTypeEventTemplateSent = msgEvent + "\\." + EventTemplateSent // Media type MediaTypeImage = "image" MediaTypeVoice = "voice" MediaTypeVideo = "video" MediaTypeThumb = "thumb" // Button type MenuButtonTypeKey = "click" MenuButtonTypeUrl = "view" MenuButtonTypeScancodePush = "scancode_push" MenuButtonTypeScancodeWaitmsg = "scancode_waitmsg" MenuButtonTypePicSysphoto = "pic_sysphoto" MenuButtonTypePicPhotoOrAlbum = "pic_photo_or_album" MenuButtonTypePicWeixin = "pic_weixin" MenuButtonTypeLocationSelect = "location_select" MenuButtonTypeMediaId = "media_id" MenuButtonTypeViewLimited = "view_limited" MenuButtonTypeMiniProgram = "miniprogram" // Template Status TemplateSentStatusSuccess = "success" TemplateSentStatusUserBlock = "failed:user block" TemplateSentStatusSystemFailed = "failed:system failed" // Redirect Scope RedirectURLScopeBasic = "snsapi_base" RedirectURLScopeUserInfo = "snsapi_userinfo" )
nolint
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessToken ¶
AccessToken define weixin access token.
type Article ¶
type Article struct {
Title string `json:"title"`
Description string `json:"description"`
PicUrl string `json:"picurl"` // nolint
Url string `json:"url"` // nolint
}
Article is the response of news message.
type HandlerFunc ¶
type HandlerFunc func(ResponseWriter, *Request)
HandlerFunc is callback function handler
type Material ¶
type Material struct {
MediaId string `json:"media_id,omitempty"` // nolint
Name string `json:"name,omitempty"`
UpdateTime int64 `json:"update_time,omitempty"`
CreateTime int64 `json:"create_time,omitempty"`
Url string `json:"url,omitempty"` // nolint
Content struct {
NewsItem []struct {
Title string `json:"title,omitempty"`
ThumbMediaId string `json:"thumb_media_id,omitempty"` // nolint
ShowCoverPic int `json:"show_cover_pic,omitempty"`
Author string `json:"author,omitempty"`
Digest string `json:"digest,omitempty"`
Content string `json:"content,omitempty"`
Url string `json:"url,omitempty"` // nolint
ContentSourceUrl string `json:"content_source_url,omitempty"` // nolint
} `json:"news_item,omitempty"`
} `json:"content,omitempty"`
}
Material data.
type Materials ¶
type Materials struct {
TotalCount int `json:"total_count,omitempty"`
ItemCount int `json:"item_count,omitempty"`
Items []Material `json:"item,omitempty"`
}
Materials is the list of material
type Menu ¶
type Menu struct {
Buttons []MenuButton `json:"button,omitempty"`
}
Menu is custom menu.
type MenuButton ¶
type MenuButton struct {
Name string `json:"name"`
Type string `json:"type,omitempty"`
Key string `json:"key,omitempty"`
Url string `json:"url,omitempty"` // nolint
MediaId string `json:"media_id,omitempty"` // nolint
SubButtons []MenuButton `json:"sub_button,omitempty"`
AppId string `json:"appid,omitempty"` // nolint
PagePath string `json:"pagepath,omitempty"`
}
MenuButton is the button of custom menu.
type MessageHeader ¶
type MessageHeader struct {
ToUserName string
FromUserName string
CreateTime int
MsgType string
Encrypt string
}
MessageHeader is the header of common message.
type Music ¶
type Music struct {
Title string `json:"title"`
Description string `json:"description"`
MusicUrl string `json:"musicurl"` // nolint
HQMusicUrl string `json:"hqmusicurl"` // nolint
ThumbMediaId string `json:"thumb_media_id"` // nolint
}
Music is the response of music message.
type QRScene ¶
type QRScene struct {
Ticket string `json:"ticket"`
ExpireSeconds int `json:"expire_seconds"`
Url string `json:"url,omitempty"` // nolint
}
QRScene is the QR code.
type Request ¶
type Request struct {
MessageHeader
MsgId int64 // nolint
Content string
PicUrl string // nolint
MediaId string // nolint
Format string
ThumbMediaId string // nolint
LocationX float32 `xml:"Location_X"`
LocationY float32 `xml:"Location_Y"`
Scale float32
Label string
Title string
Description string
Url string // nolint
Event string
EventKey string
Ticket string
Latitude float32
Longitude float32
Precision float32
Recognition string
Status string
}
Request is weixin event request.
type ResponseWriter ¶
type ResponseWriter interface {
// Get weixin
GetWeixin() *Weixin
GetUserData() interface{}
ReplyOK()
ReplyText(text string)
ReplyImage(mediaId string)
ReplyVoice(mediaId string)
ReplyVideo(mediaId string, title string, description string)
ReplyMusic(music *Music)
ReplyNews(articles []Article)
TransferCustomerService(serviceId string)
// Post message
PostText(text string) error
PostImage(mediaId string) error
PostVoice(mediaId string) error
PostVideo(mediaId string, title string, description string) error
PostMusic(music *Music) error
PostNews(articles []Article) error
PostTemplateMessage(templateid string, url string, data TmplData) (int32, error)
// Media operator
UploadMediaFromFile(mediaType string, filepath string) (string, error)
DownloadMediaToFile(mediaId string, filepath string) error
UploadMedia(mediaType string, filename string, reader io.Reader) (string, error)
DownloadMedia(mediaId string, writer io.Writer) error
// contains filtered or unexported methods
}
ResponseWriter is used to output reply nolint
type TmplItem ¶
type TmplItem struct {
Value string `json:"value,omitempty"`
Color string `json:"color,omitempty"`
}
TmplItem for mini program
type TmplMiniProgram ¶
type TmplMiniProgram struct {
AppId string `json:"appid,omitempty"` // nolint
PagePath string `json:"pagepath,omitempty"`
}
TmplMiniProgram for mini program
type TmplMsg ¶
type TmplMsg struct {
ToUser string `json:"touser"`
TemplateId string `json:"template_id"` // nolint
Url string `json:"url,omitempty"` // nolint 若填写跳转小程序 则此为版本过低的替代跳转url
MiniProgram *TmplMiniProgram `json:"miniprogram,omitempty"` // 跳转小程序 选填
Data TmplData `json:"data,omitempty"`
Color string `json:"color,omitempty"` // 全局颜色
}
TmplMsg for mini program
type UserAccessToken ¶
type UserAccessToken struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpireSeconds int `json:"expires_in"`
OpenId string `json:"openid"` // nolint
Scope string `json:"scope"`
UnionId string `json:"unionid,omitempty"` // nolint
}
UserAccessToken access token for user.
type UserInfo ¶
type UserInfo struct {
Subscribe int `json:"subscribe,omitempty"`
Language string `json:"language,omitempty"`
OpenId string `json:"openid,omitempty"` // nolint
UnionId string `json:"unionid,omitempty"` // nolint
Nickname string `json:"nickname,omitempty"`
Sex int `json:"sex,omitempty"`
City string `json:"city,omitempty"`
Country string `json:"country,omitempty"`
Province string `json:"province,omitempty"`
HeadImageUrl string `json:"headimgurl,omitempty"` // nolint
SubscribeTime int64 `json:"subscribe_time,omitempty"`
Remark string `json:"remark,omitempty"`
GroupId int `json:"groupid,omitempty"` // nolint
}
UserInfo store user information.
type Weixin ¶
type Weixin struct {
// contains filtered or unexported fields
}
Weixin instance
func NewWithUserData ¶
NewWithUserData create data with userdata.
func (*Weixin) AddTemplate ¶
AddTemplate used to add template.
func (*Weixin) BatchGetMaterial ¶
BatchGetMaterial used to batch get Material.
func (*Weixin) CreateHandlerFunc ¶
func (wx *Weixin) CreateHandlerFunc(w http.ResponseWriter, r *http.Request) http.HandlerFunc
CreateHandlerFunc used to create handler function.
func (*Weixin) CreateMenu ¶
CreateMenu used to create custom menu.
func (*Weixin) CreateQRLimitScene ¶
CreateQRLimitScene used to create QR limit scene.
func (*Weixin) CreateQRLimitSceneByString ¶
CreateQRLimitSceneByString used to create QR limit scene by str.
func (*Weixin) CreateQRScene ¶
CreateQRScene used to create QR scene.
func (*Weixin) CreateQRSceneByString ¶
CreateQRSceneByString used to create QR scene by str.
func (*Weixin) CreateRedirectURL ¶
CreateRedirectURL used to create redirect url
func (*Weixin) DownloadMedia ¶
DownloadMedia used to download media with media.
func (*Weixin) DownloadMediaToFile ¶
DownloadMediaToFile used to download media and save to local file.
func (*Weixin) GetAccessToken ¶
func (wx *Weixin) GetAccessToken() AccessToken
GetAccessToken read access token.
func (*Weixin) GetAppSecret ¶
GetAppSecret return app secret.
func (*Weixin) GetJsAPITicket ¶
GetJsAPITicket used to get js api ticket.
func (*Weixin) GetUserAccessToken ¶
func (wx *Weixin) GetUserAccessToken(code string) (*UserAccessToken, error)
GetUserAccessToken used to get open id
func (*Weixin) GetUserInfo ¶
GetUserInfo used to get user info
func (*Weixin) HandleFunc ¶
func (wx *Weixin) HandleFunc(pattern string, handler HandlerFunc)
HandleFunc used to register request callback.
func (*Weixin) JsSignature ¶
JsSignature used to sign js url.
func (*Weixin) PostTemplateMessage ¶
func (wx *Weixin) PostTemplateMessage(touser string, templateid string, url string, data TmplData) (int32, error)
PostTemplateMessage used to post template message.
func (*Weixin) PostTemplateMessageMiniProgram ¶
PostTemplateMessageMiniProgram 兼容模板消息跳转小程序
func (*Weixin) RefreshAccessToken ¶
func (wx *Weixin) RefreshAccessToken()
RefreshAccessToken update access token.
func (*Weixin) ServeHTTP ¶
func (wx *Weixin) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP used to process weixin request and send response.
func (*Weixin) SetEncodingAESKey ¶
SetEncodingAESKey set AES key
func (*Weixin) SetTemplateIndustry ¶
SetTemplateIndustry used to set template industry.
func (*Weixin) UploadMedia ¶
UploadMedia used to upload media with media.