Нет описания

SMSZXZBController.cs 32KB

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