Procházet zdrojové kódy

已经发布的,更换短信

liyuanyuan %!s(int64=11) %!d(string=před) měsíci
rodič
revize
d958ae6da4

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

@@ -90,8 +90,8 @@
90 90
       <Private>True</Private>
91 91
     </Reference>
92 92
     <Reference Include="Microsoft.CSharp" />
93
-    <Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
94
-      <HintPath>..\..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
93
+    <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
94
+      <HintPath>..\..\..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
95 95
     </Reference>
96 96
     <Reference Include="qcloudsms_csharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
97 97
       <HintPath>..\..\..\packages\qcloud.qcloudsms_csharp.0.1.6\lib\net40\qcloudsms_csharp.dll</HintPath>
@@ -116,6 +116,9 @@
116 116
     <Reference Include="System.Net.Http" />
117 117
     <Reference Include="System.Net.Http.WebRequest" />
118 118
     <Reference Include="System.Runtime.Serialization" />
119
+    <Reference Include="System.Text.Encodings.Web, Version=4.0.3.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
120
+      <HintPath>..\..\..\packages\System.Text.Encodings.Web.4.5.1\lib\netstandard2.0\System.Text.Encodings.Web.dll</HintPath>
121
+    </Reference>
119 122
     <Reference Include="System.Transactions" />
120 123
     <Reference Include="System.Web.DynamicData" />
121 124
     <Reference Include="System.Web.Entity" />
@@ -136,6 +139,9 @@
136 139
     <Reference Include="System.Web.Services" />
137 140
     <Reference Include="System.EnterpriseServices" />
138 141
     <Reference Include="System.Xml.Linq" />
142
+    <Reference Include="TencentCloud, Version=3.0.1177.0, Culture=neutral, processorArchitecture=MSIL">
143
+      <HintPath>..\..\..\packages\TencentCloudSDK.3.0.1177\lib\net45\TencentCloud.dll</HintPath>
144
+    </Reference>
139 145
     <Reference Include="TopSdk, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
140 146
       <SpecificVersion>False</SpecificVersion>
141 147
       <HintPath>Lib\TopSdk.dll</HintPath>
@@ -255,6 +261,7 @@
255 261
     <Compile Include="Controllers\tel\RecordSetController.cs" />
256 262
     <Compile Include="Controllers\tel\SeatMonitoringController.cs" />
257 263
     <Compile Include="Controllers\tel\WorkcalendarController.cs" />
264
+    <Compile Include="Controllers\TencentSmsController.cs" />
258 265
     <Compile Include="Controllers\UserAccountController.cs" />
259 266
     <Compile Include="Controllers\UserClassController.cs" />
260 267
     <Compile Include="Controllers\WebController.cs" />

+ 226 - 3
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/SMSController.cs

@@ -20,8 +20,15 @@ using System.Security.Cryptography.X509Certificates;
20 20
 using System.Text;
21 21
 using System.Web;
22 22
 using System.Web.Mvc;
23
+using TencentCloud.Common;
24
+using TencentCloud.Common.Profile;
23 25
 
24 26
 
27
+
28
+
29
+using TencentCloud.Sms.V20210111;
30
+using TencentCloud.Sms.V20210111.Models;
31
+
25 32
 namespace CallCenterApi.Interface.Controllers
26 33
 {
27 34
     public class SMSController : BaseController
@@ -35,9 +42,220 @@ namespace CallCenterApi.Interface.Controllers
35 42
         // int templateId = 392016; // NOTE: 这里的模板ID`7839`只是一个示例,真实的模板ID需要在短信控制台中申请
36 43
         // 签名
37 44
         string smsSign = "巩义市网络舆情研究中心"; // NOTE: 这里的签名只是示例,请使用真实的已申请的签名, 签名参数使用的是`签名内容`,而不是`签名ID`
38
-
45
+        private static readonly string signName = "巩义市网络舆情研究中心";
46
+        private static readonly string secretId = "AKIDugJkz1qSq21oPrAHH0Zw63rSq33tb9VQ";
47
+        private static readonly string secretKey = "sZ5eDakngNrodJpQtHgDapyueDcpriQC";
39 48
         Log log = LogFactory.GetLogger("SMSSingleshot");
40 49
 
50
+
51
+
52
+        public SendSmsResponse SmsSingle(int templateId,   string[] msg, string mobiles)
53
+        {
54
+
55
+            try
56
+            {
57
+                // 必要步骤:
58
+                // 实例化一个认证对象,入参需要传入腾讯云账户密钥对 SecretId,SecretKey。
59
+                // 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中。
60
+                // 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。
61
+                // 这里采用的是从环境变量读取的方式,需要在环境变量中先设置这两个值。
62
+                // SecretId、SecretKey 查询:https://console.cloud.tencent.com/cam/capi
63
+                Credential cred = new Credential
64
+                {
65
+                    SecretId = secretId,// Environment.GetEnvironmentVariable("TENCENTCLOUD_SECRET_ID"),
66
+                    SecretKey = secretKey// Environment.GetEnvironmentVariable("TENCENTCLOUD_SECRET_KEY")
67
+                };
68
+
69
+                /* 非必要步骤:
70
+                 * 实例化一个客户端配置对象,可以指定超时时间等配置 */
71
+                ClientProfile clientProfile = new ClientProfile();
72
+                /* SDK 默认用TC3-HMAC-SHA256进行签名
73
+                 * 非必要请不要修改这个字段 */
74
+                clientProfile.SignMethod = ClientProfile.SIGN_TC3SHA256;
75
+                /* 非必要步骤
76
+                 * 实例化一个客户端配置对象,可以指定超时时间等配置 */
77
+                HttpProfile httpProfile = new HttpProfile();
78
+                /* SDK默认使用POST方法。
79
+                 * 如果您一定要使用GET方法,可以在这里设置。GET方法无法处理一些较大的请求 */
80
+                httpProfile.ReqMethod = "POST";
81
+                httpProfile.Timeout = 10; // 请求连接超时时间,单位为秒(默认60秒)
82
+                /* 指定接入地域域名,默认就近地域接入域名为 sms.tencentcloudapi.com ,也支持指定地域域名访问,例如广州地域的域名为 sms.ap-guangzhou.tencentcloudapi.com */
83
+                httpProfile.Endpoint = "sms.tencentcloudapi.com";
84
+                // 代理服务器,当您的环境下有代理服务器时设定(无需要直接忽略)
85
+                // httpProfile.WebProxy = Environment.GetEnvironmentVariable("HTTPS_PROXY");
86
+
87
+                clientProfile.HttpProfile = httpProfile;
88
+                /* 实例化要请求产品(以sms为例)的client对象
89
+                 * 第二个参数是地域信息,可以直接填写字符串ap-guangzhou,支持的地域列表参考 https://cloud.tencent.com/document/api/382/52071#.E5.9C.B0.E5.9F.9F.E5.88.97.E8.A1.A8 */
90
+                SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
91
+
92
+                /* 实例化一个请求对象,根据调用的接口和实际情况,可以进一步设置请求参数
93
+                 * 您可以直接查询SDK源码确定SendSmsRequest有哪些属性可以设置
94
+                 * 属性可能是基本类型,也可能引用了另一个数据结构
95
+                 * 推荐使用IDE进行开发,可以方便的跳转查阅各个接口和数据结构的文档说明 */
96
+                SendSmsRequest req = new SendSmsRequest();
97
+
98
+                /* 基本类型的设置:
99
+                 * SDK采用的是指针风格指定参数,即使对于基本类型您也需要用指针来对参数赋值。
100
+                 * SDK提供对基本类型的指针引用封装函数
101
+                 * 帮助链接:
102
+                 * 短信控制台: https://console.cloud.tencent.com/smsv2
103
+                 * 腾讯云短信小助手: https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81 */
104
+                /* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 */
105
+                // 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看
106
+                req.SmsSdkAppId = "1400467981";// "1304639164";
107
+
108
+                /* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 */
109
+                // 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看
110
+                req.SignName = signName;
111
+
112
+                /* 模板 ID: 必须填写已审核通过的模板 ID */
113
+                // 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看
114
+                req.TemplateId = templateId.ToString();// "449739";
115
+
116
+                /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */
117
+                req.TemplateParamSet = msg;// new String[] { "DH20250808996" };
118
+
119
+                /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号]
120
+                 * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号*/
121
+             
122
+                req.PhoneNumberSet = new String[] { mobiles };
123
+
124
+                /* 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回 */
125
+                //req.SessionContext = "";
126
+
127
+                /* 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请联系 [腾讯云短信小助手] */
128
+                //req.ExtendCode = "";
129
+
130
+                /* 国内短信无需填写该项;国际/港澳台短信已申请独立 SenderId 需要填写该字段,默认使用公共 SenderId,无需填写该字段。注:月度使用量达到指定量级可申请独立 SenderId 使用,详情请联系 [腾讯云短信小助手](https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81)。 */
131
+                //req.SenderId = "";
132
+
133
+                SendSmsResponse resp = client.SendSmsSync(req);
134
+                return resp;
135
+                // 输出json格式的字符串回包
136
+                //   Console.WriteLine(AbstractModel.ToJsonString(resp));
137
+
138
+                /* 当出现以下错误码时,快速解决方案参考
139
+                 * [FailedOperation.SignatureIncorrectOrUnapproved](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Afailedoperation.signatureincorrectorunapproved-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)
140
+                 * [FailedOperation.TemplateIncorrectOrUnapproved](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Afailedoperation.templateincorrectorunapproved-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)
141
+                 * [UnauthorizedOperation.SmsSdkAppIdVerifyFail](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Aunauthorizedoperation.smssdkappidverifyfail-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)
142
+                 * [UnsupportedOperation.ContainDomesticAndInternationalPhoneNumber](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Aunsupportedoperation.containdomesticandinternationalphonenumber-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)
143
+                 * 更多错误,可咨询[腾讯云助手](https://tccc.qcloud.com/web/im/index.html#/chat?webAppId=8fa15978f85cb41f7e2ea36920cb3ae1&title=Sms)
144
+                 */
145
+            }
146
+            catch (Exception e)
147
+            {
148
+                log.Error("发送短信失败", e);
149
+                return null;
150
+            }
151
+           
152
+        }
153
+
154
+
155
+        public SendSmsResponse SmsGroup(int templateId, string[] msg, string[] mobiles)
156
+        {
157
+
158
+            try
159
+            {
160
+                // 必要步骤:
161
+                // 实例化一个认证对象,入参需要传入腾讯云账户密钥对 SecretId,SecretKey。
162
+                // 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中。
163
+                // 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。
164
+                // 这里采用的是从环境变量读取的方式,需要在环境变量中先设置这两个值。
165
+                // SecretId、SecretKey 查询:https://console.cloud.tencent.com/cam/capi
166
+                Credential cred = new Credential
167
+                {
168
+                    SecretId = secretId,// Environment.GetEnvironmentVariable("TENCENTCLOUD_SECRET_ID"),
169
+                    SecretKey = secretKey// Environment.GetEnvironmentVariable("TENCENTCLOUD_SECRET_KEY")
170
+                };
171
+
172
+                /* 非必要步骤:
173
+                 * 实例化一个客户端配置对象,可以指定超时时间等配置 */
174
+                ClientProfile clientProfile = new ClientProfile();
175
+                /* SDK 默认用TC3-HMAC-SHA256进行签名
176
+                 * 非必要请不要修改这个字段 */
177
+                clientProfile.SignMethod = ClientProfile.SIGN_TC3SHA256;
178
+                /* 非必要步骤
179
+                 * 实例化一个客户端配置对象,可以指定超时时间等配置 */
180
+                HttpProfile httpProfile = new HttpProfile();
181
+                /* SDK默认使用POST方法。
182
+                 * 如果您一定要使用GET方法,可以在这里设置。GET方法无法处理一些较大的请求 */
183
+                httpProfile.ReqMethod = "POST";
184
+                httpProfile.Timeout = 10; // 请求连接超时时间,单位为秒(默认60秒)
185
+                /* 指定接入地域域名,默认就近地域接入域名为 sms.tencentcloudapi.com ,也支持指定地域域名访问,例如广州地域的域名为 sms.ap-guangzhou.tencentcloudapi.com */
186
+                httpProfile.Endpoint = "sms.tencentcloudapi.com";
187
+                // 代理服务器,当您的环境下有代理服务器时设定(无需要直接忽略)
188
+                // httpProfile.WebProxy = Environment.GetEnvironmentVariable("HTTPS_PROXY");
189
+
190
+                clientProfile.HttpProfile = httpProfile;
191
+                /* 实例化要请求产品(以sms为例)的client对象
192
+                 * 第二个参数是地域信息,可以直接填写字符串ap-guangzhou,支持的地域列表参考 https://cloud.tencent.com/document/api/382/52071#.E5.9C.B0.E5.9F.9F.E5.88.97.E8.A1.A8 */
193
+                SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
194
+
195
+                /* 实例化一个请求对象,根据调用的接口和实际情况,可以进一步设置请求参数
196
+                 * 您可以直接查询SDK源码确定SendSmsRequest有哪些属性可以设置
197
+                 * 属性可能是基本类型,也可能引用了另一个数据结构
198
+                 * 推荐使用IDE进行开发,可以方便的跳转查阅各个接口和数据结构的文档说明 */
199
+                SendSmsRequest req = new SendSmsRequest();
200
+
201
+                /* 基本类型的设置:
202
+                 * SDK采用的是指针风格指定参数,即使对于基本类型您也需要用指针来对参数赋值。
203
+                 * SDK提供对基本类型的指针引用封装函数
204
+                 * 帮助链接:
205
+                 * 短信控制台: https://console.cloud.tencent.com/smsv2
206
+                 * 腾讯云短信小助手: https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81 */
207
+                /* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 */
208
+                // 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看
209
+                req.SmsSdkAppId = "1400467981";// "1304639164";
210
+
211
+                /* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 */
212
+                // 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看
213
+                req.SignName = signName;
214
+
215
+                /* 模板 ID: 必须填写已审核通过的模板 ID */
216
+                // 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看
217
+                req.TemplateId = templateId.ToString();// "449739";
218
+
219
+                /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */
220
+                req.TemplateParamSet = msg;// new String[] { "DH20250808996" };
221
+
222
+                /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号]
223
+                 * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号*/
224
+
225
+                req.PhoneNumberSet = mobiles;
226
+
227
+                /* 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回 */
228
+                //req.SessionContext = "";
229
+
230
+                /* 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请联系 [腾讯云短信小助手] */
231
+                //req.ExtendCode = "";
232
+
233
+                /* 国内短信无需填写该项;国际/港澳台短信已申请独立 SenderId 需要填写该字段,默认使用公共 SenderId,无需填写该字段。注:月度使用量达到指定量级可申请独立 SenderId 使用,详情请联系 [腾讯云短信小助手](https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81)。 */
234
+                //req.SenderId = "";
235
+
236
+                SendSmsResponse resp = client.SendSmsSync(req);
237
+                return resp;
238
+                // 输出json格式的字符串回包
239
+                //   Console.WriteLine(AbstractModel.ToJsonString(resp));
240
+
241
+                /* 当出现以下错误码时,快速解决方案参考
242
+                 * [FailedOperation.SignatureIncorrectOrUnapproved](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Afailedoperation.signatureincorrectorunapproved-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)
243
+                 * [FailedOperation.TemplateIncorrectOrUnapproved](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Afailedoperation.templateincorrectorunapproved-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)
244
+                 * [UnauthorizedOperation.SmsSdkAppIdVerifyFail](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Aunauthorizedoperation.smssdkappidverifyfail-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)
245
+                 * [UnsupportedOperation.ContainDomesticAndInternationalPhoneNumber](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Aunsupportedoperation.containdomesticandinternationalphonenumber-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)
246
+                 * 更多错误,可咨询[腾讯云助手](https://tccc.qcloud.com/web/im/index.html#/chat?webAppId=8fa15978f85cb41f7e2ea36920cb3ae1&title=Sms)
247
+                 */
248
+            }
249
+            catch (Exception e)
250
+            {
251
+                log.Error("发送短信失败", e);
252
+                return null;
253
+            }
254
+
255
+        }
256
+
257
+
258
+
41 259
         /// <summary>
42 260
         /// 单发短信
43 261
         /// </summary>
@@ -121,7 +339,9 @@ namespace CallCenterApi.Interface.Controllers
121 339
             // string  n = SendSms(msg, mobiles, templetid);
122 340
             //  string[] mag = { msg, mobiles };
123 341
             string SignName = "巩义市网络舆情研究中心";
124
-            SmsMultiSenderResult result = SMSGroupSending(mobiles,templateId, mag);
342
+
343
+            var result = SmsGroup(templateId, mag, mobiles);
344
+           // SmsMultiSenderResult result = SMSGroupSending(mobiles,templateId, mag);
125 345
             if (result != null)
126 346
             {
127 347
                 Model.T_SMS_RecvSMS dModel = new Model.T_SMS_RecvSMS();
@@ -151,9 +371,12 @@ namespace CallCenterApi.Interface.Controllers
151 371
 
152 372
         public  bool   AddSmS(int templateId ,int userId,string count, string[] mag, string mobiles)
153 373
         {
374
+            
154 375
             try
155 376
             {
156
-                SmsSingleSenderResult result = SMSSingleshot(templateId, mag, mobiles);
377
+                var result = SmsSingle(templateId, mag, mobiles);
378
+
379
+             //   SmsSingleSenderResult result = SMSSingleshot(templateId, mag, mobiles);
157 380
                 if (result != null)
158 381
                 {
159 382
                     Model.T_SMS_RecvSMS dModel = new Model.T_SMS_RecvSMS();

+ 414 - 0
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/TencentSmsController.cs

@@ -0,0 +1,414 @@
1
+using CallCenter.Utility;
2
+using CallCenterApi.Common;
3
+using CallCenterApi.Interface.Controllers.Base;
4
+using System;
5
+using System.Collections.Generic;
6
+using System.Data;
7
+using System.Linq;
8
+using System.Web;
9
+using System.Web.Mvc;
10
+ 
11
+using System.Net.Http;
12
+using System.Security.Cryptography;
13
+using System.Text;
14
+using System.Threading.Tasks;
15
+using Newtonsoft.Json;
16
+using TencentCloud.Common;
17
+using TencentCloud.Common.Profile;
18
+ 
19
+
20
+
21
+ 
22
+using TencentCloud.Sms.V20210111;
23
+using TencentCloud.Sms.V20210111.Models;
24
+
25
+namespace CallCenterApi.Interface.Controllers
26
+{
27
+    public class TencentSmsController : BaseController
28
+    {
29
+
30
+
31
+        Log log = LogFactory.GetLogger("TencentSmsController");
32
+        // private static readonly string secretId = "1400467981";
33
+        private static readonly string secretKey = "sZ5eDakngNrodJpQtHgDapyueDcpriQC";
34
+        //private static readonly string secretKey = "ba3aa1a33da088dac57bcac8ce5f8d41";
35
+        private static readonly string endpoint = "sms.tencentcloudapi.com";
36
+        private static readonly string smsSdkAppId = "1400467981";
37
+        private static readonly string signName = "巩义市网络舆情研究中心";
38
+        private static readonly string templateId = "1963450";
39
+        private static readonly string action = "SendSms";
40
+        public static string SHA256Hex(string s)
41
+        {
42
+            using (SHA256 algo = SHA256.Create())
43
+            {
44
+                byte[] hashbytes = algo.ComputeHash(Encoding.UTF8.GetBytes(s));
45
+                StringBuilder builder = new StringBuilder();
46
+                for (int i = 0; i < hashbytes.Length; ++i)
47
+                {
48
+                    builder.Append(hashbytes[i].ToString("x2"));
49
+                }
50
+                return builder.ToString();
51
+            }
52
+        }
53
+
54
+        public static byte[] HmacSHA256(byte[] key, byte[] msg)
55
+        {
56
+            using (HMACSHA256 mac = new HMACSHA256(key))
57
+            {
58
+                return mac.ComputeHash(msg);
59
+            }
60
+        }
61
+
62
+        public static Dictionary<String, String> BuildHeaders(string secretid,
63
+            string secretkey, string service, string endpoint, string region,
64
+            string action, string version, DateTime date, string requestPayload)
65
+        {
66
+            string datestr = date.ToString("yyyy-MM-dd");
67
+            DateTime startTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
68
+            long requestTimestamp = (long)Math.Round((date - startTime).TotalMilliseconds, MidpointRounding.AwayFromZero) / 1000;
69
+            // ************* 步骤 1:拼接规范请求串 *************
70
+            string algorithm = "TC3-HMAC-SHA256";
71
+            string httpRequestMethod = "POST";
72
+            string canonicalUri = "/";
73
+            string canonicalQueryString = "";
74
+            string contentType = "application/json";
75
+            string canonicalHeaders = "content-type:" + contentType + "; charset=utf-8\n" + "host:" + endpoint + "\n";
76
+            string signedHeaders = "content-type;host";
77
+            string hashedRequestPayload = SHA256Hex(requestPayload);
78
+            string canonicalRequest = httpRequestMethod + "\n"
79
+                + canonicalUri + "\n"
80
+                + canonicalQueryString + "\n"
81
+                + canonicalHeaders + "\n"
82
+                + signedHeaders + "\n"
83
+                + hashedRequestPayload;
84
+            Console.WriteLine(canonicalRequest);
85
+
86
+            // ************* 步骤 2:拼接待签名字符串 *************
87
+            string credentialScope = datestr + "/" + service + "/" + "tc3_request";
88
+            string hashedCanonicalRequest = SHA256Hex(canonicalRequest);
89
+            string stringToSign = algorithm + "\n" + requestTimestamp.ToString() + "\n" + credentialScope + "\n" + hashedCanonicalRequest;
90
+            Console.WriteLine(stringToSign);
91
+
92
+            // ************* 步骤 3:计算签名 *************
93
+            byte[] tc3SecretKey = Encoding.UTF8.GetBytes("TC3" + secretkey);
94
+            byte[] secretDate = HmacSHA256(tc3SecretKey, Encoding.UTF8.GetBytes(datestr));
95
+            byte[] secretService = HmacSHA256(secretDate, Encoding.UTF8.GetBytes(service));
96
+            byte[] secretSigning = HmacSHA256(secretService, Encoding.UTF8.GetBytes("tc3_request"));
97
+            byte[] signatureBytes = HmacSHA256(secretSigning, Encoding.UTF8.GetBytes(stringToSign));
98
+            string signature = BitConverter.ToString(signatureBytes).Replace("-", "").ToLower();
99
+            Console.WriteLine(signature);
100
+
101
+            // ************* 步骤 4:拼接 Authorization *************
102
+            string authorization = algorithm + " "
103
+                + "Credential=" + secretid + "/" + credentialScope + ", "
104
+                + "SignedHeaders=" + signedHeaders + ", "
105
+                + "Signature=" + signature;
106
+            Console.WriteLine(authorization);
107
+
108
+            Dictionary<string, string> headers = new Dictionary<string, string>();
109
+            headers.Add("Authorization", authorization);
110
+            headers.Add("Host", endpoint);
111
+            headers.Add("Content-Type", contentType + "; charset=utf-8");
112
+            headers.Add("X-TC-Timestamp", requestTimestamp.ToString());
113
+            headers.Add("X-TC-Version", version);
114
+            headers.Add("X-TC-Action", action);
115
+            headers.Add("X-TC-Region", region);
116
+            return headers;
117
+        }
118
+
119
+
120
+        //        public static async Task SendSmsAsync(string phoneNumber, string[]  templateParams)
121
+        //        {
122
+        //            var request = new
123
+        //            {
124
+        //                SmsSdkAppId = smsSdkAppId,
125
+        //                Sign = signName,
126
+        //                TemplateId = templateId,
127
+        //                PhoneNumberSet = new[] { phoneNumber },
128
+        //                TemplateParamSet = templateParams
129
+        //            };
130
+
131
+        //            var requestBody = JsonConvert.SerializeObject(request);
132
+        //            var timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString();
133
+        //            var nonce = new Random().Next(100000, 999999).ToString();
134
+        //            var signature = GenerateSignature(requestBody, timestamp, nonce);
135
+
136
+        //            using (var client = new HttpClient())
137
+        //            {
138
+        //                client.DefaultRequestHeaders.Add("Authorization", signature);
139
+        //                client.DefaultRequestHeaders.Add("X-TC-Action", "SendSms");
140
+        //                client.DefaultRequestHeaders.Add("X-TC-Timestamp", timestamp);
141
+        //                client.DefaultRequestHeaders.Add("X-TC-Nonce", nonce);
142
+        //                client.DefaultRequestHeaders.Add("X-TC-Version", "2021-01-11");
143
+
144
+        //                //foreach (KeyValuePair<string, string> kv in headers)
145
+        //                //{
146
+        //                //    // Console.WriteLine(kv.Key + ": " + kv.Value);
147
+        //                //    client.DefaultRequestHeaders.Add(kv.Key, kv.Value);
148
+        //                //}
149
+
150
+        //                var content = new StringContent(requestBody, Encoding.UTF8, "application/json");
151
+        //                var response = await client.PostAsync($"https://{endpoint}", content);
152
+
153
+        //                if (response.IsSuccessStatusCode)
154
+        //                {
155
+        //                    var responseBody = await response.Content.ReadAsStringAsync();
156
+        //                    Console.WriteLine("SMS sent successfully: " + responseBody);
157
+        //                }
158
+        //                else
159
+        //                {
160
+        //                    Console.WriteLine("Failed to send SMS: " + response.ReasonPhrase);
161
+        //                }
162
+        //            }
163
+        //        }
164
+
165
+        //        private static string GenerateSignature(string requestBody, string timestamp, string nonce)
166
+        //        {
167
+        //            var source = $"POST{smsSdkAppId}{timestamp}{nonce}{requestBody}";
168
+        //            using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secretKey)))
169
+        //            {
170
+        //                var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(source));
171
+        //                return Convert.ToBase64String(hash);
172
+        //            }
173
+        //        }
174
+        //        public static byte[] HmacSHA256(byte[] key, byte[] msg)
175
+        //        {
176
+        //            using (HMACSHA256 mac = new HMACSHA256(key))
177
+        //            {
178
+        //                return mac.ComputeHash(msg);
179
+        //            }
180
+        //        }
181
+        //        public static string SHA256Hex(string s)
182
+        //        {
183
+        //            using (SHA256 algo = SHA256.Create())
184
+        //            {
185
+        //                byte[] hashbytes = algo.ComputeHash(Encoding.UTF8.GetBytes(s));
186
+        //                StringBuilder builder = new StringBuilder();
187
+        //                for (int i = 0; i < hashbytes.Length; ++i)
188
+        //                {
189
+        //                    builder.Append(hashbytes[i].ToString("x2"));
190
+        //                }
191
+        //                return builder.ToString();
192
+        //            }
193
+        //        }
194
+
195
+        //        public static Dictionary<String, String> BuildHeaders(string secretid,
196
+        //        string secretkey, string service, string endpoint, string region,
197
+        //        string action, string version, DateTime date, string requestPayload) {
198
+
199
+
200
+        //            string datestr = date.ToString("yyyy-MM-dd");
201
+        //            DateTime startTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
202
+        //            long requestTimestamp = (long)Math.Round((date - startTime).TotalMilliseconds, MidpointRounding.AwayFromZero) / 1000;
203
+        //            // ************* 步骤 1:拼接规范请求串 *************
204
+        //            string algorithm = "TC3-HMAC-SHA256";
205
+        //            string httpRequestMethod = "POST";
206
+        //            string canonicalUri = "/";
207
+        //            string canonicalQueryString = "";
208
+        //            string contentType = "application/json";
209
+        //            string canonicalHeaders = "content-type:" + contentType + "; charset=utf-8\n"
210
+        //                + "host:" + endpoint + "\n"
211
+        //                + "x-tc-action:" + action.ToLower() + "\n";
212
+        //            string signedHeaders = "content-type;host;x-tc-action";
213
+        //            string hashedRequestPayload = SHA256Hex(requestPayload);
214
+        //            string canonicalRequest = httpRequestMethod + "\n"
215
+        //                + canonicalUri + "\n"
216
+        //                + canonicalQueryString + "\n"
217
+        //                + canonicalHeaders + "\n"
218
+        //                + signedHeaders + "\n"
219
+        //                + hashedRequestPayload;
220
+        //            Console.WriteLine(canonicalRequest);
221
+
222
+        //            // ************* 步骤 2:拼接待签名字符串 *************
223
+        //            string credentialScope = datestr + "/" + service + "/" + "tc3_request";
224
+        //            string hashedCanonicalRequest = SHA256Hex(canonicalRequest);
225
+        //            string stringToSign = algorithm + "\n"
226
+        //                + requestTimestamp.ToString() + "\n"
227
+        //                + credentialScope + "\n"
228
+        //                + hashedCanonicalRequest;
229
+        //            Console.WriteLine(stringToSign);
230
+
231
+        //            // ************* 步骤 3:计算签名 *************
232
+        //            byte[] tc3SecretKey = Encoding.UTF8.GetBytes("TC3" + secretkey);
233
+        //            byte[] secretDate = HmacSHA256(tc3SecretKey, Encoding.UTF8.GetBytes(datestr));
234
+        //            byte[] secretService = HmacSHA256(secretDate, Encoding.UTF8.GetBytes(service));
235
+        //            byte[] secretSigning = HmacSHA256(secretService, Encoding.UTF8.GetBytes("tc3_request"));
236
+        //            byte[] signatureBytes = HmacSHA256(secretSigning, Encoding.UTF8.GetBytes(stringToSign));
237
+        //            string signature = BitConverter.ToString(signatureBytes).Replace("-", "").ToLower();
238
+        //            Console.WriteLine(signature);
239
+
240
+        //            // ************* 步骤 4:拼接 Authorization *************
241
+        //            string authorization = algorithm + " "
242
+        //                + "Credential=" + secretid + "/" + credentialScope + ", "
243
+        //                + "SignedHeaders=" + signedHeaders + ", "
244
+        //                + "Signature=" + signature;
245
+        //            Console.WriteLine(authorization);
246
+        //            Dictionary<string, string> headers = new Dictionary<string, string>();
247
+        //            headers.Add("Authorization", authorization);
248
+        //            headers.Add("Host", endpoint);
249
+        //            headers.Add("Content-Type", contentType + "; charset=utf-8");
250
+        //            headers.Add("X-TC-Timestamp", requestTimestamp.ToString());
251
+        //            headers.Add("X-TC-Version", version);
252
+        //            headers.Add("X-TC-Action", action);
253
+        //            headers.Add("X-TC-Region", region);
254
+        //            return headers;
255
+        //        }
256
+
257
+        [HttpGet]
258
+        public void SmsNew()
259
+        {
260
+            //string phoneNumber = "15639002755"; // 替换为实际的手机号码
261
+            //var templateParams = new[] { "202402110000" }; // 替换为实际的模板参数
262
+            //string service = "cvm";
263
+            //string endpoint = "cvm.tencentcloudapi.com";
264
+            //string region = "ap-guangzhou";
265
+            //string action = "DescribeInstances";
266
+            //string version = "2017-03-12";
267
+            //DateTime date = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1551113065);
268
+
269
+
270
+            //  string requestPayload = "{\"Limit\": 1, \"Filters\": [{\"Values\": [\"\\u672a\\u547d\\u540d\"], \"Name\": \"instance-name\"}]}";
271
+
272
+
273
+            //  Dictionary<string, string> headers = BuildHeaders(smsSdkAppId, secretKey, service
274
+            //, endpoint, region, action, version, date);
275
+            //string SECRET_ID = "AKIDz8krbsJ5yKBZQpn74WFkmLPx3*******";
276
+            //string SECRET_KEY = "Gu5t9xGARNpq86cd98joQYCN3*******";
277
+
278
+            string service = "sms";
279
+            string endpoint = "sms.tencentcloudapi.com";
280
+            string region = "ap-guangzhou";
281
+            string action = "SendSms";
282
+            string version = "2021-01-11";
283
+
284
+            // 此处由于示例规范的原因,采用时间戳2019-02-26 00:44:25,此参数作为示例,如果在项目中,您应当使用:
285
+            DateTime date = DateTime.UtcNow;
286
+            // 注意时区,建议此时间统一采用UTC时间戳,否则容易出错
287
+            // DateTime date = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1551113065);
288
+            // 实际调用需要更新参数,这里仅作为演示签名验证通过的例子
289
+            string requestPayload = "{\"SmsSdkAppId\":\"1400467981\",\"TemplateParamSet\":[\"11111230\"],\"PhoneNumberSet\":[\"+8615639002755\"],\"SessionContext\":\"test\",\"SignName\":\"巩义市网络舆情研究中心\",\"TemplateId\":\"1963450\"}";
290
+
291
+            Dictionary<string, string> headers = BuildHeaders(smsSdkAppId, secretKey, service
292
+                , endpoint, region, action, version, date, requestPayload);
293
+
294
+            Console.WriteLine("POST https://sms.tencentcloudapi.com");
295
+            foreach (KeyValuePair<string, string> kv in headers)
296
+            {
297
+                Console.WriteLine(kv.Key + ": " + kv.Value);
298
+            }
299
+            Console.WriteLine();
300
+            Console.WriteLine(requestPayload);
301
+
302
+            string curlcmd = "curl -X POST https://" + endpoint;
303
+            foreach (KeyValuePair<string, string> kv in headers)
304
+            {
305
+                curlcmd = curlcmd + " -H \"" + kv.Key + ": " + kv.Value + "\"";
306
+            }
307
+            curlcmd = curlcmd + " -d '" + requestPayload + "'";
308
+            Console.WriteLine(curlcmd);
309
+        }
310
+
311
+        public void SmsAsync () {
312
+
313
+            try
314
+            {
315
+                // 必要步骤:
316
+                // 实例化一个认证对象,入参需要传入腾讯云账户密钥对 SecretId,SecretKey。
317
+                // 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中。
318
+                // 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。
319
+                // 这里采用的是从环境变量读取的方式,需要在环境变量中先设置这两个值。
320
+                // SecretId、SecretKey 查询:https://console.cloud.tencent.com/cam/capi
321
+                Credential cred = new Credential
322
+                {
323
+                    SecretId = "AKIDugJkz1qSq21oPrAHH0Zw63rSq33tb9VQ",// Environment.GetEnvironmentVariable("TENCENTCLOUD_SECRET_ID"),
324
+                    SecretKey = secretKey// Environment.GetEnvironmentVariable("TENCENTCLOUD_SECRET_KEY")
325
+                };
326
+
327
+                /* 非必要步骤:
328
+                 * 实例化一个客户端配置对象,可以指定超时时间等配置 */
329
+                ClientProfile clientProfile = new ClientProfile();
330
+                /* SDK 默认用TC3-HMAC-SHA256进行签名
331
+                 * 非必要请不要修改这个字段 */
332
+                clientProfile.SignMethod = ClientProfile.SIGN_TC3SHA256;
333
+                /* 非必要步骤
334
+                 * 实例化一个客户端配置对象,可以指定超时时间等配置 */
335
+                HttpProfile httpProfile = new HttpProfile();
336
+                /* SDK默认使用POST方法。
337
+                 * 如果您一定要使用GET方法,可以在这里设置。GET方法无法处理一些较大的请求 */
338
+                httpProfile.ReqMethod = "POST";
339
+                httpProfile.Timeout = 10; // 请求连接超时时间,单位为秒(默认60秒)
340
+                /* 指定接入地域域名,默认就近地域接入域名为 sms.tencentcloudapi.com ,也支持指定地域域名访问,例如广州地域的域名为 sms.ap-guangzhou.tencentcloudapi.com */
341
+                httpProfile.Endpoint = "sms.tencentcloudapi.com";
342
+                // 代理服务器,当您的环境下有代理服务器时设定(无需要直接忽略)
343
+                // httpProfile.WebProxy = Environment.GetEnvironmentVariable("HTTPS_PROXY");
344
+
345
+                clientProfile.HttpProfile = httpProfile;
346
+                /* 实例化要请求产品(以sms为例)的client对象
347
+                 * 第二个参数是地域信息,可以直接填写字符串ap-guangzhou,支持的地域列表参考 https://cloud.tencent.com/document/api/382/52071#.E5.9C.B0.E5.9F.9F.E5.88.97.E8.A1.A8 */
348
+                SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
349
+
350
+                /* 实例化一个请求对象,根据调用的接口和实际情况,可以进一步设置请求参数
351
+                 * 您可以直接查询SDK源码确定SendSmsRequest有哪些属性可以设置
352
+                 * 属性可能是基本类型,也可能引用了另一个数据结构
353
+                 * 推荐使用IDE进行开发,可以方便的跳转查阅各个接口和数据结构的文档说明 */
354
+                SendSmsRequest req = new SendSmsRequest();
355
+
356
+                /* 基本类型的设置:
357
+                 * SDK采用的是指针风格指定参数,即使对于基本类型您也需要用指针来对参数赋值。
358
+                 * SDK提供对基本类型的指针引用封装函数
359
+                 * 帮助链接:
360
+                 * 短信控制台: https://console.cloud.tencent.com/smsv2
361
+                 * 腾讯云短信小助手: https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81 */
362
+                /* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 */
363
+                // 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看
364
+                req.SmsSdkAppId = "1400467981";// "1304639164";
365
+
366
+                /* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 */
367
+                // 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看
368
+                req.SignName = signName;
369
+
370
+                /* 模板 ID: 必须填写已审核通过的模板 ID */
371
+                // 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看
372
+                req.TemplateId = templateId;// "449739";
373
+
374
+                /* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */
375
+                req.TemplateParamSet = new String[] { "DH20250808996" };
376
+
377
+                /* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号]
378
+                 * 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号*/
379
+                req.PhoneNumberSet = new String[] { "15639002755","17839539537" };
380
+
381
+                /* 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回 */
382
+                //req.SessionContext = "";
383
+
384
+                /* 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请联系 [腾讯云短信小助手] */
385
+                //req.ExtendCode = "";
386
+
387
+                /* 国内短信无需填写该项;国际/港澳台短信已申请独立 SenderId 需要填写该字段,默认使用公共 SenderId,无需填写该字段。注:月度使用量达到指定量级可申请独立 SenderId 使用,详情请联系 [腾讯云短信小助手](https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81)。 */
388
+                //req.SenderId = "";
389
+
390
+                SendSmsResponse resp = client.SendSmsSync(req);
391
+
392
+                // 输出json格式的字符串回包
393
+             //   Console.WriteLine(AbstractModel.ToJsonString(resp));
394
+
395
+                /* 当出现以下错误码时,快速解决方案参考
396
+                 * [FailedOperation.SignatureIncorrectOrUnapproved](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Afailedoperation.signatureincorrectorunapproved-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)
397
+                 * [FailedOperation.TemplateIncorrectOrUnapproved](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Afailedoperation.templateincorrectorunapproved-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)
398
+                 * [UnauthorizedOperation.SmsSdkAppIdVerifyFail](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Aunauthorizedoperation.smssdkappidverifyfail-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)
399
+                 * [UnsupportedOperation.ContainDomesticAndInternationalPhoneNumber](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Aunsupportedoperation.containdomesticandinternationalphonenumber-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)
400
+                 * 更多错误,可咨询[腾讯云助手](https://tccc.qcloud.com/web/im/index.html#/chat?webAppId=8fa15978f85cb41f7e2ea36920cb3ae1&title=Sms)
401
+                 */
402
+            }
403
+            catch (Exception e)
404
+            {
405
+                log.Error(e.Message);
406
+               // Console.WriteLine(e.ToString());
407
+            }
408
+            Console.Read();
409
+        } 
410
+    }
411
+    }
412
+
413
+
414
+ 

+ 109 - 83
CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/workorder/WorkOrderController.cs

@@ -15493,7 +15493,7 @@ namespace CallCenterApi.Interface.Controllers.workorder
15493 15493
             Model.T_Sys_UserAccount userModel = userBLL.GetModel(userId);
15494 15494
 
15495 15495
             if (userModel.F_RoleCode == "ZXHWY" || userModel.F_RoleCode == "ZXBZ" || userModel.F_RoleCode == "GLY" || userModel.F_RoleCode == "DDZG"||
15496
-                userModel.F_UserCode =="001")
15496
+                userModel.F_UserCode =="001" || userModel.F_RoleCode == "ZXLD")
15497 15497
             {
15498 15498
 
15499 15499
                 //StringBuilder sb = new StringBuilder();
@@ -15508,81 +15508,107 @@ namespace CallCenterApi.Interface.Controllers.workorder
15508 15508
 
15509 15509
 
15510 15510
                             #region 修改工单记录
15511
-                            modelT_Bus_WorkOrder.F_IsDelete = 1;
15512
-                            modelT_Bus_WorkOrder.F_DeleteUser= userModel.F_UserCode;
15513
-                            modelT_Bus_WorkOrder.F_DeleteTime = DateTime.Now;
15511
+                            //modelT_Bus_WorkOrder.F_IsDelete = 1;
15512
+                            //modelT_Bus_WorkOrder.F_DeleteUser= userModel.F_UserCode;
15513
+                            //modelT_Bus_WorkOrder.F_DeleteTime = DateTime.Now;
15514 15514
 
15515 15515
                            //办理过程
15516 15516
                            var Operation = new BLL.T_Bus_Operation().GetModelList($"F_WorkOrderId='{modelT_Bus_WorkOrder.F_WorkOrderId }'");
15517 15517
                            foreach (var cg in Operation)
15518 15518
                             {
15519
-                                cg.F_IsDelete = 1;
15520
-                                cg.F_DeleteTime = DateTime.Now;
15521
-                                new BLL.T_Bus_Operation().Update(cg);
15519
+                                //cg.F_IsDelete = 1;
15520
+                                //cg.F_DeleteTime = DateTime.Now;
15521
+                                new BLL.T_Bus_Operation().Delete(cg.F_Id);
15522 15522
                             }
15523 15523
 
15524 15524
                             //办理过程
15525 15525
                             var AssignedInfo = new BLL.T_Bus_AssignedInfo ().GetModelList($"F_WorkOrderId='{modelT_Bus_WorkOrder.F_WorkOrderId }'");
15526 15526
                             foreach (var cg in AssignedInfo)
15527 15527
                             {
15528
-                                cg.F_IsDelete = 1;
15529
-                                cg.F_DeleteUser = userModel.F_UserCode;
15530
-                                cg.F_DeleteTime = DateTime.Now;
15531
-                                new BLL.T_Bus_AssignedInfo().Update(cg);
15528
+                                //cg.F_IsDelete = 1;
15529
+                                //cg.F_DeleteUser = userModel.F_UserCode;
15530
+                                //cg.F_DeleteTime = DateTime.Now;
15531
+                                new BLL.T_Bus_AssignedInfo().Delete(cg.F_Id);
15532 15532
                             }
15533 15533
                             var AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next  ().GetModelList($"F_WorkOrderId='{modelT_Bus_WorkOrder.F_WorkOrderId }'");
15534 15534
                             foreach (var cg in AssignedInfo_Next)
15535 15535
                             {
15536
-                                cg.F_IsDelete = 1;
15537
-                                cg.F_DeleteUser = userModel.F_UserCode;
15538
-                                cg.F_DeleteTime = DateTime.Now;
15539
-                                new BLL.T_Bus_AssignedInfo_Next().Update(cg);
15536
+                                //cg.F_IsDelete = 1;
15537
+                                //cg.F_DeleteUser = userModel.F_UserCode;
15538
+                                //cg.F_DeleteTime = DateTime.Now;
15539
+                                new BLL.T_Bus_AssignedInfo_Next().Delete(cg.F_Id);
15540 15540
                             }
15541 15541
                             var Bus_Feedback = new BLL.T_Bus_Feedback ().GetModelList($"F_WorkOrderId='{modelT_Bus_WorkOrder.F_WorkOrderId }'");
15542 15542
                             foreach (var cg in Bus_Feedback)
15543 15543
                             {
15544
-                                cg.F_IsDelete = 1;
15545
-                                cg.F_DeleteUser = userModel.F_UserCode;
15546
-                                cg.F_DeleteTime = DateTime.Now;
15547
-                                new BLL.T_Bus_Feedback().Update(cg);
15544
+                                //cg.F_IsDelete = 1;
15545
+                                //cg.F_DeleteUser = userModel.F_UserCode;
15546
+                                //cg.F_DeleteTime = DateTime.Now;
15547
+                                new BLL.T_Bus_Feedback().Delete(cg.F_Id);
15548 15548
                             }
15549 15549
                             var Bus_Feedback_Next = new BLL.T_Bus_Feedback_Next().GetModelList($"F_WorkOrderId='{modelT_Bus_WorkOrder.F_WorkOrderId }'");
15550 15550
                             foreach (var cg in Bus_Feedback_Next)
15551 15551
                             {
15552
-                                cg.F_IsDelete = 1;
15553
-                                cg.F_DeleteUser = userModel.F_UserCode;
15554
-                                cg.F_DeleteTime = DateTime.Now;
15555
-                                new BLL.T_Bus_Feedback_Next().Update(cg);
15552
+                                //cg.F_IsDelete = 1;
15553
+                                //cg.F_DeleteUser = userModel.F_UserCode;
15554
+                                //cg.F_DeleteTime = DateTime.Now;
15555
+                                new BLL.T_Bus_Feedback_Next().Delete(cg.F_Id);
15556 15556
                             }
15557 15557
                             var Bus_DelayTime = new BLL.T_Bus_DelayTime ().GetModelList($"F_WorkOrderId='{modelT_Bus_WorkOrder.F_WorkOrderId }'");
15558 15558
                             foreach (var cg in Bus_DelayTime)
15559 15559
                             {
15560
-                                cg.F_IsDelete = 1;
15561
-                                cg.F_DeleteUser = userModel.F_UserCode;
15562
-                                cg.F_DeleteTime = DateTime.Now;
15563
-                                new BLL.T_Bus_DelayTime().Update(cg);
15560
+                                //cg.F_IsDelete = 1;
15561
+                                //cg.F_DeleteUser = userModel.F_UserCode;
15562
+                                //cg.F_DeleteTime = DateTime.Now;
15563
+                                new BLL.T_Bus_DelayTime().Delete(cg.F_Id);
15564 15564
                             }
15565 15565
 
15566
-                            var str = modelT_Bus_WorkOrder.F_WorkOrderId.Split('】');
15567
-                            if (str != null && str.Length > 0)
15568
-                                modelT_Bus_WorkOrder.F_WorkOrderId = $"【{str[1]}-作废-{DateTime.Now.ToString("yyyyMMdd")}】";
15569
-                            workorderBLL.Update(modelT_Bus_WorkOrder);
15570
-                            #endregion
15566
+                            //var str = modelT_Bus_WorkOrder.F_WorkOrderId.Split('】');
15567
+                            //if (str != null && str.Length > 0)
15568
+                            //    modelT_Bus_WorkOrder.F_WorkOrderId = $"【{str[1]}-作废-{DateTime.Now.ToString("yyyyMMdd")}】";
15571 15569
 
15572
-                            #region 插入操作记录
15573
-                            Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
15574
-                            oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
15575
-                            oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
15570
+                            string shuzi = modelT_Bus_WorkOrder.F_WorkOrderId;
15576 15571
 
15577
-                            string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
15578
-                            oper.F_Message = userinfo + " 删除了工单";
15579
-                            oper.F_CreateUser = userModel.F_UserCode;
15580
-                            oper.F_CreateTime = DateTime.Now;
15581
-                            oper.F_IsDelete = 0;
15572
+                            string[] yearstr = shuzi.Split('】');
15573
+                            string shuziyear = Regex.Replace(yearstr[0], "[^0-9]", "");
15574
+                            int yearid = int.Parse(shuziyear);
15582 15575
 
15583
-                            operBLL.Add(oper);
15576
+                            string[] strs = shuzi.Split('第');            
15577
+             
15578
+             
15579
+                            string shuzires = Regex.Replace(strs[1], "[^0-9]", "");
15580
+
15581
+                            int shuziid = int.Parse(shuzires);
15582
+
15583
+                            if (shuzi.Contains("频"))
15584
+                            {
15585
+                                DbHelperSQL.ExecuteSql(" delete from T_Bus_WorkOrderPFHelper where F_id='" + shuziid + "' and F_CreateTime like '%" + yearid + "%'");
15586
+                            }
15587
+                            else {
15588
+                                DbHelperSQL.ExecuteSql(" delete from T_Bus_WorkOrderHelper where F_id='" + shuziid + "' and F_CreateTime like '%" + yearid + "%'");
15589
+
15590
+                            }
15591
+
15592
+
15593
+
15594
+
15595
+                            workorderBLL.Delete(modelT_Bus_WorkOrder.F_Id);
15584 15596
                             #endregion
15585 15597
 
15598
+                            //#region 插入操作记录
15599
+                            //Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
15600
+                            //oper.F_WorkOrderId = modelT_Bus_WorkOrder.F_WorkOrderId;
15601
+                            //oper.F_State = modelT_Bus_WorkOrder.F_WorkState;
15602
+
15603
+                            //string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
15604
+                            //oper.F_Message = userinfo + " 删除了工单";
15605
+                            //oper.F_CreateUser = userModel.F_UserCode;
15606
+                            //oper.F_CreateTime = DateTime.Now;
15607
+                            //oper.F_IsDelete = 0;
15608
+
15609
+                            //operBLL.Add(oper);
15610
+                            //#endregion
15611
+
15586 15612
 
15587 15613
                     
15588 15614
 
@@ -15601,80 +15627,80 @@ namespace CallCenterApi.Interface.Controllers.workorder
15601 15627
 
15602 15628
 
15603 15629
                                 #region 修改工单记录
15604
-                                mainmodelT_Bus_WorkOrder.F_IsDelete = 1;
15605
-                                mainmodelT_Bus_WorkOrder.F_DeleteUser = userModel.F_UserCode;
15606
-                                mainmodelT_Bus_WorkOrder.F_DeleteTime = DateTime.Now;
15630
+                                //mainmodelT_Bus_WorkOrder.F_IsDelete = 1;
15631
+                                //mainmodelT_Bus_WorkOrder.F_DeleteUser = userModel.F_UserCode;
15632
+                                //mainmodelT_Bus_WorkOrder.F_DeleteTime = DateTime.Now;
15607 15633
 
15608 15634
                                 //办理过程
15609 15635
                                 var Operation = new BLL.T_Bus_Operation().GetModelList($"F_WorkOrderId='{mainmodelT_Bus_WorkOrder.F_WorkOrderId }'");
15610 15636
                                 foreach (var cg in Operation)
15611 15637
                                 {
15612
-                                    cg.F_IsDelete = 1;
15613
-                                    cg.F_DeleteTime = DateTime.Now;
15614
-                                    new BLL.T_Bus_Operation().Update(cg);
15638
+                                    //cg.F_IsDelete = 1;
15639
+                                    //cg.F_DeleteTime = DateTime.Now;
15640
+                                    new BLL.T_Bus_Operation().Delete(cg.F_Id);
15615 15641
                                 }
15616 15642
 
15617 15643
                                 //办理过程
15618 15644
                                 var AssignedInfo = new BLL.T_Bus_AssignedInfo().GetModelList($"F_WorkOrderId='{mainmodelT_Bus_WorkOrder.F_WorkOrderId }'");
15619 15645
                                 foreach (var cg in AssignedInfo)
15620 15646
                                 {
15621
-                                    cg.F_IsDelete = 1;
15622
-                                    cg.F_DeleteUser = userModel.F_UserCode;
15623
-                                    cg.F_DeleteTime = DateTime.Now;
15624
-                                    new BLL.T_Bus_AssignedInfo().Update(cg);
15647
+                                    //cg.F_IsDelete = 1;
15648
+                                    //cg.F_DeleteUser = userModel.F_UserCode;
15649
+                                    //cg.F_DeleteTime = DateTime.Now;
15650
+                                    new BLL.T_Bus_AssignedInfo().Delete(cg.F_Id);
15625 15651
                                 }
15626 15652
                                 var AssignedInfo_Next = new BLL.T_Bus_AssignedInfo_Next().GetModelList($"F_WorkOrderId='{mainmodelT_Bus_WorkOrder.F_WorkOrderId }'");
15627 15653
                                 foreach (var cg in AssignedInfo_Next)
15628 15654
                                 {
15629
-                                    cg.F_IsDelete = 1;
15630
-                                    cg.F_DeleteUser = userModel.F_UserCode;
15631
-                                    cg.F_DeleteTime = DateTime.Now;
15632
-                                    new BLL.T_Bus_AssignedInfo_Next().Update(cg);
15655
+                                    //cg.F_IsDelete = 1;
15656
+                                    //cg.F_DeleteUser = userModel.F_UserCode;
15657
+                                    //cg.F_DeleteTime = DateTime.Now;
15658
+                                    new BLL.T_Bus_AssignedInfo_Next().Delete(cg.F_Id);
15633 15659
                                 }
15634 15660
                                 var Bus_Feedback = new BLL.T_Bus_Feedback().GetModelList($"F_WorkOrderId='{mainmodelT_Bus_WorkOrder.F_WorkOrderId }'");
15635 15661
                                 foreach (var cg in Bus_Feedback)
15636 15662
                                 {
15637
-                                    cg.F_IsDelete = 1;
15638
-                                    cg.F_DeleteUser = userModel.F_UserCode;
15639
-                                    cg.F_DeleteTime = DateTime.Now;
15640
-                                    new BLL.T_Bus_Feedback().Update(cg);
15663
+                                    //cg.F_IsDelete = 1;
15664
+                                    //cg.F_DeleteUser = userModel.F_UserCode;
15665
+                                    //cg.F_DeleteTime = DateTime.Now;
15666
+                                    new BLL.T_Bus_Feedback().Delete(cg.F_Id);
15641 15667
                                 }
15642 15668
                                 var Bus_Feedback_Next = new BLL.T_Bus_Feedback_Next().GetModelList($"F_WorkOrderId='{mainmodelT_Bus_WorkOrder.F_WorkOrderId }'");
15643 15669
                                 foreach (var cg in Bus_Feedback_Next)
15644 15670
                                 {
15645
-                                    cg.F_IsDelete = 1;
15646
-                                    cg.F_DeleteUser = userModel.F_UserCode;
15647
-                                    cg.F_DeleteTime = DateTime.Now;
15648
-                                    new BLL.T_Bus_Feedback_Next().Update(cg);
15671
+                                    //cg.F_IsDelete = 1;
15672
+                                    //cg.F_DeleteUser = userModel.F_UserCode;
15673
+                                    //cg.F_DeleteTime = DateTime.Now;
15674
+                                    new BLL.T_Bus_Feedback_Next().Delete(cg.F_Id);
15649 15675
                                 }
15650 15676
                                 var Bus_DelayTime = new BLL.T_Bus_DelayTime().GetModelList($"F_WorkOrderId='{mainmodelT_Bus_WorkOrder.F_WorkOrderId }'");
15651 15677
                                 foreach (var cg in Bus_DelayTime)
15652 15678
                                 {
15653
-                                    cg.F_IsDelete = 1;
15654
-                                    cg.F_DeleteUser = userModel.F_UserCode;
15655
-                                    cg.F_DeleteTime = DateTime.Now;
15656
-                                    new BLL.T_Bus_DelayTime().Update(cg);
15679
+                                    //cg.F_IsDelete = 1;
15680
+                                    //cg.F_DeleteUser = userModel.F_UserCode;
15681
+                                    //cg.F_DeleteTime = DateTime.Now;
15682
+                                    new BLL.T_Bus_DelayTime().Delete(cg.F_Id);
15657 15683
                                 }
15658 15684
 
15659
-                                var str = mainmodelT_Bus_WorkOrder.F_WorkOrderId.Split('】');
15660
-                                if (str != null && str.Length > 0)
15661
-                                    mainmodelT_Bus_WorkOrder.F_WorkOrderId = $"【{str[1]}-作废-{DateTime.Now.ToString("yyyyMMdd")}】";
15662
-                                workorderBLL.Update(mainmodelT_Bus_WorkOrder);
15685
+                                //var str = mainmodelT_Bus_WorkOrder.F_WorkOrderId.Split('】');
15686
+                                //if (str != null && str.Length > 0)
15687
+                                //    mainmodelT_Bus_WorkOrder.F_WorkOrderId = $"【{str[1]}-作废-{DateTime.Now.ToString("yyyyMMdd")}】";
15688
+                                workorderBLL.Delete(mainmodelT_Bus_WorkOrder.F_Id);
15663 15689
                                 #endregion
15664 15690
 
15665
-                                #region 插入操作记录
15666
-                                Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
15667
-                                oper.F_WorkOrderId = mainmodelT_Bus_WorkOrder.F_WorkOrderId;
15668
-                                oper.F_State = mainmodelT_Bus_WorkOrder.F_WorkState;
15691
+                                //#region 插入操作记录
15692
+                                //Model.T_Bus_Operation oper = new Model.T_Bus_Operation();
15693
+                                //oper.F_WorkOrderId = mainmodelT_Bus_WorkOrder.F_WorkOrderId;
15694
+                                //oper.F_State = mainmodelT_Bus_WorkOrder.F_WorkState;
15669 15695
 
15670
-                                string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
15671
-                                oper.F_Message = userinfo + " 删除了工单";
15672
-                                oper.F_CreateUser = userModel.F_UserCode;
15673
-                                oper.F_CreateTime = DateTime.Now;
15674
-                                oper.F_IsDelete = 0;
15696
+                                //string userinfo = userModel.depname + "-" + userModel.F_UserName + "(" + userModel.F_UserCode + ")";
15697
+                                //oper.F_Message = userinfo + " 删除了工单";
15698
+                                //oper.F_CreateUser = userModel.F_UserCode;
15699
+                                //oper.F_CreateTime = DateTime.Now;
15700
+                                //oper.F_IsDelete = 0;
15675 15701
 
15676
-                                operBLL.Add(oper);
15677
-                                #endregion
15702
+                                //operBLL.Add(oper);
15703
+                                //#endregion
15678 15704
 
15679 15705
 
15680 15706
                             }

+ 2 - 3
CallCenterCommon/CallCenter.Utility/CallCenter.Utility.csproj

@@ -35,9 +35,8 @@
35 35
       <HintPath>..\..\packages\log4net.2.0.7\lib\net45-full\log4net.dll</HintPath>
36 36
       <Private>True</Private>
37 37
     </Reference>
38
-    <Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
39
-      <HintPath>..\..\packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
40
-      <Private>True</Private>
38
+    <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
39
+      <HintPath>..\..\packages\Newtonsoft.Json.13.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
41 40
     </Reference>
42 41
     <Reference Include="NPOI, Version=2.3.0.0, Culture=neutral, PublicKeyToken=0df73ec7942b34e1, processorArchitecture=MSIL">
43 42
       <HintPath>..\..\packages\NPOI.2.3.0\lib\net40\NPOI.dll</HintPath>