From f8015966d8b7d9237f5ada828e677b39f57da6cd Mon Sep 17 00:00:00 2001 From: b110212000 Date: Thu, 16 Sep 2021 14:06:11 +0800 Subject: [PATCH] =?UTF-8?q?Line=20function=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PowerStationController.cs | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/SolarPower/Controllers/PowerStationController.cs b/SolarPower/Controllers/PowerStationController.cs index 836f120..14da6a4 100644 --- a/SolarPower/Controllers/PowerStationController.cs +++ b/SolarPower/Controllers/PowerStationController.cs @@ -3185,6 +3185,35 @@ namespace SolarPower.Controllers throw ex; } } + /// + /// LineToken + /// + /// + /// + public string CallLineToken (string message,string LineToken) + { + try + { + HttpWebRequest Postrequest = (HttpWebRequest)WebRequest.Create("https://notify-api.line.me/api/notify?message=" + message); + Postrequest.Method = "POST"; + Postrequest.Headers.Add("Authorization", "Bearer " + LineToken); + Postrequest.PreAuthenticate = true; + HttpWebResponse response = (HttpWebResponse)Postrequest.GetResponse(); + var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); + var final = JObject.Parse(responseString); + var get = final["status"].ToString(); + if(get != "200") + { + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "CallLineToken發送Line接收失敗"); + } + return get; + } + catch (Exception ex) + { + Logger.LogError("【" + controllerName + "/" + actionName + "】" + "CallLineToken:" + ex); + throw ex; + } + } public async Task>> GetShareDevicePowerstationName (int Id) { @@ -3245,8 +3274,10 @@ namespace SolarPower.Controllers try { var powerstation = await powerStationRepository.GetOneAsync(Id); + await powerStationRepository.StationStatus(Id, 0); await powerStationRepository.StationStatus(Id, 0,powerstation.SiteDB + "."); + //CallLineToken("電站停用了", "7W3TkCpyhfQ28QHCWL2L7s9ygrI63oHRBHUc9Hn2E3A"); apiResult.Msg = "電站停用成功"; apiResult.Code = "0000";