public bool Notify(string content, string[] toUser = null, string[] toParty = null, string[] toTag = null, EventLevel level = EventLevel.Normal, int timeOut = 10000) { try { List <string> members = null;// UserHelper.GetExtendIdsFromMembers(toUser, toParty, toTag); string token = AccessTokenContainer.TryGetToken(corpID, corpSecret); string users = null; if (members != null && members.Count > 0) { users = string.Join("|", members); } if (string.IsNullOrEmpty(users)) { users = "@all"; } MassResult massresult = MassApi.SendText(token, users, null, null, "0", content, 0, timeOut); if (massresult.errcode == 0) { return(true); } } catch { } return(false); }
/// <summary> /// 发送微信消息.自动 /// </summary> /// <param name="iAppID"></param> /// <param name="strMsgType"></param> /// <param name="strContent"></param> /// <param name="lstContent"></param> /// <returns></returns> public static MassResult SendMsgToUser(int iAppID, string strMsgType, string strContent, List <ArticleInfoView> lstContent) { MassResult ret; var objConfig = WeChatCommonService.GetWeChatConfigByID(iAppID); if (objConfig.IsCorp.HasValue && objConfig.IsCorp.Value) { ret = SendMsg(iAppID, strMsgType, lstContent[0].ToUser.Replace(",", "|"), lstContent[0].ToDepartment.Replace(",", "|"), lstContent[0].ToTag.Replace(",", "|"), strContent, lstContent); } else { var retMP = WechatCommonMP.SendMsgMP(lstContent, new WeChat.Domain.ViewModelFront.SearchUserMPView() { Group = lstContent[0].NewsInfo.Group, City = lstContent[0].NewsInfo.City, Province = lstContent[0].NewsInfo.Province, Sex = lstContent[0].NewsInfo.Sex }, null); ret = new MassResult() { errcode = (ReturnCode_QY)retMP.errcode, errmsg = retMP.errmsg }; } return(ret); }
public ActionResult SendTextMsg() { var accessToken = Senparc.Weixin.QY.Containers.AccessTokenContainer.TryGetToken(CorpId, CorpSecrets); MassResult result = MassApi.SendText(accessToken, "zongsg", "", "", "1", "测试"); return(Content("")); }
/// <summary> /// 微信图文推送 /// </summary> /// <param name="appid"></param> /// <param name="article"></param> /// <param name="touser"></param> /// <param name="toparty"></param> /// <param name="totag"></param> public static MassResult PublishMessage(int appid, List <ArticleInfoView> articleList, string touser, string toparty, string totag, bool isPreview = false) { MassResult objResult = null; //LogManager.GetLogger(typeof(WechatCommon)).Debug("Publishing Article - " // + "\r\n\tTitle: " + article.Title // + "\r\n\tUrl: " + article.Url // + "\r\n\tPush Image: " + article.PicUrl // + "\r\n\tPush To: *" + touser + "*,*" + toparty + "*,*" + totag + "*" // ); if (touser == "@all") { // 只要touser=="@all"了,就忽略其他参数 objResult = WechatCommon.SendMsg(appid, "news", "@all", "", "", "", articleList); } else if (string.IsNullOrEmpty(toparty) && string.IsNullOrEmpty(totag)) { // 选择的组 和 tag 都没选的话,看touser if (string.IsNullOrEmpty(touser)) { // user也没选的话,touser就是@all touser = "******"; } objResult = WechatCommon.SendMsg(appid, "news", touser, "", "", "", articleList, isPreview); } else { // 否则的话,现在的情况是touser!="@all",三个条件组合使用 objResult = WechatCommon.SendMsg(appid, "news", touser, toparty, totag, "", articleList, isPreview); } return(objResult); }
/// <summary> /// news消息 /// </summary> /// <param name="toUser">UserID列表(消息接收者,多个接收者用‘|’分隔)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送</param> /// <param name="toParty">PartyID列表,多个接受者用‘|’分隔。当touser为@all时忽略本参数</param> /// <param name="toTag">TagID列表,多个接受者用‘|’分隔。当touser为@all时忽略本参数</param> /// <param name="agentId">企业应用的id,可在应用的设置页面查看</param> /// <param name="articles">图文信息内容,包括title(标题)、description(描述)、url(点击后跳转的链接。企业可根据url里面带的code参数校验员工的真实身份)和picurl(图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80。如不填,在客户端不显示图片)</param> /// <param name="safe">表示是否是保密消息,0表示否,1表示是,默认0</param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <returns></returns> public static MassResult SendNews(string toUser, string toParty, string toTag, string agentId, List <Article> articles, int safe = 0, int timeOut = 10000) { try { if (toParty != null && toParty.Split(new char[] { '|' }).Length > 100) { MassResult result = new MassResult(); var list = SplitArray(toParty.Split(new char[] { '|' }), 100); for (int i = 0; i < list.Count; i++) { if (i == 0) { result = MassApi.SendNews(GetToken(), toUser, string.Join("|", list[i]), toTag, agentId, articles); } else { result = MassApi.SendNews(GetToken(), null, string.Join("|", list[i]), null, agentId, articles); } } return(result); } else { return(MassApi.SendNews(GetToken(), toUser, toParty, toTag, agentId, articles)); } } catch (Exception e) { MassResult result = new MassResult(); return(result); } }
public ActionResult SendNews(List <NewsInfoView> newsList, bool isPreview = false) { int IsSec = 0; try { var news = newsList[0]; if ("video".Equals(news.NewsCate)) { news.ImageContent = SaveBase64ImageToServer(news.ImageContent); } IsSec = news.isSecurityPost.HasValue && news.isSecurityPost.Value ? 1 : 0; var objConfig = WeChatCommonService.GetWeChatConfigByID(news.AppId); string strToken = (objConfig.IsCorp != null && !objConfig.IsCorp.Value) ? Innocellence.Weixin.MP.CommonAPIs.AccessTokenContainer.GetToken(objConfig.WeixinCorpId, objConfig.WeixinCorpSecret) : Innocellence.Weixin.QY.CommonAPIs.AccessTokenContainer.TryGetToken(objConfig.WeixinCorpId, objConfig.WeixinCorpSecret); string strUser = news.SendToPerson == null ? null : string.Join("|", news.SendToPerson); string strDept = news.SendToGroup == null ? null : string.Join("|", news.SendToGroup); string strTags = news.SendToTag == null ? null : string.Join("|", news.SendToTag); // var configs = Infrastructure.Web.Domain.Service.CommonService.lstSysConfig; using (var transactionScope = new TransactionScope(TransactionScopeOption.Suppress, new TransactionOptions { IsolationLevel = IsolationLevel.RepeatableRead })) { MassResult result = null; var lstArticles = GetArticleList(newsList, isPreview); if (!isPreview) { InsertMsgLog(string.Join(",", lstArticles.Select(a => a.Id)), newsList[0]); } if (news.PostType == (int)MessagePostTypeEnum.定时推送) { transactionScope.Complete(); } else { result = WechatCommon.SendMsgQY(news.AppId, news.NewsCate == "news" && IsSec == 1 ? "mpnews" : news.NewsCate, strUser, strDept, strTags, "", lstArticles, IsSec, isPreview); if (result.errcode == Weixin.ReturnCode_QY.请求成功) { transactionScope.Complete(); } } } //if (pp != null) //{ // _attachmentsItemService.ThumbImageAndInsertIntoDB(pp); //} } catch (Exception e) { _Logger.Error(e, "An error occurred while sending news."); return(Json(new { results = new { Data = 500 } })); } return(Json(new { results = new { Data = 200 } })); }
/// <summary> /// 微信图文推送。该函数不建议使用,建议使用PublishMessage函数代替。 /// </summary> /// <param name="iAppID"></param> /// <param name="strMsgType"></param> /// <param name="strUser"></param> /// <param name="strDept"></param> /// <param name="strTags"></param> /// <param name="strContent"></param> /// <param name="lstContent"></param> /// <returns></returns> public static MassResult SendMsg(int iAppID, string strMsgType, string strUser, string strDept, string strTags, string strContent, List <Article> lstContent) { MassResult objResult = null; int IsSec = 0; var objConfig = WeChatCommonService.GetWeChatConfig(iAppID); LogManager.GetLogger(typeof(WechatCommon)).Debug("strUser:{0} strDept:{1} strTags:{2} Msg:{3}", strUser, strDept, strTags, strContent); string strToken = AccessTokenContainer.TryGetToken(objConfig.WeixinCorpId, objConfig.WeixinCorpSecret); switch (strMsgType) { case "text": objResult = MassApi.SendText(strToken, strUser, strDept, strTags, iAppID.ToString(), strContent, IsSec); break; case "image": Dictionary <string, Stream> dic = new Dictionary <string, Stream>(); // for (int i = 0; i < Request.Files.Count; i++) { var stream = System.IO.File.OpenRead(HttpContext.Current.Server.MapPath("~/") + "/style/images/meteorshower.jpg"); dic.Add("meteorshower.jpg", stream); } var ret = MediaApi.Upload(strToken, UploadMediaFileType.file, dic, ""); objResult = MassApi.SendImage(strToken, strUser, strDept, strTags, iAppID.ToString(), ret.media_id, IsSec); break; case "news": objResult = MassApi.SendNews(strToken, strUser, strDept, strTags, iAppID.ToString(), lstContent, IsSec); break; case "file": Dictionary <string, Stream> dic1 = new Dictionary <string, Stream>(); for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++) { var stream = System.IO.File.OpenRead(HttpContext.Current.Server.MapPath("~/") + "/style/images/meteorshower.jpg"); dic1.Add("meteorshower.jpg", stream); } var ret1 = MediaApi.Upload(strToken, UploadMediaFileType.file, dic1, ""); objResult = MassApi.SendFile(strToken, strUser, strDept, strTags, iAppID.ToString(), ret1.media_id, IsSec); break; } return(objResult); }
/// <summary> /// text消息 /// </summary> /// <param name="toUser"></param> /// <param name="toParty"></param> /// <param name="toTag"></param> /// <param name="agentId"></param> /// <param name="content"></param> /// <param name="safe"></param> /// <param name="timeOut"></param> /// <returns></returns> public static MassResult SendText(string toUser, string toParty, string toTag, string agentId, string content, int safe = 0, int timeOut = 10000) { try { return(MassApi.SendText(GetToken(), toUser, toParty, toTag, agentId, content)); } catch (Exception e) { MassResult result = new MassResult(); return(result); } }
//update history after send out public async Task Update(MassResult messageResult, int historyId) { if (messageResult.errcode != 0) { await _historyDetailService.Repository.InsertAsync(new PushHistoryDetailEntity { HistoryId = historyId, ErrorUsers = messageResult.invaliduser, ErrorTags = messageResult.invalidtag, ErrorDepartments = messageResult.invalidparty, ErrorType = ErrorType.Returned.ToString() }); } }
// GET: SendMessage public void SendTest(string content, string toParty) { String corpId = ConfigurationManager.AppSettings["CorpId"]; //企业ID String secret = ConfigurationManager.AppSettings["Secret"]; String agentId = ConfigurationManager.AppSettings["AgentId"]; String accessToken = AccessTokenContainer.BuildingKey(corpId, secret); int safe = 0; String toUser = ConfigurationManager.AppSettings["toUser"]; String toTag = ConfigurationManager.AppSettings["toTag"]; int timeOut = 10000; MassResult massResult = MassApi.SendText(accessToken, agentId, content, toUser, toParty, toTag, safe, timeOut); }
public ActionResult SendTextMsg(QyTextMsgModel model) { LogWriter.Info("SendTextMsg1111111111"); LogWriter.Info(string.Format("SendTextMsg-QyTextMsgModel={0}", JsonHelper.ToJson(model))); #region 校验 var account = GetAccount(model.corpid); if (account == null) { LogWriter.Info(string.Format("corpid为“{0}”的SendTextMsg获取失败,原因:企业号不存在", model.corpid)); return(Json(new { errorcode = "500", errormsg = "企业号不存在", })); } if (!ValidateAccessToken(account, model.accesstoken)) { LogWriter.Info(string.Format("corpid为“{0}”的SendTextMsg获取失败,原因:accesstoken错误", model.corpid)); return(Json(new { errorcode = "500", errormsg = "非法访问", })); } #endregion #region 发送文本消息 var wxFO = Formula.FormulaHelper.CreateFO <WxFO>(); MassResult userinfo = null; try { userinfo = wxFO.SendTextMsg(model.corpid, model.toUser, model.toParty, model.toTag, model.agentId, model.content, model.safe); LogWriter.Info(string.Format("SendTextMsg-userinfo={0}", JsonHelper.ToJson(userinfo))); } catch (Exception ex) { return(Json(new { errorcode = "500", errormsg = ex.Message, })); } #endregion return(Json(userinfo)); }
public static MessageResult ToMsgResult(this MassResult result) { if (result == null) { throw new ArgumentNullException(nameof(result)); } return(new MessageResult { ErrorCode = result.ErrorCodeValue, ErrorMessage = result.errmsg, InvalidParty = result.invalidparty, InvalidTag = result.invalidtag, InvalidUser = result.invaliduser }); }
/// <summary> /// 发送链接消息 /// </summary> /// <param name="QyID">企业ID</param> /// <param name="toUser">UserID列表(消息接收者,多个接收者用‘|’分隔)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送</param> /// <param name="toParty">PartyID列表,多个接受者用‘|’分隔。当touser为@all时忽略本参数</param> /// <param name="toTag">TagID列表,多个接受者用‘|’分隔。当touser为@all时忽略本参数</param> /// <param name="agentId">企业应用的id,可在应用的设置页面查看</param> /// <param name="articles">图文信息内容,包括title(标题)、description(描述)、url(点击后跳转的链接。企业可根据url里面带的code参数校验员工的真实身份)和picurl(图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80。如不填,在客户端不显示图片)</param> /// <param name="safe">表示是否是保密消息,0表示否,1表示是,默认0</param> /// <returns></returns> public MassResult SendNewsMsg(string QyID, string toUser, string toParty, string toTag, string agentId, List <Article> articles, int safe = 0) { MassResult result = null; try { result = MassApi.SendNews(GetAccessToken(QyID), toUser, toParty, toTag, agentId, articles, safe); } catch (Exception ex) { LogWriter.Error(ex, string.Format("发送QyID为{0}的链接消息失败", QyID)); result = MassApi.SendNews(GetAccessToken(QyID, true), toUser, toParty, toTag, agentId, articles, safe); } if (result.errcode != ReturnCode_QY.请求成功) { LogWriter.Info(string.Format("发送QyID为{0}的链接消息失败,原因:{1}", QyID, result.errmsg)); } return(result); }
/// <summary> /// 发送文本消息 /// </summary> /// <param name="QyID">企业ID</param> /// <param name="toUser">UserID列表(消息接收者,多个接收者用‘|’分隔)。特殊情况:指定为@all,则向关注该企业应用的全部成员发送</param> /// <param name="toParty">PartyID列表,多个接受者用‘|’分隔。当touser为@all时忽略本参数</param> /// <param name="toTag">TagID列表,多个接受者用‘|’分隔。当touser为@all时忽略本参数</param> /// <param name="agentId">企业应用的id,可在应用的设置页面查看</param> /// <param name="content">消息内容</param> /// <param name="safe">表示是否是保密消息,0表示否,1表示是,默认0</param> /// <returns></returns> public MassResult SendTextMsg(string QyID, string toUser, string toParty, string toTag, string agentId, string content, int safe = 0) { MassResult result = null; try { result = MassApi.SendText(GetAccessToken(QyID), toUser, toParty, toTag, agentId, content, safe); } catch (Exception ex) { LogWriter.Error(ex, string.Format("发送QyID为{0}的文本消息失败,接收人:{1},PartID:{2},totag:{3}", toUser, QyID, toParty, toTag)); result = MassApi.SendText(GetAccessToken(QyID, true), toUser, toParty, toTag, agentId, content, safe); } if (result.errcode != ReturnCode_QY.请求成功) { LogWriter.Info(string.Format("发送QyID为{0}的文本消息失败,原因:{1}", QyID, result.errmsg)); } return(result); }
/// <summary> /// 微信文字推送 /// </summary> /// <param name="appid">应用id</param> /// <param name="content">文字内容</param> /// <param name="touser">给用户</param> /// <param name="toparty">给部门</param> /// <param name="totag">给标签</param> /// <returns></returns> public static MassResult PublishMessageText(int appid, string content, string touser, string toparty, string totag) { MassResult objResult = null; if (touser == "@all") { objResult = WechatCommon.SendMsg(appid, "text", "@all", "", "", content, null); } else if (string.IsNullOrEmpty(toparty) && string.IsNullOrEmpty(totag)) { if (string.IsNullOrEmpty(touser)) { touser = "******"; } objResult = WechatCommon.SendMsg(appid, "text", touser, "", "", content, null); } else { objResult = WechatCommon.SendMsg(appid, "text", touser, toparty, totag, content, null); } return(objResult); }
private static void UpdateMsgLog(List <ArticleInfoView> lstContent, MassResult sendResult) { try { if (lstContent != null) { string newsIdList = string.Join(",", lstContent.Select(a => a.Id)); if (!string.IsNullOrEmpty(newsIdList)) { MessageLogService msgLogService = new MessageLogService(); var needUpdateMsgLogs = msgLogService.Repository.Entities.Where(m => newsIdList.Equals(m.NewsIdList, StringComparison.OrdinalIgnoreCase)).ToList(); if (needUpdateMsgLogs != null) { if (sendResult != null) { foreach (var needUpdateMsgLog in needUpdateMsgLogs) { needUpdateMsgLog.SendMsgStatus = sendResult.errcode == ReturnCode_QY.请求成功 ? (int)SendMessageStatus.Success : (int)SendMessageStatus.Failed; needUpdateMsgLog.SendTotalMembers = GetAllMemberCount(lstContent); } } else { needUpdateMsgLogs.ForEach(m => m.SendMsgStatus = (int)SendMessageStatus.Failed); } msgLogService.Repository.Update(needUpdateMsgLogs); } } } } catch (Exception e) { log.Error("更新消息列表失败"); log.Error(e); } }
public static MassResult SendMsgQY(int iAppID, string strMsgType, string strUser, string strDept, string strTags, string strContent, List <ArticleInfoView> lstContent, int IsSec, bool isPreview = false) { MassResult objResult = null; try { var objConfig = WeChatCommonService.GetWeChatConfigByID(iAppID); log.Warn("SendMsgQY strUser:{0} strDept:{1} strTags:{2} Msg:{3} APPID:{4} strMsgType:{5} IsSec:{6} MsgCount:{7}", strUser, strDept, strTags, strContent, iAppID, strMsgType, IsSec, lstContent.Count); string strToken = (objConfig.IsCorp != null && !objConfig.IsCorp.Value) ? Innocellence.Weixin.MP.CommonAPIs.AccessTokenContainer.GetToken(objConfig.WeixinCorpId, objConfig.WeixinCorpSecret) : AccessTokenContainer.TryGetToken(objConfig.WeixinCorpId, objConfig.WeixinCorpSecret); var news = lstContent[0].NewsInfo; //保密图文消息需要用mpnews发送 strMsgType = strMsgType == "news" && IsSec == 1 ? "mpnews" : strMsgType; switch (strMsgType) { case "text": objResult = MassApi.SendText(strToken, strUser, strDept, strTags, objConfig.WeixinAppId.ToString(), lstContent[0].ArticleContent, IsSec); break; case "image": news.MediaId = DoNewsInfo(news, objConfig, AutoReplyContentEnum.IMAGE, news.ImageContent); objResult = MassApi.SendImage(strToken, strUser, strDept, strTags, objConfig.WeixinAppId.ToString(), news.MediaId, IsSec); break; case "news": #region news var wechatBaseUrl = CommonService.GetSysConfig("WeChatUrl", ""); var lstArticle = new List <Article>(); int i = 0; foreach (var objModel in lstContent) { if (i == 0) //位置不同,缩略图的比例不一样 { objModel.ImageCoverUrl = doGetFileCover(objModel.ImageCoverUrl, "_B"); } else { objModel.ImageCoverUrl = doGetFileCover(objModel.ImageCoverUrl, "_T"); } i++; lstArticle.Add(new Article() { Title = objModel.ArticleTitle, Description = objModel.ArticleComment, // PicUrl = aiv.ThumbImageId == null ? wechatBaseUrl+"/Content/img/LogoRed.png" : string.Format("{0}/Common/PushFile?id={1}&FileName={2}", wechatBaseUrl, aiv.ThumbImageId, aiv.ThumbImageUrl), //PicUrl = objModel.ImageCoverUrl == null ? wechatBaseUrl + "Content/img/LogoRed.png" : string.Format("{0}{1}", wechatBaseUrl, objModel.ImageCoverUrl), PicUrl = string.Format("{0}{1}", wechatBaseUrl, objModel.ImageCoverUrl).Replace("/\\", "/").Replace("\\", "/"), Url = string.Format("{0}/News/ArticleInfo/WxDetail/{1}?wechatid={2}&isPreview={3}", wechatBaseUrl, objModel.Id, objModel.AppId, isPreview) }); } //var lstArticle = lstContent.Select(objModel => new Article() //{ // Title = objModel.ArticleTitle, // Description = objModel.ArticleComment, // // PicUrl = aiv.ThumbImageId == null ? wechatBaseUrl+"/Content/img/LogoRed.png" : string.Format("{0}/Common/PushFile?id={1}&FileName={2}", wechatBaseUrl, aiv.ThumbImageId, aiv.ThumbImageUrl), // //PicUrl = objModel.ImageCoverUrl == null ? wechatBaseUrl + "Content/img/LogoRed.png" : string.Format("{0}{1}", wechatBaseUrl, objModel.ImageCoverUrl), // PicUrl = string.Format("{0}{1}", wechatBaseUrl, objModel.ImageCoverUrl).Replace("/\\", "/").Replace("\\", "/"), // Url = string.Format("{0}/News/ArticleInfo/WxDetail/{1}?wechatid={2}&isPreview={3}", wechatBaseUrl, objModel.Id, objModel.AppId, isPreview) //}).ToList(); objResult = MassApi.SendNews(strToken, strUser, strDept, strTags, objConfig.WeixinAppId.ToString(), lstArticle, IsSec); #endregion break; case "mpnews": #region mpnews var wechatBaseUrl1 = CommonService.GetSysConfig("WeChatUrl", ""); var lstMpArticle = new List <MpNewsArticle>(); int ii = 0; foreach (var objModel in lstContent) { if (ii == 0) //位置不同,缩略图的比例不一样 { objModel.ImageCoverUrl = doGetFileCover(objModel.ImageCoverUrl, "_B"); } else { objModel.ImageCoverUrl = doGetFileCover(objModel.ImageCoverUrl, "_T"); } ii++; lstMpArticle.Add(new MpNewsArticle() { title = objModel.ArticleTitle, digest = objModel.ArticleComment, content = objModel.ArticleContent, author = objModel.UpdatedUserID, show_cover_pic = "1", thumb_media_id = GetMediaId(objModel.ImageCoverUrl, strToken), // PicUrl = aiv.ThumbImageId == null ? wechatBaseUrl+"/Content/img/LogoRed.png" : string.Format("{0}/Common/PushFile?id={1}&FileName={2}", wechatBaseUrl, aiv.ThumbImageId, aiv.ThumbImageUrl), //PicUrl = objModel.ImageCoverUrl == null ? wechatBaseUrl + "Content/img/LogoRed.png" : string.Format("{0}{1}", wechatBaseUrl, objModel.ImageCoverUrl), // = string.Format("{0}{1}", wechatBaseUrl, objModel.ImageCoverUrl), content_source_url = string.Format("{0}/News/ArticleInfo/WxDetail/{1}?wechatid={2}&isPreview={3}", wechatBaseUrl1, objModel.Id, objModel.AppId, isPreview) }); } objResult = MassApi.SendMpNews(strToken, strUser, strDept, strTags, objConfig.WeixinAppId.ToString(), lstMpArticle, IsSec); #endregion break; case "video": //WechatCommon.GetMediaInfo(AutoReplyContentEnum.VIDEO, news, news.AppId); news.MediaId = DoNewsInfo(news, objConfig, AutoReplyContentEnum.VIDEO, news.VideoContent); objResult = MassApi.SendVideo(strToken, strUser, strDept, strTags, objConfig.WeixinAppId.ToString(), news.MediaId, news.NewsTitle, news.NewsComment, IsSec); //NewsToAttachments(news, "video", news.VideoContent); break; case "file": // WechatCommon.GetMediaInfo(AutoReplyContentEnum.FILE, news, news.AppId); news.MediaId = DoNewsInfo(news, objConfig, AutoReplyContentEnum.FILE, news.FileSrc); objResult = MassApi.SendFile(strToken, strUser, strDept, strTags, objConfig.WeixinAppId.ToString(), news.MediaId, IsSec); // NewsToAttachments(news, "file", news.FileSrc); break; case "voice": // WechatCommon.GetMediaInfo(AutoReplyContentEnum.VOICE, news, news.AppId); news.MediaId = DoNewsInfo(news, objConfig, AutoReplyContentEnum.VOICE, news.SoundSrc); objResult = MassApi.SendVoice(strToken, strUser, strDept, strTags, objConfig.WeixinAppId.ToString(), news.MediaId, IsSec); //NewsToAttachments(news, "voice", news.SoundSrc); break; } } catch (Exception e) { log.Error(e); throw; } //在更新MsgLog时保持原来的错误处理, 即不进行任何处理 finally { UpdateMsgLog(lstContent, objResult); } return(objResult); }