protected override void PublishByRole(int appid, Article article, ArticleInfoView articleInfoView) { List <TagItem> tagList = WeChatCommonService.lstTag; switch (articleInfoView.ArticleCateSub) { case "SM_SALES_VEEVA": case "SM_SALES_RAPID": case "SM_SALES_OTHER": WechatCommon.PublishMessage(appid, new List <Article>() { article }, "", "", GetTagIdByTagName(tagList, "SF_REP|SF_DM|SF_NSD|SF_Trainer")); break; case "SM_MARKET_HCP": case "SM_MARKET_SPEAKER": case "SM_MARKET_VEEVA": case "SM_MARKET_FAQ": WechatCommon.PublishMessage(appid, new List <Article>() { article }, "", "", GetTagIdByTagName(tagList, "SPP_MKT")); break; default: WechatCommon.PublishMessage(appid, new List <Article>() { article }, "@all", "", ""); break; } }
protected virtual void PublishByRole(int appid, Article article, ArticleInfoView articleInfoView) { var category = CommonService.lstCategory.First(r => r.CategoryCode == articleInfoView.ArticleCateSub);//.Role.Replace(',', '|'); if (string.IsNullOrEmpty(category.Role) || category.Role == "@all") { // 如果role里为空或者为@all,就是发给所有人的 WechatCommon.PublishMessage(appid, new List <Article>() { article }, "@all", "", ""); } else { //WeChatCommonService.lstTag var roles = category.Role.Split(','); var tagIds = WeChatCommonService.lstTag.Where(x => roles.Any(y => y == x.tagname)).Select(x => x.tagid); // 如果role里不是@all,就是发给指定人的,特指标签组 WechatCommon.PublishMessage(appid, new List <Article>() { article }, "", "", string.Join("|", tagIds)); } }
/// <summary> /// 批量发布文章 /// </summary> /// <param name="Ids">文章的ID-数组</param> /// <param name="appid">当前应用ID</param> /// <returns></returns> public JsonResult ChangeStatusBatch(string[] Ids) { int iRet = 0; List <Article> articleList = new List <Article>(); var dateNow = DateTime.Now; var appid = 0; for (int i = 0; i < Ids.Length; i++) { var objModel = _BaseService.Repository.GetByKey(int.Parse(Ids[i])); appid = objModel.AppId.GetValueOrDefault(); if (objModel.ArticleStatus == null || objModel.ArticleStatus == ConstData.STATUS_NEW) { objModel.ArticleStatus = ConstData.STATUS_PUBLISH; objModel.PublishDate = dateNow.AddSeconds(Ids.Length - i);//更新时间越加越少,这样倒序排才能与后台顺序一致 //向前台推送提醒信息 ArticleInfoView aiv = (ArticleInfoView) new ArticleInfoView().ConvertAPIModel(objModel); LogManager.GetLogger(this.GetType()).Debug(string.Format("ImageUrl = '{0}', ArticleUrl='{1}'", aiv.ThumbImageUrl, aiv.ArticleURL)); var article = new Article() { Title = objModel.ArticleTitle, Description = objModel.ArticleComment, PicUrl = aiv.ThumbImageId == null ? "http://wechatcms.lillyadmin.cn/Content/img/LillyLogoRed.png" : string.Format("{0}/Common/PushFile?id={1}&FileName={2}", WechatBaseUrl, aiv.ThumbImageId, aiv.ThumbImageUrl), Url = string.Format("{0}/News/ArticleInfo/WxDetail/{1}", WechatBaseUrl, objModel.Id) }; //添加到文章列表中去 articleList.Add(article); } else { objModel.ArticleStatus = ConstData.STATUS_NEW; objModel.PublishDate = null; } iRet = _BaseService.Repository.Update(objModel, new List <string>() { "ArticleStatus", "PublishDate" }); } if (articleList.Any()) { //最后将文章列表推送--批量默认推送给全部人 WechatCommon.PublishMessage(appid, articleList, "@all", "", ""); } if (iRet > 0) { return(SuccessNotification("Success")); } else { return(ErrorNotification("Change Status Falid")); } }
private Result <object> PushMessage(Message objModel, int historyId) { var result = new Result <object> { Status = 200 }; if (objModel.Status == null || objModel.Status == ConstData.STATUS_NEW) { objModel.Status = ConstData.STATUS_PUBLISH; objModel.PublishDate = DateTime.Now; //向前台推送提醒信息 var aiv = (MessageView) new MessageView().ConvertAPIModel(objModel); var article = new Article() { Title = objModel.Title, PicUrl = string.Format("{0}/Common/PushFile?id={1}&FileName={2}", WechatBaseUrl, aiv.ThumbImageId, aiv.ThumbImageUrl), Description = objModel.Comment, Url = string.Format("{0}/Message/WxDetailh5/{1}", WechatBaseUrl, objModel.Id) }; var pushResult = WechatCommon.PublishMessage(objModel.AppId.GetValueOrDefault(), new List <Article>() { article }, aiv.toUser, aiv.toDepartment, aiv.toTag); if (pushResult.errcode != ReturnCode_QY.请求成功) { _pushHistoryDetailService.Repository.Insert(new PushHistoryDetailEntity { HistoryId = historyId, ErrorDepartments = pushResult.invalidparty, ErrorTags = pushResult.invalidtag, ErrorUsers = pushResult.invaliduser, ErrorType = ErrorType.Returned.ToString(), }); result.Status = (int)StatusCode.Others; result.Message = pushResult.errcode.ToString(); } _BaseService.Repository.Update(objModel, new List <string> { "Status", "PublishDate" }); } else { result.Status = 99; result.Message = "message不能重复推送!"; } return(result); }
/// <summary> /// 发布消息 /// </summary> /// <param name="Id">消息ID</param> /// <param name="ispush">是否推送到前台</param> /// <returns></returns> public virtual JsonResult ChangeStatus(string Id, int appid, bool ispush) { int iRet = 0; var objModel = _BaseService.Repository.GetByKey(int.Parse(Id)); if (objModel.ArticleStatus == null || objModel.ArticleStatus == ConstData.STATUS_NEW) { objModel.ArticleStatus = ConstData.STATUS_PUBLISH; objModel.PublishDate = DateTime.Now; //向前台推送提醒信息 ArticleInfoView aiv = (ArticleInfoView) new ArticleInfoView().ConvertAPIModel(objModel); if (ispush) { //var article = new ArticleInfoView() //{ // ArticleTitle = objModel.ArticleTitle, // ImageCoverUrl = aiv.ThumbImageUrl, // //Description = objModel.Comment, // //Url = string.Format("{0}/Message/WxDetailh5/{1}", wechatBaseUrl, objModel.Id) //}; WechatCommon.PublishMessage(objModel.AppId.GetValueOrDefault(), new List <ArticleInfoView>() { aiv }, aiv.ToUser, aiv.ToDepartment, aiv.ToTag); } } else { objModel.ArticleStatus = ConstData.STATUS_NEW; objModel.PublishDate = null; } iRet = _BaseService.Repository.Update(objModel, new List <string>() { "Status", "PublishDate" }); if (iRet > 0) { return(SuccessNotification("Success")); } else { return(ErrorNotification("Change Status Falid")); } }
public virtual JsonResult WxPreview(ArticleInfoView objModal) { //从post过来的form拿数据 string Id = Request.Form["ID"]; //验证错误 if (!BeforeAddOrUpdate(objModal, Id) || !ModelState.IsValid) { return(Json(GetErrorJson(), JsonRequestBehavior.AllowGet)); } // ID变更为CategoryCode var cateInfo = CommonService.lstCategory.FirstOrDefault(a => a.Id == Convert.ToInt32(objModal.ArticleCateSub) && a.IsDeleted == false); if (cateInfo == null) { return(Json(GetErrorJson(), JsonRequestBehavior.AllowGet)); } objModal.ArticleCateSub = cateInfo.CategoryCode; InsertOrUpdate(objModal, Id); //向前台推送提醒信息 var article = new Article() { Title = "[预览]" + objModal.ArticleTitle, Description = objModal.ArticleComment, PicUrl = string.Format("{0}/Common/PushFile?id={1}&FileName={2}", WechatBaseUrl, objModal.ThumbImageId, objModal.ThumbImageUrl), Url = string.Format("{0}/News/ArticleInfo/WxPreview/{1}", WechatBaseUrl, objModal.Id) }; //为了fix掉新建文章预览 微信接口报错后 再save 出现2条数据 try { WechatCommon.PublishMessage(objModal.AppId.GetValueOrDefault(), new List <Article>() { article }, objModal.Previewers, "", ""); } catch (Exception ex) { return(SuccessNotification(string.Format("{0};{1}", objModal.Id, ex.Message))); } return(SuccessNotification(string.Format("{0}", objModal.Id))); }
protected override void PublishByRole(int appid, Article article, ArticleInfoView articleInfoView) { List <TagItem> tagList = this.PrepareEditData(appid); switch (articleInfoView.ArticleCateSub) { case "ST_RCOUR_VIEW": case "ST_RTRA_BAA": case "ST_RMICRO_FORUM": case "ST_RMICRO_SHARE": case "ST_RLEARN_TYRANT": WechatCommon.PublishMessage(appid, new List <Article>() { article }, "", "", GetTagIdByTagName(tagList, "SF_REP|SF_DM|SF_RSD|SF_NSD|SF_Trainer")); break; case "ST_ECOUR_VIEW": case "ST_ETRA_BAA": case "ST_EMICRO_FORUM": case "ST_EMICRO_SHARE": WechatCommon.PublishMessage(appid, new List <Article>() { article }, "", "", GetTagIdByTagName(tagList, "SF_DM|SF_RSD|SF_NSD|SF_Trainer")); break; case "ST_TRAIN_CALA": case "ST_RDPAC_GUIDE": case "ST_LEARN_GUIDE": case "ST_CONNECT_US": WechatCommon.PublishMessage(appid, new List <Article>() { article }, "@all", "", ""); break; default: WechatCommon.PublishMessage(appid, new List <Article>() { article }, "@all", "", ""); break; } }
public virtual JsonResult WxPreview(ArticleInfoView objModal) { //从前台form里拿数据 string Id = objModal.Id.ToString(); //验证错误 if (!BeforeAddOrUpdate(objModal, Id) || !ModelState.IsValid) { return(Json(GetErrorJson(), JsonRequestBehavior.AllowGet)); } InsertOrUpdate(objModal, Id); //向前台推送提醒信息 var article = new ArticleInfoView() { //Title = "[预览]" + objModal.Title, //PicUrl = string.Format("{0}/Common/PushFile?id={1}&FileName={2}", wechatBaseUrl, objModal.ThumbImageId, objModal.ThumbImageUrl), //Description = objModal.Comment, //Url = string.Format("{0}/Message/WxPreviewh5/{1}", wechatBaseUrl, objModal.Id) }; //为了fix掉新建文章预览 微信接口报错后 再save 出现2条数据 try { WechatCommon.PublishMessage(objModal.AppId.GetValueOrDefault(), new List <ArticleInfoView>() { article }, objModal.Previewers, "", ""); } catch (Exception ex) { return(SuccessNotification(string.Format("{0};{1}", objModal.Id, ex.Message))); } return(SuccessNotification(string.Format("{0}", objModal.Id))); }
public JsonResult SendNewEmployee() { var AppId = CommonService.GetSysConfig("NewEmployeeAppId", ""); var articleSettingList = _localSADService.SendArticleToNewEmployee(); try { foreach (var em in articleSettingList) { if (em.employeeLst.Count > 0) { string[] ids = em.ArticleId.Split(','); List <Article> articlelist = new List <Article>(); foreach (var item in ids) { Message message = _messageService.Repository.Entities.Where(a => a.Id.ToString() == item).SingleOrDefault(); if (message != null) { var article = new Article() { Title = message.Title, Description = message.Comment, PicUrl = string.Format("{0}/Common/PushFile?id={1}&FileName={2}", WechatBaseUrl, message.ThumbImageId, message.ThumbImageUrl), Url = string.Format("{0}/News/Message/WxDetailh5/{1}", WechatBaseUrl, item) }; articlelist.Add(article); } } WechatCommon.PublishMessage(int.Parse(AppId), articlelist, em.UserLst, "", ""); BaseService <LogsModel> objServLogs = new BaseService <LogsModel>(); string tmpCategory = em.Month + "&" + em.Days; string tmpCateDis = ""; switch (tmpCategory) { case "&7": tmpCateDis = "7 days"; break; case "&15": tmpCateDis = "15 days"; break; case "5&": tmpCateDis = "5 months"; break; case "6&": tmpCateDis = "6 months"; break; default: break; } string[] arrID = em.UserLst.Split('|'); foreach (string strID in arrID) { if (strID != "") { objServLogs.Repository.Insert(new LogsModel() { LogCate = tmpCateDis, LogContent = "发送成功", CreatedUserID = strID, CreatedUserName = strID }); } } } } var deleteuserList = _localSADService.GetDeleteNewEmployee(); string newname = CommonService.GetSysConfig("TagNameNewEmployee", ""); var Config = WeChatCommonService.GetWeChatConfig(int.Parse(AppId)); var token = AccessTokenContainer.TryGetToken(Config.WeixinCorpId, Config.WeixinCorpSecret); //var taglist = MailListApi.GetTagList(token).taglist.Where(x => x.tagname == tagName); var taglist = WeChatCommonService.lstTag.Where(x => x.tagname == newname); int tagid = taglist.FirstOrDefault() != null?Convert.ToInt32(taglist.FirstOrDefault().tagid) : 0; string[] userLst = deleteuserList.Split('|'); List <string> userlist = new List <string>(); foreach (string user in userLst) { userlist.Add(user); } MailListApi.DelTagMember(token, tagid, userlist.ToArray()); } catch (Exception ex) { _logger.Error("Publish Message Error: {0}", ex.Message.ToString()); return(Json(false, JsonRequestBehavior.AllowGet)); } return(Json(true, JsonRequestBehavior.AllowGet)); }