|
|
@@ -2,19 +2,104 @@
|
|
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
|
{
|
|
|
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 bool 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
|
+ if (access_token == "0")
|
|
|
77
|
+ n = true;
|
|
|
78
|
+ return n;
|
|
|
79
|
+ }
|
|
|
80
|
+ public static bool AddSmS(int userId,string count ,string msg, string mobiles, string templetid)
|
|
|
81
|
+ {
|
|
|
82
|
+
|
|
|
83
|
+ bool n = SendSms(msg, mobiles, templetid);
|
|
|
84
|
+ if (n ==false )
|
|
|
85
|
+ return n;
|
|
|
86
|
+ Model.T_SMS_RecvSMS dModel = new Model.T_SMS_RecvSMS();
|
|
|
87
|
+ dModel.CallerNum = mobiles.Trim();
|
|
|
88
|
+ dModel.Content = count.Trim();
|
|
|
89
|
+ dModel.State = 0;
|
|
|
90
|
+ dModel.F_UserID = userId;
|
|
|
91
|
+ dModel.RecvTime = DateTime.Now;
|
|
|
92
|
+ int b = new BLL.T_SMS_RecvSMS().Add(dModel);
|
|
|
93
|
+ if (b > 0)
|
|
|
94
|
+ {
|
|
|
95
|
+ return true;
|
|
|
96
|
+ }
|
|
|
97
|
+ else
|
|
|
98
|
+ {
|
|
|
99
|
+ return false;
|
|
|
100
|
+ }
|
|
|
101
|
+ }
|
|
16
|
102
|
#region 接收短信
|
|
17
|
|
-
|
|
18
|
103
|
[Authority]
|
|
19
|
104
|
/// <summary>
|
|
20
|
105
|
/// 获取接收短信列表
|
|
|
@@ -79,7 +164,6 @@ namespace CallCenterApi.Interface.Controllers
|
|
79
|
164
|
return Content(obj.ToJson());
|
|
80
|
165
|
|
|
81
|
166
|
}
|
|
82
|
|
-
|
|
83
|
167
|
[Authority]
|
|
84
|
168
|
/// <summary>
|
|
85
|
169
|
/// 新增接收短信
|
|
|
@@ -88,7 +172,6 @@ namespace CallCenterApi.Interface.Controllers
|
|
88
|
172
|
public ActionResult AddRecv(string tel, string cont)
|
|
89
|
173
|
{
|
|
90
|
174
|
Model.T_SMS_RecvSMS dModel = new Model.T_SMS_RecvSMS();
|
|
91
|
|
-
|
|
92
|
175
|
dModel.CallerNum = tel.Trim();
|
|
93
|
176
|
dModel.Content = cont.Trim();
|
|
94
|
177
|
dModel.State = 0;
|
|
|
@@ -638,6 +721,8 @@ namespace CallCenterApi.Interface.Controllers
|
|
638
|
721
|
}
|
|
639
|
722
|
return msg;
|
|
640
|
723
|
}
|
|
|
724
|
+
|
|
|
725
|
+
|
|
641
|
726
|
#endregion
|
|
642
|
727
|
}
|
|
643
|
728
|
}
|