Created
January 22, 2021 21:28
-
-
Save ricoisme/5ac130880ba290b04b92dcc2b2d99dc6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//簡訊王發送Function | |
private string SendInTime(string userid, string pwd, string dstanumber, string smsbody) | |
{ | |
Encoding myenc = Encoding.GetEncoding("big5"); | |
string smsurl = | |
string.Format(@"http://202.39.48.216/kotsmsapi-1.php?username={0}&password={1}&dstaddr={2}&smbody={3}" | |
, userid, pwd, dstanumber, HttpUtility.UrlEncode(smsbody, myenc)); | |
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(smsurl); | |
req.Method = "GET"; | |
using (WebResponse wr = req.GetResponse()) | |
{ | |
using (StreamReader sr = new StreamReader(wr.GetResponseStream(), myenc)) | |
{ | |
return sr.ReadToEnd(); | |
} | |
} | |
} | |
private string ParserCode(string code) | |
{ | |
string replacement = Regex.Replace(code, @"\t|\n|\r|kmsgid=", ""); | |
string content = ""; | |
switch (replacement) | |
{ | |
case "-1": | |
content = @"CGI string error ,系統維護中或其他錯誤 ,帶入的參數異常,伺服器異常"; | |
break; | |
case "-2": | |
content = @"授權錯誤(帳號/密碼錯誤)"; | |
break; | |
case "-4": | |
content = @"A Number違反規則 發送端 870短碼VCSN 設定異常"; | |
break; | |
case "-5": | |
content = @"B Number違反規則 接收端 門號錯誤"; | |
break; | |
case "-6": | |
content = @"Closed User 接收端的門號停話異常090 094 099 付費代號等"; | |
break; | |
case "-20": | |
content = @"Schedule Time錯誤 預約時間錯誤 或時間已過"; | |
break; | |
case "-21": | |
content = @"Valid Time錯誤 有效時間錯誤"; | |
break; | |
case "-59999": | |
content = @"帳務系統異常 簡訊無法扣款送出"; | |
break; | |
case "-60002": | |
content = @"點數不足"; | |
break; | |
case "-60014": | |
content = @"該用戶已申請 拒收簡訊平台之簡訊 ( 2010 NCC新規)"; | |
break; | |
default: | |
break; | |
} | |
return content; | |
} | |
//SSIS EntryPoint(示範發送目前硬碟總空間和可用空間) | |
public void Main() | |
{ | |
// TODO: Add your code here | |
StringBuilder sb = new StringBuilder(); | |
DriveInfo[] allDrives = DriveInfo.GetDrives(); | |
foreach (DriveInfo d in allDrives) | |
{ | |
if (d.IsReady) | |
{ | |
sb.AppendLine(string.Format("{0}: 總共空間(GB):{1} , 可用空間(GB):{2}", | |
d.Name, d.TotalSize / (1024 * 1024 * 1024), d.TotalFreeSpace / (1024 * 1024*1024))); | |
//if ((d.TotalSize * 0.2) <= d.TotalFreeSpace) | |
//{ | |
// sb.AppendLine(string.Format("{0}: 總共空間(GB):{1} , 可用空間(GB):{2}", | |
// d.Name, d.TotalSize / (1024 * 1024 * 1024), d.TotalFreeSpace / (1024 * 1024 * 1024))); | |
//} | |
} | |
} | |
if (sb.ToString().Length > 0) | |
{ | |
//使用簡訊王API | |
string message = ParserCode(SendInTime("***", "***", Dts.Variables["PhoneNumber"].Value.ToString(), sb.ToString())); | |
bool fireAgain = true; | |
if (message.Length > 0) | |
{ | |
Dts.Events.FireError(0, "硬碟空間不足,簡訊發送失敗", | |
string.Format("簡訊發送失敗代碼:{0}", message), "", 0); | |
Dts.TaskResult = (int)ScriptResults.Failure; | |
} | |
else | |
{ | |
Dts.Events.FireInformation(0, Dts.Variables["System::TaskName"].Value.ToString() | |
, "硬碟空間正常", "", 0, ref fireAgain); | |
Dts.TaskResult = (int)ScriptResults.Success; | |
} | |
} | |
else | |
{ | |
Dts.TaskResult = (int)ScriptResults.Success; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment