123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using System;
- using System.Collections.Generic;
- using System.Web;
- using System.IO;
- using System.Net;
- using System.Text;
- using System.Xml;
- namespace Com.Jpsoft.Hospital.Web.Common
- {
- public class MSG_WS
- {
- public static bool SendMsg(string msg, string numbers, out string errorMsg, out string successNoteCountMsg, out string successMobileCountMsg, out string errorMobileCountMsg, string type)
- {
- string urlpass = Com.Jpsoft.Hospital.Web.Common.MD5Encoding.GetMD5_Str("08526" + "yi19890211" + numbers).ToUpper();
- WebClient wc = new WebClient();
- //wc.Encoding = Encoding.UTF8;
- wc.Encoding = Encoding.GetEncoding("gb2312");
- wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
- string para = "Message=" + msg + "&Mobiles=" + numbers + "&TeacherID=08526&UrlPass=" + urlpass;
- string result = wc.UploadString("http://ejz.welsend.net/Teacher/SendMobileMSXML.asp", "POST", para);
- //string result = wc.UploadString("http://localhost:1514/Module/FllowUp/MedicalQuality/SendWindow.aspx", "POST", para);
- string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + "短信发送回执信息.xml";
- Write(filename, result);
- XmlDocument xdoc = new XmlDocument();
- xdoc.LoadXml(result);
- XmlNode xnode = xdoc.SelectSingleNode("result/code");
- string code = xnode.InnerText;
- xnode = xdoc.SelectSingleNode("result/error");
- string error = xnode.InnerText;
- xnode = xdoc.SelectSingleNode("result/sendResultList");
- string successNoteCount = string.Empty;
- string successMobileCount = string.Empty;
- string errorMobileCount = string.Empty;
- successNoteCountMsg = "0";
- successMobileCountMsg = "0";
- errorMobileCountMsg = "0";
- errorMsg = error;
- if (code == "1")
- {
- if (xnode != null)
- {
- successNoteCount = xnode.Attributes.Item(0).InnerText;
- successMobileCount = xnode.Attributes.Item(1).InnerText;
- errorMobileCount = xnode.Attributes.Item(2).InnerText;
- XmlNodeList xnodes = xnode.ChildNodes;
- //写入数据库
- Com.Jpsoft.Hospital.BLL.jp_msg_sendrecord re = new BLL.jp_msg_sendrecord();
- Com.Jpsoft.Hospital.BLL.jp_msg_senddetail de = new BLL.jp_msg_senddetail();
- Com.Jpsoft.Hospital.Model.jp_msg_sendrecord rm = new Model.jp_msg_sendrecord();
- Com.Jpsoft.Hospital.Model.jp_msg_senddetail dm = new Model.jp_msg_senddetail();
- if (code == "1")
- rm.r_code = true;
- else
- rm.r_code = false;
- rm.r_createdate = DateTime.Now;
- rm.r_error = error;
- rm.r_msg = msg;
- rm.r_successMobileCount = Convert.ToInt32(successMobileCount);
- rm.r_successNoteCount = Convert.ToInt32(successNoteCount);
- rm.r_type = Convert.ToInt32(type);
- int rid = re.Add(rm);
- successNoteCountMsg = successNoteCount;
- successMobileCountMsg = successMobileCount;
- errorMobileCountMsg = errorMobileCount;
- foreach (XmlNode node in xnodes)
- {
- if (node.Attributes.Item(1).InnerText == "1")
- dm.d_code = true;
- else
- dm.d_code = false;
- dm.d_phone = node.Attributes.Item(0).InnerText;
- dm.d_rid = rid;
- de.Add(dm);
- }
- }
- return true;
- }
- else
- return false;
- }
- public static void Write(string filename, string text)
- {
- FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("~/Module/Report/Msg/") + filename, FileMode.Create);
- StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
- sw.WriteLine(text);
- sw.Close();
- fs.Close();
- }
- }
- }
|