发布时间:2024-11-05 14:57:47
$ 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)