PingAnYeXianSZCG_API 接口代码

SMSController.cs 33KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. 
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Mvc;
  7. using CallCenterApi.Interface.Controllers.Base;
  8. using System.Data;
  9. using CallCenter.Utility;
  10. using System.Configuration;
  11. using Top.Api;
  12. using Top.Api.Request;
  13. using Top.Api.Response;
  14. using CallCenterApi.Common;
  15. namespace CallCenterApi.Interface.Controllers
  16. {
  17. public class SMSController : BaseController
  18. {
  19. #region 接收短信
  20. /// <summary>
  21. /// 获取接收短信列表
  22. /// </summary>
  23. /// <returns></returns>
  24. public ActionResult GetRecvList()
  25. {
  26. ActionResult res = NoToken("未知错误,请重新登录");
  27. string sql = "";
  28. DataTable dt = new DataTable();
  29. string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  30. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  31. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  32. string strpageindex = RequestString.GetQueryString("page");
  33. int pageindex = 1;
  34. string strpagesize = RequestString.GetQueryString("pagesize");
  35. int pagesize = 10;
  36. if (strtel.Trim() != "" && strtel != "undefined")
  37. {
  38. sql += " and CallerNum= '" + strtel.Trim() + "' ";
  39. }
  40. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  41. {
  42. sql += " and RecvTime >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
  43. }
  44. if (strendtime.Trim() != "" && strendtime != "undefined")
  45. {
  46. sql += " and RecvTime <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
  47. }
  48. if (strpageindex.Trim() != "")
  49. {
  50. pageindex = Convert.ToInt32(strpageindex);
  51. }
  52. if (strpagesize.Trim() != "")
  53. {
  54. pagesize = Convert.ToInt32(strpagesize);
  55. }
  56. int recordCount = 0;
  57. dt = BLL.PagerBLL.GetListPager(
  58. "T_SMS_RecvSMS",
  59. "SMSID",
  60. "*",
  61. sql,
  62. "ORDER BY SMSID desc",
  63. pagesize,
  64. pageindex,
  65. true,
  66. out recordCount);
  67. var obj = new
  68. {
  69. state = "success",
  70. message = "成功",
  71. rows = dt,
  72. total = recordCount
  73. };
  74. res = Content(obj.ToJson());
  75. return res;
  76. }
  77. /// <summary>
  78. /// 新增接收短信
  79. /// </summary>
  80. /// <returns></returns>
  81. public ActionResult AddRecv(string tel,string cont)
  82. {
  83. ActionResult res = NoToken("未知错误,请重新登录");
  84. Model.T_SMS_RecvSMS dModel = new Model.T_SMS_RecvSMS();
  85. dModel.CallerNum = tel.Trim();
  86. dModel.Content = cont.Trim();
  87. dModel.State = 0;
  88. dModel.RecvTime = DateTime.Now;
  89. dModel.F_CreateDate = DateTime.Now;
  90. int b = new BLL.T_SMS_RecvSMS().Add(dModel);
  91. if (b > 0)
  92. {
  93. res = Success("添加成功");
  94. }
  95. else
  96. {
  97. res = Success("添加失败");
  98. }
  99. return res;
  100. }
  101. /// <summary>
  102. /// 删除接收短信
  103. /// </summary>
  104. /// <param name="ids"></param>
  105. /// <returns></returns>
  106. public ActionResult DelRecv(string[] ids)
  107. {
  108. ActionResult res = NoToken("未知错误,请重新登录");
  109. if (ids != null && ids.Length > 0)
  110. {
  111. string idd = " ";
  112. foreach (string str in ids)
  113. {
  114. idd += str + ",";
  115. }
  116. if (new BLL.T_SMS_RecvSMS().DeleteList(idd.TrimEnd(',')))
  117. {
  118. res = Success("删除成功");
  119. }
  120. else
  121. {
  122. res = Error("删除失败");
  123. }
  124. }
  125. else
  126. {
  127. res = Error("请选择要删除的接收短信");
  128. }
  129. return res;
  130. }
  131. #endregion
  132. #region 发送短信
  133. /// <summary>
  134. /// 获取发送短信任务列表
  135. /// </summary>
  136. /// <returns></returns>
  137. public ActionResult GetSendTaskList()
  138. {
  139. ActionResult res = NoToken("未知错误,请重新登录");
  140. string sql = "";
  141. DataTable dt = new DataTable();
  142. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  143. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  144. string strpageindex = RequestString.GetQueryString("page");
  145. int pageindex = 1;
  146. string strpagesize = RequestString.GetQueryString("pagesize");
  147. int pagesize = 10;
  148. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  149. {
  150. sql += " and F_CreateDate >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
  151. }
  152. if (strendtime.Trim() != "" && strendtime != "undefined")
  153. {
  154. sql += " and F_CreateDate <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
  155. }
  156. if (strpageindex.Trim() != "")
  157. {
  158. pageindex = Convert.ToInt32(strpageindex);
  159. }
  160. if (strpagesize.Trim() != "")
  161. {
  162. pagesize = Convert.ToInt32(strpagesize);
  163. }
  164. int recordCount = 0;
  165. dt = BLL.PagerBLL.GetListPager(
  166. "T_SMS_SendSMSTask",
  167. "SMSID",
  168. "*",
  169. sql,
  170. "ORDER BY SMSID desc",
  171. pagesize,
  172. pageindex,
  173. true,
  174. out recordCount);
  175. var obj = new
  176. {
  177. state = "success",
  178. message = "成功",
  179. rows = dt,
  180. total = recordCount
  181. };
  182. res = Content(obj.ToJson()); ;
  183. return res;
  184. }
  185. /// <summary>
  186. /// 新增短信任务
  187. /// </summary>
  188. /// <returns></returns>
  189. public ActionResult AddSendTask()
  190. {
  191. ActionResult res = NoToken("未知错误,请重新登录");
  192. string strid = HttpUtility.UrlDecode(RequestString.GetQueryString("id"));
  193. string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
  194. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  195. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  196. string strstarttime1 = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime1"));
  197. string strendtime1 = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime1"));
  198. string strstarttime2 = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime2"));
  199. string strendtime2 = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime2"));
  200. string strsignname = HttpUtility.UrlDecode(RequestString.GetQueryString("signname"));
  201. string strtempcode = HttpUtility.UrlDecode(RequestString.GetQueryString("tempcode"));
  202. Model.T_SMS_SendSMSTask dModel = new Model.T_SMS_SendSMSTask();
  203. if (strid != "")
  204. {
  205. int id = Int32.Parse(strid);
  206. dModel = new BLL.T_SMS_SendSMSTask().GetModel(id);
  207. dModel.Name = strname.Trim();
  208. if (!string.IsNullOrEmpty(strstarttime))
  209. {
  210. dModel.StartTime = DateTime.Parse(strstarttime);
  211. }
  212. else
  213. {
  214. dModel.StartTime = null;
  215. }
  216. if (!string.IsNullOrEmpty(strendtime))
  217. {
  218. dModel.EndTime = DateTime.Parse(strendtime);
  219. }
  220. else
  221. {
  222. dModel.EndTime = null;
  223. }
  224. dModel.PeriodStartTime = strstarttime1;
  225. dModel.PeriodEndTime = strendtime1;
  226. dModel.PeriodStartTime1 = strstarttime2;
  227. dModel.PeriodEndTime1 = strendtime2;
  228. dModel.SignName = strsignname;
  229. dModel.TempCode = strtempcode;
  230. if (dModel.State == 1) { dModel.State = 0; }//短信服务
  231. if (new BLL.T_SMS_SendSMSTask().Update(dModel))
  232. {
  233. res = Success("修改成功");
  234. }
  235. else
  236. {
  237. res = Success("修改失败");
  238. }
  239. }
  240. else
  241. {
  242. dModel.Name = strname.Trim();
  243. if (!string.IsNullOrEmpty(strstarttime))
  244. {
  245. dModel.StartTime = DateTime.Parse(strstarttime);
  246. }
  247. if (!string.IsNullOrEmpty(strendtime))
  248. {
  249. dModel.EndTime = DateTime.Parse(strendtime);
  250. }
  251. dModel.PeriodStartTime = strstarttime1;
  252. dModel.PeriodEndTime = strendtime1;
  253. dModel.PeriodStartTime1 = strstarttime2;
  254. dModel.PeriodEndTime1 = strendtime2;
  255. dModel.SignName = strsignname;
  256. dModel.TempCode = strtempcode;
  257. dModel.State = 0;
  258. dModel.F_CreateDate = DateTime.Now;
  259. int b = new BLL.T_SMS_SendSMSTask().Add(dModel);
  260. if (b > 0)
  261. {
  262. res = Success("添加成功");
  263. }
  264. else
  265. {
  266. res = Success("添加失败");
  267. }
  268. }
  269. return res;
  270. }
  271. /// <summary>
  272. /// 删除短信任务
  273. /// </summary>
  274. /// <param name="ids"></param>
  275. /// <returns></returns>
  276. public ActionResult DelSendTask(string[] ids)
  277. {
  278. ActionResult res = NoToken("未知错误,请重新登录");
  279. if (ids != null && ids.Length > 0)
  280. {
  281. string idd = " ";
  282. foreach (string str in ids)
  283. {
  284. idd += str + ",";
  285. }
  286. if (new BLL.T_SMS_SendSMSTask().DeleteList(idd.TrimEnd(',')))
  287. {
  288. res = Success("删除成功");
  289. }
  290. else
  291. {
  292. res = Error("删除失败");
  293. }
  294. }
  295. else
  296. {
  297. res = Error("请选择要删除的短信任务");
  298. }
  299. return res;
  300. }
  301. /// <summary>
  302. /// 获取发送短信列表
  303. /// </summary>
  304. /// <returns></returns>
  305. public ActionResult GetSendList()
  306. {
  307. ActionResult res = NoToken("未知错误,请重新登录");
  308. string sql = "";
  309. DataTable dt = new DataTable();
  310. int taskid = 0;
  311. string strtaskid = HttpUtility.UrlDecode(RequestString.GetQueryString("id"));
  312. string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  313. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  314. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  315. string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
  316. string strpageindex = RequestString.GetQueryString("page");
  317. int pageindex = 1;
  318. string strpagesize = RequestString.GetQueryString("pagesize");
  319. int pagesize = 10;
  320. if (strtaskid != "" && strtaskid != "undefined")
  321. {
  322. taskid = Convert.ToInt32(strtaskid);
  323. }
  324. if (strtel.Trim() != "" && strtel != "undefined")
  325. {
  326. sql += " and TelNum= '" + strtel.Trim() + "' ";
  327. }
  328. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  329. {
  330. sql += " and F_CreateDate >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
  331. }
  332. if (strendtime.Trim() != "" && strendtime != "undefined")
  333. {
  334. sql += " and F_CreateDate <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
  335. }
  336. if (strstate.Trim() != "" && strstate != "undefined")
  337. {
  338. sql += " and State= '" + strstate.Trim() + "' ";
  339. }
  340. if (strpageindex.Trim() != "")
  341. {
  342. pageindex = Convert.ToInt32(strpageindex);
  343. }
  344. if (strpagesize.Trim() != "")
  345. {
  346. pagesize = Convert.ToInt32(strpagesize);
  347. }
  348. int recordCount = 0;
  349. dt = BLL.PagerBLL.GetListPager(
  350. "T_SMS_SentSMS",
  351. "SMSID",
  352. "*",
  353. sql,
  354. "ORDER BY SMSID desc",
  355. pagesize,
  356. pageindex,
  357. true,
  358. out recordCount);
  359. var obj = new
  360. {
  361. state = "success",
  362. message = "成功",
  363. rows = dt,
  364. total = recordCount
  365. };
  366. res = Content(obj.ToJson()); ;
  367. return res;
  368. }
  369. /// <summary>
  370. /// 新增短信
  371. /// </summary>
  372. /// <returns></returns>
  373. public ActionResult AddSend(string id,string taskid,string tel,string cont)
  374. {
  375. ActionResult res = NoToken("未知错误,请重新登录");
  376. Model.T_SMS_SentSMS dModel = new Model.T_SMS_SentSMS();
  377. if (id != "")
  378. {
  379. int sid = Int32.Parse(id);
  380. dModel = new BLL.T_SMS_SentSMS().GetModel(sid);
  381. dModel.TelNum = tel.Trim();
  382. dModel.Content = cont;
  383. if (new BLL.T_SMS_SentSMS().Update(dModel))
  384. {
  385. res = Success("修改成功");
  386. }
  387. else
  388. {
  389. res = Success("修改失败");
  390. }
  391. }
  392. else
  393. {
  394. dModel.TaskID = Int32.Parse(taskid);
  395. dModel.TelNum = tel.Trim();
  396. dModel.Content = cont;
  397. dModel.State = 0;
  398. dModel.F_CreateDate = DateTime.Now;
  399. int b = new BLL.T_SMS_SentSMS().Add(dModel);
  400. if (b > 0)
  401. {
  402. res = Success("添加成功");
  403. }
  404. else
  405. {
  406. res = Success("添加失败");
  407. }
  408. }
  409. return res;
  410. }
  411. /// <summary>
  412. /// 删除短信
  413. /// </summary>
  414. /// <param name="ids"></param>
  415. /// <returns></returns>
  416. public ActionResult DelSend(string[] ids)
  417. {
  418. ActionResult res = NoToken("未知错误,请重新登录");
  419. if (ids != null && ids.Length > 0)
  420. {
  421. string idd = " ";
  422. foreach (string str in ids)
  423. {
  424. idd += str + ",";
  425. }
  426. if (new BLL.T_SMS_SentSMS().DeleteList(idd.TrimEnd(',')))
  427. {
  428. res = Success("删除成功");
  429. }
  430. else
  431. {
  432. res = Error("删除失败");
  433. }
  434. }
  435. else
  436. {
  437. res = Error("请选择要删除的短信");
  438. }
  439. return res;
  440. }
  441. /// <summary>
  442. /// 导入短信
  443. /// </summary>
  444. /// <returns></returns>
  445. public ActionResult ImportSend()
  446. {
  447. ActionResult res = NoToken("未知错误,请重新登录");
  448. if (Request.IsAuthenticated)
  449. {
  450. int userId = CurrentUser.UserData.F_UserId;
  451. if (userId != 0)
  452. {
  453. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  454. if (userModel != null)
  455. {
  456. HttpPostedFile _upfile = RequestString.GetFile("upFile");
  457. int taskid = RequestString.GetInt("taskid", 0);
  458. int headrow = 1;
  459. NPOIHelper np = new NPOIHelper();
  460. DataTable dt = np.ExcelToTable(_upfile, headrow);
  461. string msg = string.Empty;
  462. foreach (DataRow dr in dt.Rows)
  463. {
  464. headrow = headrow + 1;
  465. if (dr[0].ToString() != "" && dr[1].ToString() != "")
  466. {
  467. Model.T_SMS_SentSMS dModel = new Model.T_SMS_SentSMS();
  468. dModel.TaskID = taskid;
  469. dModel.TelNum = dr[0].ToString();
  470. dModel.Content = dr[1].ToString();
  471. dModel.State = 0;
  472. dModel.F_UserID = userModel.F_UserId;
  473. dModel.F_Name = userModel.F_UserName;
  474. dModel.F_CreateDate = DateTime.Now;
  475. if (new BLL.T_SMS_SentSMS().Add(dModel) > 0)
  476. {
  477. msg = msg + "第" + headrow + "行,导入失败<br>";
  478. }
  479. }
  480. else
  481. {
  482. msg = msg + "第"+ headrow+"行,手机号或者内容为空,未导入<br>";
  483. }
  484. }
  485. if (string.IsNullOrEmpty(msg))
  486. {
  487. res = Error(msg);
  488. }
  489. }
  490. }
  491. }
  492. return res;
  493. }
  494. #endregion
  495. #region 短信服务
  496. /// <summary>
  497. /// 获取发送短信列表
  498. /// </summary>
  499. /// <returns></returns>
  500. public ActionResult GetSendTaskListByJob(string state, string count)
  501. {
  502. ActionResult res = NoToken("未知错误,请重新登录");
  503. DataTable dt = new DataTable();
  504. string str = "";
  505. if (!string.IsNullOrEmpty(count))
  506. {
  507. int ct = Int32.Parse(count);
  508. str = "top " + ct;
  509. }
  510. dt = DB.DbHelperSQL.Query(" select " + str + " * from T_SMS_SendSMSTask where isnull(State,0)='" + state + "' and getdate() between isnull(StartTime,'1900-01-01 00:00:00') and isnull(EndTime,'9999-12-31 23:59:59') order by F_CreateDate ").Tables[0];
  511. res = Success("成功", dt);
  512. return res;
  513. }
  514. /// <summary>
  515. /// 获取发送短信列表
  516. /// </summary>
  517. /// <returns></returns>
  518. public ActionResult GetSendListByJob(string taskid, string count)
  519. {
  520. ActionResult res = NoToken("未知错误,请重新登录");
  521. DataTable dt = new DataTable();
  522. string str = "";
  523. if (!string.IsNullOrEmpty(count))
  524. {
  525. int ct = Int32.Parse(count);
  526. str = "top " + ct;
  527. }
  528. //dt = DB.DbHelperSQL.Query(" select top "+ ct+ " s.*,t.PeriodStartTime,t.PeriodStartTime1,t.PeriodEndTime,t.PeriodEndTime1 from T_SMS_SentSMS s left join T_SMS_SendSMSTask t on s.TaskID=t.SMSID where isnull(s.State,0)=0 and getdate() between t.StartTime and t.EndTime order by s.F_CreateDate ").Tables[0];
  529. dt = DB.DbHelperSQL.Query(" select " + str + " * from T_SMS_SentSMS where TaskID='" + taskid + "' and isnull(State,0)='0' order by F_CreateDate ").Tables[0];
  530. res = Success("成功", dt);
  531. return res;
  532. }
  533. /// <summary>
  534. /// 执行发送短信
  535. /// </summary>
  536. /// <returns></returns>
  537. public ActionResult ExecSMSByJob(string taskid, string count)
  538. {
  539. ActionResult res = NoToken("未知错误,请重新登录");
  540. DataTable dt = new DataTable();
  541. string tels = string.Empty;
  542. string errtels = string.Empty;
  543. string isdel = string.Empty;
  544. string str = string.Empty;
  545. if (!string.IsNullOrEmpty(count))
  546. {
  547. int ct = Int32.Parse(count);
  548. str = "top " + ct;
  549. }
  550. var task = new BLL.T_SMS_SendSMSTask().GetModel(Int32.Parse(taskid));
  551. if (task != null)
  552. {
  553. bool bl = true;
  554. DateTime dte = DateTime.Now;
  555. if (task.StartTime != null)
  556. {
  557. bl = dte >= task.StartTime.Value;
  558. }
  559. if (bl && task.EndTime != null)
  560. {
  561. bl = dte <= task.EndTime.Value;
  562. }
  563. if (bl)
  564. {
  565. //dt = DB.DbHelperSQL.Query(" select top "+ ct+ " s.*,t.PeriodStartTime,t.PeriodStartTime1,t.PeriodEndTime,t.PeriodEndTime1 from T_SMS_SentSMS s left join T_SMS_SendSMSTask t on s.TaskID=t.SMSID where isnull(s.State,0)=0 and getdate() between t.StartTime and t.EndTime order by s.F_CreateDate ").Tables[0];
  566. dt = DB.DbHelperSQL.Query(" select " + str + " * from T_SMS_SentSMS where TaskID='" + task.SMSID + "' and isnull(State,0)=0 order by F_CreateDate ").Tables[0];
  567. foreach (DataRow dr in dt.Rows)
  568. {
  569. string err = SendSMS(dr["TelNum"].ToString(), dr["Content"].ToString(), task.SignName, task.TempCode);
  570. if (err == "")
  571. {
  572. UpdateSendState(dr["SMSID"].ToString());
  573. if (string.IsNullOrEmpty(tels))
  574. {
  575. tels = dr["TelNum"].ToString();
  576. }
  577. else
  578. {
  579. tels = tels + "," + dr["TelNum"].ToString();
  580. }
  581. }
  582. else
  583. {
  584. if (string.IsNullOrEmpty(tels))
  585. {
  586. errtels = dr["TelNum"].ToString();
  587. }
  588. else
  589. {
  590. errtels = errtels + "," + dr["TelNum"].ToString();
  591. }
  592. }
  593. }
  594. isdel = "0";
  595. }
  596. else
  597. {
  598. isdel = "1";
  599. }
  600. }
  601. else
  602. {
  603. isdel = "1";
  604. }
  605. res = Success("成功", new { suc = tels, err = errtels, isdel = isdel });
  606. return res;
  607. }
  608. /// <summary>
  609. /// 根据结束时间结束任务
  610. /// </summary>
  611. /// <returns></returns>
  612. public ActionResult EndSMSTask()
  613. {
  614. ActionResult res = NoToken("未知错误,请重新登录");
  615. string str = string.Empty;
  616. string strerr = string.Empty;
  617. BLL.T_SMS_SendSMSTask bll = new BLL.T_SMS_SendSMSTask();
  618. var list = bll.GetModelList(" isnull(State,0)=1 ");
  619. foreach (var l in list)
  620. {
  621. if (l.EndTime <= DateTime.Now)
  622. {
  623. l.State = 9;
  624. if (bll.Update(l))
  625. {
  626. if (string.IsNullOrEmpty(str))
  627. {
  628. str = l.SMSID.ToString();
  629. }
  630. else
  631. {
  632. str = str + "," + l.SMSID.ToString();
  633. }
  634. }
  635. else
  636. {
  637. if (string.IsNullOrEmpty(strerr))
  638. {
  639. strerr = l.SMSID.ToString();
  640. }
  641. else
  642. {
  643. strerr = strerr + "," + l.SMSID.ToString();
  644. }
  645. }
  646. }
  647. }
  648. res = Success("成功", new { suc = str, err = strerr});
  649. return res;
  650. }
  651. /// <summary>
  652. /// 短信服务停止后重置正在执行的任务
  653. /// </summary>
  654. /// <returns></returns>
  655. public ActionResult ResetSMSTask()
  656. {
  657. ActionResult res = NoToken("未知错误,请重新登录");
  658. string str = string.Empty;
  659. string strerr = string.Empty;
  660. BLL.T_SMS_SendSMSTask bll = new BLL.T_SMS_SendSMSTask();
  661. var list = bll.GetModelList(" isnull(State,0)=1 ");
  662. foreach (var l in list)
  663. {
  664. l.State = 0;
  665. if (bll.Update(l))
  666. {
  667. if (string.IsNullOrEmpty(str))
  668. {
  669. str = l.SMSID.ToString();
  670. }
  671. else
  672. {
  673. str = str + "," + l.SMSID.ToString();
  674. }
  675. }
  676. else
  677. {
  678. if (string.IsNullOrEmpty(strerr))
  679. {
  680. strerr = l.SMSID.ToString();
  681. }
  682. else
  683. {
  684. strerr = strerr + "," + l.SMSID.ToString();
  685. }
  686. }
  687. }
  688. res = Success("成功", new { suc = str, err = strerr });
  689. return res;
  690. }
  691. /// <summary>
  692. /// 更新短信发送状态
  693. /// </summary>
  694. /// <returns></returns>
  695. public ActionResult UpdateSendTaskState(string id, string state)
  696. {
  697. ActionResult res = NoToken("未知错误,请重新登录");
  698. Model.T_SMS_SendSMSTask dModel = new Model.T_SMS_SendSMSTask();
  699. if (id != "")
  700. {
  701. int sid = Int32.Parse(id);
  702. dModel = new BLL.T_SMS_SendSMSTask().GetModel(sid);
  703. if (dModel != null)
  704. {
  705. dModel.State = Int32.Parse(state);
  706. if (new BLL.T_SMS_SendSMSTask().Update(dModel))
  707. {
  708. res = Success("修改成功");
  709. }
  710. else
  711. {
  712. res = Success("修改失败");
  713. }
  714. }
  715. }
  716. return res;
  717. }
  718. /// <summary>
  719. /// 更新短信发送状态
  720. /// </summary>
  721. /// <returns></returns>
  722. public ActionResult UpdateSendState(string id)
  723. {
  724. ActionResult res = NoToken("未知错误,请重新登录");
  725. Model.T_SMS_SentSMS dModel = new Model.T_SMS_SentSMS();
  726. if (id != "")
  727. {
  728. int sid = Int32.Parse(id);
  729. dModel = new BLL.T_SMS_SentSMS().GetModel(sid);
  730. if (dModel != null && dModel.State == 0)
  731. {
  732. dModel.State = 1;
  733. dModel.SendTime = DateTime.Now;
  734. if (new BLL.T_SMS_SentSMS().Update(dModel))
  735. {
  736. res = Success("修改成功");
  737. }
  738. else
  739. {
  740. res = Success("修改失败");
  741. }
  742. }
  743. }
  744. return res;
  745. }
  746. #endregion
  747. #region 发送短信接口
  748. /// <summary>
  749. /// 发送短信接口
  750. /// </summary>
  751. /// <returns></returns>
  752. public ActionResult SentSMS()
  753. {
  754. //调用示例--/sms/sendsms?tel=15512345678,15812341234&cont={"name":"张三","time":"11:00"}&signname=活动验证&tempcode=SMS_40865007
  755. ActionResult res = NoToken("未知错误,请重新登录");
  756. string signname = HttpUtility.UrlDecode(RequestString.GetQueryString("signname"));//"活动验证";
  757. string tempcode = HttpUtility.UrlDecode(RequestString.GetQueryString("tempcode"));//"SMS_40865007";
  758. string tel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));//多个用 , 隔开
  759. string cont = HttpUtility.UrlDecode(RequestString.GetQueryString("cont"));
  760. string err = SendSMS(tel, cont, signname, tempcode);
  761. if (err == "")
  762. {
  763. res = Success("成功");
  764. }
  765. else
  766. {
  767. res = Error(err);
  768. }
  769. return res;
  770. }
  771. /// <summary>
  772. /// 发送短信
  773. /// </summary>
  774. /// <param name="tel"></param>
  775. /// <param name="cont"></param>
  776. /// <param name="signname"></param>
  777. /// <param name="tempcode"></param>
  778. /// <returns></returns>
  779. public string SendSMS(string tel, string cont, string signname, string tempcode)
  780. {
  781. string res = string.Empty;
  782. string url = ConfigurationManager.AppSettings["url"];
  783. string key = ConfigurationManager.AppSettings["key"];
  784. string secret = ConfigurationManager.AppSettings["secret"];
  785. try
  786. {
  787. ITopClient client = new DefaultTopClient(url, key, secret);
  788. AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
  789. req.Extend = "123456";//公共回传参数
  790. req.SmsType = "normal";//短信类型,传入值请填写normal
  791. req.SmsFreeSignName = signname;//签名
  792. req.SmsParam = cont; //短信模参数示例: "{\"name\":\"张三\",\"time\":\"11:00\"}";
  793. req.RecNum = tel; //短信接收号码
  794. req.SmsTemplateCode = tempcode;//短信模板ID
  795. AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req);
  796. if (!rsp.IsError)
  797. {
  798. if (!rsp.Result.Success)
  799. {
  800. res = rsp.Result.Msg;
  801. }
  802. }
  803. else
  804. {
  805. if (!string.IsNullOrEmpty(rsp.SubErrMsg))
  806. {
  807. res = rsp.SubErrMsg;
  808. }
  809. else
  810. {
  811. res = rsp.ErrMsg;
  812. }
  813. }
  814. }
  815. catch
  816. {
  817. res = "接口异常!";
  818. }
  819. return res;
  820. }
  821. #endregion
  822. }
  823. }