/// <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); }
public override IWorkResponseMessageBase OnTextRequest(RequestMessageText requestMessage) { var responseMessage = this.CreateResponseMessage<ResponseMessageText>(); responseMessage.Content = "您发送了消息:" + requestMessage.Content; //发送一条客服消息 var weixinSetting = Config.SenparcWeixinSetting.WorkSetting; var appKey = AccessTokenContainer.BuildingKey(weixinSetting.WeixinCorpId, weixinSetting.WeixinCorpSecret); MassApi.SendText(appKey, weixinSetting.WeixinCorpAgentId, "这是一条客服消息,对应您发送的消息:" + requestMessage.Content, OpenId); return responseMessage; }
public static void SendTextCard(string app, string toUser, string title, string desc) { var env = IocManager.Instance.Resolve <IHostingEnvironment>(); var appConfiguration = env.GetAppConfiguration(); string corpId = appConfiguration["SenparcWeixinSetting:CorpId"]; string secret = appConfiguration[string.Format("SenparcWeixinSetting:{0}:Secret", app)]; string agentId = appConfiguration[string.Format("SenparcWeixinSetting:{0}:AgentId", app)]; var accessToken = AccessTokenContainer.GetToken(corpId, secret); MassApi.SendTextCardAsync(accessToken, agentId, title, desc, "work.weixin.qq.com", null, toUser); }
public WorkJsonResult MassApiSendNews(SendNewsDataDto dto) { var token = GetAccessToken(QyConfig.CorpID, QyConfig.CorpSecret); dto.agentid = 91; //dto.news.articles.ForEach(p=> { // p.description= striphtml(p.description.Replace("'", "”")).Replace("'", "”"); //}); var result = MassApi.SendNews(token, dto); return(result); }
/// <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); } }
public ActionResult SendNewMsgToBase64(string by, string value, string applicationId, string data, string type, string safe, string clientId) { if (!VerifyNewParam("by,value,applicationId,type,safe", clientId, _signCheckService)) { return(ErrMsg()); } if (string.IsNullOrEmpty(data) == false) { byte[] bytes = Convert.FromBase64String(data.Replace(" ", "+")); data = Encoding.UTF8.GetString(bytes); data = HttpUtility.HtmlDecode(data); } var weChatConfig = GetWechatConfig(); var toUsrids = string.Join("|", value); var token = Innocellence.Weixin.QY.CommonAPIs.AccessTokenContainer.GetToken(weChatConfig.WeixinCorpId, weChatConfig.WeixinCorpSecret); Weixin.QY.AdvancedAPIs.Mass.MassResult objResult; if (type == "news") { var lst = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Article> >(data); objResult = MassApi.SendNews(token, toUsrids, "", "", weChatConfig.WeixinAppId.ToString(), lst, safe == "true" ? 1 : 0); } else { objResult = MassApi.SendText(token, toUsrids, "", "", weChatConfig.WeixinAppId.ToString(), data, safe == "true" ? 1 : 0); } if (objResult.errcode == Weixin.ReturnCode_QY.请求成功) { return(Json(new { message = "", success = true }, JsonRequestBehavior.AllowGet)); } else { return(ErrMsg(objResult.errmsg)); } // return Json(new { success = true, message = "" }, JsonRequestBehavior.AllowGet); }
public ResultJSON <Store> Put([FromBody] Store model) { r.CurrentUser = UserName; //推送到“系统设置” this.option.系统设置AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.系统设置Secret); MassApi.SendTextCard(option.系统设置AccessToken, option.系统设置AgentId, $"{UserName}修改了{model.Name}" , $"<div class=\"gray\">时间:{DateTime.Now.ToString("yyyy-MM-dd hh:mm")}</div>" , "https://vue.car0774.com/#/oilstore/store", toUser: "******"); return(new ResultJSON <Store> { Code = 0, Data = r.InsertOrUpdate(model) }); }
// 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); }
/// <summary> /// 发送文本消息到给定的用户; /// </summary> /// <param name="userOpenId">用户的openid</param> /// <param name="content"></param> public bool SendMessage(string userOpenId, string content) { // userOpenId = "qy01c0f1cc0310c7002848a37e2e"; //var appkey = AccessTokenContainer.BuildingKey(Config.CorpId, Config.AppSecret); // var result = MassApi.SendText(AccessToken, Config.AppId, content, CorrectUserOpenId(userOpenId)); //var result = MassApi.SendText(appkey, Config.AppId, content, CorrectUserOpenId(userOpenId)); var result = MassApi.SendText(AccessTokenOrAppKey, Config.AppId, content, CorrectUserOpenId(userOpenId)); if (result.errcode != 0) { return(false); } return(true); //var massResult = MassApi.SendText(AccessToken, userOpenId, null, null, Config.AgentId, content); }
public void SendTPMSG(string ModelCode, List <Article> MODEL, string strUserS = "@all") { try { var app = new JH_Auth_ModelB().GetEntity(p => p.ModelCode == ModelCode); if (strUserS == "") { return; } if (Qyinfo.IsUseWX == "Y") { MassApi.SendNews(GetToken(app.AppID.ToString()), app.AppID, MODEL, strUserS, "", ""); } } catch { } }
/// <summary> /// 文字消息 /// </summary> /// <param name="MsgText"></param> /// <param name="strAPPID"></param> /// <param name="strUserS"></param> public void SendWXRText(string MsgText, string ModelCode, string strUserS = "@all") { try { var app = new JH_Auth_ModelB().GetEntity(p => p.ModelCode == ModelCode); if (strUserS == "") { return; } if (Qyinfo.IsUseWX == "Y") { MassApi.SendText(GetToken(app.AppID.ToString()), strUserS, "", "", app.AppID, MsgText); } } catch { } }
/// <summary> /// 图片消息 /// </summary> /// <param name="filePath"></param> /// <param name="strAPPID"></param> /// <param name="strUserS"></param> public void SendImage(string filePath, string strAPPID, string strUserS = "@all") { try { if (strUserS == "") { return; } if (Qyinfo.IsUseWX == "Y") { Senparc.Weixin.Work.AdvancedAPIs.Media.UploadTemporaryResultJson md = MediaApi.Upload(GetToken(), Senparc.Weixin.Work.UploadMediaFileType.image, filePath); if (md.media_id != "") { MassApi.SendImage(GetToken(), strUserS, "", "", strAPPID, md.media_id); } } } catch { } }
/// <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); }
public ResultJSON <string> ApplyClientToCompany(int cid, int coid, string carNo, string companyName) { try { this.option.客户AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.客户Secret); //推送到“客户” MassApi.SendTextCard(this.option.客户AccessToken, this.option.客户AgentId, $"{UserName}申请{carNo}编入{companyName}" , $"<div class=\"gray\">申请编入公司:{companyName}</div>" , $"https://vue.car0774.com/#/sales/clienttocompany/{cid.ToString()}/{coid.ToString()}/{companyName}", toUser: "******"); return(new ResultJSON <string> { Code = 0, Msg = "提交申请成功" }); } catch { return(new ResultJSON <string> { Code = 503, Msg = "推送失败请重试" }); } }
public ResultJSON <Purchase> Post([FromBody] Purchase p) { //判断是否重复单号 if (r.Has(pu => pu.Name == p.Name)) { return new ResultJSON <Purchase> { Code = 502 } } ; var product = p.Product; p.Product = null; r.CurrentUser = UserName; var result = r.Insert(p); //推送到“进油看板” this.option.进油看板AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.进油看板Secret); MassApi.SendTextCard(option.进油看板AccessToken, option.进油看板AgentId, $"{UserName}开出了进油计划单" , $"<div class=\"gray\">单号:{result.Name}</div>" + $"<div class=\"normal\">商品:{product.Name}</div>" + $"<div class=\"normal\">运输车号:{result.CarNo}{result.TrailerNo}</div>" + $"<div class=\"normal\">预计到达:{result.ArrivalTime}</div>" , $"https://vue.car0774.com/#/produce/buyboard", toUser: "******"); //推送到“陆上卸油” this.option.陆上卸油AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.陆上卸油Secret); MassApi.SendTextCard(option.陆上卸油AccessToken, option.陆上卸油AgentId, $"{UserName}开出了进油计划单" , $"<div class=\"gray\">单号:{result.Name}</div>" + $"<div class=\"normal\">商品:{product.Name}</div>" + $"<div class=\"normal\">运输车号:{result.CarNo}{result.TrailerNo}</div>" + $"<div class=\"normal\">预计到达:{result.ArrivalTime}</div>" , $"https://vue.car0774.com/#/produce/buyboard", toUser: "******"); return(new ResultJSON <Purchase> { Code = 0, Data = result }); }
public async Task <ResultJSON <MoveStore> > UpdateInOutFact([FromBody] MoveStore m) { r.CurrentUser = UserName; var result = r.UpdateInOutFact(m); //推送到“油仓情况” this.option.油仓情况AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.油仓情况Secret); await MassApi.SendTextCardAsync(option.油仓情况AccessToken, option.油仓情况AgentId, "转仓生产完工,已更新油仓油量" , $"<div class=\"gray\">单号:{result.Name}</div>" + $"<div class=\"normal\">施工人:{result.LastUpdatedBy}</div>" + $"<div class=\"normal\">转出:{result.OutStoreName} - {result.OutFact}升</div>" + $"<div class=\"normal\">转入:{result.InStoreName} - {result.InFact}升</div>" , $"https://vue.car0774.com/#/oilstore/inout", toUser : "******"); return(new ResultJSON <MoveStore> { Code = 0, Data = result }); }
public void SendNew(string title, string description, string picUrl, string url, string toUser) { List <Article> articles = new List <Article>(); if (!string.IsNullOrWhiteSpace(picUrl) && picUrl.IndexOf("http") < 0) { picUrl = workSetting.Value.SendMsgHost + picUrl; } if (!string.IsNullOrWhiteSpace(url) && url.IndexOf("http") < 0) { url = workSetting.Value.SendMsgHost + url; } articles.Add(new Article() { Title = title, Description = description, PicUrl = picUrl, Url = url }); MassApi.SendNews(workSetting.Value.MsgAccessTokenKey, workSetting.Value.MsgAppId, articles, toUser); }
public ResultJSON <Product> ModifyProdPrice([FromBody] List <Product> list) { r.CurrentUser = UserName; int count = r.ModifyProdPrice(list); if (count == 0) { return new ResultJSON <Product> { Code = 501, Msg = "提交的单价没有变化" } } ; if (count == -1) { return new ResultJSON <Product> { Code = 501, Msg = "保存出错,请联系开发人员" } } ; #if DEBUG //推送到“水上计划” this.option.水上计划AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.水上计划Secret); MassApi.SendTextCard(option.水上计划AccessToken, option.水上计划AgentId, $"{UserName}修改了{count}项商品限价" , $"<div class=\"gray\">时间:{DateTime.Now.ToString("yyyy-MM-dd hh:mm")}</div>" , "https://", toUser: "******"); //推送到“陆上计划” this.option.陆上计划AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.陆上计划Secret); MassApi.SendTextCard(option.陆上计划AccessToken, option.陆上计划AgentId, $"{UserName}修改了{count}项商品限价" , $"<div class=\"gray\">时间:{DateTime.Now.ToString("yyyy-MM-dd hh:mm")}</div>" , "https://", toUser: "******"); //推送到“销售单” this.option.销售单AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.销售单Secret); MassApi.SendTextCard(option.销售单AccessToken, option.销售单AgentId, $"{UserName}修改了{count}项商品限价" , $"<div class=\"gray\">时间:{DateTime.Now.ToString("yyyy-MM-dd hh:mm")}</div>" , "https://", toUser: "******"); #endif return(new ResultJSON <Product> { Code = 0 }); }
public ResultJSON <Purchase> Del(int id, string delreason) { try { Purchase purchase = r.SetIsDel(id, delreason); //推送到“进油看板” this.option.进油看板AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.进油看板Secret); MassApi.SendTextCard(option.进油看板AccessToken, option.进油看板AgentId, $"{UserName}作废了进油计划单" , $"<div class=\"gray\">单号:{purchase.Name}</div>" + $"<div class=\"normal\">原因:{purchase.DelReason}</div>" , $"https://vue.car0774.com/#/purchase/purchase/" + purchase.Id + "/buyboard", toUser: "******"); return(new ResultJSON <Purchase> { Code = 0, Data = purchase }); } catch (Exception e) { return(new ResultJSON <Purchase> { Code = 503, Msg = e.Message }); } }
public ResultJSON <Purchase> AuditingOK([FromBody] Purchase pu) { pu.State = Purchase.UnloadState.已审核; decimal infactTotal = r.UpdateStoreOil(pu); string pName = p_r.Get(pu.ProductId).Name;//取得商品名称 //更新油仓相关数量,平均单价,出入仓记录 if (infactTotal > 0) { //推送到“油仓情况” this.option.油仓情况AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.油仓情况Secret); MassApi.SendTextCard(option.油仓情况AccessToken, option.油仓情况AgentId, "卸油审核成功,已更新油仓油量" , $"<div class=\"gray\">卸油单号:{pu.Name}</div>" + $"<div class=\"normal\">审核人:{UserName}</div>" + $"<div class=\"normal\">商品:{pName}</div>" + $"<div class=\"normal\">计划:{pu.Count}吨</div>" + $"<div class=\"normal\">实际:{infactTotal}升</div>" + $"<div class=\"normal\">密度:{pu.Density}</div>" , $"https://vue.car0774.com/#/purchase/purchase/{pu.Id}/unloadaudit", toUser: "******"); return(new ResultJSON <Purchase> { Code = 0, Data = r.Update(pu) }); } else { return new ResultJSON <Purchase> { Code = 500, Msg = "操作失败" } }; }
public static void SendNews(string agentId, List <string> userCodes, List <Article> articles) { userCodes.ForEach(userCode => MassApi.SendNews(GetToken(agentId), agentId, articles, userCode)); }
public void SendTextMsg(string content, string toUser = null, string toParty = null) { var reObj = MassApi.SendText(workSetting.Value.MsgAccessTokenKey, workSetting.Value.MsgAppId, content, toUser: toUser, toParty: toParty); }
public override void ExecuteResult(ControllerContext context) { if (base.Content == null) { //使用IMessageHandler输出 if (_messageHandlerDocument == null) { throw new Innocellence.Weixin.Exceptions.WeixinException("执行WeixinResult时提供的MessageHandler不能为Null!", null); } if (_messageHandlerDocument.ResponseMessage == null) { //throw new Innocellence.Weixin.MP.WeixinException("ResponseMessage不能为Null!", null); } else { context.HttpContext.Response.ClearContent(); context.HttpContext.Response.ContentType = "text/xml"; foreach (var a in _messageHandlerDocument.ResponseMessage) { var config = WeChatCommonService.lstSysWeChatConfig.Find(aa => aa.WeixinCorpId == a.FromUserName); var strToken = WeChatCommonService.GetWeiXinToken(config.Id); if ((a as ResponseMessageBaseWechat).isSafe) { if (a is ResponseMessageImage) { var b = (ResponseMessageImage)a; MassApi.SendImage(strToken, b.ToUserName, "", "", config.WeixinAppId.ToString(), b.Image.MediaId, 1); } else if (a is ResponseMessageVideo) { var b = (ResponseMessageVideo)a; MassApi.SendVideo(strToken, b.ToUserName, "", "", config.WeixinAppId.ToString(), b.Video.MediaId, b.Video.Title, b.Video.Description, 1); } else if (a is ResponseMessageVoice) { var b = (ResponseMessageVoice)a; MassApi.SendVoice(strToken, b.ToUserName, "", "", config.WeixinAppId.ToString(), b.Voice.MediaId, 1); } else if (a is ResponseMessageText) { var b = (ResponseMessageText)a; MassApi.SendText(strToken, b.ToUserName, "", "", config.WeixinAppId.ToString(), b.Content, 1); } else if (a is ResponseMessageMpNews) { var b = (ResponseMessageMpNews)a; MassApi.SendMpNews(strToken, b.ToUserName, "", "", config.WeixinAppId.ToString(), b.MpNewsArticles, 1); } else if (a is ResponseMessageNews) { log.Error("ExecuteResult ResponseMessageNews but Type is safe message!"); _messageHandlerDocument.FinalResponseDocument(a as ResponseMessageBaseWechat).Save(context.HttpContext.Response.OutputStream); } } else { _messageHandlerDocument.FinalResponseDocument(a as ResponseMessageBaseWechat).Save(context.HttpContext.Response.OutputStream); } } } } base.ExecuteResult(context); }
public async Task <ResultJSON <Order> > Post([FromBody] Order o) { //判断是否重复单号 if (r.Has(od => od.Name == o.Name)) { return new ResultJSON <Order> { Code = 502 } } ; r.CurrentUser = UserName; if (r.Has(od => od.Name == o.Name)) { return new ResultJSON <Order> { Code = 501, Msg = "已存在单号" + o.Name + ",请勿重复提交" } } ; //如果不存在该客户,则新增到Client表中,并关联ClientId if (!cr.Has(cl => cl.CarNo == o.CarNo)) { Client c = cr.Insert(new Client { Name = "个人", CarNo = o.CarNo }); o.ClientId = c.Id; } //如果没有计划,则不用指定销售员,客户需求,不用计算提成 if (!o.SalesPlanId.HasValue) { o.Salesman = ""; } //标识“陆上”和“水上”的单 o.IsWater = o.OrderType == SalesPlanType.水上加油 || o.OrderType == SalesPlanType.水上机油 ? true : false; var result = r.Insert(o); //"水上加油"不再独立施工流程,跳过施工过程直接“完工”状态 if (o.OrderType == SalesPlanType.水上加油) { o.State = OrderState.已完成; o.OilCountLitre = o.Count; o.OilCount = o.Count; var res = r.ChangeState(o); //推送到“油仓情况” this.option.油仓情况AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.油仓情况Secret); await MassApi.SendTextCardAsync(option.油仓情况AccessToken, option.油仓情况AgentId, $"{result.CarNo}加油完工,已更新油仓油量" , $"<div class=\"gray\">单号:{result.Name}</div>" + $"<div class=\"normal\">施工人:{result.Worker}</div>" + $"<div class=\"normal\">数量:{Math.Round(result.OilCountLitre, 2)}升</div>" , $"https://vue.car0774.com/#/sales/order/{result.Id}/order", toUser : "******"); } //推送打印指令 //await _hub.Clients.All.InvokeAsync("printorder", result); //初始化推送需要到的AccessToken this.option.销售单AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.销售单Secret); this.option.加油AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.加油Secret); //#if !DEBUG //推送到“收银” this.option.收银AccessToken = AccessTokenContainer.TryGetToken(this.option.CorpId, this.option.收银Secret); await MassApi.SendTextCardAsync(option.收银AccessToken, option.收银AgentId, "已开单" , $"<div class=\"gray\">单号:{result.Name}</div>" + $"<div class=\"normal\">开单人:{UserName}</div>" + $"<div class=\"normal\">船号/车号/客户名称:{result.CarNo}</div>" , $"https://vue.car0774.com/#/sales/order/{result.Id}/order", toUser : "******"); string strType = "", orderUrl = "", produceUrl = "", carOrBoat = ""; switch (result.OrderType) { case SalesPlanType.水上加油: strType = "水上加油"; orderUrl = $"https://vue.car0774.com/#/sales/order/{result.Id}/order"; produceUrl = $"https://vue.car0774.com/#/produce/load/{result.Id}/0"; carOrBoat = "船号"; break; case SalesPlanType.陆上装车: strType = "陆上装车"; orderUrl = $"https://vue.car0774.com/#/sales/order/{result.Id}/order"; produceUrl = $"https://vue.car0774.com/#/produce/landload/{result.Id}"; carOrBoat = "车号/客户名"; break; case SalesPlanType.汇鸿车辆加油: strType = "汇鸿车辆加油"; orderUrl = $"https://vue.car0774.com/#/sales/order/{result.Id}/order"; produceUrl = $"https://vue.car0774.com/#/produce/load/{result.Id}/4"; carOrBoat = "车号/客户名"; break; case SalesPlanType.外来车辆加油: strType = "外来车加油"; orderUrl = $"https://vue.car0774.com/#/sales/order/{result.Id}/order"; produceUrl = $"https://vue.car0774.com/#/produce/load/{result.Id}/5"; carOrBoat = "车号/客户名"; break; } //推送到“销售单” await MassApi.SendTextCardAsync(option.销售单AccessToken, option.销售单AgentId, $"【{strType}】{UserName}开了销售单" , $"<div class=\"gray\">单号:{result.Name}</div>" + $"<div class=\"normal\">{carOrBoat}:{result.CarNo}</div>" , orderUrl, toUser : "******"); if (result.OrderType != SalesPlanType.水上机油 && result.OrderType != SalesPlanType.水上加油) { //推送到“加油”施工 await MassApi.SendTextCardAsync(option.加油AccessToken, option.加油AgentId, $"{strType},请施工" , $"<div class=\"gray\">单号:{result.Name}</div>" + $"<div class=\"normal\">开单人:{UserName}</div>" + $"<div class=\"normal\">{carOrBoat}:{result.CarNo}</div>" , produceUrl, toUser : "******"); } //#endif return(new ResultJSON <Order> { Code = 0, Data = result }); }
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); }
public static void SendText(string agentId, List <string> userCodes, string text) { userCodes.ForEach(userCode => MassApi.SendText(GetToken(agentId), agentId, text, userCode)); }
/// <summary> /// 发送消息 /// </summary> /// <param name="by">类型</param> /// <param name="value">用户,by是userid,支持10000每次,其他支持1000每次</param> /// <param name="applicationId"></param> /// <param name="data">内容</param> /// <param name="type">类型text和news,默认text</param> /// <param name="safe">true 保密 false 不保密</param> /// <returns></returns> public ActionResult SendMsg(string by, string value, string applicationId, string data, string type, string safe) { if (!VerifyParam("by,value,applicationId,data,type,safe")) { return(ErrMsg()); } var weChatConfig = GetWechatConfig(); var toUsrids = value; var token = Innocellence.Weixin.QY.CommonAPIs.AccessTokenContainer.GetToken(weChatConfig.WeixinCorpId, weChatConfig.WeixinCorpSecret); Expression <Func <SysAddressBookMember, bool> > predicate = (a) => a.DeleteFlag == 0 && a.Status == 1; PageCondition ConPage = new PageCondition() { PageIndex = 1, PageSize = 1000 }; if (value.IndexOf("|") >= 0) { var toUsers = value.Split('|'); switch (by) { case "id": var toInt = toUsers.Select(a => int.Parse(a)).ToArray(); predicate = predicate.AndAlso(a => toInt.Contains(a.Id)); break; case "hrcode": predicate = predicate.AndAlso(a => toUsers.Contains(a.EmployeeNo)); break; case "userid": predicate = null; break; case "wxid": predicate = predicate.AndAlso(a => toUsers.Contains(a.WeiXinId)); break; case "email": predicate = predicate.AndAlso(a => toUsers.Contains(a.Email)); break; default: predicate = null; break; } } else { switch (by) { case "id": predicate = predicate.AndAlso(a => a.Id == int.Parse(value)); break; case "hrcode": predicate = predicate.AndAlso(a => a.EmployeeNo == value); break; case "userid": predicate = null; break; case "wxid": predicate = predicate.AndAlso(a => a.WeiXinId == value); break; case "email": predicate = predicate.AndAlso(a => a.Email == value); break; default: predicate = null; break; } } if (predicate != null) { var lst = ((IAddressBookService)_BaseService).GetList <AddressBookMemberView>(predicate, ConPage).Select(a => a.UserId).ToArray(); if (lst.Length > 0) { toUsrids = string.Join("|", lst); } else { return(ErrMsg("用户未找到!" + value)); } } Weixin.QY.AdvancedAPIs.Mass.MassResult objResult; if (type == "news") { var lst = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Article> >(data); objResult = MassApi.SendNews(token, toUsrids, "", "", weChatConfig.WeixinAppId.ToString(), lst, safe == "true" ? 1 : 0); } else { objResult = MassApi.SendText(token, toUsrids, "", "", weChatConfig.WeixinAppId.ToString(), data, safe == "true" ? 1 : 0); } if (objResult.errcode == Weixin.ReturnCode_QY.请求成功) { return(Json(new { message = "", success = true }, JsonRequestBehavior.AllowGet)); } else { return(ErrMsg(objResult.errmsg)); } // return Json(new { success = true, message = "" }, JsonRequestBehavior.AllowGet); }
public static void SendImage(string agentId, List <string> userCodes, string mediaId) { userCodes.ForEach(userCode => MassApi.SendImage(GetToken(agentId), agentId, mediaId, userCode)); }
/// <summary> /// 发送文本消息 /// </summary> /// <param name="accessTokenOrAppKey">接口凭证(AccessToken)或AppKey(根据AccessTokenManager.BuildingKey(corpId, corpSecret)方法获得)</param> /// <param name="agentId">应用ID</param> /// <param name="content">文本内容</param> /// <param name="toUser"></param> /// <param name="toParty"></param> /// <param name="toTag"></param> /// <param name="safe"></param> /// <param name="timeOut"></param> /// <returns></returns> public static MessageResult SendText(string accessTokenOrAppKey, int agentId, string content, string toUser = null, string toParty = null, string toTag = null, int safe = 0, int timeOut = Config.TIME_OUT) { var result = MassApi.SendText(accessTokenOrAppKey, agentId.ToString(), content, toUser, toParty, toTag, safe, timeOut); return(result.ToMsgResult()); }