No Description

SMSController.cs 31KB

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