No Description

SMSController.cs 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.DB;
  4. using CallCenterApi.Interface.Controllers.Base;
  5. using CallCenterApi.Interface.Controllers.Sms;
  6. using Newtonsoft.Json;
  7. using Newtonsoft.Json.Linq;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.Specialized;
  11. using System.Data;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Net;
  15. using System.Net.Http;
  16. using System.Security.Cryptography;
  17. using System.Text;
  18. using System.Web;
  19. using System.Web.Mvc;
  20. namespace CallCenterApi.Interface.Controllers
  21. {
  22. public class SMSController : BaseController
  23. {
  24. private static string Smsurl = "http://rcsapi.wo.cn:8000/umcinterface/sendtempletmsg";
  25. private static string Smsurl1 = "http://220.250.65.184:9014/union-gjdx-sms-api/sms/submit";
  26. static string cpcode = "AABJYC";
  27. static string key = "724ee6be83d8d6f4d64ef5a537a9985d";
  28. //private static string Smsurl = Configs.GetValue("Smsurl");
  29. //private static string Smsurl1 = Configs.GetValue("Smsurl1");
  30. //static string cpcode = Configs.GetValue("Smscpcode");
  31. //static string key = Configs.GetValue("Smskey");
  32. /// <summary>
  33. /// MD5加密
  34. /// </summary>
  35. /// <param name="txt"></param>
  36. /// <returns></returns>
  37. public static string Md5(string txt)
  38. {
  39. byte[] sor = Encoding.UTF8.GetBytes(txt);
  40. MD5 md5 = MD5.Create();
  41. byte[] result = md5.ComputeHash(sor);
  42. StringBuilder strbul = new StringBuilder(40);
  43. for (int i = 0; i < result.Length; i++)
  44. {
  45. //加密结果"x2"结果为32位,"x3"结果为48位,"x4"结果为64位
  46. strbul.Append(result[i].ToString("x2"));
  47. }
  48. return strbul.ToString().ToLower (); ;
  49. }
  50. public static string SendSms(string msg,string mobiles,string templetid,string excode = "")
  51. {
  52. bool n=false ;
  53. string sign = Md5(cpcode + msg + mobiles + excode + templetid + key);
  54. var dic = new SortedDictionary<string, string>
  55. {
  56. {"cpcode", cpcode},
  57. {"msg", msg},
  58. {"mobiles", mobiles},
  59. {"excode", excode},
  60. {"templetid",templetid},
  61. {"sign", sign},
  62. };
  63. //序列化参数
  64. var jsonParam = JsonConvert.SerializeObject(dic);
  65. ////发送请求
  66. //var request = (HttpWebRequest)WebRequest.Create(Smsurl);
  67. //request.Method = "POST";
  68. //request.ContentType = "application/json;charset=UTF-8";
  69. //var byteData = Encoding.UTF8.GetBytes(jsonParam);
  70. //var length = byteData.Length;
  71. //request.ContentLength = length;
  72. //var writer = request.GetRequestStream();
  73. //writer.Write(byteData, 0, length);
  74. //writer.Close();
  75. ////接收数据
  76. //var response = (HttpWebResponse)request.GetResponse();
  77. //var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
  78. var responseString = HttpMethods.HttpPost(Smsurl, jsonParam, "application/json;charset=UTF-8");
  79. JObject jo = (JObject)JsonConvert.DeserializeObject(responseString );
  80. string access_token = jo["resultcode"].ToString();
  81. string taskid = jo["taskid"].ToString();
  82. return access_token;
  83. }
  84. private static readonly HttpClient client = new HttpClient();
  85. public static string SendSms1( string mobiles, string templetid, string templet="" )
  86. {
  87. bool n = false;
  88. // string sign = Md5(cpcode + msg + mobiles + excode + templetid + key);
  89. Dictionary<string, string> values = new Dictionary<string, string>();
  90. values.Add("account", "ayxzfwzx");
  91. values.Add("passwd", "ayxzfwzx123");
  92. values.Add("mobile", mobiles);
  93. values.Add("templateId", templetid);
  94. values.Add("templateParams", templet);
  95. // var content = new FormUrlEncodedContent(values);
  96. var content = new StringContent(values.ToJson(), Encoding.UTF8, "application/json");
  97. var response = client.PostAsync(Smsurl1, content).Result;
  98. var responseString = response.Content.ReadAsByteArrayAsync().Result;
  99. string ret = Encoding.Default.GetString(responseString);//"\"success\": true";
  100. return ret;
  101. }
  102. public class Reply
  103. {
  104. public string fisp { set; get; }
  105. public string mobile { set; get; }
  106. public string msg { set; get; }
  107. public string time { set; get; }
  108. }
  109. /// <summary>
  110. /// 获取接收短信列表
  111. /// </summary>
  112. /// <returns></returns>
  113. [HttpPost ]
  114. public ActionResult GetReply()
  115. {
  116. StreamReader reader = new StreamReader(System.Web.HttpContext.Current.Request.InputStream);
  117. var postString = reader.ReadToEnd();
  118. var replies = JsonConvert.DeserializeObject<List<Reply>>(postString);
  119. if (replies!=null && replies.Count >0)
  120. {
  121. foreach (var it in replies)
  122. {
  123. var dModel = new BLL.T_SMS_RecvSMS()
  124. .GetModelList("CallerNum='" + it.mobile + "'and F_Name !='' and F_Name is not null"
  125. + " order by RecvTime desc ");
  126. if (dModel != null && dModel.Count > 0)
  127. {
  128. dModel[0].Content += it.msg;
  129. new BLL.T_SMS_RecvSMS().Update(dModel[0]);
  130. }
  131. }
  132. }
  133. var obj = new
  134. {
  135. status = 0
  136. };
  137. return Content(obj.ToJson ());
  138. }
  139. public static bool AddSmS(int userId,string msg,string Content, string mobiles, string templetid
  140. ,string templet = "",string workorderid="")
  141. {
  142. bool res = false ;
  143. // string n = SendSms(msg,mobiles, templetid, templet);
  144. string sign = Md5(cpcode + msg + mobiles + "" + templetid + key);
  145. var dic = new SortedDictionary<string, string>
  146. {
  147. {"cpcode", cpcode},
  148. {"msg", msg},
  149. {"mobiles", mobiles},
  150. {"excode", ""},
  151. {"templetid",templetid},
  152. {"sign", sign},
  153. };
  154. //序列化参数
  155. var jsonParam = JsonConvert.SerializeObject(dic);
  156. // 发送请求
  157. var request = (HttpWebRequest)WebRequest.Create(Smsurl);
  158. request.Method = "POST";
  159. request.ContentType = "application/json;charset=UTF-8";
  160. var byteData = Encoding.UTF8.GetBytes(jsonParam);
  161. var length = byteData.Length;
  162. request.ContentLength = length;
  163. var writer = request.GetRequestStream();
  164. writer.Write(byteData, 0, length);
  165. writer.Close();
  166. //接收数据
  167. var response = (HttpWebResponse)request.GetResponse();
  168. var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
  169. // var responseString = HttpMethods.HttpPost(Smsurl, jsonParam, "application/json;charset=UTF-8");
  170. JObject jo = (JObject)JsonConvert.DeserializeObject(responseString);
  171. string access_token = jo["resultcode"].ToString();
  172. string taskid = jo["taskid"].ToString();
  173. // string result = SmsNewHelper.Send(mobiles, Content);
  174. if (access_token=="0")
  175. {
  176. Model.T_SMS_RecvSMS dModel = new Model.T_SMS_RecvSMS();
  177. dModel.CallerNum = mobiles.Trim();
  178. dModel.Content = Content.Trim();
  179. dModel.RecvModemIMEI = "";
  180. dModel.F_Name = workorderid;
  181. dModel.State = 0;
  182. dModel.F_UserID = userId;
  183. dModel.RecvTime = DateTime.Now;
  184. int b = new BLL.T_SMS_RecvSMS().Add(dModel);
  185. if (b > 0)
  186. {
  187. return true;
  188. }
  189. else
  190. {
  191. return false;
  192. }
  193. }
  194. return res;
  195. }
  196. public ActionResult GetReceive(string mobile,string smsContent,string sendTime,string addSerial)
  197. {
  198. Model.T_SMS_RecvSMS dModel = new Model.T_SMS_RecvSMS();
  199. dModel.CallerNum = mobile.Trim();
  200. dModel.Content = smsContent.Trim();
  201. dModel.RecvModemIMEI = addSerial;
  202. // dModel.F_Name = workorderid;
  203. dModel.State = 1;
  204. // dModel.F_UserID = userId;
  205. try
  206. {
  207. dModel.RecvTime = DateTime.Parse(addSerial);
  208. }
  209. catch
  210. {
  211. dModel.RecvTime = DateTime .Now ;
  212. }
  213. int b = new BLL.T_SMS_RecvSMS().Add(dModel);
  214. if (b > 0)
  215. {
  216. return Success ("获取成功");
  217. }
  218. else
  219. {
  220. return Error ("获取失败");
  221. }
  222. }
  223. /// <summary>
  224. /// 发送市长信箱短信
  225. /// </summary>
  226. /// <param name="phone"></param>
  227. /// <param name="WorkOrderId"></param>
  228. /// <returns></returns>
  229. public ActionResult SendMailbox(string phone)
  230. {
  231. // string result = SmsNewHelper.Send(phone, "市长信箱留言网址:https://zwfw.anyang.gov.cn/#/mayor_mail");
  232. string result = SmsNewController.AddSmS(0, "您可在市长信箱进行留言,留言地址:https://zwfw.anyang.gov.cn/#/mayor_mail", phone, "681239973756440576", "","");
  233. if (result==string .Empty )
  234. return Success("发送成功");
  235. else
  236. return Error("发送失败");
  237. }
  238. #region 接收短信
  239. [Authority]
  240. /// <summary>
  241. /// 获取接收短信列表
  242. /// </summary>
  243. /// <returns></returns>
  244. public ActionResult GetRecvList()
  245. {
  246. string sql = "";
  247. DataTable dt = new DataTable();
  248. string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  249. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  250. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  251. int type = RequestString.GetInt("type", 0);
  252. int State = RequestString.GetInt ("state", 0);
  253. int acceptance = RequestString.GetInt("acceptance", 0);
  254. string strpageindex = RequestString.GetQueryString("page");
  255. int pageindex = 1;
  256. string strpagesize = RequestString.GetQueryString("pagesize");
  257. int pagesize = 10;
  258. sql += " and State= '" + State + "' ";
  259. if (strtel.Trim() != "" && strtel != "undefined")
  260. {
  261. sql += " and CallerNum= '" + strtel.Trim() + "' ";
  262. }
  263. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  264. {
  265. sql += " and RecvTime >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
  266. }
  267. if (strendtime.Trim() != "" && strendtime != "undefined")
  268. {
  269. sql += " and RecvTime <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
  270. }
  271. if (type>0)
  272. {
  273. if (type ==1)
  274. {
  275. sql += " and F_CustomerID=1 ";
  276. }
  277. else
  278. {
  279. sql += " and F_CustomerID is null ";
  280. }
  281. }
  282. if (strpageindex.Trim() != "")
  283. {
  284. pageindex = Convert.ToInt32(strpageindex);
  285. }
  286. if (strpagesize.Trim() != "")
  287. {
  288. pagesize = Convert.ToInt32(strpagesize);
  289. }
  290. if (acceptance>0)
  291. {
  292. if (acceptance==1)
  293. {
  294. sql += " and F_Name !=''";
  295. }
  296. else
  297. {
  298. sql += " and (F_Name ='' or F_Name is null )";
  299. }
  300. }
  301. int recordCount = 0;
  302. dt = BLL.PagerBLL.GetListPager(
  303. "T_SMS_RecvSMS",
  304. "SMSID",
  305. "*",
  306. sql,
  307. "ORDER BY SMSID desc",
  308. pagesize,
  309. pageindex,
  310. true,
  311. out recordCount);
  312. List<Model.T_SMS_RecvSMS> modelList = new BLL.T_SMS_RecvSMS().DataTableToList(dt);
  313. var obj = new
  314. {
  315. rows = modelList.Select(x => new
  316. {
  317. x.CallerNum,
  318. x.Content,
  319. x.SMSID ,
  320. x.F_Name,
  321. type=x.F_CustomerID,
  322. usercode ="",
  323. x.RecvTime
  324. }),
  325. total = recordCount
  326. };
  327. return Content(obj.ToJson());
  328. }
  329. [Authority]
  330. /// <summary>
  331. /// 新增接收短信
  332. /// </summary>
  333. /// <returns></returns>
  334. public ActionResult AddRecv(string tel, string cont)
  335. {
  336. Model.T_SMS_RecvSMS dModel = new Model.T_SMS_RecvSMS();
  337. dModel.CallerNum = tel.Trim();
  338. dModel.Content = cont.Trim();
  339. dModel.State = 0;
  340. dModel.RecvTime = DateTime.Now;
  341. int b = new BLL.T_SMS_RecvSMS().Add(dModel);
  342. if (b > 0)
  343. {
  344. return Success("添加成功");
  345. }
  346. else
  347. {
  348. return Success("添加失败");
  349. }
  350. }
  351. [Authority]
  352. /// <summary>
  353. /// 删除接收短信
  354. /// </summary>
  355. /// <param name="ids"></param>
  356. /// <returns></returns>
  357. public ActionResult DelRecv(string[] ids)
  358. {
  359. if (ids != null && ids.Length > 0)
  360. {
  361. string idd = " ";
  362. foreach (string str in ids)
  363. {
  364. idd += str + ",";
  365. }
  366. if (new BLL.T_SMS_RecvSMS().DeleteList(idd.TrimEnd(',')))
  367. {
  368. return Success("删除成功");
  369. }
  370. else
  371. {
  372. return Error("删除失败");
  373. }
  374. }
  375. else
  376. {
  377. return Error("请选择要删除的接收短信");
  378. }
  379. }
  380. [Authority]
  381. /// <summary>
  382. /// 更新接收短信状态
  383. /// </summary>
  384. /// <param name="ids"></param>
  385. /// <returns></returns>
  386. public ActionResult UpdateRecvState(string[] ids, string state)
  387. {
  388. int n = -1;
  389. if (ids != null && ids.Length > 0 && Int32.TryParse(state, out n))
  390. {
  391. string idd = " ";
  392. foreach (string str in ids)
  393. {
  394. idd += str + ",";
  395. }
  396. string sql = "update T_SMS_RecvSMS set State='" + n + "' where ID in(" + idd.TrimEnd(',') + ")";
  397. if (!string.IsNullOrEmpty(idd.Trim()))
  398. {
  399. if (DbHelperSQL.ExecuteSql(sql) > 0)
  400. {
  401. return Success("更新成功");
  402. }
  403. else
  404. {
  405. return Error("更新失败");
  406. }
  407. }
  408. else
  409. {
  410. return Error("请选择记录");
  411. }
  412. }
  413. else
  414. {
  415. return Error("获取参数失败");
  416. }
  417. }
  418. #endregion
  419. #region 发送短信
  420. [Authority]
  421. /// <summary>
  422. /// 获取发送短信任务列表
  423. /// </summary>
  424. /// <returns></returns>
  425. public ActionResult GetSendTaskList()
  426. {
  427. string sql = "";
  428. DataTable dt = new DataTable();
  429. string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  430. string strcont = HttpUtility.UrlDecode(RequestString.GetQueryString("cont"));
  431. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  432. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  433. string strpageindex = RequestString.GetQueryString("page");
  434. int pageindex = 1;
  435. string strpagesize = RequestString.GetQueryString("pagesize");
  436. int pagesize = 10;
  437. if (strtel.Trim() != "" && strtel != "undefined")
  438. {
  439. sql += " and TelNum like '%" + strtel.Trim() + "%' ";
  440. }
  441. if (strcont.Trim() != "" && strcont != "undefined")
  442. {
  443. sql += " and Content like '%" + strcont.Trim() + "%' ";
  444. }
  445. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  446. {
  447. sql += " and CommitTime >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
  448. }
  449. if (strendtime.Trim() != "" && strendtime != "undefined")
  450. {
  451. sql += " and CommitTime <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
  452. }
  453. if (strpageindex.Trim() != "")
  454. {
  455. pageindex = Convert.ToInt32(strpageindex);
  456. }
  457. if (strpagesize.Trim() != "")
  458. {
  459. pagesize = Convert.ToInt32(strpagesize);
  460. }
  461. int recordCount = 0;
  462. dt = BLL.PagerBLL.GetListPager(
  463. "T_SMS_SendSMSTask",
  464. "SMSID",
  465. "*",
  466. sql,
  467. "ORDER BY SMSID desc",
  468. pagesize,
  469. pageindex,
  470. true,
  471. out recordCount);
  472. var obj = new
  473. {
  474. state = "success",
  475. message = "成功",
  476. rows = dt,
  477. total = recordCount
  478. };
  479. return Content(obj.ToJson());
  480. }
  481. [Authority]
  482. /// <summary>
  483. /// 新增短信任务
  484. /// </summary>
  485. /// <returns></returns>
  486. public ActionResult AddSendTask()
  487. {
  488. string strid = HttpUtility.UrlDecode(RequestString.GetFormString("id"));
  489. string strtel = HttpUtility.UrlDecode(RequestString.GetFormString("tel"));
  490. string strtype = HttpUtility.UrlDecode(RequestString.GetFormString("type"));
  491. string strdssj = HttpUtility.UrlDecode(RequestString.GetFormString("dssj"));
  492. string strcusid = HttpUtility.UrlDecode(RequestString.GetFormString("cusid"));
  493. string strcont = HttpUtility.UrlDecode(RequestString.GetFormString("cont"));
  494. string strmax = HttpUtility.UrlDecode(RequestString.GetFormString("max"));
  495. Model.T_SMS_SendSMSTask dModel = new Model.T_SMS_SendSMSTask();
  496. if (strid != "")
  497. {
  498. int id = Int32.Parse(strid);
  499. dModel = new BLL.T_SMS_SendSMSTask().GetModel(id);
  500. if (dModel != null)
  501. {
  502. dModel.TelNum = strtel.Trim();
  503. dModel.Content = strcont;
  504. dModel.CurSentCount = 0;
  505. dModel.MaxSendCount = Int32.Parse(strmax);
  506. dModel.Info = "立即短信";
  507. dModel.SendTime = DateTime.Now;
  508. if (strtype == "1")
  509. {
  510. dModel.Info = "定时短信";
  511. dModel.SendTime = DateTime.Parse(strdssj);
  512. }
  513. dModel.F_UserID = User.F_UserId;
  514. if (!string.IsNullOrEmpty(strcusid))
  515. {
  516. int cid = Int32.Parse(strcusid);
  517. var user = new BLL.T_Sys_UserAccount().GetModel(cid);
  518. if (user != null)
  519. {
  520. dModel.F_CustomerID = User.F_UserId;
  521. dModel.F_Name = user.F_UserName;
  522. }
  523. }
  524. dModel.State = 0;
  525. dModel.CommitTime = DateTime.Now;
  526. if (new BLL.T_SMS_SendSMSTask().Update(dModel))
  527. {
  528. return Success("修改成功");
  529. }
  530. else
  531. {
  532. return Error("修改失败");
  533. }
  534. }
  535. else
  536. {
  537. return Error("修改失败");
  538. }
  539. }
  540. else
  541. {
  542. foreach (string tel in strtel.Split(','))
  543. {
  544. dModel.TelNum = tel;
  545. dModel.Content = strcont;
  546. dModel.CurSentCount = 0;
  547. dModel.MaxSendCount = Int32.Parse(strmax);
  548. dModel.Info = "立即短信";
  549. dModel.SendTime = DateTime.Now;
  550. if (strtype == "1")
  551. {
  552. dModel.Info = "定时短信";
  553. dModel.SendTime = DateTime.Parse(strdssj);
  554. }
  555. dModel.F_UserID = User.F_UserId;
  556. if (!string.IsNullOrEmpty(strcusid))
  557. {
  558. int cid = Int32.Parse(strcusid);
  559. var user = new BLL.T_Sys_UserAccount().GetModel(cid);
  560. if (user != null)
  561. {
  562. dModel.F_CustomerID = User.F_UserId;
  563. dModel.F_Name = user.F_UserName;
  564. }
  565. }
  566. dModel.State = 0;
  567. dModel.CommitTime = DateTime.Now;
  568. new BLL.T_SMS_SendSMSTask().Add(dModel);
  569. //int b = new BLL.T_SMS_SendSMSTask().Add(dModel);
  570. //if (b > 0)
  571. //{
  572. // return Success("添加成功");
  573. //}
  574. //else
  575. //{
  576. // return Success("添加失败");
  577. //}
  578. }
  579. return Success("成功");
  580. }
  581. }
  582. [Authority]
  583. /// <summary>
  584. /// 删除短信任务
  585. /// </summary>
  586. /// <param name="ids"></param>
  587. /// <returns></returns>
  588. public ActionResult DelSendTask(string[] ids)
  589. {
  590. if (ids != null && ids.Length > 0)
  591. {
  592. string idd = " ";
  593. foreach (string str in ids)
  594. {
  595. idd += str + ",";
  596. }
  597. if (new BLL.T_SMS_SendSMSTask().DeleteList(idd.TrimEnd(',')))
  598. {
  599. return Success("删除成功");
  600. }
  601. else
  602. {
  603. return Error("删除失败");
  604. }
  605. }
  606. else
  607. {
  608. return Error("请选择要删除的短信任务");
  609. }
  610. }
  611. [Authority]
  612. /// <summary>
  613. /// 获取发送短信列表
  614. /// </summary>
  615. /// <returns></returns>
  616. public ActionResult GetSendList()
  617. {
  618. string sql = "";
  619. DataTable dt = new DataTable();
  620. string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  621. string strcont = HttpUtility.UrlDecode(RequestString.GetQueryString("cont"));
  622. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  623. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  624. string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
  625. string strpageindex = RequestString.GetQueryString("page");
  626. int pageindex = 1;
  627. string strpagesize = RequestString.GetQueryString("pagesize");
  628. int pagesize = 10;
  629. if (strtel.Trim() != "" && strtel != "undefined")
  630. {
  631. sql += " and TelNum like '%" + strtel.Trim() + "%' ";
  632. }
  633. if (strcont.Trim() != "" && strcont != "undefined")
  634. {
  635. sql += " and Content like '%" + strcont.Trim() + "%' ";
  636. }
  637. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  638. {
  639. sql += " and CommitTime >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
  640. }
  641. if (strendtime.Trim() != "" && strendtime != "undefined")
  642. {
  643. sql += " and CommitTime <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
  644. }
  645. if (strstate.Trim() != "" && strstate != "undefined")
  646. {
  647. sql += " and State= '" + strstate.Trim() + "' ";
  648. }
  649. if (strpageindex.Trim() != "")
  650. {
  651. pageindex = Convert.ToInt32(strpageindex);
  652. }
  653. if (strpagesize.Trim() != "")
  654. {
  655. pagesize = Convert.ToInt32(strpagesize);
  656. }
  657. int recordCount = 0;
  658. dt = BLL.PagerBLL.GetListPager(
  659. "T_SMS_SentSMS",
  660. "SMSID",
  661. "*",
  662. sql,
  663. "ORDER BY SMSID desc",
  664. pagesize,
  665. pageindex,
  666. true,
  667. out recordCount);
  668. var obj = new
  669. {
  670. state = "success",
  671. message = "成功",
  672. rows = dt,
  673. total = recordCount
  674. };
  675. return Content(obj.ToJson());
  676. }
  677. [Authority]
  678. /// <summary>
  679. /// 删除短信
  680. /// </summary>
  681. /// <param name="ids"></param>
  682. /// <returns></returns>
  683. public ActionResult DelSend(string[] ids)
  684. {
  685. if (ids != null && ids.Length > 0)
  686. {
  687. string idd = " ";
  688. foreach (string str in ids)
  689. {
  690. idd += str + ",";
  691. }
  692. if (new BLL.T_SMS_SentSMS().DeleteList(idd.TrimEnd(',')))
  693. {
  694. return Success("删除成功");
  695. }
  696. else
  697. {
  698. return Error("删除失败");
  699. }
  700. }
  701. else
  702. {
  703. return Error("请选择要删除的短信");
  704. }
  705. }
  706. [Authority]
  707. /// <summary>
  708. /// 导入短信
  709. /// </summary>
  710. /// <returns></returns>
  711. public ActionResult ImportSend()
  712. {
  713. string strtype = HttpUtility.UrlDecode(RequestString.GetFormString("type"));
  714. string strdssj = HttpUtility.UrlDecode(RequestString.GetFormString("dssj"));
  715. HttpPostedFile _upfile = RequestString.GetFile("upFile");
  716. int headrow = 1;
  717. NPOIHelper np = new NPOIHelper();
  718. DataTable dt = np.ExcelToTable(_upfile, headrow);
  719. string msg = string.Empty;
  720. foreach (DataRow dr in dt.Rows)
  721. {
  722. headrow = headrow + 1;
  723. if (dr[0].ToString() != "" && dr[1].ToString() != "")
  724. {
  725. Model.T_SMS_SendSMSTask dModel = new Model.T_SMS_SendSMSTask();
  726. dModel.TelNum = dr[0].ToString();
  727. dModel.Content = dr[1].ToString();
  728. dModel.CurSentCount = 0;
  729. //dModel.MaxSendCount = Int32.Parse(strmax);
  730. dModel.Info = "立即短信";
  731. dModel.SendTime = DateTime.Now;
  732. if (strtype == "1")
  733. {
  734. dModel.Info = "定时短信";
  735. dModel.SendTime = DateTime.Parse(strdssj);
  736. }
  737. dModel.State = 0;
  738. dModel.F_UserID = User.F_UserId;
  739. dModel.F_Name = User.F_UserName;
  740. if (new BLL.T_SMS_SendSMSTask().Add(dModel) <= 0)
  741. {
  742. msg = msg + "第" + headrow + "行,导入失败<br>";
  743. }
  744. }
  745. else
  746. {
  747. msg = msg + "第" + headrow + "行,手机号或者内容为空,未导入<br>";
  748. }
  749. }
  750. if (!string.IsNullOrEmpty(msg))
  751. {
  752. return Error(msg);
  753. }
  754. else
  755. {
  756. return Success("成功");
  757. }
  758. }
  759. #endregion
  760. #region 短信服务
  761. /// <summary>
  762. /// 执行发送短信
  763. /// </summary>
  764. /// <returns></returns>
  765. public ActionResult ExecSendByJob()
  766. {
  767. DataTable dt = new DataTable();
  768. int ct = RequestString.GetInt("count", 10);
  769. string str = string.Empty;
  770. if (ct != 0)
  771. {
  772. str = " top " + ct;
  773. }
  774. dt = DB.DbHelperSQL.Query(" select " + ct + " * from T_SMS_SendSMSTask where State=0 and SendTime<=getdate() order by CommitTime asc ").Tables[0];
  775. foreach (DataRow dr in dt.Rows)
  776. {
  777. Model.T_SMS_SendSMSTask dModel = new BLL.T_SMS_SendSMSTask().GetModel(Int32.Parse(dr["ID"].ToString()));
  778. if (dModel != null && dModel.State == 0)
  779. {
  780. lock (this)
  781. {
  782. dModel.State = 1;
  783. new BLL.T_SMS_SendSMSTask().Update(dModel);
  784. string msg = SendSMS(dr["Telephone"].ToString(), dr["Detail"].ToString());
  785. int State = 2;
  786. if (!string.IsNullOrEmpty(msg))
  787. {
  788. State = -1;
  789. }
  790. Model.T_SMS_SentSMS model = new Model.T_SMS_SentSMS();
  791. model.State = State;
  792. model.TelNum = dModel.TelNum;
  793. model.LastSentTime = DateTime.Now;
  794. model.F_UserID = dModel.F_UserID;
  795. model.F_Name = dModel.F_Name;
  796. model.F_CustomerID = dModel.F_CustomerID;
  797. model.CurSentCount = dModel.CurSentCount;
  798. model.Content = dModel.Content;
  799. model.CommitTime = dModel.CommitTime;
  800. model.Info = dModel.Info;
  801. model.MaxSendCount = dModel.MaxSendCount;
  802. model.SendTime = dModel.SendTime;
  803. new BLL.T_SMS_SentSMS().Add(model);
  804. new BLL.T_SMS_SendSMSTask().Delete(dModel.SMSID);
  805. }
  806. }
  807. }
  808. return Success("成功", dt);
  809. }
  810. /// <summary>
  811. /// 发送短信接口
  812. /// </summary>
  813. /// <returns></returns>
  814. public string SendSMS(string tel, string cont)
  815. {
  816. string msg = string.Empty;
  817. try
  818. {
  819. }
  820. catch (Exception ex)
  821. {
  822. msg = ex.Message;
  823. }
  824. return msg;
  825. }
  826. #endregion
  827. }
  828. }