This is a creation in Article, where the information may have evolved or changed.
WeChat SDK for Go
The SDK developed with Golang is simple and easy to use.
Project Address: Https://github.com/silenceper/wechat
Document Address: Docs
Quick Start
Here is an example of handling message reception and reply:
//配置参数config := &wechat.Config{ AppID: "xxxx", AppSecret: "xxxx", Token: "xxxx", EncodingAESKey: "xxxx", Cache: memCache}wc := wechat.NewWechat(config)// 传入request和responseWriterserver := wc.GetServer(request, responseWriter)server.SetMessageHandler(func(msg message.MixMessage) *message.Reply { //回复消息:演示回复用户发送的消息 text := message.NewText(msg.Content) return &message.Reply{message.MsgText, text}})server.Serve()server.Send()
Complete code: EXAMPLES/HTTP/HTTP.GO
Used in conjunction with the mainstream framework
The main thing is that request and responsewriter may not get the same way in different frameworks:
Basic Configuration
memcache := cache.NewMemcache("127.0.0.1:11211")wcConfig := &wechat.Config{ AppID: cfg.AppID, AppSecret: cfg.AppSecret, Token: cfg.Token, EncodingAESKey: cfg.EncodingAESKey,//消息加解密时用到 Cache: memcache,}
Cache settings
The cache is primarily used to save global Access_token and ticket in JS-SDK:
Memcache storage is used by default. Of course, you can also directly implement cache/cache.go
the interface in
Basic API Usage
Message Management
Receive normal messages
Receive event push
Passive reply message
Reply text message
Reply to Picture message
Reply to a video message
Reply to music messages
Reply text message
customizing menus
custom Menu Creation Interface
Custom Menu Query Interface
Custom Menu Delete Interface
Custom Menu Event Push
Personalized Menu Interface
Get the public Number menu configuration
Web Development
Oauth2 Authorization
Get JS-SDK Configuration
Material Management
For more API usage please refer to the documentation:
Https://github.com/silenceper ...