1f47447756807c4f8e1bf5eba8b6d87d2abc5431.svn-base 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Text;
  8. using System.Web;
  9. namespace iBemsDataService.Controllers.Fms.WorkManagement.ScheduledTask
  10. {
  11. public class AlarmConfigSMS
  12. {
  13. HttpWebRequest request;
  14. HttpWebResponse response;
  15. private string usercode_tmp = null;
  16. private string deptcode_tmp = null;
  17. private string phoneno_tmp = null;
  18. public void SetSMSInfo(string Usercode, string Deptcode, string Phoneno)
  19. {
  20. usercode_tmp = Usercode;
  21. deptcode_tmp = Deptcode;
  22. phoneno_tmp = Phoneno;
  23. }
  24. public string SendAlarmSMS(string ToNumber, string Message)
  25. {
  26. string init_url = "https://toll.surem.com:440/message/direct_call_sms_return_post.asp?";
  27. string usercode = usercode_tmp; //"icontrols01";
  28. string deptcode = deptcode_tmp; //"SW-91F-I3";
  29. string group_name = "";
  30. string str_tmp = phoneno_tmp;
  31. string[] Phone = str_tmp.Split(new char[] { '-' });
  32. string from_num1 = Phone[0];//"031";//031
  33. string from_num2 = Phone[1];//"785";//785
  34. string from_num3 = Phone[2];//"1700";//1700
  35. string member = "1";
  36. string to_message = "";
  37. string Encoding = "UNICODE";
  38. //string rurl = "direct"; //미입력가능
  39. string url = "";
  40. to_message = Message;
  41. group_name = ToNumber;
  42. if ((to_message != "") && (group_name != ""))
  43. {
  44. string temp_string = "";
  45. temp_string = getStringToUnicode(to_message);
  46. url = init_url + "usercode=" + usercode +
  47. "&deptcode=" + deptcode +
  48. "&group_name=" + group_name +
  49. "&from_num1=" + from_num1 +
  50. "&from_num2=" + from_num2 +
  51. "&from_num3=" + from_num3 +
  52. "&member=" + member +
  53. "&to_message=" + temp_string +
  54. "&Encoding=" + Encoding;
  55. request = (HttpWebRequest)WebRequest.Create(url);
  56. request.Method = "GET";
  57. }
  58. using (response = (HttpWebResponse)request.GetResponse())
  59. {
  60. // 응답 받아오는 부분
  61. HttpStatusCode status = response.StatusCode;
  62. Console.WriteLine(status);
  63. Stream responsePostStream = response.GetResponseStream();
  64. StreamReader readerPost = new StreamReader(responsePostStream, System.Text.Encoding.Default, true);
  65. string result = readerPost.ReadToEnd();
  66. readerPost.Close();
  67. responsePostStream.Close();
  68. int iLastPosition = result.LastIndexOf("Result");
  69. string temp = result.Substring(244, 2);
  70. if (temp == "FA") //실패
  71. {
  72. return "FAIL";
  73. }
  74. else //성공
  75. {
  76. return "OK";
  77. }
  78. }
  79. }
  80. public string getStringToUnicode(string str)
  81. {
  82. StringBuilder ret = new StringBuilder();
  83. string input = str; // 유니코드 문자 배열을 생성한다.
  84. char[] values = input.ToCharArray();
  85. foreach (char ch in values)
  86. {
  87. if ((char.GetUnicodeCategory(ch) == UnicodeCategory.OtherLetter))
  88. { //한글
  89. int value = Convert.ToInt32(ch); // 유니코드 16진수 변환
  90. string hex = String.Format("{0:X}", value);
  91. ret.Append(hex);
  92. }
  93. else
  94. {//한글, 영어 소문자, 영어 대문자가 아닐때
  95. int value = Convert.ToInt32(ch); // 유니코드 16진수 변환
  96. string hex = String.Format("{0:X}", value);
  97. ret.Append("00" + hex);
  98. }
  99. }
  100. return ret.ToString();
  101. }
  102. }
  103. }