using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Web; namespace iBemsDataService.Controllers.Fms.WorkManagement.ScheduledTask { public class AlarmConfigSMS { HttpWebRequest request; HttpWebResponse response; private string usercode_tmp = null; private string deptcode_tmp = null; private string phoneno_tmp = null; public void SetSMSInfo(string Usercode, string Deptcode, string Phoneno) { usercode_tmp = Usercode; deptcode_tmp = Deptcode; phoneno_tmp = Phoneno; } public string SendAlarmSMS(string ToNumber, string Message) { string init_url = "https://toll.surem.com:440/message/direct_call_sms_return_post.asp?"; string usercode = usercode_tmp; //"icontrols01"; string deptcode = deptcode_tmp; //"SW-91F-I3"; string group_name = ""; string str_tmp = phoneno_tmp; string[] Phone = str_tmp.Split(new char[] { '-' }); string from_num1 = Phone[0];//"031";//031 string from_num2 = Phone[1];//"785";//785 string from_num3 = Phone[2];//"1700";//1700 string member = "1"; string to_message = ""; string Encoding = "UNICODE"; //string rurl = "direct"; //미입력가능 string url = ""; to_message = Message; group_name = ToNumber; if ((to_message != "") && (group_name != "")) { string temp_string = ""; temp_string = getStringToUnicode(to_message); url = init_url + "usercode=" + usercode + "&deptcode=" + deptcode + "&group_name=" + group_name + "&from_num1=" + from_num1 + "&from_num2=" + from_num2 + "&from_num3=" + from_num3 + "&member=" + member + "&to_message=" + temp_string + "&Encoding=" + Encoding; request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; } using (response = (HttpWebResponse)request.GetResponse()) { // 응답 받아오는 부분 HttpStatusCode status = response.StatusCode; Console.WriteLine(status); Stream responsePostStream = response.GetResponseStream(); StreamReader readerPost = new StreamReader(responsePostStream, System.Text.Encoding.Default, true); string result = readerPost.ReadToEnd(); readerPost.Close(); responsePostStream.Close(); int iLastPosition = result.LastIndexOf("Result"); string temp = result.Substring(244, 2); if (temp == "FA") //실패 { return "FAIL"; } else //성공 { return "OK"; } } } public string getStringToUnicode(string str) { StringBuilder ret = new StringBuilder(); string input = str; // 유니코드 문자 배열을 생성한다. char[] values = input.ToCharArray(); foreach (char ch in values) { if ((char.GetUnicodeCategory(ch) == UnicodeCategory.OtherLetter)) { //한글 int value = Convert.ToInt32(ch); // 유니코드 16진수 변환 string hex = String.Format("{0:X}", value); ret.Append(hex); } else {//한글, 영어 소문자, 영어 대문자가 아닐때 int value = Convert.ToInt32(ch); // 유니코드 16진수 변환 string hex = String.Format("{0:X}", value); ret.Append("00" + hex); } } return ret.ToString(); } } }