Sfoglia il codice sorgente

新增新短信模块

zhoufan 4 anni fa
parent
commit
ee05fd278e

+ 2 - 3
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/CallCenterApi.Interface.csproj

@@ -206,6 +206,7 @@
206 206
     <Compile Include="Controllers\Quality\IndexBaseController.cs" />
207 207
     <Compile Include="Controllers\Quality\IndexCategoryController.cs" />
208 208
     <Compile Include="Controllers\Quality\QCManageController.cs" />
209
+    <Compile Include="Controllers\Sms\SmsNewController.cs" />
209 210
     <Compile Include="Controllers\WebChart\InfoController.cs" />
210 211
     <Compile Include="Controllers\information\InternalMessagesController.cs" />
211 212
     <Compile Include="Controllers\information\NoticeController.cs" />
@@ -238,7 +239,7 @@
238 239
     <Compile Include="Controllers\RoleFunctionController.cs" />
239 240
     <Compile Include="Controllers\RoleInfoController.cs" />
240 241
     <Compile Include="Controllers\SeatGroupController.cs" />
241
-    <Compile Include="Controllers\SMSController.cs" />
242
+    <Compile Include="Controllers\Sms\SMSController.cs" />
242 243
     <Compile Include="Controllers\SysConfigController.cs" />
243 244
     <Compile Include="Controllers\tel\CallblackController.cs" />
244 245
     <Compile Include="Controllers\tel\CallInScreenController.cs" />
@@ -340,8 +341,6 @@
340 341
   </ItemGroup>
341 342
   <ItemGroup>
342 343
     <Folder Include="App_Data\" />
343
-    <Folder Include="Views\Achievements\" />
344
-    <Folder Include="Views\Policy\" />
345 344
   </ItemGroup>
346 345
   <ItemGroup>
347 346
     <ProjectReference Include="..\..\..\CallCenterCommon\CallCenter.QuartzService\CallCenter.QuartzService.csproj">

+ 4 - 0
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Configs/system.config

@@ -94,6 +94,10 @@
94 94
   <add key="Smsurl1" value="http://220.250.65.184:9014/union-gjdx-sms-api/sms/submit" />
95 95
   <add key="Smscpcode" value="AABJYC" />
96 96
   <add key="Smskey" value="724ee6be83d8d6f4d64ef5a537a9985d" />
97
+  <!-- ================== 13:短信配置new ================== -->
98
+  <add key="SmsNewUrl" value="https://opassapi.infocloud.cc/message/send" />
99
+  <add key="SmsNewApiKey" value="b1672487a0d46d3b3376c55897b8c705" />
100
+  <add key="SmsNewSecretKey" value="31492894daed7e09001a95c6e0df7db57bbbf6e6d378b2a9d043b2cc96a9a380" />
97 101
   <!-- ================== 14:其他配置 ================== -->
98 102
   <add key="AuthDate" value="2021-10-12" />
99 103
   <add key="OutSignCode" value="$AY12345#" />

+ 15 - 0
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/HomeController.cs

@@ -429,6 +429,10 @@ namespace CallCenterApi.Interface.Controllers
429 429
             return Success(Configs.GetValue(key));
430 430
         }
431 431
 
432
+        /// <summary>
433
+        /// 导出
434
+        /// </summary>
435
+        /// <returns></returns>
432 436
         public ActionResult Export()
433 437
         {
434 438
             var aw = new AsposeWord();
@@ -436,6 +440,17 @@ namespace CallCenterApi.Interface.Controllers
436 440
             var bt = aw.ExportAs();
437 441
             return File(bt, "application/msword", DateTime.Now.Ticks.ToString() + ".doc");
438 442
         }
443
+
444
+        /// <summary>
445
+        /// 发送短信
446
+        /// </summary>
447
+        /// <returns></returns>
448
+        public ActionResult Send()
449
+        {
450
+            string result=SmsHelper.Send("15515701425", "614915038222241792");
451
+
452
+            return Success(result);
453
+        }
439 454
     }
440 455
 
441 456
 

CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/SMSController.cs → CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/Sms/SMSController.cs


+ 18 - 0
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/Sms/SmsNewController.cs

@@ -0,0 +1,18 @@
1
+using CallCenterApi.Interface.Controllers.Base;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Linq;
5
+using System.Web;
6
+using System.Web.Mvc;
7
+
8
+namespace CallCenterApi.Interface.Controllers.Sms
9
+{
10
+    public class SmsNewController : BaseController
11
+    {
12
+        // GET: SmsNew
13
+        public ActionResult Index()
14
+        {
15
+            return Content("Index");
16
+        }
17
+    }
18
+}

+ 1 - 0
CallCenterCommon/CallCenter.Utility/CallCenter.Utility.csproj

@@ -94,6 +94,7 @@
94 94
     <Compile Include="RedisHelper1.cs" />
95 95
     <Compile Include="RedisHelper.cs" />
96 96
     <Compile Include="SaltAndHashHelper.cs" />
97
+    <Compile Include="Sms\SmsHelper.cs" />
97 98
     <Compile Include="SysInformationHelper.cs" />
98 99
     <Compile Include="Time\DateTimeConvert.cs" />
99 100
     <Compile Include="Time\DateTools.cs" />

+ 145 - 0
CallCenterCommon/CallCenter.Utility/Sms/SmsHelper.cs

@@ -0,0 +1,145 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Net.Http;
5
+using System.Security.Cryptography;
6
+using System.Text;
7
+using System.Threading.Tasks;
8
+
9
+namespace CallCenter.Utility
10
+{
11
+    /// <summary>
12
+    /// 短信
13
+    /// </summary>
14
+    public static class SmsHelper
15
+    {
16
+        /// <summary>
17
+        /// 发送短信
18
+        /// </summary>
19
+        /// <param name="phones"></param>
20
+        /// <param name="templateCode"></param>
21
+        /// <param name="templateParam"></param>
22
+        /// <returns></returns>
23
+        public static string Send(string phones,string templateCode,string templateParam="")
24
+        {
25
+            string result = string.Empty;
26
+
27
+            try
28
+            {
29
+                string apiKey = Configs.GetValue("SmsNewApiKey");
30
+                string accessKey = Configs.GetValue("SmsNewSecretKey");
31
+                string authHost = Configs.GetValue("SmsNewUrl");
32
+
33
+                var ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
34
+                var currentTime = Convert.ToInt64(ts.TotalMilliseconds).ToString();
35
+                HttpClient client = new HttpClient();
36
+
37
+                var requestHeaders = new Dictionary<string, string>();
38
+                //签名算法。支持HmacSHA256、HmacMD5、HmacSHA224、HmacSHA384、HmacSHA512
39
+                requestHeaders.Add("x-sign-method", "HmacSHA256");
40
+                requestHeaders.Add("x-api-key", $"{apiKey}");
41
+                //随机数。每次请求随机数建议不相同
42
+                requestHeaders.Add("x-nonce", $"{GetRandom()}");
43
+                //时间戳
44
+                requestHeaders.Add("x-timestamp", $"{currentTime}");
45
+
46
+
47
+                // client.DefaultRequestHeaders.Host = "recognition.image.myqcloud.com";
48
+                //设置headers请求参数 
49
+                foreach (var item in requestHeaders)
50
+                {
51
+                    client.DefaultRequestHeaders.Add(item.Key, item.Value);
52
+                }
53
+
54
+                //短信接口请求参数。参见接口规范
55
+                var jsArr = new Dictionary<string, string>();
56
+                jsArr.Add("phones", phones);
57
+                jsArr.Add("templateCode", templateCode);
58
+                if (!string.IsNullOrEmpty(templateParam))
59
+                {
60
+                    jsArr.Add("templateParam", templateParam);
61
+                }
62
+
63
+                //将headers参与与接口报文参数合并、排序,并生成本次请求的签名信息
64
+                var signDic = jsArr.Union(requestHeaders).ToDictionary(k => k.Key, v => v.Value);
65
+                var dicStr = GetSignContent(signDic);
66
+                var sign = Hmacsha256Encrypt(dicStr, accessKey);
67
+                //在header中设置本次请求签名信息
68
+                client.DefaultRequestHeaders.Add("x-sign", sign);
69
+
70
+
71
+                HttpContent str = new StringContent(jsArr.ToJson());
72
+                str.Headers.Remove("Content-Type");
73
+                str.Headers.Add("Content-Type", "application/json");
74
+                HttpResponseMessage response = client.PostAsync(authHost, str).Result;
75
+                var result1 = response.Content.ReadAsStringAsync().Result;
76
+                var objresult = result1.ToJObject();
77
+                if (objresult["code"].ToString() != "200")
78
+                {
79
+                    LogFactory.GetLogger("SmsHelper").Error(phones + "\r\n" + templateCode + "\r\n" + templateParam + "\r\n" + result1);
80
+                }
81
+
82
+            }
83
+            catch (Exception ex)
84
+            {
85
+                LogFactory.GetLogger("SmsHelper").Error(phones + "\r\n" + templateCode + "\r\n" + templateParam + "\r\n" + ex.ToString());
86
+            }
87
+            return result;
88
+        }
89
+
90
+        /// <summary>
91
+        /// Get Sign Content
92
+        /// </summary>
93
+        /// <param name="parameters"></param>
94
+        /// <returns></returns>
95
+        private static string GetSignContent(IDictionary<string, string> parameters)
96
+        {
97
+            // 第一步:把字典按Key的字母顺序排序
98
+            IDictionary<string, string> sortedParams = new SortedDictionary<string, string>(parameters);
99
+            IEnumerator<KeyValuePair<string, string>> dem = sortedParams.GetEnumerator();
100
+
101
+            // 第二步:把所有参数名和参数值串在一起
102
+            StringBuilder query = new StringBuilder("");
103
+            while (dem.MoveNext())
104
+            {
105
+                string key = dem.Current.Key;
106
+                string value = dem.Current.Value;
107
+                if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(value))
108
+                {
109
+                    query.Append(key).Append("=").Append(value).Append("&");
110
+                }
111
+            }
112
+            string content = query.ToString().Substring(0, query.Length - 1);
113
+
114
+            return content;
115
+        }
116
+
117
+        /// <summary>
118
+        /// HMACSHA1算法加密
119
+        /// </summary>
120
+        private static string Hmacsha256Encrypt(string encryptText, string encryptKey)
121
+        {
122
+            var encoding = new System.Text.UTF8Encoding();
123
+            StringBuilder builder = new StringBuilder();
124
+
125
+            using (var hmacsha256 = new HMACSHA256(encoding.GetBytes(encryptKey)))
126
+            {
127
+                byte[] hashmessage = hmacsha256.ComputeHash(encoding.GetBytes(encryptText));
128
+                for (int i = 0; i < hashmessage.Length; i++)
129
+                {
130
+                    builder.Append(hashmessage[i].ToString("x2"));
131
+                }
132
+            }
133
+            return builder.ToString();
134
+        }
135
+        /// <summary>
136
+        /// 获取随机数
137
+        /// </summary>
138
+        private static int GetRandom()
139
+        {
140
+            var random = new Random();
141
+            var rand = random.Next(10000, 999999999);
142
+            return rand;
143
+        }
144
+    }
145
+}