MSG_WS.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Web;
  4. using System.IO;
  5. using System.Net;
  6. using System.Text;
  7. using System.Xml;
  8. namespace Com.Jpsoft.Hospital.Web.Common
  9. {
  10. public class MSG_WS
  11. {
  12. public static bool SendMsg(string msg, string numbers, out string errorMsg, out string successNoteCountMsg, out string successMobileCountMsg, out string errorMobileCountMsg, string type)
  13. {
  14. string urlpass = Com.Jpsoft.Hospital.Web.Common.MD5Encoding.GetMD5_Str("08526" + "yi19890211" + numbers).ToUpper();
  15. WebClient wc = new WebClient();
  16. //wc.Encoding = Encoding.UTF8;
  17. wc.Encoding = Encoding.GetEncoding("gb2312");
  18. wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
  19. string para = "Message=" + msg + "&Mobiles=" + numbers + "&TeacherID=08526&UrlPass=" + urlpass;
  20. string result = wc.UploadString("http://ejz.welsend.net/Teacher/SendMobileMSXML.asp", "POST", para);
  21. //string result = wc.UploadString("http://localhost:1514/Module/FllowUp/MedicalQuality/SendWindow.aspx", "POST", para);
  22. string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + "短信发送回执信息.xml";
  23. Write(filename, result);
  24. XmlDocument xdoc = new XmlDocument();
  25. xdoc.LoadXml(result);
  26. XmlNode xnode = xdoc.SelectSingleNode("result/code");
  27. string code = xnode.InnerText;
  28. xnode = xdoc.SelectSingleNode("result/error");
  29. string error = xnode.InnerText;
  30. xnode = xdoc.SelectSingleNode("result/sendResultList");
  31. string successNoteCount = string.Empty;
  32. string successMobileCount = string.Empty;
  33. string errorMobileCount = string.Empty;
  34. successNoteCountMsg = "0";
  35. successMobileCountMsg = "0";
  36. errorMobileCountMsg = "0";
  37. errorMsg = error;
  38. if (code == "1")
  39. {
  40. if (xnode != null)
  41. {
  42. successNoteCount = xnode.Attributes.Item(0).InnerText;
  43. successMobileCount = xnode.Attributes.Item(1).InnerText;
  44. errorMobileCount = xnode.Attributes.Item(2).InnerText;
  45. XmlNodeList xnodes = xnode.ChildNodes;
  46. //写入数据库
  47. Com.Jpsoft.Hospital.BLL.jp_msg_sendrecord re = new BLL.jp_msg_sendrecord();
  48. Com.Jpsoft.Hospital.BLL.jp_msg_senddetail de = new BLL.jp_msg_senddetail();
  49. Com.Jpsoft.Hospital.Model.jp_msg_sendrecord rm = new Model.jp_msg_sendrecord();
  50. Com.Jpsoft.Hospital.Model.jp_msg_senddetail dm = new Model.jp_msg_senddetail();
  51. if (code == "1")
  52. rm.r_code = true;
  53. else
  54. rm.r_code = false;
  55. rm.r_createdate = DateTime.Now;
  56. rm.r_error = error;
  57. rm.r_msg = msg;
  58. rm.r_successMobileCount = Convert.ToInt32(successMobileCount);
  59. rm.r_successNoteCount = Convert.ToInt32(successNoteCount);
  60. rm.r_type = Convert.ToInt32(type);
  61. int rid = re.Add(rm);
  62. successNoteCountMsg = successNoteCount;
  63. successMobileCountMsg = successMobileCount;
  64. errorMobileCountMsg = errorMobileCount;
  65. foreach (XmlNode node in xnodes)
  66. {
  67. if (node.Attributes.Item(1).InnerText == "1")
  68. dm.d_code = true;
  69. else
  70. dm.d_code = false;
  71. dm.d_phone = node.Attributes.Item(0).InnerText;
  72. dm.d_rid = rid;
  73. de.Add(dm);
  74. }
  75. }
  76. return true;
  77. }
  78. else
  79. return false;
  80. }
  81. public static void Write(string filename, string text)
  82. {
  83. FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("~/Module/Report/Msg/") + filename, FileMode.Create);
  84. StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
  85. sw.WriteLine(text);
  86. sw.Close();
  87. fs.Close();
  88. }
  89. }
  90. }