go-wechat-sdkGolang 開發(fā)的微信 SDK
WeChat SDK for Go
WeChat SDK 是一個Golang版本微信SDK,簡單、易用。
快速開始
以下是一個處理消息接收以及回復(fù)的例子:
//使用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)
//設(shè)置接收消息的處理方法
server.SetMessageHandler(func(msg message.MixMessage) *message.Reply {
//回復(fù)消息:演示回復(fù)用戶發(fā)送的消息
text := message.NewText(msg.Content)
return &message.Reply{MsgType: message.MsgTypeText, MsgData: text}
})
//處理消息接收以及回復(fù)
err := server.Serve()
if err != nil {
fmt.Println(err)
return
}
//發(fā)送回復(fù)的消息
server.Send()
功能:
- officialaccount: 微信公眾號API
- miniprogram: 小程序API
- minigame:小游戲API
- pay:微信支付API
- opernplatform:開放平臺API
- work:企業(yè)微信
- aispeech:智能對話
評論
圖片
表情
