发布时间:2024-11-24 18:15:32
$ go get github.com/silenceper/wechat
import (
"github.com/silenceper/wechat"
"github.com/silenceper/wechat/message"
)
cfg := &wechat.Config{
AppID: "your_app_id",
AppSecret: "your_app_secret",
Token: "your_token",
AESKey: "your_aes_key",
}
wc := wechat.NewWechat(cfg)
wc.Message.Handle(message.MsgTypeText, func(ctx context.Context, msg *message.MixMessage) (*message.Reply, error) {
// 处理文本消息
reply := &message.Reply{
MsgType: message.MsgTypeText,
Content: "Hello, world!",
}
return reply, nil
})
reply := &message.Reply{
MsgType: message.MsgTypeText,
Content: "Hello, world!",
}
return reply, nil
menu := &menu.Menu{
Button: []*menu.Button{
{
Type: menu.ButtonTypeClick,
Name: "按钮1",
Key: "button1",
},
{
Type: menu.ButtonTypeView,
Name: "按钮2",
URL: "http://example.com",
},
},
}
err := wc.Menu.Create(menu)
$ go get github.com/silenceper/wechat
import (
"github.com/silenceper/wechat"
"github.com/silenceper/wechat/message"
)
cfg := &wechat.Config{
AppID: "your_app_id",
AppSecret: "your_app_secret",
Token: "your_token",
AESKey: "your_aes_key",
}
wc := wechat.NewWechat(cfg)
wc.Message.Handle(message.MsgTypeText, func(ctx context.Context, msg *message.MixMessage) (*message.Reply, error) {
// 处理文本消息
reply := &message.Reply{
MsgType: message.MsgTypeText,
Content: "Hello, world!",
}
return reply, nil
})
reply := &message.Reply{
MsgType: message.MsgTypeText,
Content: "Hello, world!",
}
return reply, nil
menu := &menu.Menu{
Button: []*menu.Button{
{
Type: menu.ButtonTypeClick,
Name: "按钮1",
Key: "button1",
},
{
Type: menu.ButtonTypeView,
Name: "按钮2",
URL: "http://example.com",
},
},
}
err := wc.Menu.Create(menu)