No Description

SMSZXZBController.cs 35KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  1. using CallCenter.Utility;
  2. using CallCenterApi.Common;
  3. using CallCenterApi.DB;
  4. using CallCenterApi.Interface.Controllers.Base;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Configuration;
  9. using System.Data;
  10. using System.Linq;
  11. using System.Web;
  12. using System.Web.Mvc;
  13. namespace CallCenterApi.Interface.Controllers
  14. {
  15. public class SMSZXZBController : BaseController
  16. {
  17. #region 接收短信
  18. /// <summary>
  19. /// 获取接收短信列表
  20. /// </summary>
  21. /// <returns></returns>
  22. public ActionResult GetRecvList()
  23. {
  24. ActionResult res = NoToken("未知错误,请重新登录");
  25. string sql = "";
  26. DataTable dt = new DataTable();
  27. string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  28. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  29. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  30. string strpageindex = RequestString.GetQueryString("page");
  31. int pageindex = 1;
  32. string strpagesize = RequestString.GetQueryString("pagesize");
  33. int pagesize = 10;
  34. if (strtel.Trim() != "" && strtel != "undefined")
  35. {
  36. sql += " and Telephone like '%" + strtel.Trim() + "%' ";
  37. }
  38. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  39. {
  40. sql += " and CreateDate >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
  41. }
  42. if (strendtime.Trim() != "" && strendtime != "undefined")
  43. {
  44. sql += " and CreateDate <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
  45. }
  46. if (strpageindex.Trim() != "")
  47. {
  48. pageindex = Convert.ToInt32(strpageindex);
  49. }
  50. if (strpagesize.Trim() != "")
  51. {
  52. pagesize = Convert.ToInt32(strpagesize);
  53. }
  54. int recordCount = 0;
  55. dt = BLL.PagerBLL.GetListPager(
  56. "T_SMS_Receive",
  57. "T_SMS_Receive.ID",
  58. "*",
  59. sql,
  60. "ORDER BY T_SMS_Receive.ID desc",
  61. pagesize,
  62. pageindex,
  63. true,
  64. out recordCount);
  65. var obj = new
  66. {
  67. state = "success",
  68. message = "成功",
  69. rows = dt,
  70. total = recordCount
  71. };
  72. res = Content(obj.ToJson());
  73. return res;
  74. }
  75. /// <summary>
  76. /// 新增接收短信
  77. /// </summary>
  78. /// <returns></returns>
  79. public ActionResult AddRecv()
  80. {
  81. ActionResult res = NoToken("未知错误,请重新登录");
  82. string tel = HttpUtility.UrlDecode(RequestString.GetFormString("sender"));
  83. string cont = HttpUtility.UrlDecode(RequestString.GetFormString("content"));
  84. string rec = HttpUtility.UrlDecode(RequestString.GetFormString("receiver"));
  85. string time = HttpUtility.UrlDecode(RequestString.GetFormString("revceivtime"));
  86. Model.T_SMS_Receive dModel = new Model.T_SMS_Receive();
  87. dModel.Telephone = tel.Trim();
  88. dModel.Detail = cont.Trim();
  89. dModel.State = 0;
  90. //dModel.CreateDate = DateTime.Now;
  91. dModel.CreateDate = DateTime.Parse(time);
  92. int b = new BLL.T_SMS_Receive().Add(dModel);
  93. if (b > 0)
  94. {
  95. res = Success("添加成功");
  96. }
  97. else
  98. {
  99. res = Success("添加失败");
  100. }
  101. return res;
  102. }
  103. /// <summary>
  104. /// 删除接收短信
  105. /// </summary>
  106. /// <param name="ids"></param>
  107. /// <returns></returns>
  108. public ActionResult DelRecv(string[] ids)
  109. {
  110. ActionResult res = NoToken("未知错误,请重新登录");
  111. if (Request.IsAuthenticated)
  112. {
  113. int userId = CurrentUser.UserData.F_UserId;
  114. if (userId != 0)
  115. {
  116. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  117. if (ua != null)
  118. {
  119. if (ids != null && ids.Length > 0)
  120. {
  121. string idd = " ";
  122. foreach (string str in ids)
  123. {
  124. idd += str + ",";
  125. }
  126. string sql = "delete T_SMS_Receive where ID in(" + idd.TrimEnd(',') + ")";
  127. if (!string.IsNullOrEmpty(idd.Trim()))
  128. {
  129. if (DbHelperSQL.ExecuteSql(sql) > 0)
  130. {
  131. res = Success("删除成功");
  132. }
  133. else
  134. {
  135. res = Error("删除失败");
  136. }
  137. }
  138. else
  139. {
  140. res = Error("请选择记录");
  141. }
  142. }
  143. else
  144. {
  145. res = Error("获取参数失败");
  146. }
  147. }
  148. }
  149. }
  150. return res;
  151. }
  152. /// <summary>
  153. /// 更新接收短信状态
  154. /// </summary>
  155. /// <param name="ids"></param>
  156. /// <returns></returns>
  157. public ActionResult UpdateRecvState(string[] ids,string state)
  158. {
  159. ActionResult res = NoToken("未知错误,请重新登录");
  160. if (Request.IsAuthenticated)
  161. {
  162. int userId = CurrentUser.UserData.F_UserId;
  163. if (userId != 0)
  164. {
  165. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  166. if (ua != null)
  167. {
  168. int n = -1;
  169. if (ids != null && ids.Length > 0 && Int32.TryParse(state,out n))
  170. {
  171. string idd = " ";
  172. foreach (string str in ids)
  173. {
  174. idd += str + ",";
  175. }
  176. string sql = "update T_SMS_Receive set State='"+ n + "' where ID in(" + idd.TrimEnd(',') + ")";
  177. if (!string.IsNullOrEmpty(idd.Trim()))
  178. {
  179. if (DbHelperSQL.ExecuteSql(sql) > 0)
  180. {
  181. res = Success("更新成功");
  182. }
  183. else
  184. {
  185. res = Error("更新失败");
  186. }
  187. }
  188. else
  189. {
  190. res = Error("请选择记录");
  191. }
  192. }
  193. else
  194. {
  195. res = Error("获取参数失败");
  196. }
  197. }
  198. }
  199. }
  200. return res;
  201. }
  202. #endregion
  203. #region 发送短信
  204. /// <summary>
  205. /// 获取发送短信列表
  206. /// </summary>
  207. /// <returns></returns>
  208. public ActionResult GetSendList()
  209. {
  210. ActionResult res = NoToken("未知错误,请重新登录");
  211. string sql = "";
  212. DataTable dt = new DataTable();
  213. int type = 0;
  214. string strtype = HttpUtility.UrlDecode(RequestString.GetQueryString("type"));
  215. string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
  216. string strsendway = HttpUtility.UrlDecode(RequestString.GetQueryString("sendway"));
  217. string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
  218. string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
  219. string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
  220. string strbno = HttpUtility.UrlDecode(RequestString.GetQueryString("bno"));
  221. string strpageindex = RequestString.GetQueryString("page");
  222. int pageindex = 1;
  223. string strpagesize = RequestString.GetQueryString("pagesize");
  224. int pagesize = 10;
  225. if (strtype != "" && strtype != "undefined")
  226. {
  227. type = Convert.ToInt32(strtype);
  228. sql += " and Type= '" + type + "' ";
  229. }
  230. if (strsendway != "" && strsendway != "undefined")
  231. {
  232. sql += " and SendWay= '" + Convert.ToInt32(strsendway) + "' ";
  233. }
  234. if (strtel.Trim() != "" && strtel != "undefined")
  235. {
  236. sql += " and Telephone like '%" + strtel.Trim() + "%' ";
  237. }
  238. if (strstarttime.Trim() != "" && strstarttime != "undefined")
  239. {
  240. sql += " and CreateDate >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
  241. }
  242. if (strendtime.Trim() != "" && strendtime != "undefined")
  243. {
  244. sql += " and CreateDate <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
  245. }
  246. if (strstate.Trim() != "" && strstate != "undefined")
  247. {
  248. sql += " and IsSend= '" + strstate.Trim() + "' ";
  249. }
  250. if (strbno.Trim() != "" && strbno != "undefined")
  251. {
  252. sql += " and BatchNo like '%" + strbno.Trim() + "%' ";
  253. }
  254. if (strpageindex.Trim() != "")
  255. {
  256. pageindex = Convert.ToInt32(strpageindex);
  257. }
  258. if (strpagesize.Trim() != "")
  259. {
  260. pagesize = Convert.ToInt32(strpagesize);
  261. }
  262. int recordCount = 0;
  263. dt = BLL.PagerBLL.GetListPager(
  264. "T_SMS_List",
  265. "T_SMS_List.ID",
  266. "*,dbo.GetDictionaryName(Type) as TypeName",
  267. sql,
  268. "ORDER BY T_SMS_List.ID desc",
  269. pagesize,
  270. pageindex,
  271. true,
  272. out recordCount);
  273. var obj = new
  274. {
  275. state = "success",
  276. message = "成功",
  277. rows = dt,
  278. total = recordCount
  279. };
  280. res = Content(obj.ToJson());
  281. return res;
  282. }
  283. /// <summary>
  284. /// 新增短信
  285. /// </summary>
  286. /// <returns></returns>
  287. public ActionResult AddSend()
  288. {
  289. ActionResult res = NoToken("未知错误,请重新登录");
  290. if (Request.IsAuthenticated)
  291. {
  292. int userId = CurrentUser.UserData.F_UserId;
  293. if (userId != 0)
  294. {
  295. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  296. if (ua != null)
  297. {
  298. int id= RequestString.GetFormInt("id",0);
  299. int type = RequestString.GetFormInt("type", 0);
  300. int sendway = RequestString.GetFormInt("sendway", 0);
  301. int mbid = RequestString.GetFormInt("mbid", 0);
  302. DateTime? dssj = null;
  303. string time = HttpUtility.UrlDecode(RequestString.GetFormString("dssj"));
  304. string tel = HttpUtility.UrlDecode(RequestString.GetFormString("tel"));
  305. string cont=HttpUtility.UrlDecode(RequestString.GetFormString("cont"));
  306. if (!string.IsNullOrEmpty(time))
  307. {
  308. dssj = DateTime.Parse(time);
  309. }
  310. Model.T_SMS_List dModel = new Model.T_SMS_List();
  311. if (id != 0)
  312. {
  313. dModel = new BLL.T_SMS_List().GetModel(id);
  314. dModel.Type = type;
  315. dModel.SendWay = sendway;
  316. dModel.DSSendTime = dssj;
  317. dModel.Telephone = tel;
  318. dModel.Detail = cont;
  319. dModel.MBID = mbid;
  320. if (new BLL.T_SMS_List().Update(dModel))
  321. {
  322. res = Success("修改成功");
  323. }
  324. else
  325. {
  326. res = Success("修改失败");
  327. }
  328. }
  329. else
  330. {
  331. string bno = DateTime.Now.ToString("yyyyMMddHHmmssfff");
  332. string[] tels = tel.Split(',');
  333. foreach (string tl in tels)
  334. {
  335. dModel.BatchNo = bno;
  336. dModel.Type = type;
  337. dModel.SendWay = sendway;
  338. dModel.DSSendTime = dssj;
  339. dModel.Telephone = tl;
  340. dModel.Detail = cont;
  341. dModel.MBID = mbid;
  342. dModel.IsSend = 0;
  343. dModel.CreateDate = DateTime.Now;
  344. dModel.MID = ua.F_UserCode;
  345. dModel.MName = ua.F_UserName;
  346. int b = new BLL.T_SMS_List().Add(dModel);
  347. //if (b > 0)
  348. //{
  349. // res = Success("添加成功");
  350. //}
  351. //else
  352. //{
  353. // res = Success("添加失败");
  354. //}
  355. }
  356. res = Success("添加成功");
  357. }
  358. }
  359. }
  360. }
  361. return res;
  362. }
  363. /// <summary>
  364. /// 发送短信
  365. /// </summary>
  366. /// <returns></returns>
  367. public ActionResult SendSMSByID()
  368. {
  369. ActionResult res = NoToken("未知错误,请重新登录");
  370. int ID = RequestString.GetInt("ID", 0);
  371. if (ID != 0)
  372. {
  373. Model.T_SMS_List model = new BLL.T_SMS_List().GetModel(ID);
  374. if (model != null)
  375. {
  376. string msg = SendSMS(model.Telephone, model.Detail);
  377. if (string.IsNullOrEmpty(msg))
  378. {
  379. res = Success("成功");
  380. }
  381. else
  382. {
  383. Error("失败,错误:" + msg);
  384. }
  385. }
  386. }
  387. return res;
  388. }
  389. /// <summary>
  390. /// 删除短信
  391. /// </summary>
  392. /// <param name="ids"></param>
  393. /// <returns></returns>
  394. public ActionResult DelSend(string[] ids)
  395. {
  396. ActionResult res = NoToken("未知错误,请重新登录");
  397. if (Request.IsAuthenticated)
  398. {
  399. int userId = CurrentUser.UserData.F_UserId;
  400. if (userId != 0)
  401. {
  402. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  403. if (ua != null)
  404. {
  405. if (ids != null && ids.Length > 0)
  406. {
  407. string idd = " ";
  408. foreach (string str in ids)
  409. {
  410. idd += str + ",";
  411. }
  412. string sql = "delete T_SMS_List where ID in(" + idd.TrimEnd(',') + ")";
  413. if (!string.IsNullOrEmpty(idd.Trim()))
  414. {
  415. if (DbHelperSQL.ExecuteSql(sql) > 0)
  416. {
  417. res = Success("删除成功");
  418. }
  419. else
  420. {
  421. res = Error("删除失败");
  422. }
  423. }
  424. else
  425. {
  426. res = Error("请选择记录");
  427. }
  428. }
  429. else
  430. {
  431. res = Error("获取参数失败");
  432. }
  433. }
  434. }
  435. }
  436. return res;
  437. }
  438. /// <summary>
  439. /// 通过批次号删除记录
  440. /// </summary>
  441. /// <param name="bathno"></param>
  442. /// <returns></returns>
  443. public ActionResult DelSendByBathNo()
  444. {
  445. ActionResult res = NoToken("未知错误,请重新登录");
  446. if (Request.IsAuthenticated)
  447. {
  448. int userId = CurrentUser.UserData.F_UserId;
  449. if (userId != 0)
  450. {
  451. Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
  452. if (ua != null)
  453. {
  454. string strbno = HttpUtility.UrlDecode(RequestString.GetQueryString("bno"));
  455. if (!string.IsNullOrEmpty(strbno))
  456. {
  457. string sql = "delete T_SMS_List where BathNo ='" + strbno + "'";
  458. if (DbHelperSQL.ExecuteSql(sql) > 0)
  459. {
  460. res = Success("删除成功");
  461. }
  462. else
  463. {
  464. res = Error("删除失败");
  465. }
  466. }
  467. else
  468. {
  469. res = Error("获取参数失败");
  470. }
  471. }
  472. }
  473. }
  474. return res;
  475. }
  476. /// <summary>
  477. /// 导入短信
  478. /// </summary>
  479. /// <returns></returns>
  480. public ActionResult ImportSend()
  481. {
  482. ActionResult res = NoToken("未知错误,请重新登录");
  483. if (Request.IsAuthenticated)
  484. {
  485. int userId = CurrentUser.UserData.F_UserId;
  486. if (userId != 0)
  487. {
  488. Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
  489. if (userModel != null)
  490. {
  491. HttpPostedFile _upfile = RequestString.GetFile("upFile");
  492. int headrow = 1;
  493. NPOIHelper np = new NPOIHelper();
  494. DataTable dt = np.ExcelToTable(_upfile, headrow);
  495. string bno = DateTime.Now.ToString("yyyyMMddHHmmssfff");
  496. string msg = string.Empty;
  497. string tels = string.Empty;
  498. foreach (DataRow dr in dt.Rows)
  499. {
  500. headrow = headrow + 1;
  501. //if (dr[0].ToString() != "" && dr[1].ToString() != "")
  502. //{
  503. // Model.T_SMS_List dModel = new Model.T_SMS_List();
  504. // dModel.BatchNo = bno;
  505. // dModel.Telephone = dr[0].ToString();
  506. // dModel.Detail = dr[1].ToString();
  507. // dModel.IsSend = 0;
  508. // dModel.SendWay = 1;
  509. // dModel.MID = userModel.F_UserCode;
  510. // dModel.MName = userModel.F_UserName;
  511. // dModel.CreateDate = DateTime.Now;
  512. // if (new BLL.T_SMS_List().Add(dModel) > 0)
  513. // {
  514. // msg = msg + "第" + headrow + "行,导入失败<br>";
  515. // }
  516. //}
  517. //else
  518. //{
  519. // msg = msg + "第" + headrow + "行,手机号或者内容为空,未导入<br>";
  520. //}
  521. if (dr[0].ToString() != "")
  522. {
  523. if (string.IsNullOrEmpty(tels))
  524. {
  525. tels = dr[0].ToString();
  526. }
  527. else
  528. {
  529. tels = tels + "," + dr[0].ToString();
  530. }
  531. }
  532. }
  533. res = Success("成功", tels);
  534. //if (string.IsNullOrEmpty(msg))
  535. //{
  536. // res = Error(msg);
  537. //}
  538. }
  539. }
  540. }
  541. return res;
  542. }
  543. #endregion
  544. #region 短信服务
  545. /// <summary>
  546. /// 获取发送短信列表
  547. /// </summary>
  548. /// <returns></returns>
  549. public ActionResult GetSendListByJob()
  550. {
  551. ActionResult res = NoToken("未知错误,请重新登录");
  552. DataTable dt = new DataTable();
  553. int ct = RequestString.GetInt("count", 0);
  554. string str = string.Empty;
  555. if (ct != 0)
  556. {
  557. str = " top " + ct;
  558. }
  559. dt = DB.DbHelperSQL.Query(" select " + str + " * from T_SMS_List where IsSend=0 and (SendWay=1 or (SendWay=2 and DSSendTime<=getdate() )) order by CreateDate asc ").Tables[0];
  560. res = Success("成功", dt);
  561. return res;
  562. }
  563. /// <summary>
  564. /// 更新短信发送状态
  565. /// </summary>
  566. /// <returns></returns>
  567. public ActionResult UpdateSendStateByJob()
  568. {
  569. ActionResult res = NoToken("未知错误,请重新登录");
  570. int id = RequestString.GetInt("id", 0);
  571. if (id != 0)
  572. {
  573. Model.T_SMS_List dModel = new BLL.T_SMS_List().GetModel(id);
  574. if (dModel != null && dModel.IsSend == 0)
  575. {
  576. dModel.IsSend = 1;
  577. dModel.SendTime = DateTime.Now;
  578. if (new BLL.T_SMS_List().Update(dModel))
  579. {
  580. res = Success("修改成功");
  581. }
  582. else
  583. {
  584. res = Success("修改失败");
  585. }
  586. }
  587. }
  588. return res;
  589. }
  590. /// <summary>
  591. /// 执行发送短信
  592. /// </summary>
  593. /// <returns></returns>
  594. public ActionResult ExecSendByJob()
  595. {
  596. ActionResult res = NoToken("未知错误,请重新登录");
  597. DataTable dt = new DataTable();
  598. string suc = string.Empty;
  599. string err = string.Empty;
  600. int ct = RequestString.GetInt("count", 0);
  601. string str = string.Empty;
  602. if (ct != 0)
  603. {
  604. str = " top " + ct;
  605. }
  606. dt = DB.DbHelperSQL.Query(" select " + str + " * from T_SMS_List where IsSend=0 and (SendWay=1 or (SendWay=2 and DSSendTime<=getdate() )) order by CreateDate asc ").Tables[0];
  607. foreach (DataRow dr in dt.Rows)
  608. {
  609. string msg = SendSMS(dr["Telephone"].ToString(), dr["Detail"].ToString());
  610. lock (this)
  611. {
  612. Model.T_SMS_List dModel = new BLL.T_SMS_List().GetModel(Int32.Parse(dr["ID"].ToString()));
  613. if (dModel != null && dModel.IsSend == 0)
  614. {
  615. if (string.IsNullOrEmpty(msg))
  616. {
  617. dModel.IsSend = 1;
  618. suc = suc + "," + dModel.Telephone;
  619. }
  620. else
  621. {
  622. dModel.IsSend = -1;
  623. err = err + "," + dModel.Telephone;
  624. }
  625. dModel.SendTime = DateTime.Now;
  626. new BLL.T_SMS_List().Update(dModel);
  627. }
  628. }
  629. }
  630. var obj = new
  631. {
  632. suc = string.IsNullOrEmpty(suc) ? "" : suc.TrimEnd(','),
  633. err = string.IsNullOrEmpty(err) ? "" : err.TrimEnd(',')
  634. };
  635. res = Success("成功", obj);
  636. return res;
  637. }
  638. #endregion
  639. #region 发送短信接口
  640. /// <summary>
  641. /// 发送短信接口
  642. /// </summary>
  643. /// <returns></returns>
  644. public string SendSMS(string tel, string cont)
  645. {
  646. string msg = string.Empty;
  647. try
  648. {
  649. var date = DateTime.Now;
  650. string url = Configs.GetValue("smsurl")+ "Send.aspx";
  651. string sign = Configs.GetValue("smssign") ;
  652. string username = Configs.GetValue("smsusername");
  653. string password = Configs.GetValue("smspassword");
  654. string content = HttpUtility.UrlEncode(System.Text.Encoding.GetEncoding("GB2312").GetBytes(cont + "【" + sign + "】"));
  655. string param = "username=" + username + "&password=" + CommonHelper.MD5(password+ date.ToString("yyyy-MM-dd HH:mm:ss"));
  656. param += "&mobiles=" + tel + "&content=" + content + "&f=1&timestamp="+ date.ToString("yyyy-MM-dd HH:mm:ss");
  657. string result = HttpMethods.HttpPost(url, param);
  658. //Hashtable res = new Hashtable();
  659. Dictionary<String, String> res = new Dictionary<string, string>();
  660. if (!string.IsNullOrEmpty(result))
  661. {
  662. string[] strs = result.Split('&');
  663. foreach (string str in strs)
  664. {
  665. string[] items = str.Split('=');
  666. res.Add(items[0], items[1]);
  667. }
  668. }
  669. if (res.Count > 0)
  670. {
  671. string suc = res["result"];
  672. string dec = System.Text.Encoding.GetEncoding("GB2312").GetString(HttpUtility.UrlDecodeToBytes(res["description"]));
  673. if (suc != "0")
  674. {
  675. msg = dec;
  676. }
  677. }
  678. }
  679. catch (Exception ex)
  680. {
  681. msg = ex.Message;
  682. }
  683. return msg;
  684. }
  685. /// <summary>
  686. /// 发送模板短信
  687. /// </summary>
  688. /// <param name="cont"></param>
  689. /// <param name="paras"></param>
  690. /// <returns></returns>
  691. public string SendSMSByTemplate(string cont, string paras)
  692. {
  693. string msg = string.Empty;
  694. try
  695. {
  696. var date = DateTime.Now;
  697. string url = Configs.GetValue("smsurl") + "SendVarSms.aspx";
  698. string sign = Configs.GetValue("smssign");
  699. string username = Configs.GetValue("smsusername");
  700. string password = Configs.GetValue("smspassword");
  701. string param = "username=" + username + "&password=" + password; //CommonHelper.MD5(password + date.ToString("yyyy-MM-dd HH:mm:ss"));
  702. param += "&content=" + cont + "【" + sign + "】" + "&params=" + paras;
  703. string result = HttpMethods.HttpPost(url, param);
  704. //Hashtable res = new Hashtable();
  705. Dictionary<String, String> res = new Dictionary<string, string>();
  706. if (!string.IsNullOrEmpty(result))
  707. {
  708. string[] strs = result.Split('&');
  709. foreach (string str in strs)
  710. {
  711. string[] items = str.Split('=');
  712. res.Add(items[0], items[1]);
  713. }
  714. }
  715. if (res.Count > 0)
  716. {
  717. string suc = res["result"];
  718. //string dec = System.Text.Encoding.GetEncoding("GB2312").GetString(HttpUtility.UrlDecodeToBytes(res["description"]));
  719. string dec = HttpUtility.UrlDecode(res["description"]);
  720. if (suc != "0")
  721. {
  722. msg = dec;
  723. }
  724. }
  725. }
  726. catch (Exception ex)
  727. {
  728. msg = ex.Message;
  729. }
  730. return msg;
  731. }
  732. /// <summary>
  733. /// 修改短信接口密码
  734. /// </summary>
  735. /// <param name="newpsd"></param>
  736. /// <returns></returns>
  737. public string UpdateSMSPassword(string newpsd)
  738. {
  739. string msg = string.Empty;
  740. try
  741. {
  742. var date = DateTime.Now;
  743. string url = Configs.GetValue("smsurl") + "SendVarSms.aspx";
  744. string sign = Configs.GetValue("smssign");
  745. string username = Configs.GetValue("smsusername");
  746. string password = Configs.GetValue("smspassword");
  747. string param = "username=" + username + "&password=" + password + "&newpwd=" + newpsd;
  748. string result = HttpMethods.HttpPost(url, param);
  749. Dictionary<String, String> res = new Dictionary<string, string>();
  750. if (!string.IsNullOrEmpty(result))
  751. {
  752. string[] strs = result.Split('&');
  753. foreach (string str in strs)
  754. {
  755. string[] items = str.Split('=');
  756. res.Add(items[0], items[1]);
  757. }
  758. }
  759. if (res.Count > 0)
  760. {
  761. string suc = res["result"];
  762. string dec = HttpUtility.UrlDecode(res["description"]);
  763. if (suc != "0")
  764. {
  765. msg = dec;
  766. }
  767. else
  768. {
  769. Configs.SetValue("smspassword", newpsd);
  770. }
  771. }
  772. }
  773. catch (Exception ex)
  774. {
  775. msg = ex.Message;
  776. }
  777. return msg;
  778. }
  779. /// <summary>
  780. /// 查询余额
  781. /// </summary>
  782. /// <returns></returns>
  783. public string QuerySMSBalance()
  784. {
  785. string msg = string.Empty;
  786. try
  787. {
  788. var date = DateTime.Now;
  789. string url = Configs.GetValue("smsurl") + "Query.aspx";
  790. string username = Configs.GetValue("smsusername");
  791. string password = Configs.GetValue("smspassword");
  792. string param = "username=" + username + "&password=" + password;
  793. string result = HttpMethods.HttpPost(url, param);
  794. Dictionary<String, String> res = new Dictionary<string, string>();
  795. if (!string.IsNullOrEmpty(result))
  796. {
  797. string[] strs = result.Split('&');
  798. foreach (string str in strs)
  799. {
  800. string[] items = str.Split('=');
  801. res.Add(items[0], items[1]);
  802. }
  803. }
  804. if (res.Count > 0)
  805. {
  806. string suc = res["result"];
  807. string dec = System.Text.Encoding.GetEncoding("GB2312").GetString(HttpUtility.UrlDecodeToBytes(res["description"]));
  808. if (suc != "0")
  809. {
  810. msg = dec;
  811. }
  812. }
  813. }
  814. catch (Exception ex)
  815. {
  816. msg = ex.Message;
  817. }
  818. return msg;
  819. }
  820. #endregion
  821. }
  822. }