private void button7_Click(object sender, EventArgs e) { DeilyStockNotiflyServices a = new DeilyStockNotiflyServices(); var tg = Task.Run(() => a.DoNotifly()); tg.Wait(); return; List <HighQualityListModel> QueryQuality = StableStockServices.QueryQuality(); String Context = ""; int i = 0; String temp = DateTime.Now.ToString("yyyyMMdd") + "(預測型)價提醒: \r\n"; QueryQuality.ForEach(t => { temp += $"{t.StockNum}{t.StockName} \r\n"; }); string channelAccessToken = "SALEdmTrZ001uP7nelpndyaRH5NPeTlEHd0QioPjNrNfOOzxfYj1QgDWZhPdePPYbrju9fe08TplcdB00qfArHWqfxs0Ob/B5jYwCmIIowTfjik14pb/EbjrdNqAdi2JIBLspjzBIYCuAdsUUsKPGwdB04t89/1O/w1cDnyilFU="; string AdminUserId = "U06bdebb439e5566c04d9a40bf48ecdd8"; var bot = new Bot(channelAccessToken); try { List <String> users = new List <string>(); users.Add("U06bdebb439e5566c04d9a40bf48ecdd8"); //users.Add("U3ba8b8ce8d3c64bc338bcaddfde466f4"); //users.Add("Uc4e3e555d10de47b5a45c64b615a1e30"); List <String> msg = new List <string>(); msg.Add(temp); //bot.PushMessage(AdminUserId, temp); bot.PushMulticast(users, msg); //MultiCastMessageAsync(users, msg); //https://api.line.me/v2/bot/message/multicast } catch { bot.PushMessage(AdminUserId, $" {DateTime.Now.ToString()} ,群發發生錯誤"); } }
public void DoNotifly() { string AdminUserId = Setting.AppSettings("LineAdminUserId"); string channelAccessToken = Setting.AppSettings("LineChannelAccessToken"); var bot = new Bot(channelAccessToken); try { if (CheckIsDone()) { LogHelper.doLog(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, "執行過了,do Nothing"); return; } List <HighQualityListModel> QueryQuality = StableStockServices.QueryQuality(); String StableTitle = $"==={GetDate.ToString("yyyy-MM-dd")}===\n保守型-到價提醒: \n "; String UnStableTitle = $"==={GetDate.ToString("yyyy-MM-dd")}===\n預估型-到價提醒: \n "; String StableContext = ""; String UnStableContext = ""; String LZUrl = "\nhttp://lazystock.azurewebsites.net"; QueryQuality.OrderBy(x => x.StockNum).ToList().ForEach(t => { if (t.StableIsBuy == "1") { StableContext += $"{t.StockNum}{t.StockName} \n "; } else if (t.UnStableIsBuy == "1") { UnStableContext += $"{t.StockNum}{t.StockName} \n "; } }); //List<String> users = new List<string>(); //string _userid = ""; foreach (String userid in Setting.AppSettings("LineNotiflyUserIds").Split(',')) { if (String.IsNullOrEmpty(userid)) { continue; } if (!String.IsNullOrEmpty(StableContext)) { bot.PushMessage(userid, StableTitle + StableContext + LZUrl); } if (!String.IsNullOrEmpty(UnStableContext)) { bot.PushMessage(userid, UnStableTitle + UnStableContext + LZUrl); } } if (!System.IO.Directory.Exists(CheckDoneDirPath)) { System.IO.Directory.CreateDirectory(CheckDoneDirPath); } System.IO.File.WriteAllText(this.CheckDoneFullPath, "done"); LogHelper.doLog(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, "發送成功!"); } catch (Exception e) { LogHelper.doLog(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, "[Exception]" + e.Message); try { bot.PushMessage(AdminUserId, $" {DateTime.Now.ToString()} ,群發發生錯誤"); } catch { } } }