From bcfab4f3d8ae8f04dfa658c5ff0f5168169d9dd2 Mon Sep 17 00:00:00 2001 From: jiangyong27 Date: Wed, 24 Jan 2024 22:59:28 +0800 Subject: [PATCH] parsemedia --- qyweixin/app_customer.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/qyweixin/app_customer.go b/qyweixin/app_customer.go index a253d5e..fc0ed5d 100644 --- a/qyweixin/app_customer.go +++ b/qyweixin/app_customer.go @@ -318,8 +318,8 @@ func (m *CustomerMessage) From(data map[string]interface{}) { m.parseEvent(data) } else if m.Msgtype == string(message.MsgTypeText) { m.parseText(data) - } else if m.Msgtype == message.MsgTypeImage { - m.parseText(data) + } else if m.Msgtype == message.MsgTypeImage || m.Msgtype == message.MsgTypeVideo || m.Msgtype == message.MsgTypeVoice { + m.parseMedia(m.Msgtype, data) } } @@ -361,14 +361,24 @@ func (m *CustomerMessage) parseText(data map[string]interface{}) error { return nil } -func (m *CustomerMessage) parseImage(data map[string]interface{}) error { - image, err := cast.ToStringMapE(data["image"]) +func (m *CustomerMessage) parseMedia(msgType string, data map[string]interface{}) error { + media, err := cast.ToStringMapE(data[msgType]) if err != nil { return err } - m.Image = &CustomerImage{ - MediaId: cast.ToString(image["media_id"]), + if msgType == message.MsgTypeImage { + m.Image = &CustomerImage{ + MediaId: cast.ToString(media["media_id"]), + } + } else if msgType == message.MsgTypeVideo { + m.Video = &CustomerVideo{ + MediaId: cast.ToString(media["media_id"]), + } + } else if msgType == message.MsgTypeVoice { + m.Voice = &CustomerVoice{ + MediaId: cast.ToString(media["media_id"]), + } } return nil }