|
|
@@ -14,7 +14,9 @@ using System.Data;
|
|
14
|
14
|
using System.IO;
|
|
15
|
15
|
using System.Linq;
|
|
16
|
16
|
using System.Net;
|
|
|
17
|
+using System.Net.Security;
|
|
17
|
18
|
using System.Security.Cryptography;
|
|
|
19
|
+using System.Security.Cryptography.X509Certificates;
|
|
18
|
20
|
using System.Text;
|
|
19
|
21
|
using System.Web;
|
|
20
|
22
|
using System.Web.Mvc;
|
|
|
@@ -33,39 +35,43 @@ namespace CallCenterApi.Interface.Controllers
|
|
33
|
35
|
// int templateId = 392016; // NOTE: 这里的模板ID`7839`只是一个示例,真实的模板ID需要在短信控制台中申请
|
|
34
|
36
|
// 签名
|
|
35
|
37
|
string smsSign = "巩义市12345市长热线"; // NOTE: 这里的签名只是示例,请使用真实的已申请的签名, 签名参数使用的是`签名内容`,而不是`签名ID`
|
|
36
|
|
-
|
|
|
38
|
+
|
|
|
39
|
+ Log log = LogFactory.GetLogger("SMSSingleshot");
|
|
|
40
|
+
|
|
37
|
41
|
/// <summary>
|
|
38
|
42
|
/// 单发短信
|
|
39
|
43
|
/// </summary>
|
|
40
|
44
|
/// <param name="phone"></param>
|
|
41
|
45
|
/// <param name="cont"></param>
|
|
42
|
|
- public SmsSingleSenderResult SMSSingleshot(int templateId, string[] msg, string cusphone)
|
|
|
46
|
+ public SmsSingleSenderResult SMSSingleshot(int templateId, string[] msg, string cusphone)
|
|
43
|
47
|
{
|
|
44
|
|
-
|
|
45
|
|
- try
|
|
46
|
|
- {
|
|
47
|
|
- SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
|
|
48
|
|
- var result = ssender.sendWithParam("86", cusphone,
|
|
49
|
|
- templateId, msg, smsSign, "", "");
|
|
50
|
|
- return result;
|
|
51
|
|
- }
|
|
52
|
|
- catch (JSONException e)
|
|
53
|
|
- {
|
|
54
|
|
- Console.WriteLine(e);
|
|
55
|
|
- return null;
|
|
56
|
|
- }
|
|
57
|
|
- catch (HTTPException e)
|
|
58
|
|
- {
|
|
59
|
|
- Console.WriteLine(e);
|
|
60
|
|
- return null;
|
|
61
|
|
- }
|
|
62
|
|
- catch (Exception e)
|
|
63
|
|
- {
|
|
64
|
|
- Console.WriteLine(e);
|
|
65
|
|
- return null;
|
|
66
|
|
- }
|
|
67
|
|
-
|
|
68
|
|
-
|
|
|
48
|
+ try
|
|
|
49
|
+ {
|
|
|
50
|
+ ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
|
|
|
51
|
+ SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
|
|
|
52
|
+ var result = ssender.sendWithParam("86", cusphone,
|
|
|
53
|
+ templateId, msg, smsSign, "", "");
|
|
|
54
|
+ return result;
|
|
|
55
|
+ }
|
|
|
56
|
+ catch (JSONException e)
|
|
|
57
|
+ {
|
|
|
58
|
+ log.Error("发送短信失败", e);
|
|
|
59
|
+ return null;
|
|
|
60
|
+ }
|
|
|
61
|
+ catch (HTTPException e)
|
|
|
62
|
+ {
|
|
|
63
|
+ log.Error("发送短信失败", e);
|
|
|
64
|
+ return null;
|
|
|
65
|
+ }
|
|
|
66
|
+ catch (Exception e)
|
|
|
67
|
+ {
|
|
|
68
|
+ log.Error("发送短信失败", e);
|
|
|
69
|
+ return null;
|
|
|
70
|
+ }
|
|
|
71
|
+ }
|
|
|
72
|
+ private static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
|
|
|
73
|
+ {
|
|
|
74
|
+ return true; //总是接受
|
|
69
|
75
|
}
|
|
70
|
76
|
/// <summary>
|
|
71
|
77
|
/// 群发短信
|
|
|
@@ -76,6 +82,7 @@ namespace CallCenterApi.Interface.Controllers
|
|
76
|
82
|
{
|
|
77
|
83
|
try
|
|
78
|
84
|
{
|
|
|
85
|
+ ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
|
|
79
|
86
|
SmsMultiSender msender = new SmsMultiSender(appid, appkey);
|
|
80
|
87
|
var sresult = msender.sendWithParam("86", phone, templateId,
|
|
81
|
88
|
msg, smsSign, "", "");
|
|
|
@@ -83,17 +90,17 @@ namespace CallCenterApi.Interface.Controllers
|
|
83
|
90
|
}
|
|
84
|
91
|
catch (JSONException e)
|
|
85
|
92
|
{
|
|
86
|
|
- Console.WriteLine(e);
|
|
|
93
|
+ log.Error("发送短信失败", e);
|
|
87
|
94
|
return null;
|
|
88
|
95
|
}
|
|
89
|
96
|
catch (HTTPException e)
|
|
90
|
97
|
{
|
|
91
|
|
- Console.WriteLine(e);
|
|
|
98
|
+ log.Error("发送短信失败", e);
|
|
92
|
99
|
return null;
|
|
93
|
100
|
}
|
|
94
|
101
|
catch (Exception e)
|
|
95
|
102
|
{
|
|
96
|
|
- Console.WriteLine(e);
|
|
|
103
|
+ log.Error("发送短信失败", e);
|
|
97
|
104
|
return null;
|
|
98
|
105
|
}
|
|
99
|
106
|
}
|