本文整理汇总了Golang中github.com/chanxuehong/wechat/v2/mp/core.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DefaultEventHandler
func DefaultEventHandler(ctx *core.Context) {
log.Printf("收到事件:\n%s\n", ctx.MsgPlaintext)
event := menu.GetClickEvent(ctx.MixedMsg)
var desc string
switch event.EventType {
case "subscribe":
subevent := request.GetSubscribeEvent(ctx.MixedMsg)
desc = "谢谢关注" + subevent.EventKey
case "unsubscribe":
desc = "取消关注"
case "SCAN":
scanEvent := request.GetScanEvent(ctx.MixedMsg)
desc = "车位编码:" + scanEvent.EventKey + "\n当前时段:12:00-20:00\n当前时段价格:20元/小时\n当前时段封顶:100元\n停车回复是,否则回复"
case "scancode_waitmsg":
scanEvent := request.GetScanEvent(ctx.MixedMsg)
desc = "车位编码:" + scanEvent.EventKey + "\n当前时段:12:00-20:00\n当前时段价格:20元/小时\n当前时段封顶:100元\n停车回复是,否则回复"
default:
desc = "sorry I don't know"
}
log.Println(desc)
resp := response.NewText(event.FromUserName, event.ToUserName, event.CreateTime, desc)
ctx.RawResponse(resp) // 明文回复
}
示例2: menuClickEventHandler
func menuClickEventHandler(ctx *core.Context) {
log.Printf("收到菜单 click 事件:\n%s\n", ctx.MsgPlaintext)
event := menu.GetClickEvent(ctx.MixedMsg)
resp := response.NewText(event.FromUserName, event.ToUserName, event.CreateTime, "收到 click 类型的事件")
//ctx.RawResponse(resp) // 明文回复
ctx.AESResponse(resp, 0, "", nil) // aes密文回复
}
示例3: MenuClickEventHandler
func MenuClickEventHandler(ctx *core.Context) {
log.Printf("收到菜单 click 事件:\n%s\n", ctx.MsgPlaintext)
event := menu.GetClickEvent(ctx.MixedMsg)
var desc string
switch event.EventKey {
case "scan":
desc = "停车"
case "park":
desc = "停车"
default:
desc = "sorry I don't know"
}
resp := response.NewText(event.FromUserName, event.ToUserName, event.CreateTime, "收到 click 类型的事件"+desc)
ctx.RawResponse(resp) // 明文回复
// ctx.AESResponse(resp, 0, "", nil) // aes密文回复
}
示例4: textMsgHandler
func textMsgHandler(ctx *core.Context) {
log.Printf("收到文本消息:\n%s\n", ctx.MsgPlaintext)
msg := request.GetText(ctx.MixedMsg)
if msg.Content == "抛硬币" {
ms := "正面"
if rand.Intn(2) == 0 {
ms = "反面"
}
rs := response.NewText(msg.FromUserName, msg.ToUserName, msg.CreateTime, ms)
ctx.AESResponse(rs, 0, "", nil)
} else {
resp := response.NewText(msg.FromUserName, msg.ToUserName, msg.CreateTime, msg.Content)
//ctx.RawResponse(resp) // 明文回复
ctx.AESResponse(resp, 0, "", nil) // aes密文回复
}
}
示例5: TextMsgHandler
func TextMsgHandler(ctx *core.Context) {
log.Printf("收到文本消息:\n%s\n", ctx.MsgPlaintext)
BoradcastMessage(string(ctx.MsgPlaintext))
msg := request.GetText(ctx.MixedMsg)
if msg.Content == "是" {
re := "小鱼停车感谢您的信任,此次停车从" + time.Now().Format("2016-01-01 12:01:01") + "开始计费"
resp := response.NewText(msg.FromUserName, msg.ToUserName, msg.CreateTime, re)
ctx.RawResponse(resp) // 明文回复
} else if msg.Content == "否" {
re := "小鱼停车会继续努力,虔诚为您服务"
resp := response.NewText(msg.FromUserName, msg.ToUserName, msg.CreateTime, re)
ctx.RawResponse(resp) // 明文回复
} else {
// resp := response.NewText(msg.FromUserName, msg.ToUserName, msg.CreateTime, msg.Content)
articles := []response.Article{{Title: "title1", Description: "小鱼祝您生活愉快", PicURL: "https://iguiyu.com/images/car.png", URL: "https://iguiyu.com/"}}
resp := response.NewNews(msg.FromUserName, msg.ToUserName, msg.CreateTime, articles)
ctx.RawResponse(resp) // 明文回复
// ctx.AESResponse(resp, 0, "", nil) // aes密文回复
}
}
示例6: DefaultMsgHandler
func DefaultMsgHandler(ctx *core.Context) {
log.Printf("收到消息:\n%s\n", ctx.MsgPlaintext)
ctx.NoneResponse()
}
示例7: defaultEventHandler
func defaultEventHandler(ctx *core.Context) {
log.Printf("收到事件:\n%s\n", ctx.MsgPlaintext)
ctx.NoneResponse()
}