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 }