WeChat SDK for Go (微信SDK:简单、易用)
|
|
hai 1 ano | |
|---|---|---|
| .github | %!s(int64=2) %!d(string=hai) anos | |
| aispeech | %!s(int64=6) %!d(string=hai) anos | |
| cache | hai 1 ano | |
| credential | %!s(int64=2) %!d(string=hai) anos | |
| doc | %!s(int64=2) %!d(string=hai) anos | |
| domain | %!s(int64=2) %!d(string=hai) anos | |
| internal | %!s(int64=3) %!d(string=hai) anos | |
| minigame | %!s(int64=4) %!d(string=hai) anos | |
| miniprogram | hai 1 ano | |
| officialaccount | hai 1 ano | |
| openplatform | %!s(int64=2) %!d(string=hai) anos | |
| pay | %!s(int64=2) %!d(string=hai) anos | |
| util | hai 1 ano | |
| work | hai 1 ano | |
| .gitignore | %!s(int64=5) %!d(string=hai) anos | |
| .golangci.yml | %!s(int64=2) %!d(string=hai) anos | |
| LICENSE | %!s(int64=9) %!d(string=hai) anos | |
| README.md | %!s(int64=3) %!d(string=hai) anos | |
| doc.go | %!s(int64=3) %!d(string=hai) anos | |
| go.mod | %!s(int64=3) %!d(string=hai) anos | |
| go.sum | %!s(int64=3) %!d(string=hai) anos | |
| wechat.go | %!s(int64=2) %!d(string=hai) anos |
使用Golang开发的微信SDK,简单、易用。
注意:当前版本为v2版本,v1版本已废弃
import "github.com/silenceper/wechat/v2"
以下是一个微信公众号处理消息接收以及回复的例子:
// 使用memcache保存access_token,也可选择redis或自定义cache
wc := wechat.NewWechat()
memory := cache.NewMemory()
cfg := &offConfig.Config{
AppID: "xxx",
AppSecret: "xxx",
Token: "xxx",
// EncodingAESKey: "xxxx",
Cache: memory,
}
officialAccount := wc.GetOfficialAccount(cfg)
// 传入request和responseWriter
server := officialAccount.GetServer(req, rw)
// 设置接收消息的处理方法
server.SetMessageHandler(func(msg *message.MixMessage) *message.Reply {
// 回复消息:演示回复用户发送的消息
text := message.NewText(msg.Content)
return &message.Reply{MsgType: message.MsgTypeText, MsgData: text}
})
// 处理消息接收以及回复
err := server.Serve()
if err != nil {
fmt.Println(err)
return
}
// 发送回复的消息
server.Send()
Apache License, Version 2.0