本文整理匯總了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()
}