Browse Source

发送短信

liyuanyuan 4 years ago
parent
commit
2abc195fea

+ 10 - 1
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/Base/BaseController.cs

14
         {
14
         {
15
             get
15
             get
16
             {
16
             {
17
-                return (FormsPrincipal<Cache.Models.CurrentUserInfo>)base.User;
17
+                try
18
+                {
19
+                    return (FormsPrincipal<Cache.Models.CurrentUserInfo>)base.User;
20
+                }
21
+                catch (Exception)
22
+                {
23
+
24
+                    return null;
25
+                }
26
+              
18
             }
27
             }
19
         }
28
         }
20
         /// <summary>
29
         /// <summary>

+ 38 - 30
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/SMSController.cs

1
 
1
 
2
-using System;
3
-using System.Collections.Generic;
4
-using System.Linq;
5
-using System.Web;
6
-using System.Web.Mvc;
7
-using CallCenterApi.Interface.Controllers.Base;
8
-using System.Data;
9
 using CallCenter.Utility;
2
 using CallCenter.Utility;
10
-using System.Configuration;
11
 //using Top.Api;
3
 //using Top.Api;
12
 //using Top.Api.Request;
4
 //using Top.Api.Request;
13
 //using Top.Api.Response;
5
 //using Top.Api.Response;
14
 using CallCenterApi.Common;
6
 using CallCenterApi.Common;
15
-using System.Net;
16
-using System.Text;
7
+using CallCenterApi.Interface.Controllers.Base;
17
 using Newtonsoft.Json;
8
 using Newtonsoft.Json;
18
-using System.Xml;
9
+using Newtonsoft.Json.Linq;
10
+using System;
11
+using System.Collections.Generic;
12
+using System.Data;
19
 using System.IO;
13
 using System.IO;
14
+using System.Linq;
15
+using System.Net;
20
 using System.Security.Cryptography;
16
 using System.Security.Cryptography;
21
-using Newtonsoft.Json.Linq;
17
+using System.Text;
18
+using System.Web;
19
+using System.Web.Mvc;
22
 
20
 
23
 namespace CallCenterApi.Interface.Controllers
21
 namespace CallCenterApi.Interface.Controllers
24
 {
22
 {
27
         #region 接收短信
25
         #region 接收短信
28
         //string url = "http://47.92.26.244/sms.aspx?";
26
         //string url = "http://47.92.26.244/sms.aspx?";
29
         //string account = "yhyy"; string password = "yhyy190903";
27
         //string account = "yhyy"; string password = "yhyy190903";
30
-        string url = "http://sdk.lx198.com/sdk/";                                      
28
+        string url = "http://sdk.lx198.com/sdk/";
31
         string accName = "15003877636"; string password = "759089";
29
         string accName = "15003877636"; string password = "759089";
30
+
31
+        // string accName = "13783690587"; string password = "yhyy66";
32
         /// <summary>
32
         /// <summary>
33
         /// MD5加密
33
         /// MD5加密
34
         /// </summary>
34
         /// </summary>
63
 
63
 
64
         public string SendSMS(string mobile,  string sendTime, string content,int sendWay, int MBID )
64
         public string SendSMS(string mobile,  string sendTime, string content,int sendWay, int MBID )
65
         {
65
         {
66
-            WebClient web = new WebClient();
67
-            web.Encoding = Encoding.UTF8;
66
+            //WebClient web = new WebClient();
67
+            //web.Encoding = Encoding.UTF8;
68
             content += "【郑州颐和医院】";
68
             content += "【郑州颐和医院】";
69
            // url += "send?accName="+ accName + "&accPwd="+ Md5 (password) + "&aimcodes=" + mobile.Trim() + "&content=" + content.Trim() + "&schTime=" + DateTime .Now .ToString ("yyyy-MM-dd HH:mm:ss") + "&dataType=json& msgId=" + sendTime.Trim() + "454163135423543";
69
            // url += "send?accName="+ accName + "&accPwd="+ Md5 (password) + "&aimcodes=" + mobile.Trim() + "&content=" + content.Trim() + "&schTime=" + DateTime .Now .ToString ("yyyy-MM-dd HH:mm:ss") + "&dataType=json& msgId=" + sendTime.Trim() + "454163135423543";
70
-
70
+           string param= string.Empty;
71
             string mbid = DateTime.Now.ToString("yyyyMMddHHmmss");
71
             string mbid = DateTime.Now.ToString("yyyyMMddHHmmss");
72
             if (!string.IsNullOrEmpty(sendTime))
72
             if (!string.IsNullOrEmpty(sendTime))
73
             {
73
             {
74
                 string  st = Convert.ToDateTime(sendTime).ToString ("yyyy-MM-dd HH:mm:ss");
74
                 string  st = Convert.ToDateTime(sendTime).ToString ("yyyy-MM-dd HH:mm:ss");
75
-                url += "send?accName=" + accName + "&accPwd=" + Md5(password) + "&aimcodes=" + mobile.Trim() + "&content=" + content.Trim() + "&schTime=" + st + "&dataType=json& msgId=" + mbid;// "454163135423543";
75
+                param = "accName=" + accName + "&accPwd=" + Md5(password) + "&aimcodes=" + mobile.Trim() + "&content=" + content.Trim() + "&schTime=" + st + "&dataType=json& msgId=" + mbid;// "454163135423543";
76
+               // url += "send?accName=" + accName + "&accPwd=" + Md5(password) + "&aimcodes=" + mobile.Trim() + "&content=" + content.Trim() + "&schTime=" + st + "&dataType=json& msgId=" + mbid;// "454163135423543";
77
+
76
             }
78
             }
77
 
79
 
78
             else {
80
             else {
81
+              //  url += "send?accName=" + accName + "&accPwd=" + Md5(password) + "&aimcodes=" + mobile.Trim() + "&content=" + content.Trim() + "&schTime=" + "&dataType=json& msgId=" + mbid;// "454163135423543";
79
 
82
 
80
-                url += "send?accName=" + accName + "&accPwd=" + Md5(password) + "&aimcodes=" + mobile.Trim() + "&content=" + content.Trim() + "&schTime=" + "&dataType=json& msgId=" + mbid;// "454163135423543";
83
+                param = "accName=" + accName + "&accPwd=" + Md5(password) + "&aimcodes=" + mobile.Trim() + "&content=" + content.Trim() + "&schTime=" + "&dataType=json& msgId=" + mbid;// "454163135423543";
81
             }
84
             }
82
-
83
-            string Dataaa = web.DownloadString(url);//这一句话就能请求到数据了
85
+             string Dataaa=HttpMethods.HttpPost(url +"send", param);
86
+         //  string Dataaa = web.DownloadString(url);//这一句话就能请求到数据了
84
             JObject jo = (JObject)JsonConvert.DeserializeObject(Dataaa);
87
             JObject jo = (JObject)JsonConvert.DeserializeObject(Dataaa);
85
             string replyCode = jo["replyCode"].ToString();
88
             string replyCode = jo["replyCode"].ToString();
86
             string replyMsg = jo["replyMsg"].ToString();
89
             string replyMsg = jo["replyMsg"].ToString();
87
 
90
 
88
             string[] tel = mobile.Split(',');
91
             string[] tel = mobile.Split(',');
89
 
92
 
90
-            foreach (var item in tel)
91
-            {
92
 
93
 
93
-                if (sendWay == 0)//立即发送
94
-                {
95
-                    AddSMSList(sendWay, null, DateTime.Now, Convert.ToInt32(replyCode), item, content, MBID);
96
-                }
97
-                else //定时发送
94
+            if (replyCode == "1")
95
+            {
96
+                foreach (var item in tel)
98
                 {
97
                 {
99
-                    AddSMSList(sendWay, Convert.ToDateTime(sendTime), Convert.ToDateTime(sendTime), Convert.ToInt32(replyCode), item, content, MBID);
98
+
99
+                    if (sendWay == 0)//立即发送
100
+                    {
101
+                        AddSMSList(sendWay, null, DateTime.Now, Convert.ToInt32(replyCode), item, content, MBID);
102
+                    }
103
+                    else //定时发送
104
+                    {
105
+                        AddSMSList(sendWay, Convert.ToDateTime(sendTime), Convert.ToDateTime(sendTime), Convert.ToInt32(replyCode), item, content, MBID);
106
+
107
+                    }
100
 
108
 
101
                 }
109
                 }
102
 
110
 
103
-            }
104
-            if (replyCode == "1")
105
                 return "发送成功";
111
                 return "发送成功";
112
+            }
113
+               
106
             else
114
             else
107
                 return "发送失败";
115
                 return "发送失败";
108
 
116