|
|
@@ -2,19 +2,110 @@
|
|
2
|
2
|
using CallCenterApi.Common;
|
|
3
|
3
|
using CallCenterApi.DB;
|
|
4
|
4
|
using CallCenterApi.Interface.Controllers.Base;
|
|
|
5
|
+using Newtonsoft.Json;
|
|
|
6
|
+using Newtonsoft.Json.Linq;
|
|
5
|
7
|
using System;
|
|
6
|
8
|
using System.Collections.Generic;
|
|
|
9
|
+using System.Collections.Specialized;
|
|
7
|
10
|
using System.Data;
|
|
|
11
|
+using System.IO;
|
|
8
|
12
|
using System.Linq;
|
|
|
13
|
+using System.Net;
|
|
|
14
|
+using System.Security.Cryptography;
|
|
|
15
|
+using System.Text;
|
|
9
|
16
|
using System.Web;
|
|
10
|
17
|
using System.Web.Mvc;
|
|
11
|
18
|
|
|
|
19
|
+
|
|
12
|
20
|
namespace CallCenterApi.Interface.Controllers
|
|
13
|
21
|
{
|
|
14
|
22
|
public class SMSController : BaseController
|
|
15
|
23
|
{
|
|
16
|
|
- #region 接收短信
|
|
|
24
|
+
|
|
|
25
|
+ private static string Smsurl = "http://rcsapi.wo.cn:8000/umcinterface/sendtempletmsg";
|
|
|
26
|
+ static string cpcode = "AAAOFV";
|
|
|
27
|
+ static string key = "2e12579ba6a6576f8980b628b8008247";
|
|
|
28
|
+ /// <summary>
|
|
|
29
|
+ /// MD5加密
|
|
|
30
|
+ /// </summary>
|
|
|
31
|
+ /// <param name="txt"></param>
|
|
|
32
|
+ /// <returns></returns>
|
|
|
33
|
+ public static string Md5(string txt)
|
|
|
34
|
+ {
|
|
|
35
|
+ byte[] sor = Encoding.UTF8.GetBytes(txt);
|
|
|
36
|
+ MD5 md5 = MD5.Create();
|
|
|
37
|
+ byte[] result = md5.ComputeHash(sor);
|
|
|
38
|
+ StringBuilder strbul = new StringBuilder(40);
|
|
|
39
|
+ for (int i = 0; i < result.Length; i++)
|
|
|
40
|
+ {
|
|
|
41
|
+ //加密结果"x2"结果为32位,"x3"结果为48位,"x4"结果为64位
|
|
|
42
|
+ strbul.Append(result[i].ToString("x2"));
|
|
|
43
|
+ }
|
|
|
44
|
+ return strbul.ToString().ToLower (); ;
|
|
|
45
|
+ }
|
|
|
46
|
+ public static string SendSms(string msg,string mobiles,string templetid,string excode = "")
|
|
|
47
|
+ {
|
|
|
48
|
+ bool n=false ;
|
|
|
49
|
+ string sign = Md5(cpcode + msg + mobiles + excode + templetid + key);
|
|
|
50
|
+ var dic = new SortedDictionary<string, string>
|
|
|
51
|
+ {
|
|
|
52
|
+ {"cpcode", cpcode},
|
|
|
53
|
+ {"msg", msg},
|
|
|
54
|
+ {"mobiles", mobiles},
|
|
|
55
|
+ {"excode", excode},
|
|
|
56
|
+ {"templetid",templetid},
|
|
|
57
|
+ {"sign", sign},
|
|
|
58
|
+ };
|
|
|
59
|
+ //序列化参数
|
|
|
60
|
+ var jsonParam = JsonConvert.SerializeObject(dic);
|
|
|
61
|
+ //发送请求
|
|
|
62
|
+ var request = (HttpWebRequest)WebRequest.Create(Smsurl);
|
|
|
63
|
+ request.Method = "POST";
|
|
|
64
|
+ request.ContentType = "application/json;charset=UTF-8";
|
|
|
65
|
+ var byteData = Encoding.UTF8.GetBytes(jsonParam);
|
|
|
66
|
+ var length = byteData.Length;
|
|
|
67
|
+ request.ContentLength = length;
|
|
|
68
|
+ var writer = request.GetRequestStream();
|
|
|
69
|
+ writer.Write(byteData, 0, length);
|
|
|
70
|
+ writer.Close();
|
|
|
71
|
+ //接收数据
|
|
|
72
|
+ var response = (HttpWebResponse)request.GetResponse();
|
|
|
73
|
+ var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")).ReadToEnd();
|
|
|
74
|
+ JObject jo = (JObject)JsonConvert.DeserializeObject(responseString );
|
|
|
75
|
+ string access_token = jo["resultcode"].ToString();
|
|
|
76
|
+ return access_token;
|
|
|
77
|
+ }
|
|
|
78
|
+ public static bool AddSmS(int userId,string count ,string msg, string mobiles, string templetid)
|
|
|
79
|
+ {
|
|
|
80
|
+ bool res = false ;
|
|
|
81
|
+ string n = SendSms(msg, mobiles, templetid);
|
|
|
82
|
+ Model.T_SMS_RecvSMS dModel = new Model.T_SMS_RecvSMS();
|
|
|
83
|
+ dModel.CallerNum = mobiles.Trim();
|
|
|
84
|
+ dModel.Content = count.Trim();
|
|
|
85
|
+ dModel.RecvModemIMEI = n;
|
|
|
86
|
+ dModel.State = 0;
|
|
|
87
|
+ dModel.F_UserID = userId;
|
|
|
88
|
+ dModel.RecvTime = DateTime.Now;
|
|
|
89
|
+ int b = new BLL.T_SMS_RecvSMS().Add(dModel);
|
|
|
90
|
+ if (n == "0")
|
|
|
91
|
+ res = true;
|
|
|
92
|
+ if (res)
|
|
|
93
|
+ {
|
|
|
94
|
+ if (b > 0)
|
|
|
95
|
+ {
|
|
|
96
|
+ return true;
|
|
|
97
|
+ }
|
|
|
98
|
+ else
|
|
|
99
|
+ {
|
|
|
100
|
+ return false;
|
|
|
101
|
+ }
|
|
|
102
|
+ }
|
|
|
103
|
+ else
|
|
|
104
|
+ return res;
|
|
|
105
|
+
|
|
17
|
106
|
|
|
|
107
|
+ }
|
|
|
108
|
+ #region 接收短信
|
|
18
|
109
|
[Authority]
|
|
19
|
110
|
/// <summary>
|
|
20
|
111
|
/// 获取接收短信列表
|
|
|
@@ -46,7 +137,7 @@ namespace CallCenterApi.Interface.Controllers
|
|
46
|
137
|
{
|
|
47
|
138
|
sql += " and RecvTime <= '" + Convert.ToDateTime(strendtime.Trim()) + "' ";
|
|
48
|
139
|
}
|
|
49
|
|
-
|
|
|
140
|
+ sql += "and F_UserID is not null";
|
|
50
|
141
|
if (strpageindex.Trim() != "")
|
|
51
|
142
|
{
|
|
52
|
143
|
pageindex = Convert.ToInt32(strpageindex);
|
|
|
@@ -67,19 +158,24 @@ namespace CallCenterApi.Interface.Controllers
|
|
67
|
158
|
pageindex,
|
|
68
|
159
|
true,
|
|
69
|
160
|
out recordCount);
|
|
70
|
|
-
|
|
|
161
|
+ List<Model.T_SMS_RecvSMS> modelList = new BLL.T_SMS_RecvSMS().DataTableToList(dt);
|
|
71
|
162
|
var obj = new
|
|
72
|
163
|
{
|
|
73
|
|
- state = "success",
|
|
74
|
|
- message = "成功",
|
|
75
|
|
- rows = dt,
|
|
|
164
|
+ rows = modelList.Select(x => new
|
|
|
165
|
+ {
|
|
|
166
|
+ x.CallerNum,
|
|
|
167
|
+ x.Content,
|
|
|
168
|
+ x.F_Name,
|
|
|
169
|
+ usercode = new BLL.T_Sys_UserAccount().GetModel((int)x.F_UserID) != null ? new BLL.T_Sys_UserAccount().GetModel((int)x.F_UserID).F_UserCode : "系统发送",
|
|
|
170
|
+ x.RecvTime
|
|
|
171
|
+ }),
|
|
76
|
172
|
total = recordCount
|
|
77
|
173
|
};
|
|
|
174
|
+
|
|
78
|
175
|
|
|
79
|
176
|
return Content(obj.ToJson());
|
|
80
|
177
|
|
|
81
|
178
|
}
|
|
82
|
|
-
|
|
83
|
179
|
[Authority]
|
|
84
|
180
|
/// <summary>
|
|
85
|
181
|
/// 新增接收短信
|
|
|
@@ -88,7 +184,6 @@ namespace CallCenterApi.Interface.Controllers
|
|
88
|
184
|
public ActionResult AddRecv(string tel, string cont)
|
|
89
|
185
|
{
|
|
90
|
186
|
Model.T_SMS_RecvSMS dModel = new Model.T_SMS_RecvSMS();
|
|
91
|
|
-
|
|
92
|
187
|
dModel.CallerNum = tel.Trim();
|
|
93
|
188
|
dModel.Content = cont.Trim();
|
|
94
|
189
|
dModel.State = 0;
|
|
|
@@ -638,6 +733,8 @@ namespace CallCenterApi.Interface.Controllers
|
|
638
|
733
|
}
|
|
639
|
734
|
return msg;
|
|
640
|
735
|
}
|
|
|
736
|
+
|
|
|
737
|
+
|
|
641
|
738
|
#endregion
|
|
642
|
739
|
}
|
|
643
|
740
|
}
|