public static Message CreateMessage(AddMsg msg) { //MsgType //1 文本消息 //3 图片消息 //34 语音消息 //37 VERIFYMSG //40 POSSIBLEFRIEND_MSG //42 共享名片 //43 视频通话消息 //47 动画表情 //48 位置消息 //49 分享链接 //50 VOIPMSG //51 微信初始化消息 //52 VOIPNOTIFY //53 VOIPINVITE //62 小视频 //9999 SYSNOTICE //10000 系统消息 //10002 撤回消息 bool isSend = IsSend(msg.FromUserName); Contact remote = (isSend) ? WechatAPIService.GetContact(msg.ToUserName) : WechatAPIService.GetContact(msg.FromUserName); Message ret = new Message(); switch (msg.MsgType) { case 1: ret.Content = msg.Content; break; case 3: string sevePath = Path.Combine(m_Service.CachePath, DateTime.Now.Ticks + ".bmp"); ret.fileName = sevePath; ret.FileSize = msg.FileSize; string thumbnail = string.Format("/cgi-bin/mmwebwx-bin/webwxgetmsgimg?MsgID={0}&type=slave", msg.MsgId); ret.Content = string.Format("/cgi-bin/mmwebwx-bin/webwxgetmsgimg?MsgID={0}", msg.MsgId); Image image = m_Service.GetMsgImage(thumbnail); if (image == null) { break; } image.Save(sevePath); break; case 34: sevePath = Path.Combine(m_Service.CachePath, DateTime.Now.Ticks + ".MP3"); ret.fileName = sevePath; ret.FileSize = msg.FileSize; ret.VoiceLength = msg.VoiceLength; string url = string.Format("/cgi-bin/mmwebwx-bin/webwxgetvoice?MsgID={0}", msg.MsgId); m_Service.GetMsgFile(url, sevePath); break; case 47: //下载图片 sevePath = Path.Combine(m_Service.CachePath, Path.GetRandomFileName()); ret.fileName = sevePath; ret.FileSize = msg.FileSize; if (string.IsNullOrEmpty(msg.Content)) { break; } url = XMLTools.GetImageUrl(msg.Content); if (string.IsNullOrEmpty(url)) { break; } image = m_Service.GetImage(url); if (image == null) { break; } image.Save(sevePath); break; default: ret.Content = msg.Content; break; } if (ret == null) { ret = new Message(); } ret.MsgType = msg.MsgType; ret.IsSend = isSend; ret.Remote = remote; ret.FromContactID = msg.FromUserName; ret.ToContactD = msg.ToUserName; ret.Mime = WechatAPIService.Self; ret.MsgId = msg.MsgId; if (msg.MsgType != 51) { DaoMaster.GetSession().GetMessageDao().InsertMessage(ret, remote.Seq); } return(ret); }