static void MsgSend(LVipOldBLL lVipOldBLL, LVipOldEntity vipEntity, string msg) { string mailto = vipEntity.Mobile; string mailBody = msg; try { var success = SMSSend(mailto, mailBody); if (success) { vipEntity.IsPush = 1; vipEntity.PushCount = vipEntity.PushCount == null ? 1 : vipEntity.PushCount + 1; vipEntity.LastPushTime = DateTime.Now; lVipOldBLL.Update(vipEntity); Console.WriteLine("短信发送成功: {0}--{1}", mailto, mailBody); } else { vipEntity.PushCount = vipEntity.PushCount == null ? 1 : vipEntity.PushCount + 1; vipEntity.LastPushTime = DateTime.Now; vipEntity.ErrReason = "短信发送失败"; lVipOldBLL.Update(vipEntity); Console.WriteLine("短信发送失败: {0}--{1}", mailto, mailBody); } } catch (Exception ex) { vipEntity.PushCount = vipEntity.PushCount == null ? 1 : vipEntity.PushCount + 1; vipEntity.LastPushTime = DateTime.Now; vipEntity.ErrReason = "短信发送失败:" + ex.ToString(); lVipOldBLL.Update(vipEntity); Console.WriteLine("短信发送失败: {0}--{1}--{2}", mailto, mailBody, vipEntity.ErrReason); } }
static int SendDelayTime = 10; // ms static void Main(string[] args) { try { int cycleTime = int.Parse(ConfigurationManager.AppSettings["cycleTime"]); string batId = string.Empty; while (true) { if (ConfigurationManager.AppSettings["EnableTaskSend"] == "1") { Console.WriteLine(string.Format("[{0}]任务开始...", Utils.GetNow())); GOrderBLL gOrderBLL = new GOrderBLL(GetLoginUser("bs")); var msgUrl = ConfigurationManager.AppSettings["push_weixin_msg_url"]; var error = ""; var flag = gOrderBLL.SetGOrderPushAll(msgUrl, out error); if (flag) { Console.WriteLine(string.Format("[{0}] 执行成功", Utils.GetNow())); } else { Console.WriteLine(string.Format("[{0}] 执行失败:{1}", Utils.GetNow(), error)); } Thread.Sleep(SendDelayTime); Console.WriteLine(string.Format("[{0}]任务结束", Utils.GetNow())); } if (ConfigurationManager.AppSettings["EnableMsgSend_lj"] == "1") { Console.WriteLine(string.Format("[{0}]lj消息发送任务开始...", Utils.GetNow())); LVipOldBLL lVipOldBLL = new LVipOldBLL(GetLoginUser("lj")); // 获取lj消息列表 var msgList = lVipOldBLL.GetVipListForMsgSend(new LVipOldEntity() { }); // 发送lj消息 Console.WriteLine(string.Format("[{0}]消息数量:{1}", Utils.GetNow(), (msgList == null ? 0 : msgList.Count))); if (msgList != null) { foreach (var msgItem in msgList) { if (msgItem == null || msgItem.Mobile == null || msgItem.Mobile.Length < 10) { continue; } string weixin = "泸州老窖VIP尊享"; string msg = string.Format( //"亲爱的{0},泸州老窖最新推出的官方微信公众号“{1}”上线了,我们等待您的关注,请关注后在平台的菜单中选择积分券兑换,并输入积分券号“{2}”,赢取积分,兑换精美礼品。", "亲爱的{0},泸州老窖最新推出的官方微信“{1}”上线了,我们等待您的关注,请关注后在平台的菜单中选择“贵宾卡领取”,并输入贵宾卡号“{2}”验证,您将成为我们泸州老窖的VIP贵宾,独享更多的尊崇服务。", msgItem.VipName, weixin, msgItem.CardCode); MsgSend(lVipOldBLL, msgItem, msg); Thread.Sleep(SendDelayTime); } } Console.WriteLine(string.Format("[{0}]lj消息发送任务结束", Utils.GetNow())); } Console.WriteLine(string.Format("".PadLeft(50, '='))); Thread.Sleep(cycleTime); } } catch (Exception ex) { Loggers.Debug(new DebugLogInfo() { Message = string.Format("Exception:", ex.ToString()) }); Console.Write(ex.ToString()); Console.Read(); } }