地铁二期项目正式开始

SMSController.cs 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. using YTSoft.BaseCallCenter.MVCWeb.Models;
  9. using YTSoft.BaseCallCenter.Model;
  10. using YTSoft.BaseCallCenter.MVCWeb.Commons;
  11. namespace YTSoft.BaseCallCenter.MVCWeb.Controllers
  12. {
  13. public class SMSController : BaseController
  14. {
  15. //
  16. // GET: /SMS/
  17. BLL.T_SMS_SendSMSTask smsdll = new BLL.T_SMS_SendSMSTask();
  18. BLL.T_SMS_SentSMS smsBLL = new BLL.T_SMS_SentSMS();
  19. #region 初使化页面
  20. //短信发送
  21. public ActionResult SMS_Send(int? smsId)
  22. {
  23. Model.T_SMS_SendSMSTask viewsmsmodel = new Model.T_SMS_SendSMSTask();
  24. if (smsId > 0 && smsId != null)
  25. {
  26. viewsmsmodel = smsdll.GetModel(int.Parse(smsId.ToString()));
  27. }
  28. return View(viewsmsmodel);
  29. }
  30. //待发短信
  31. public ActionResult SMS_SendTask()
  32. {
  33. Model.T_SMS_SentSMS sentokmodel = new Model.T_SMS_SentSMS();
  34. return View(sentokmodel);
  35. }
  36. //已发短信
  37. public ActionResult SMS_SendTaskOK()
  38. {
  39. Model.T_SMS_SentSMS sentokmodel = new Model.T_SMS_SentSMS();
  40. return View(sentokmodel);
  41. }
  42. #endregion
  43. #region 短信发送信息
  44. /// <summary>
  45. /// 保存编辑
  46. /// </summary>
  47. /// <param name="workOrderBaseModel"></param>
  48. /// <returns></returns>
  49. [AcceptVerbs(HttpVerbs.Post)]
  50. public bool SendDataSave(T_SMS_SendSMSTask smsInfoModel)
  51. {
  52. bool bl = false;
  53. int savedata = 0;
  54. string strtelnum = smsInfoModel.TelNum.Trim();
  55. string[] strarr = strtelnum.Split(',');
  56. try {
  57. //判断是否用非英文逗号
  58. if (strtelnum.Contains(","))
  59. {
  60. bl = false;
  61. }
  62. else
  63. {
  64. for (int i = 0; i <= strarr.Length - 1; i++)
  65. {
  66. smsInfoModel.TelNum = strarr[i].Trim();
  67. smsInfoModel.CommitTime = DateTime.Now;
  68. smsInfoModel.Info = "待发送";
  69. smsInfoModel.F_UserID = F_UserID;
  70. smsInfoModel.F_Name=HttpUtility.UrlDecode( F_UserName);
  71. savedata = smsdll.Add(smsInfoModel);
  72. MessageNotice(smsInfoModel.Content, smsInfoModel.TelNum, strarr.Length);
  73. }
  74. }
  75. //return smsdll.Add(smsInfoModel) > 0;
  76. if (savedata > 0)
  77. {
  78. bl = true;
  79. }
  80. else
  81. {
  82. bl = false;
  83. }
  84. }
  85. catch (Exception ex)
  86. {
  87. }
  88. return bl;
  89. }
  90. #endregion
  91. #region 发送、待发短信
  92. //获取已发短信
  93. [ActionName("Sendtoklist")]
  94. [HttpGet]
  95. public string Sendtoklist(DateTime? NowDateTime, int page,
  96. int limit, string dateParty, string cusName, string cusNum,string content)
  97. {
  98. //数据结果集
  99. ResponseData dataModel = new ResponseData();
  100. string sql = "";
  101. if (cusNum != null)
  102. {
  103. sql += " and TelNum like '%" + cusNum + "%'";
  104. }
  105. //内容模糊查询
  106. if (content != null)
  107. {
  108. sql += " and Content like '%" + content + "%'";
  109. }
  110. if (!string.IsNullOrEmpty(dateParty))
  111. {
  112. string startDate = dateParty.Substring(0, 19);
  113. string endDate = dateParty.Substring(21);
  114. sql += " and SendTime>= '" + startDate + "'";
  115. sql += " and SendTime<= '" + endDate + "'";
  116. }
  117. DataTable dt = new DataTable();
  118. int recordCount = 0;
  119. Model.PageData<Model.T_SMS_SentSMS> pageModel = new Model.PageData<Model.T_SMS_SentSMS>();
  120. dt = BLL.PagerBLL.GetListPager(
  121. "T_SMS_SentSMS",
  122. "SMSID",
  123. " SMSID,TelNum ,Content , CONVERT(varchar(100), CommitTime, 20) CommitTime,CONVERT(varchar(100), SendTime, 20) SendTime,LastSentTime,MaxSendCount , CurSentCount, Info, SendModemIMEI, F_UserID, F_CustomerID, F_Name",
  124. sql,
  125. "ORDER BY SMSID desc",
  126. limit,
  127. page,
  128. true,
  129. out recordCount);
  130. dataModel.code = 0;
  131. dataModel.count = recordCount;
  132. dataModel.data = dt;
  133. return JsonConvert.SerializeObject(dataModel);
  134. }
  135. //
  136. // GET: /SMS/Details/5
  137. //获取已发短信
  138. [ActionName("Sendtlist")]
  139. [HttpGet]
  140. public string Sendtlist(DateTime? NowDateTime, int page, int limit, string dateParty, string cusName, string cusNum)
  141. {
  142. //数据结果集
  143. ResponseData dataModel = new ResponseData();
  144. string sql = " and SendTime is null ";
  145. if (cusNum != null)
  146. {
  147. sql += " and TelNum like '%" + cusNum + "%'";
  148. }
  149. if (!string.IsNullOrEmpty(dateParty))
  150. {
  151. string startDate = dateParty.Substring(0, 19);
  152. string endDate = dateParty.Substring(21);
  153. sql += " and CommitTime>= '" + startDate + "'";
  154. sql += " and CommitTime<= '" + endDate + "'";
  155. }
  156. DataTable dt = new DataTable();
  157. int recordCount = 0;
  158. Model.PageData<Model.T_SMS_SentSMS> pageModel = new Model.PageData<Model.T_SMS_SentSMS>();
  159. dt = BLL.PagerBLL.GetListPager(
  160. "T_SMS_SendSMSTask",
  161. "SMSID",
  162. " SMSID,TelNum ,Content , CONVERT(varchar(100), CommitTime, 20) CommitTime,CONVERT(varchar(100), SendTime, 20) SendTime,LastSentTime,MaxSendCount , CurSentCount, Info, F_UserID, F_CustomerID, F_Name",
  163. sql,
  164. "ORDER BY SMSID desc",
  165. limit,
  166. page,
  167. true,
  168. out recordCount);
  169. dataModel.code = 0;
  170. dataModel.count = recordCount;
  171. dataModel.data = dt;
  172. return JsonConvert.SerializeObject(dataModel);
  173. }
  174. /// <summary>
  175. //删除待发短信
  176. /// </summary>
  177. /// <param name="workOrderBaseModel"></param>
  178. /// <returns></returns>
  179. [AcceptVerbs(HttpVerbs.Get)]
  180. public bool DeleteSmsData(string smsId)
  181. {
  182. return smsdll.DeleteList(smsId);
  183. }
  184. #endregion
  185. /// <summary>
  186. /// 发送短信接口
  187. /// </summary>
  188. /// <param name="MessageCount">手动发送短信</param>
  189. /// <returns></returns>
  190. [ActionName("MessageNotice")]
  191. [HttpGet]
  192. public bool MessageNotice(string MessageContent,string TelNum,int Length)
  193. {
  194. //数据结果集
  195. bool SendResult = false;
  196. try
  197. {
  198. //用户名:zzmetro 接口密码:r9ffaa
  199. //MD5(username+MD5(pwd)),pwd为明文密码,32位小写md5
  200. string smsUrl = "http://www.jc-chn.cn/smsSend.do?username=zzmetro&password=28fc33e97e092b633f47a456740b636e&mobile=" + TelNum +"&content=";
  201. System.Web.HttpUtility.UrlEncode("发送短信!" + MessageContent , System.Text.Encoding.UTF8);
  202. Model.T_SMS_SentSMS model = new Model.T_SMS_SentSMS();
  203. model.State = 0;
  204. model.CommitTime = DateTime.Now;
  205. model.MaxSendCount = 5; //最大发送次数
  206. model.Content = MessageContent;//发送内容
  207. for (int i = 1; i <= model.MaxSendCount; i++)
  208. {
  209. model.CurSentCount = i;
  210. string addWxResult = HttpHelper.HttpSMSSend(smsUrl+ MessageContent+ "【郑州地铁】");
  211. //判断返回接口是否发送成功!
  212. if (!string.IsNullOrEmpty(addWxResult) )
  213. {
  214. switch (addWxResult)
  215. {
  216. case "-1": SendResult = false;
  217. model.State = 0;//发送成功
  218. model.Info = "用户名或者密码不正确!";
  219. break;
  220. case "0":
  221. SendResult = false;
  222. model.State = 0;//发送成功
  223. model.Info = "失败!";
  224. break;
  225. case "-5":
  226. SendResult = false;
  227. model.State = 0;//发送成功
  228. model.Info = "余额不够!";
  229. break;
  230. case "-10":
  231. SendResult = false;
  232. model.State = 0;//发送成功
  233. model.Info = "用户被禁用!";
  234. break;
  235. case "-11":
  236. SendResult = false;
  237. model.State = 0;//发送成功
  238. model.Info = "短信内容超过500字!";
  239. break;
  240. }
  241. if (addWxResult.Length>7) {
  242. SendResult = true;
  243. model.State = 1;//发送成功
  244. model.Info = "发送成功";
  245. }
  246. model.SendTime = DateTime.Now;
  247. model.F_UserID = F_UserID;
  248. model.F_Name = HttpUtility.UrlDecode(F_UserName);
  249. model.SendModemIMEI = "用户:" + HttpUtility.UrlDecode(F_UserName) + "提供";
  250. model.TelNum = TelNum;
  251. //将短信发送信息存储到内容中
  252. smsBLL.Add(model);
  253. break;
  254. }
  255. //将短信发送信息存储到内容中
  256. // smsBLL.Add(model);
  257. }
  258. }
  259. catch (Exception ex) { }
  260. return SendResult;
  261. }
  262. }
  263. }