From c0d9ac74206f4fc305b65594d37c38ae1319aae5 Mon Sep 17 00:00:00 2001 From: jiangyong27 Date: Thu, 18 Jul 2024 19:18:15 +0800 Subject: [PATCH] parse channel --- qyweixin/app_customer.go | 22 ++++++++++++++++++++++ wechat/message/message.go | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/qyweixin/app_customer.go b/qyweixin/app_customer.go index 561b69c..b6a8c74 100644 --- a/qyweixin/app_customer.go +++ b/qyweixin/app_customer.go @@ -52,6 +52,7 @@ type CustomerMessage struct { Image *CustomerImage Video *CustomerVideo Voice *CustomerVoice + Channels *CustomerChannels } type CustomerServicer struct { @@ -69,6 +70,12 @@ type CustomerText struct { MenuId string } +type CustomerChannels struct { + Nickname string + Title string + SubType int +} + type CustomerImage struct { MediaId string } @@ -323,8 +330,23 @@ func (m *CustomerMessage) From(data map[string]interface{}) { m.parseText(data) } else if m.Msgtype == message.MsgTypeImage || m.Msgtype == message.MsgTypeVideo || m.Msgtype == message.MsgTypeVoice { m.parseMedia(m.Msgtype, data) + } else if m.Msgtype == message.MsgTypeChannels { + m.parseChannels(data) } } +func (m *CustomerMessage) parseChannels(data map[string]interface{}) error { + channels, err := cast.ToStringMapE(data["channels"]) + if err != nil { + return err + } + + m.Channels = &CustomerChannels{ + Title: cast.ToString(channels["title"]), + Nickname: cast.ToString(channels["nickname"]), + SubType: cast.ToInt(channels["sub_type"]), + } + return nil +} func (m *CustomerMessage) parseEvent(data map[string]interface{}) error { event, err := cast.ToStringMapE(data["event"]) diff --git a/wechat/message/message.go b/wechat/message/message.go index b6a69e0..0b74d2e 100644 --- a/wechat/message/message.go +++ b/wechat/message/message.go @@ -35,7 +35,8 @@ const ( //MsgTypeTransfer 表示消息消息转发到客服 MsgTypeTransfer = "transfer_customer_service" //MsgTypeEvent 表示事件推送消息 - MsgTypeEvent = "event" + MsgTypeEvent = "event" + MsgTypeChannels = "channels" ) const (