| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921 |
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using CallCenterApi.Interface.Controllers.Base;
- using System.Data;
- using CallCenter.Utility;
- using System.Configuration;
- using Top.Api;
- using Top.Api.Request;
- using Top.Api.Response;
- using CallCenterApi.Common;
- namespace CallCenterApi.Interface.Controllers
- {
- public class SMSController : BaseController
- {
- #region 接收短信
- /// <summary>
- /// 获取接收短信列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetRecvList()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- string sql = "";
- DataTable dt = new DataTable();
-
- string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
- string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
- string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
- string strpageindex = RequestString.GetQueryString("page");
- int pageindex = 1;
- string strpagesize = RequestString.GetQueryString("pagesize");
- int pagesize = 10;
- if (strtel.Trim() != "" && strtel != "undefined")
- {
- sql += " and CallerNum= '" + strtel.Trim() + "' ";
- }
- if (strstarttime.Trim() != "" && strstarttime != "undefined")
- {
- sql += " and RecvTime >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
- }
- if (strendtime.Trim() != "" && strendtime != "undefined")
- {
- sql += " and RecvTime <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
- }
- if (strpageindex.Trim() != "")
- {
- pageindex = Convert.ToInt32(strpageindex);
- }
- if (strpagesize.Trim() != "")
- {
- pagesize = Convert.ToInt32(strpagesize);
- }
- int recordCount = 0;
- dt = BLL.PagerBLL.GetListPager(
- "T_SMS_RecvSMS",
- "SMSID",
- "*",
- sql,
- "ORDER BY SMSID desc",
- pagesize,
- pageindex,
- true,
- out recordCount);
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = dt,
- total = recordCount
- };
- res = Content(obj.ToJson());
-
- return res;
- }
- /// <summary>
- /// 新增接收短信
- /// </summary>
- /// <returns></returns>
- public ActionResult AddRecv(string tel,string cont)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
-
- Model.T_SMS_RecvSMS dModel = new Model.T_SMS_RecvSMS();
- dModel.CallerNum = tel.Trim();
- dModel.Content = cont.Trim();
- dModel.State = 0;
- dModel.RecvTime = DateTime.Now;
- dModel.F_CreateDate = DateTime.Now;
- int b = new BLL.T_SMS_RecvSMS().Add(dModel);
- if (b > 0)
- {
- res = Success("添加成功");
- }
- else
- {
- res = Success("添加失败");
- }
-
- return res;
- }
- /// <summary>
- /// 删除接收短信
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public ActionResult DelRecv(string[] ids)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
-
- if (ids != null && ids.Length > 0)
- {
- string idd = " ";
- foreach (string str in ids)
- {
- idd += str + ",";
- }
- if (new BLL.T_SMS_RecvSMS().DeleteList(idd.TrimEnd(',')))
- {
- res = Success("删除成功");
- }
- else
- {
- res = Error("删除失败");
- }
- }
- else
- {
- res = Error("请选择要删除的接收短信");
- }
-
- return res;
- }
- #endregion
- #region 发送短信
- /// <summary>
- /// 获取发送短信任务列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetSendTaskList()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- string sql = "";
- DataTable dt = new DataTable();
-
- string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
- string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
- string strpageindex = RequestString.GetQueryString("page");
- int pageindex = 1;
- string strpagesize = RequestString.GetQueryString("pagesize");
- int pagesize = 10;
- if (strstarttime.Trim() != "" && strstarttime != "undefined")
- {
- sql += " and F_CreateDate >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
- }
- if (strendtime.Trim() != "" && strendtime != "undefined")
- {
- sql += " and F_CreateDate <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
- }
- if (strpageindex.Trim() != "")
- {
- pageindex = Convert.ToInt32(strpageindex);
- }
- if (strpagesize.Trim() != "")
- {
- pagesize = Convert.ToInt32(strpagesize);
- }
- int recordCount = 0;
- dt = BLL.PagerBLL.GetListPager(
- "T_SMS_SendSMSTask",
- "SMSID",
- "*",
- sql,
- "ORDER BY SMSID desc",
- pagesize,
- pageindex,
- true,
- out recordCount);
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = dt,
- total = recordCount
- };
- res = Content(obj.ToJson()); ;
-
- return res;
- }
- /// <summary>
- /// 新增短信任务
- /// </summary>
- /// <returns></returns>
- public ActionResult AddSendTask()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
-
- string strid = HttpUtility.UrlDecode(RequestString.GetQueryString("id"));
- string strname = HttpUtility.UrlDecode(RequestString.GetQueryString("name"));
- string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
- string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
- string strstarttime1 = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime1"));
- string strendtime1 = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime1"));
- string strstarttime2 = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime2"));
- string strendtime2 = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime2"));
- string strsignname = HttpUtility.UrlDecode(RequestString.GetQueryString("signname"));
- string strtempcode = HttpUtility.UrlDecode(RequestString.GetQueryString("tempcode"));
- Model.T_SMS_SendSMSTask dModel = new Model.T_SMS_SendSMSTask();
- if (strid != "")
- {
- int id = Int32.Parse(strid);
- dModel = new BLL.T_SMS_SendSMSTask().GetModel(id);
- dModel.Name = strname.Trim();
- if (!string.IsNullOrEmpty(strstarttime))
- {
- dModel.StartTime = DateTime.Parse(strstarttime);
- }
- else
- {
- dModel.StartTime = null;
- }
- if (!string.IsNullOrEmpty(strendtime))
- {
- dModel.EndTime = DateTime.Parse(strendtime);
- }
- else
- {
- dModel.EndTime = null;
- }
- dModel.PeriodStartTime = strstarttime1;
- dModel.PeriodEndTime = strendtime1;
- dModel.PeriodStartTime1 = strstarttime2;
- dModel.PeriodEndTime1 = strendtime2;
- dModel.SignName = strsignname;
- dModel.TempCode = strtempcode;
- if (dModel.State == 1) { dModel.State = 0; }//短信服务
- if (new BLL.T_SMS_SendSMSTask().Update(dModel))
- {
- res = Success("修改成功");
- }
- else
- {
- res = Success("修改失败");
- }
- }
- else
- {
- dModel.Name = strname.Trim();
- if (!string.IsNullOrEmpty(strstarttime))
- {
- dModel.StartTime = DateTime.Parse(strstarttime);
- }
- if (!string.IsNullOrEmpty(strendtime))
- {
- dModel.EndTime = DateTime.Parse(strendtime);
- }
- dModel.PeriodStartTime = strstarttime1;
- dModel.PeriodEndTime = strendtime1;
- dModel.PeriodStartTime1 = strstarttime2;
- dModel.PeriodEndTime1 = strendtime2;
- dModel.SignName = strsignname;
- dModel.TempCode = strtempcode;
- dModel.State = 0;
- dModel.F_CreateDate = DateTime.Now;
- int b = new BLL.T_SMS_SendSMSTask().Add(dModel);
- if (b > 0)
- {
- res = Success("添加成功");
- }
- else
- {
- res = Success("添加失败");
- }
- }
-
- return res;
- }
- /// <summary>
- /// 删除短信任务
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public ActionResult DelSendTask(string[] ids)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
-
- if (ids != null && ids.Length > 0)
- {
- string idd = " ";
- foreach (string str in ids)
- {
- idd += str + ",";
- }
- if (new BLL.T_SMS_SendSMSTask().DeleteList(idd.TrimEnd(',')))
- {
- res = Success("删除成功");
- }
- else
- {
- res = Error("删除失败");
- }
- }
- else
- {
- res = Error("请选择要删除的短信任务");
- }
-
- return res;
- }
- /// <summary>
- /// 获取发送短信列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetSendList()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- string sql = "";
- DataTable dt = new DataTable();
-
- int taskid = 0;
- string strtaskid = HttpUtility.UrlDecode(RequestString.GetQueryString("id"));
- string strtel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));
- string strstarttime = HttpUtility.UrlDecode(RequestString.GetQueryString("starttime"));
- string strendtime = HttpUtility.UrlDecode(RequestString.GetQueryString("endtime"));
- string strstate = HttpUtility.UrlDecode(RequestString.GetQueryString("state"));
- string strpageindex = RequestString.GetQueryString("page");
- int pageindex = 1;
- string strpagesize = RequestString.GetQueryString("pagesize");
- int pagesize = 10;
- if (strtaskid != "" && strtaskid != "undefined")
- {
- taskid = Convert.ToInt32(strtaskid);
- }
- if (strtel.Trim() != "" && strtel != "undefined")
- {
- sql += " and TelNum= '" + strtel.Trim() + "' ";
- }
- if (strstarttime.Trim() != "" && strstarttime != "undefined")
- {
- sql += " and F_CreateDate >= '" + Convert.ToDateTime(strstarttime.Trim()) + "' ";
- }
- if (strendtime.Trim() != "" && strendtime != "undefined")
- {
- sql += " and F_CreateDate <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
- }
- if (strstate.Trim() != "" && strstate != "undefined")
- {
- sql += " and State= '" + strstate.Trim() + "' ";
- }
- if (strpageindex.Trim() != "")
- {
- pageindex = Convert.ToInt32(strpageindex);
- }
- if (strpagesize.Trim() != "")
- {
- pagesize = Convert.ToInt32(strpagesize);
- }
- int recordCount = 0;
- dt = BLL.PagerBLL.GetListPager(
- "T_SMS_SentSMS",
- "SMSID",
- "*",
- sql,
- "ORDER BY SMSID desc",
- pagesize,
- pageindex,
- true,
- out recordCount);
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = dt,
- total = recordCount
- };
- res = Content(obj.ToJson()); ;
-
- return res;
- }
- /// <summary>
- /// 新增短信
- /// </summary>
- /// <returns></returns>
- public ActionResult AddSend(string id,string taskid,string tel,string cont)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- Model.T_SMS_SentSMS dModel = new Model.T_SMS_SentSMS();
- if (id != "")
- {
- int sid = Int32.Parse(id);
- dModel = new BLL.T_SMS_SentSMS().GetModel(sid);
- dModel.TelNum = tel.Trim();
- dModel.Content = cont;
- if (new BLL.T_SMS_SentSMS().Update(dModel))
- {
- res = Success("修改成功");
- }
- else
- {
- res = Success("修改失败");
- }
- }
- else
- {
- dModel.TaskID = Int32.Parse(taskid);
- dModel.TelNum = tel.Trim();
- dModel.Content = cont;
- dModel.State = 0;
- dModel.F_CreateDate = DateTime.Now;
- int b = new BLL.T_SMS_SentSMS().Add(dModel);
- if (b > 0)
- {
- res = Success("添加成功");
- }
- else
- {
- res = Success("添加失败");
- }
- }
- return res;
- }
- /// <summary>
- /// 删除短信
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public ActionResult DelSend(string[] ids)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (ids != null && ids.Length > 0)
- {
- string idd = " ";
- foreach (string str in ids)
- {
- idd += str + ",";
- }
- if (new BLL.T_SMS_SentSMS().DeleteList(idd.TrimEnd(',')))
- {
- res = Success("删除成功");
- }
- else
- {
- res = Error("删除失败");
- }
- }
- else
- {
- res = Error("请选择要删除的短信");
- }
- return res;
- }
- /// <summary>
- /// 导入短信
- /// </summary>
- /// <returns></returns>
- public ActionResult ImportSend()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- if (Request.IsAuthenticated)
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- Model.T_Sys_UserAccount userModel = new BLL.T_Sys_UserAccount().GetModel(userId);
- if (userModel != null)
- {
- HttpPostedFile _upfile = RequestString.GetFile("upFile");
- int taskid = RequestString.GetInt("taskid", 0);
- int headrow = 1;
- NPOIHelper np = new NPOIHelper();
- DataTable dt = np.ExcelToTable(_upfile, headrow);
- string msg = string.Empty;
- foreach (DataRow dr in dt.Rows)
- {
- headrow = headrow + 1;
- if (dr[0].ToString() != "" && dr[1].ToString() != "")
- {
- Model.T_SMS_SentSMS dModel = new Model.T_SMS_SentSMS();
- dModel.TaskID = taskid;
- dModel.TelNum = dr[0].ToString();
- dModel.Content = dr[1].ToString();
- dModel.State = 0;
- dModel.F_UserID = userModel.F_UserId;
- dModel.F_Name = userModel.F_UserName;
- dModel.F_CreateDate = DateTime.Now;
- if (new BLL.T_SMS_SentSMS().Add(dModel) > 0)
- {
- msg = msg + "第" + headrow + "行,导入失败<br>";
- }
- }
- else
- {
- msg = msg + "第"+ headrow+"行,手机号或者内容为空,未导入<br>";
- }
- }
- if (string.IsNullOrEmpty(msg))
- {
- res = Error(msg);
- }
- }
- }
- }
- return res;
- }
- #endregion
- #region 短信服务
- /// <summary>
- /// 获取发送短信列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetSendTaskListByJob(string state, string count)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- DataTable dt = new DataTable();
- string str = "";
- if (!string.IsNullOrEmpty(count))
- {
- int ct = Int32.Parse(count);
- str = "top " + ct;
- }
- 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];
- res = Success("成功", dt);
- return res;
- }
- /// <summary>
- /// 获取发送短信列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetSendListByJob(string taskid, string count)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- DataTable dt = new DataTable();
- string str = "";
- if (!string.IsNullOrEmpty(count))
- {
- int ct = Int32.Parse(count);
- str = "top " + ct;
- }
- //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];
- dt = DB.DbHelperSQL.Query(" select " + str + " * from T_SMS_SentSMS where TaskID='" + taskid + "' and isnull(State,0)='0' order by F_CreateDate ").Tables[0];
- res = Success("成功", dt);
- return res;
- }
- /// <summary>
- /// 执行发送短信
- /// </summary>
- /// <returns></returns>
- public ActionResult ExecSMSByJob(string taskid, string count)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- DataTable dt = new DataTable();
- string tels = string.Empty;
- string errtels = string.Empty;
- string isdel = string.Empty;
- string str = string.Empty;
- if (!string.IsNullOrEmpty(count))
- {
- int ct = Int32.Parse(count);
- str = "top " + ct;
- }
- var task = new BLL.T_SMS_SendSMSTask().GetModel(Int32.Parse(taskid));
- if (task != null)
- {
- bool bl = true;
- DateTime dte = DateTime.Now;
- if (task.StartTime != null)
- {
- bl = dte >= task.StartTime.Value;
- }
- if (bl && task.EndTime != null)
- {
- bl = dte <= task.EndTime.Value;
- }
- if (bl)
- {
- //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];
- 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];
- foreach (DataRow dr in dt.Rows)
- {
- string err = SendSMS(dr["TelNum"].ToString(), dr["Content"].ToString(), task.SignName, task.TempCode);
- if (err == "")
- {
- UpdateSendState(dr["SMSID"].ToString());
- if (string.IsNullOrEmpty(tels))
- {
- tels = dr["TelNum"].ToString();
- }
- else
- {
- tels = tels + "," + dr["TelNum"].ToString();
- }
- }
- else
- {
- if (string.IsNullOrEmpty(tels))
- {
- errtels = dr["TelNum"].ToString();
- }
- else
- {
- errtels = errtels + "," + dr["TelNum"].ToString();
- }
- }
- }
- isdel = "0";
- }
- else
- {
- isdel = "1";
- }
- }
- else
- {
- isdel = "1";
- }
- res = Success("成功", new { suc = tels, err = errtels, isdel = isdel });
- return res;
- }
- /// <summary>
- /// 根据结束时间结束任务
- /// </summary>
- /// <returns></returns>
- public ActionResult EndSMSTask()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- string str = string.Empty;
- string strerr = string.Empty;
- BLL.T_SMS_SendSMSTask bll = new BLL.T_SMS_SendSMSTask();
- var list = bll.GetModelList(" isnull(State,0)=1 ");
- foreach (var l in list)
- {
- if (l.EndTime <= DateTime.Now)
- {
- l.State = 9;
- if (bll.Update(l))
- {
- if (string.IsNullOrEmpty(str))
- {
- str = l.SMSID.ToString();
- }
- else
- {
- str = str + "," + l.SMSID.ToString();
- }
- }
- else
- {
- if (string.IsNullOrEmpty(strerr))
- {
- strerr = l.SMSID.ToString();
- }
- else
- {
- strerr = strerr + "," + l.SMSID.ToString();
- }
- }
- }
- }
- res = Success("成功", new { suc = str, err = strerr});
-
- return res;
- }
- /// <summary>
- /// 短信服务停止后重置正在执行的任务
- /// </summary>
- /// <returns></returns>
- public ActionResult ResetSMSTask()
- {
- ActionResult res = NoToken("未知错误,请重新登录");
-
- string str = string.Empty;
- string strerr = string.Empty;
- BLL.T_SMS_SendSMSTask bll = new BLL.T_SMS_SendSMSTask();
- var list = bll.GetModelList(" isnull(State,0)=1 ");
- foreach (var l in list)
- {
- l.State = 0;
- if (bll.Update(l))
- {
- if (string.IsNullOrEmpty(str))
- {
- str = l.SMSID.ToString();
- }
- else
- {
- str = str + "," + l.SMSID.ToString();
- }
- }
- else
- {
- if (string.IsNullOrEmpty(strerr))
- {
- strerr = l.SMSID.ToString();
- }
- else
- {
- strerr = strerr + "," + l.SMSID.ToString();
- }
- }
- }
- res = Success("成功", new { suc = str, err = strerr });
- return res;
- }
- /// <summary>
- /// 更新短信发送状态
- /// </summary>
- /// <returns></returns>
- public ActionResult UpdateSendTaskState(string id, string state)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- Model.T_SMS_SendSMSTask dModel = new Model.T_SMS_SendSMSTask();
- if (id != "")
- {
- int sid = Int32.Parse(id);
- dModel = new BLL.T_SMS_SendSMSTask().GetModel(sid);
- if (dModel != null)
- {
- dModel.State = Int32.Parse(state);
- if (new BLL.T_SMS_SendSMSTask().Update(dModel))
- {
- res = Success("修改成功");
- }
- else
- {
- res = Success("修改失败");
- }
- }
- }
- return res;
- }
- /// <summary>
- /// 更新短信发送状态
- /// </summary>
- /// <returns></returns>
- public ActionResult UpdateSendState(string id)
- {
- ActionResult res = NoToken("未知错误,请重新登录");
- Model.T_SMS_SentSMS dModel = new Model.T_SMS_SentSMS();
- if (id != "")
- {
- int sid = Int32.Parse(id);
- dModel = new BLL.T_SMS_SentSMS().GetModel(sid);
- if (dModel != null && dModel.State == 0)
- {
- dModel.State = 1;
- dModel.SendTime = DateTime.Now;
- if (new BLL.T_SMS_SentSMS().Update(dModel))
- {
- res = Success("修改成功");
- }
- else
- {
- res = Success("修改失败");
- }
- }
- }
- return res;
- }
- #endregion
- #region 发送短信接口
- /// <summary>
- /// 发送短信接口
- /// </summary>
- /// <returns></returns>
- public ActionResult SentSMS()
- {
- //调用示例--/sms/sendsms?tel=15512345678,15812341234&cont={"name":"张三","time":"11:00"}&signname=活动验证&tempcode=SMS_40865007
- ActionResult res = NoToken("未知错误,请重新登录");
- string signname = HttpUtility.UrlDecode(RequestString.GetQueryString("signname"));//"活动验证";
- string tempcode = HttpUtility.UrlDecode(RequestString.GetQueryString("tempcode"));//"SMS_40865007";
- string tel = HttpUtility.UrlDecode(RequestString.GetQueryString("tel"));//多个用 , 隔开
- string cont = HttpUtility.UrlDecode(RequestString.GetQueryString("cont"));
- string err = SendSMS(tel, cont, signname, tempcode);
- if (err == "")
- {
- res = Success("成功");
- }
- else
- {
- res = Error(err);
- }
- return res;
- }
- /// <summary>
- /// 发送短信
- /// </summary>
- /// <param name="tel"></param>
- /// <param name="cont"></param>
- /// <param name="signname"></param>
- /// <param name="tempcode"></param>
- /// <returns></returns>
- public string SendSMS(string tel, string cont, string signname, string tempcode)
- {
- string res = string.Empty;
- string url = ConfigurationManager.AppSettings["url"];
- string key = ConfigurationManager.AppSettings["key"];
- string secret = ConfigurationManager.AppSettings["secret"];
- try
- {
- ITopClient client = new DefaultTopClient(url, key, secret);
- AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
- req.Extend = "123456";//公共回传参数
- req.SmsType = "normal";//短信类型,传入值请填写normal
- req.SmsFreeSignName = signname;//签名
- req.SmsParam = cont; //短信模参数示例: "{\"name\":\"张三\",\"time\":\"11:00\"}";
- req.RecNum = tel; //短信接收号码
- req.SmsTemplateCode = tempcode;//短信模板ID
- AlibabaAliqinFcSmsNumSendResponse rsp = client.Execute(req);
- if (!rsp.IsError)
- {
- if (!rsp.Result.Success)
- {
- res = rsp.Result.Msg;
- }
- }
- else
- {
- if (!string.IsNullOrEmpty(rsp.SubErrMsg))
- {
- res = rsp.SubErrMsg;
- }
- else
- {
- res = rsp.ErrMsg;
- }
- }
- }
- catch
- {
- res = "接口异常!";
- }
- return res;
- }
- #endregion
- }
- }
|