Нет описания

SMSController.cs 47KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  1. 
  2. using CallCenterApi.Interface.Controllers.Base;
  3. using System;
  4. using System.Web.Mvc;
  5. using qcloudsms_csharp;
  6. using qcloudsms_csharp.json;
  7. using qcloudsms_csharp.httpclient;
  8. namespace CallCenterApi.Interface.Controllers
  9. {
  10. public class SMSController : BaseController
  11. {
  12. #region 接收短信
  13. // 短信应用SDK AppID
  14. int appid = 1400238721;
  15. // 短信应用SDK AppKey
  16. string appkey = "2b2094bcaf2c841fdb50bcaebabf6f54";
  17. // 需要发送短信的手机号码
  18. int templateId = 392016; // NOTE: 这里的模板ID`7839`只是一个示例,真实的模板ID需要在短信控制台中申请
  19. // 签名
  20. string smsSign = "河南心连心客服"; // NOTE: 这里的签名只是示例,请使用真实的已申请的签名, 签名参数使用的是`签名内容`,而不是`签名ID`
  21. #endregion
  22. public ActionResult SMSSend(string name,string phone,string cusphone)
  23. {
  24. SmsSingleSenderResult result = SMSSingleshot(cusphone, "您好,感谢你的致电反馈,稍后会安排业务经理和你联系,请你保持电话畅通。业务经理姓名:"+ name+",电话:"+ phone+"。");
  25. if (result != null)
  26. {
  27. return Success("发送短信", result);
  28. }
  29. else
  30. {
  31. return Error ("发送失败,请检查客户电话");
  32. }
  33. }
  34. /// <summary>
  35. /// 单发短信
  36. /// </summary>
  37. /// <param name="phone"></param>
  38. /// <param name="cont"></param>
  39. public SmsSingleSenderResult SMSSingleshot(string phone, string cont)
  40. {
  41. try
  42. {
  43. SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
  44. var result = ssender.send(0, "86", phone,
  45. cont, "", "");
  46. Console.WriteLine(result);
  47. return result;
  48. }
  49. catch (JSONException e)
  50. {
  51. Console.WriteLine(e);
  52. return null;
  53. }
  54. catch (HTTPException e)
  55. {
  56. Console.WriteLine(e);
  57. return null;
  58. }
  59. catch (Exception e)
  60. {
  61. Console.WriteLine(e);
  62. return null;
  63. }
  64. }
  65. /// <summary>
  66. /// 群发短信
  67. /// </summary>
  68. /// <param name="phone"></param>
  69. /// <param name="cont"></param>
  70. public SmsMultiSenderResult SMSGroupSending(string[] phone, string cont)
  71. {
  72. try
  73. {
  74. SmsMultiSender msender = new SmsMultiSender(appid, appkey);
  75. var result = msender.send(0, "86", phone,
  76. cont, "", "");
  77. Console.WriteLine(result);
  78. return result;
  79. }
  80. catch (JSONException e)
  81. {
  82. Console.WriteLine(e);
  83. return null;
  84. }
  85. catch (HTTPException e)
  86. {
  87. Console.WriteLine(e);
  88. return null;
  89. }
  90. catch (Exception e)
  91. {
  92. Console.WriteLine(e);
  93. return null;
  94. }
  95. }
  96. /// <summary>
  97. /// int beginTime = 1511125600; // 开始时间(UNIX timestamp)
  98. /// int endTime = 1511841600; // 结束时间(UNIX timestamp)
  99. /// int maxNum = 10; // 单次拉取最大量
  100. /// 拉取单个手机回执
  101. /// </summary>
  102. /// <param name="beginTime"></param>
  103. public SmsStatusPullCallbackResult SMSSingleReceipt(int maxNum = 10)
  104. {
  105. try
  106. {
  107. // Note: 短信拉取功能需要联系腾讯云短信技术支持(QQ:3012203387)开通权限
  108. SmsStatusPuller spuller = new SmsStatusPuller(appid, appkey);
  109. // 拉取短信回执
  110. var callbackResult = spuller.pullCallback(maxNum);
  111. Console.WriteLine(callbackResult);
  112. return callbackResult;
  113. }
  114. catch (JSONException e)
  115. {
  116. Console.WriteLine(e);
  117. return null;
  118. }
  119. catch (HTTPException e)
  120. {
  121. Console.WriteLine(e);
  122. return null;
  123. }
  124. catch (Exception e)
  125. {
  126. Console.WriteLine(e);
  127. return null;
  128. }
  129. }
  130. /// <summary>
  131. /// 短信拉取
  132. /// </summary>
  133. /// <returns></returns>
  134. BLL.T_Wo_MaterialManage mmBLL = new BLL.T_Wo_MaterialManage();
  135. public ActionResult SMSReply()
  136. {
  137. Model.T_Wo_MaterialManage dModel = new Model.T_Wo_MaterialManage();
  138. SmsStatusPullReplyResult result = SMSSingleReply(1);
  139. if (result != null)
  140. {
  141. return Success("短信测试", result);
  142. }
  143. else
  144. {
  145. return null;
  146. }
  147. }
  148. BLL.T_Wo_WorkOrder workOrder = new BLL.T_Wo_WorkOrder();
  149. /// <summary>
  150. /// int beginTime = 1511125600; // 开始时间(UNIX timestamp)
  151. /// int endTime = 1511841600; // 结束时间(UNIX timestamp)
  152. /// int maxNum = 10; // 单次拉取最大量
  153. /// 拉取手机回复
  154. /// </summary>
  155. /// <param name="beginTime"></param>
  156. public SmsStatusPullReplyResult SMSSingleReply( int maxNum=1)
  157. {
  158. try
  159. {
  160. SmsStatusPuller spuller = new SmsStatusPuller(appid, appkey);
  161. // 拉取短信回执
  162. var callbackResult = spuller.pullCallback(maxNum);
  163. Console.WriteLine(callbackResult);
  164. // 拉取回复,仅国内短信支持拉取回复状态
  165. var replyResult = spuller.pullReply(maxNum);
  166. if (callbackResult != null )
  167. {
  168. if (callbackResult.callbacks.Count >0)
  169. {
  170. for (int i=0;i< callbackResult.callbacks.Count;i++)
  171. {
  172. if (!string .IsNullOrEmpty (callbackResult.callbacks[i ].sid .Trim ()))
  173. {
  174. Model.T_Wo_WorkOrder model = new BLL.T_Wo_WorkOrder().GetModelSid(callbackResult.callbacks[i].sid.Trim());
  175. if (model !=null )
  176. {
  177. try
  178. {
  179. model.F_SMSReply = int.Parse(replyResult.replys[i].text);
  180. workOrder.Update(model);
  181. SMSSingleshot(replyResult.replys[i].mobile , "心连心感谢您的评价,祝你生活愉快!");
  182. }
  183. catch
  184. {
  185. model.F_SMSReply =0;
  186. }
  187. }
  188. }
  189. }
  190. }
  191. }
  192. Console.WriteLine(replyResult);
  193. return replyResult;
  194. }
  195. catch (JSONException e)
  196. {
  197. Console.WriteLine(e);
  198. return null;
  199. }
  200. catch (HTTPException e)
  201. {
  202. Console.WriteLine(e);
  203. return null;
  204. }
  205. catch (Exception e)
  206. {
  207. Console.WriteLine(e);
  208. return null;
  209. }
  210. }
  211. #region
  212. //// /// <summary>
  213. //// /// 获取接收短信列表
  214. //// /// </summary>
  215. //// /// <returns></returns>
  216. //// public ActionResult GetRecvList()
  217. //// {
  218. //// ActionResult res = NoToken("未知错误,请重新登录");
  219. //// string sql = "";
  220. //// DataTable dt = new DataTable();
  221. //// string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  222. //// string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  223. //// string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  224. //// string strpageindex = RequestString.GetQueryString("page");
  225. //// int pageindex = 1;
  226. //// string strpagesize = RequestString.GetQueryString("pagesize");
  227. //// int pagesize = 10;
  228. //// if (strtel.Trim() != "" && strtel != "undefined")
  229. //// {
  230. //// sql += " and CallerNum= '" + strtel.Trim() + "' ";
  231. //// }
  232. //// if (strstarttime.Trim() != "" && strstarttime != "undefined")
  233. //// {
  234. //// sql += " and RecvTime >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
  235. //// }
  236. //// if (strendtime.Trim() != "" && strendtime != "undefined")
  237. //// {
  238. //// sql += " and RecvTime <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
  239. //// }
  240. //// if (strpageindex.Trim() != "")
  241. //// {
  242. //// pageindex = Convert.ToInt32(strpageindex);
  243. //// }
  244. //// if (strpagesize.Trim() != "")
  245. //// {
  246. //// pagesize = Convert.ToInt32(strpagesize);
  247. //// }
  248. //// int recordCount = 0;
  249. //// dt = BLL.PagerBLL.GetListPager(
  250. //// "T_SMS_RecvSMS",
  251. //// "SMSID",
  252. //// "*",
  253. //// sql,
  254. //// "ORDER BY SMSID desc",
  255. //// pagesize,
  256. //// pageindex,
  257. //// true,
  258. //// out recordCount);
  259. //// var obj = new
  260. //// {
  261. //// state = "success",
  262. //// message = "成功",
  263. //// rows = dt,
  264. //// total = recordCount
  265. //// };
  266. //// res = Content(obj.ToJson());
  267. //// return res;
  268. //// }
  269. //// /// <summary>
  270. //// /// 新增接收短信
  271. //// /// </summary>
  272. //// /// <returns></returns>
  273. //// public ActionResult AddRecv(string tel,string cont)
  274. //// {
  275. //// ActionResult res = NoToken("未知错误,请重新登录");
  276. //// Model.T_SMS_RecvSMS dModel = new Model.T_SMS_RecvSMS();
  277. //// dModel.CallerNum = tel.Trim();
  278. //// dModel.Content = cont.Trim();
  279. //// dModel.State = 0;
  280. //// dModel.RecvTime = DateTime.Now;
  281. //// dModel.F_CreateDate = DateTime.Now;
  282. //// int b = new BLL.T_SMS_RecvSMS().Add(dModel);
  283. //// if (b > 0)
  284. //// {
  285. //// res = Success("添加成功");
  286. //// }
  287. //// else
  288. //// {
  289. //// res = Success("添加失败");
  290. //// }
  291. //// return res;
  292. //// }
  293. //// /// <summary>
  294. //// /// 删除接收短信
  295. //// /// </summary>
  296. //// /// <param name="ids"></param>
  297. //// /// <returns></returns>
  298. //// public ActionResult DelRecv(string[] ids)
  299. //// {
  300. //// ActionResult res = NoToken("未知错误,请重新登录");
  301. //// if (ids != null && ids.Length > 0)
  302. //// {
  303. //// string idd = " ";
  304. //// foreach (string str in ids)
  305. //// {
  306. //// idd += str + ",";
  307. //// }
  308. //// if (new BLL.T_SMS_RecvSMS().DeleteList(idd.TrimEnd(',')))
  309. //// {
  310. //// res = Success("删除成功");
  311. //// }
  312. //// else
  313. //// {
  314. //// res = Error("删除失败");
  315. //// }
  316. //// }
  317. //// else
  318. //// {
  319. //// res = Error("请选择要删除的接收短信");
  320. //// }
  321. //// return res;
  322. //// }
  323. //// #endregion
  324. //// #region 发送短信
  325. //// /// <summary>
  326. //// /// 获取发送短信任务列表
  327. //// /// </summary>
  328. //// /// <returns></returns>
  329. //// public ActionResult GetSendTaskList()
  330. //// {
  331. //// ActionResult res = NoToken("未知错误,请重新登录");
  332. //// string sql = "";
  333. //// DataTable dt = new DataTable();
  334. //// string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  335. //// string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  336. //// string strpageindex = RequestString.GetQueryString("page");
  337. //// int pageindex = 1;
  338. //// string strpagesize = RequestString.GetQueryString("pagesize");
  339. //// int pagesize = 10;
  340. //// if (strstarttime.Trim() != "" && strstarttime != "undefined")
  341. //// {
  342. //// sql += " and F_CreateDate >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
  343. //// }
  344. //// if (strendtime.Trim() != "" && strendtime != "undefined")
  345. //// {
  346. //// sql += " and F_CreateDate <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
  347. //// }
  348. //// if (strpageindex.Trim() != "")
  349. //// {
  350. //// pageindex = Convert.ToInt32(strpageindex);
  351. //// }
  352. //// if (strpagesize.Trim() != "")
  353. //// {
  354. //// pagesize = Convert.ToInt32(strpagesize);
  355. //// }
  356. //// int recordCount = 0;
  357. //// dt = BLL.PagerBLL.GetListPager(
  358. //// "T_SMS_SendSMSTask",
  359. //// "SMSID",
  360. //// "*",
  361. //// sql,
  362. //// "ORDER BY SMSID desc",
  363. //// pagesize,
  364. //// pageindex,
  365. //// true,
  366. //// out recordCount);
  367. //// var obj = new
  368. //// {
  369. //// state = "success",
  370. //// message = "成功",
  371. //// rows = dt,
  372. //// total = recordCount
  373. //// };
  374. //// res = Content(obj.ToJson()); ;
  375. //// return res;
  376. //// }
  377. //// /// <summary>
  378. //// /// 新增短信任务
  379. //// /// </summary>
  380. //// /// <returns></returns>
  381. //// public ActionResult AddSendTask()
  382. //// {
  383. //// ActionResult res = NoToken("未知错误,请重新登录");
  384. //// string strid = HttpUtility.UrlDecode(RequestString.GetQueryString("id"));
  385. //// string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
  386. //// string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  387. //// string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  388. //// string strstarttime1 = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime1"));
  389. //// string strendtime1 = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime1"));
  390. //// string strstarttime2 = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime2"));
  391. //// string strendtime2 = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime2"));
  392. //// string strsignname = HttpUtility.UrlDecode(RequestString.GetQueryString("signname"));
  393. //// string strtempcode = HttpUtility.UrlDecode(RequestString.GetQueryString("tempcode"));
  394. //// Model.T_SMS_SendSMSTask dModel = new Model.T_SMS_SendSMSTask();
  395. //// if (strid != "")
  396. //// {
  397. //// int id = Int32.Parse(strid);
  398. //// dModel = new BLL.T_SMS_SendSMSTask().GetModel(id);
  399. //// dModel.Name = strname.Trim();
  400. //// if (!string.IsNullOrEmpty(strstarttime))
  401. //// {
  402. //// dModel.StartTime = DateTime.Parse(strstarttime);
  403. //// }
  404. //// else
  405. //// {
  406. //// dModel.StartTime = null;
  407. //// }
  408. //// if (!string.IsNullOrEmpty(strendtime))
  409. //// {
  410. //// dModel.EndTime = DateTime.Parse(strendtime);
  411. //// }
  412. //// else
  413. //// {
  414. //// dModel.EndTime = null;
  415. //// }
  416. //// dModel.PeriodStartTime = strstarttime1;
  417. //// dModel.PeriodEndTime = strendtime1;
  418. //// dModel.PeriodStartTime1 = strstarttime2;
  419. //// dModel.PeriodEndTime1 = strendtime2;
  420. //// dModel.SignName = strsignname;
  421. //// dModel.TempCode = strtempcode;
  422. //// if (dModel.State == 1) { dModel.State = 0; }//短信服务
  423. //// if (new BLL.T_SMS_SendSMSTask().Update(dModel))
  424. //// {
  425. //// res = Success("修改成功");
  426. //// }
  427. //// else
  428. //// {
  429. //// res = Success("修改失败");
  430. //// }
  431. //// }
  432. //// else
  433. //// {
  434. //// dModel.Name = strname.Trim();
  435. //// if (!string.IsNullOrEmpty(strstarttime))
  436. //// {
  437. //// dModel.StartTime = DateTime.Parse(strstarttime);
  438. //// }
  439. //// if (!string.IsNullOrEmpty(strendtime))
  440. //// {
  441. //// dModel.EndTime = DateTime.Parse(strendtime);
  442. //// }
  443. //// dModel.PeriodStartTime = strstarttime1;
  444. //// dModel.PeriodEndTime = strendtime1;
  445. //// dModel.PeriodStartTime1 = strstarttime2;
  446. //// dModel.PeriodEndTime1 = strendtime2;
  447. //// dModel.SignName = strsignname;
  448. //// dModel.TempCode = strtempcode;
  449. //// dModel.State = 0;
  450. //// dModel.F_CreateDate = DateTime.Now;
  451. //// int b = new BLL.T_SMS_SendSMSTask().Add(dModel);
  452. //// if (b > 0)
  453. //// {
  454. //// res = Success("添加成功");
  455. //// }
  456. //// else
  457. //// {
  458. //// res = Success("添加失败");
  459. //// }
  460. //// }
  461. //// return res;
  462. //// }
  463. //// /// <summary>
  464. //// /// 删除短信任务
  465. //// /// </summary>
  466. //// /// <param name="ids"></param>
  467. //// /// <returns></returns>
  468. //// public ActionResult DelSendTask(string[] ids)
  469. //// {
  470. //// ActionResult res = NoToken("未知错误,请重新登录");
  471. //// if (ids != null && ids.Length > 0)
  472. //// {
  473. //// string idd = " ";
  474. //// foreach (string str in ids)
  475. //// {
  476. //// idd += str + ",";
  477. //// }
  478. //// if (new BLL.T_SMS_SendSMSTask().DeleteList(idd.TrimEnd(',')))
  479. //// {
  480. //// res = Success("删除成功");
  481. //// }
  482. //// else
  483. //// {
  484. //// res = Error("删除失败");
  485. //// }
  486. //// }
  487. //// else
  488. //// {
  489. //// res = Error("请选择要删除的短信任务");
  490. //// }
  491. //// return res;
  492. //// }
  493. //// /// <summary>
  494. //// /// 获取发送短信列表
  495. //// /// </summary>
  496. //// /// <returns></returns>
  497. //// public ActionResult GetSendList()
  498. //// {
  499. //// ActionResult res = NoToken("未知错误,请重新登录");
  500. //// string sql = "";
  501. //// DataTable dt = new DataTable();
  502. //// int taskid = 0;
  503. //// string strtaskid = HttpUtility.UrlDecode(RequestString.GetQueryString("id"));
  504. //// string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  505. //// string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  506. //// string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  507. //// string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
  508. //// string strpageindex = RequestString.GetQueryString("page");
  509. //// int pageindex = 1;
  510. //// string strpagesize = RequestString.GetQueryString("pagesize");
  511. //// int pagesize = 10;
  512. //// if (strtaskid != "" && strtaskid != "undefined")
  513. //// {
  514. //// taskid = Convert.ToInt32(strtaskid);
  515. //// }
  516. //// if (strtel.Trim() != "" && strtel != "undefined")
  517. //// {
  518. //// sql += " and TelNum= '" + strtel.Trim() + "' ";
  519. //// }
  520. //// if (strstarttime.Trim() != "" && strstarttime != "undefined")
  521. //// {
  522. //// sql += " and F_CreateDate >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
  523. //// }
  524. //// if (strendtime.Trim() != "" && strendtime != "undefined")
  525. //// {
  526. //// sql += " and F_CreateDate <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
  527. //// }
  528. //// if (strstate.Trim() != "" && strstate != "undefined")
  529. //// {
  530. //// sql += " and State= '" + strstate.Trim() + "' ";
  531. //// }
  532. //// if (strpageindex.Trim() != "")
  533. //// {
  534. //// pageindex = Convert.ToInt32(strpageindex);
  535. //// }
  536. //// if (strpagesize.Trim() != "")
  537. //// {
  538. //// pagesize = Convert.ToInt32(strpagesize);
  539. //// }
  540. //// int recordCount = 0;
  541. //// dt = BLL.PagerBLL.GetListPager(
  542. //// "T_SMS_SentSMS",
  543. //// "SMSID",
  544. //// "*",
  545. //// sql,
  546. //// "ORDER BY SMSID desc",
  547. //// pagesize,
  548. //// pageindex,
  549. //// true,
  550. //// out recordCount);
  551. //// var obj = new
  552. //// {
  553. //// state = "success",
  554. //// message = "成功",
  555. //// rows = dt,
  556. //// total = recordCount
  557. //// };
  558. //// res = Content(obj.ToJson()); ;
  559. //// return res;
  560. //// }
  561. //// /// <summary>
  562. //// /// 新增短信
  563. //// /// </summary>
  564. //// /// <returns></returns>
  565. //// public ActionResult AddSend(string id,string taskid,string tel,string cont)
  566. //// {
  567. //// ActionResult res = NoToken("未知错误,请重新登录");
  568. //// Model.T_SMS_SentSMS dModel = new Model.T_SMS_SentSMS();
  569. //// if (id != "")
  570. //// {
  571. //// int sid = Int32.Parse(id);
  572. //// dModel = new BLL.T_SMS_SentSMS().GetModel(sid);
  573. //// dModel.TelNum = tel.Trim();
  574. //// dModel.Content = cont;
  575. //// if (new BLL.T_SMS_SentSMS().Update(dModel))
  576. //// {
  577. //// res = Success("修改成功");
  578. //// }
  579. //// else
  580. //// {
  581. //// res = Success("修改失败");
  582. //// }
  583. //// }
  584. //// else
  585. //// {
  586. //// dModel.TaskID = Int32.Parse(taskid);
  587. //// dModel.TelNum = tel.Trim();
  588. //// dModel.Content = cont;
  589. //// dModel.State = 0;
  590. //// dModel.F_CreateDate = DateTime.Now;
  591. //// int b = new BLL.T_SMS_SentSMS().Add(dModel);
  592. //// if (b > 0)
  593. //// {
  594. //// res = Success("添加成功");
  595. //// }
  596. //// else
  597. //// {
  598. //// res = Success("添加失败");
  599. //// }
  600. //// }
  601. //// return res;
  602. //// }
  603. //// /// <summary>
  604. //// /// 删除短信
  605. //// /// </summary>
  606. //// /// <param name="ids"></param>
  607. //// /// <returns></returns>
  608. //// public ActionResult DelSend(string[] ids)
  609. //// {
  610. //// ActionResult res = NoToken("未知错误,请重新登录");
  611. //// if (ids != null && ids.Length > 0)
  612. //// {
  613. //// string idd = " ";
  614. //// foreach (string str in ids)
  615. //// {
  616. //// idd += str + ",";
  617. //// }
  618. //// if (new BLL.T_SMS_SentSMS().DeleteList(idd.TrimEnd(',')))
  619. //// {
  620. //// res = Success("删除成功");
  621. //// }
  622. //// else
  623. //// {
  624. //// res = Error("删除失败");
  625. //// }
  626. //// }
  627. //// else
  628. //// {
  629. //// res = Error("请选择要删除的短信");
  630. //// }
  631. //// return res;
  632. //// }
  633. //// /// <summary>
  634. //// /// 导入短信
  635. //// /// </summary>
  636. //// /// <returns></returns>
  637. //// public ActionResult ImportSend()
  638. //// {
  639. //// ActionResult res = NoToken("未知错误,请重新登录");
  640. //// if (Request.IsAuthenticated)
  641. //// {
  642. //// int userId = CurrentUser.UserData.F_UserId;
  643. //// if (userId != 0)
  644. //// {
  645. //// Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  646. //// if (userModel != null)
  647. //// {
  648. //// HttpPostedFile _upfile = RequestString.GetFile("upFile");
  649. //// int taskid = RequestString.GetInt("taskid", 0);
  650. //// int headrow = 1;
  651. //// NPOIHelper np = new NPOIHelper();
  652. //// DataTable dt = np.ExcelToTable(_upfile, headrow);
  653. //// string msg = string.Empty;
  654. //// foreach (DataRow dr in dt.Rows)
  655. //// {
  656. //// headrow = headrow + 1;
  657. //// if (dr[0].ToString() != "" && dr[1].ToString() != "")
  658. //// {
  659. //// Model.T_SMS_SentSMS dModel = new Model.T_SMS_SentSMS();
  660. //// dModel.TaskID = taskid;
  661. //// dModel.TelNum = dr[0].ToString();
  662. //// dModel.Content = dr[1].ToString();
  663. //// dModel.State = 0;
  664. //// dModel.F_UserID = userModel.F_UserId;
  665. //// dModel.F_Name = userModel.F_UserName;
  666. //// dModel.F_CreateDate = DateTime.Now;
  667. //// if (new BLL.T_SMS_SentSMS().Add(dModel) > 0)
  668. //// {
  669. //// msg = msg + "第" + headrow + "行,导入失败<br>";
  670. //// }
  671. //// }
  672. //// else
  673. //// {
  674. //// msg = msg + "第"+ headrow+"行,手机号或者内容为空,未导入<br>";
  675. //// }
  676. //// }
  677. //// if (string.IsNullOrEmpty(msg))
  678. //// {
  679. //// res = Error(msg);
  680. //// }
  681. //// }
  682. //// }
  683. //// }
  684. //// return res;
  685. //// }
  686. //// #endregion
  687. //// #region 短信服务
  688. //// /// <summary>
  689. //// /// 获取发送短信列表
  690. //// /// </summary>
  691. //// /// <returns></returns>
  692. //// public ActionResult GetSendTaskListByJob(string state, string count)
  693. //// {
  694. //// ActionResult res = NoToken("未知错误,请重新登录");
  695. //// DataTable dt = new DataTable();
  696. //// string str = "";
  697. //// if (!string.IsNullOrEmpty(count))
  698. //// {
  699. //// int ct = Int32.Parse(count);
  700. //// str = "top " + ct;
  701. //// }
  702. //// 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];
  703. //// res = Success("成功", dt);
  704. //// return res;
  705. //// }
  706. //// /// <summary>
  707. //// /// 获取发送短信列表
  708. //// /// </summary>
  709. //// /// <returns></returns>
  710. //// public ActionResult GetSendListByJob(string taskid, string count)
  711. //// {
  712. //// ActionResult res = NoToken("未知错误,请重新登录");
  713. //// DataTable dt = new DataTable();
  714. //// string str = "";
  715. //// if (!string.IsNullOrEmpty(count))
  716. //// {
  717. //// int ct = Int32.Parse(count);
  718. //// str = "top " + ct;
  719. //// }
  720. //// //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];
  721. //// dt = DB.DbHelperSQL.Query(" select " + str + " * from T_SMS_SentSMS where TaskID='" + taskid + "' and isnull(State,0)='0' order by F_CreateDate ").Tables[0];
  722. //// res = Success("成功", dt);
  723. //// return res;
  724. //// }
  725. //// /// <summary>
  726. //// /// 执行发送短信
  727. //// /// </summary>
  728. //// /// <returns></returns>
  729. //// public ActionResult ExecSMSByJob(string taskid, string count)
  730. //// {
  731. //// ActionResult res = NoToken("未知错误,请重新登录");
  732. //// DataTable dt = new DataTable();
  733. //// string tels = string.Empty;
  734. //// string errtels = string.Empty;
  735. //// string isdel = string.Empty;
  736. //// string str = string.Empty;
  737. //// if (!string.IsNullOrEmpty(count))
  738. //// {
  739. //// int ct = Int32.Parse(count);
  740. //// str = "top " + ct;
  741. //// }
  742. //// var task = new BLL.T_SMS_SendSMSTask().GetModel(Int32.Parse(taskid));
  743. //// if (task != null)
  744. //// {
  745. //// bool bl = true;
  746. //// DateTime dte = DateTime.Now;
  747. //// if (task.StartTime != null)
  748. //// {
  749. //// bl = dte >= task.StartTime.Value;
  750. //// }
  751. //// if (bl && task.EndTime != null)
  752. //// {
  753. //// bl = dte <= task.EndTime.Value;
  754. //// }
  755. //// if (bl)
  756. //// {
  757. //// //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];
  758. //// 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];
  759. //// foreach (DataRow dr in dt.Rows)
  760. //// {
  761. //// string err = SendSMS(dr["TelNum"].ToString(), dr["Content"].ToString(), task.SignName, task.TempCode);
  762. //// if (err == "")
  763. //// {
  764. //// UpdateSendState(dr["SMSID"].ToString());
  765. //// if (string.IsNullOrEmpty(tels))
  766. //// {
  767. //// tels = dr["TelNum"].ToString();
  768. //// }
  769. //// else
  770. //// {
  771. //// tels = tels + "," + dr["TelNum"].ToString();
  772. //// }
  773. //// }
  774. //// else
  775. //// {
  776. //// if (string.IsNullOrEmpty(tels))
  777. //// {
  778. //// errtels = dr["TelNum"].ToString();
  779. //// }
  780. //// else
  781. //// {
  782. //// errtels = errtels + "," + dr["TelNum"].ToString();
  783. //// }
  784. //// }
  785. //// }
  786. //// isdel = "0";
  787. //// }
  788. //// else
  789. //// {
  790. //// isdel = "1";
  791. //// }
  792. //// }
  793. //// else
  794. //// {
  795. //// isdel = "1";
  796. //// }
  797. //// res = Success("成功", new { suc = tels, err = errtels, isdel = isdel });
  798. //// return res;
  799. //// }
  800. //// /// <summary>
  801. //// /// 根据结束时间结束任务
  802. //// /// </summary>
  803. //// /// <returns></returns>
  804. //// public ActionResult EndSMSTask()
  805. //// {
  806. //// ActionResult res = NoToken("未知错误,请重新登录");
  807. //// string str = string.Empty;
  808. //// string strerr = string.Empty;
  809. //// BLL.T_SMS_SendSMSTask bll = new BLL.T_SMS_SendSMSTask();
  810. //// var list = bll.GetModelList(" isnull(State,0)=1 ");
  811. //// foreach (var l in list)
  812. //// {
  813. //// if (l.EndTime <= DateTime.Now)
  814. //// {
  815. //// l.State = 9;
  816. //// if (bll.Update(l))
  817. //// {
  818. //// if (string.IsNullOrEmpty(str))
  819. //// {
  820. //// str = l.SMSID.ToString();
  821. //// }
  822. //// else
  823. //// {
  824. //// str = str + "," + l.SMSID.ToString();
  825. //// }
  826. //// }
  827. //// else
  828. //// {
  829. //// if (string.IsNullOrEmpty(strerr))
  830. //// {
  831. //// strerr = l.SMSID.ToString();
  832. //// }
  833. //// else
  834. //// {
  835. //// strerr = strerr + "," + l.SMSID.ToString();
  836. //// }
  837. //// }
  838. //// }
  839. //// }
  840. //// res = Success("成功", new { suc = str, err = strerr});
  841. //// return res;
  842. //// }
  843. //// /// <summary>
  844. //// /// 短信服务停止后重置正在执行的任务
  845. //// /// </summary>
  846. //// /// <returns></returns>
  847. //// public ActionResult ResetSMSTask()
  848. //// {
  849. //// ActionResult res = NoToken("未知错误,请重新登录");
  850. //// string str = string.Empty;
  851. //// string strerr = string.Empty;
  852. //// BLL.T_SMS_SendSMSTask bll = new BLL.T_SMS_SendSMSTask();
  853. //// var list = bll.GetModelList(" isnull(State,0)=1 ");
  854. //// foreach (var l in list)
  855. //// {
  856. //// l.State = 0;
  857. //// if (bll.Update(l))
  858. //// {
  859. //// if (string.IsNullOrEmpty(str))
  860. //// {
  861. //// str = l.SMSID.ToString();
  862. //// }
  863. //// else
  864. //// {
  865. //// str = str + "," + l.SMSID.ToString();
  866. //// }
  867. //// }
  868. //// else
  869. //// {
  870. //// if (string.IsNullOrEmpty(strerr))
  871. //// {
  872. //// strerr = l.SMSID.ToString();
  873. //// }
  874. //// else
  875. //// {
  876. //// strerr = strerr + "," + l.SMSID.ToString();
  877. //// }
  878. //// }
  879. //// }
  880. //// res = Success("成功", new { suc = str, err = strerr });
  881. //// return res;
  882. //// }
  883. //// /// <summary>
  884. //// /// 更新短信发送状态
  885. //// /// </summary>
  886. //// /// <returns></returns>
  887. //// public ActionResult UpdateSendTaskState(string id, string state)
  888. //// {
  889. //// ActionResult res = NoToken("未知错误,请重新登录");
  890. //// Model.T_SMS_SendSMSTask dModel = new Model.T_SMS_SendSMSTask();
  891. //// if (id != "")
  892. //// {
  893. //// int sid = Int32.Parse(id);
  894. //// dModel = new BLL.T_SMS_SendSMSTask().GetModel(sid);
  895. //// if (dModel != null)
  896. //// {
  897. //// dModel.State = Int32.Parse(state);
  898. //// if (new BLL.T_SMS_SendSMSTask().Update(dModel))
  899. //// {
  900. //// res = Success("修改成功");
  901. //// }
  902. //// else
  903. //// {
  904. //// res = Success("修改失败");
  905. //// }
  906. //// }
  907. //// }
  908. //// return res;
  909. //// }
  910. //// /// <summary>
  911. //// /// 更新短信发送状态
  912. //// /// </summary>
  913. //// /// <returns></returns>
  914. //// public ActionResult UpdateSendState(string id)
  915. //// {
  916. //// ActionResult res = NoToken("未知错误,请重新登录");
  917. //// Model.T_SMS_SentSMS dModel = new Model.T_SMS_SentSMS();
  918. //// if (id != "")
  919. //// {
  920. //// int sid = Int32.Parse(id);
  921. //// dModel = new BLL.T_SMS_SentSMS().GetModel(sid);
  922. //// if (dModel != null && dModel.State == 0)
  923. //// {
  924. //// dModel.State = 1;
  925. //// dModel.SendTime = DateTime.Now;
  926. //// if (new BLL.T_SMS_SentSMS().Update(dModel))
  927. //// {
  928. //// res = Success("修改成功");
  929. //// }
  930. //// else
  931. //// {
  932. //// res = Success("修改失败");
  933. //// }
  934. //// }
  935. //// }
  936. //// return res;
  937. //// }
  938. //// #endregion
  939. //// #region 发送短信接口
  940. //// /// <summary>
  941. //// /// 发送短信接口
  942. //// /// </summary>
  943. //// /// <returns></returns>
  944. //// public ActionResult SentSMS()
  945. //// {
  946. //// //调用示例--/sms/sendsms?tel=15512345678,15812341234&cont={"name":"张三","time":"11:00"}&signname=活动验证&tempcode=SMS_40865007
  947. //// ActionResult res = NoToken("未知错误,请重新登录");
  948. //// string signname = HttpUtility.UrlDecode(RequestString.GetQueryString("signname"));//"活动验证";
  949. //// string tempcode = HttpUtility.UrlDecode(RequestString.GetQueryString("tempcode"));//"SMS_40865007";
  950. //// string tel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));//多个用 , 隔开
  951. //// string cont = HttpUtility.UrlDecode(RequestString.GetQueryString("cont"));
  952. //// string err = SendSMS(tel, cont, signname, tempcode);
  953. //// if (err == "")
  954. //// {
  955. //// res = Success("成功");
  956. //// }
  957. //// else
  958. //// {
  959. //// res = Error(err);
  960. //// }
  961. //// return res;
  962. //// }
  963. //// /// <summary>
  964. //// /// 发送短信
  965. //// /// </summary>
  966. //// /// <param name="tel"></param>
  967. //// /// <param name="cont"></param>
  968. //// /// <param name="signname"></param>
  969. //// /// <param name="tempcode"></param>
  970. //// /// <returns></returns>
  971. //// public string SendSMS(string tel, string cont, string signname, string tempcode)
  972. //// {
  973. //// string res = string.Empty;
  974. //// string url = ConfigurationManager.AppSettings["url"];
  975. //// string key = ConfigurationManager.AppSettings["key"];
  976. //// string secret = ConfigurationManager.AppSettings["secret"];
  977. //// try
  978. //// {
  979. //// ITopClient client = new DefaultTopClient(url, key, secret);
  980. //// AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
  981. //// req.Extend = "123456";//公共回传参数
  982. //// req.SmsType = "normal";//短信类型,传入值请填写normal
  983. //// req.SmsFreeSignName = signname;//签名
  984. //// req.SmsParam = cont; //短信模参数示例: "{\"name\":\"张三\",\"time\":\"11:00\"}";
  985. //// req.RecNum = tel; //短信接收号码
  986. //// req.SmsTemplateCode = tempcode;//短信模板ID
  987. //// AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req);
  988. //// if (!rsp.IsError)
  989. //// {
  990. //// if (!rsp.Result.Success)
  991. //// {
  992. //// res = rsp.Result.Msg;
  993. //// }
  994. //// }
  995. //// else
  996. //// {
  997. //// if (!string.IsNullOrEmpty(rsp.SubErrMsg))
  998. //// {
  999. //// res = rsp.SubErrMsg;
  1000. //// }
  1001. //// else
  1002. //// {
  1003. //// res = rsp.ErrMsg;
  1004. //// }
  1005. //// }
  1006. //// }
  1007. //// catch
  1008. //// {
  1009. //// res = "接口异常!";
  1010. //// }
  1011. //// return res;
  1012. //// }
  1013. #endregion
  1014. }
  1015. }