1550076451 11 ay önce
ebeveyn
işleme
95f1a14e15

+ 5 - 0
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Configs/system.config

@@ -53,4 +53,9 @@
53 53
   <add key="AccessKeyID" value="LTAI5t74YpfDp5ULqyR78bPy" />
54 54
   <!-- 设置归属地查询AccessKeySecret -->
55 55
   <add key="AccessKeySecret" value="elRaejiGbEEp3SMy9uNNR2QkLd9ZjF" />
56
+
57
+ 
58
+  <add key="FeiShui_AppId" value="cli_a7242e417af7900c" />
59
+  
60
+  <add key="FeiShui_AppSecret" value="QJIWfIUKJjVLZgEl5JqxoguOYlnCphV5" />
56 61
 </appSettings>

+ 10 - 0
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/HomeController.cs

@@ -207,7 +207,17 @@ namespace CallCenterApi.Interface.Controllers
207 207
         {
208 208
             return "sss  " + name + pass;
209 209
         }
210
+        public ActionResult SendMessage(string mobile,string msg)
211
+        {
212
+            var result= FeiShuiHelper.SendMsg(mobile, msg);
213
+            return Content(result);
214
+        }
210 215
 
216
+        public ActionResult GetMobile(string code)
217
+        {
218
+            var result = FeiShuiHelper.GetUser(code);
219
+            return Content(result);
220
+        }
211 221
         /// <summary>
212 222
         /// 抛出HTTP 500
213 223
         /// </summary>

+ 72 - 1
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/Login/LoginController.cs

@@ -96,7 +96,78 @@ namespace CallCenterApi.Interface.Controllers
96 96
                 return Error("授权过期,请联系系统厂家。");
97 97
             }
98 98
         }
99
-      
99
+
100
+        //飞书免登陆
101
+        public ActionResult FeiShuilogin(string code)
102
+        {
103
+            var model = FeiShuiHelper.GetUser(code);
104
+            if (model!=null&&model.Length>=11)
105
+            {
106
+                model = model.Substring(model.Length - 11); ;
107
+            }
108
+             var  mdoel = new BLL.T_Sys_UserAccount().GetModelList($"F_Mobile='{model}' and  F_DeleteFlag=0");
109
+
110
+                if (mdoel != null&& mdoel.Count>0)
111
+                {
112
+                  var loginUser = mdoel.FirstOrDefault();
113
+                    string deptcode = "";
114
+                    Model.T_Sys_Department deptModel = new BLL.T_Sys_Department().GetModel(loginUser.F_DeptId);
115
+                    if (deptModel != null)
116
+                    {
117
+                        deptcode = deptModel.F_DeptCode;
118
+                    }
119
+                    //写入登录日志
120
+                    new CallCenterApi.BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
121
+                    {
122
+                        F_LoginName = loginUser.F_UserName,
123
+                        F_LoginId = loginUser.F_UserId,
124
+                        F_Result = "登录成功",
125
+                        F_LoginIP = Common.DTRequest.GetIP(),
126
+                        F_Hostname = Common.DTRequest.GetIP(),
127
+                        F_LoginDate = DateTime.Now,
128
+                        F_Remark = "",
129
+                        F_State = 0
130
+                    });
131
+                    Cache.Models.CurrentUserInfo currentUserInfo = new Cache.Models.CurrentUserInfo()
132
+                    {
133
+                        F_UserId = loginUser.F_UserId,
134
+                        F_UserName = loginUser.F_UserName,
135
+                        F_UserCode = loginUser.F_UserCode,
136
+                        F_GroupId = loginUser.F_GroupId,
137
+                        F_RoleId = loginUser.F_RoleId,
138
+                        F_SeartGroupID = loginUser.F_SeartGroupID,
139
+                        F_WorkNumber = loginUser.F_WorkNumber,
140
+                        F_DeptId = loginUser.F_DeptId,
141
+                        F_DeptCode = deptcode
142
+                    };
143
+                    var token = FormsPrincipal<Cache.Models.CurrentUserInfo>.GetCookieValue(currentUserInfo.F_UserCode, currentUserInfo);
144
+
145
+                    //放入redis缓存
146
+                    RedisHelper.StringSet(token, currentUserInfo.ToJson(), new TimeSpan(24, 0, 0));
147
+
148
+                    return Success("登录成功", new
149
+                    {
150
+                        token = token
151
+                    });
152
+                }
153
+                else
154
+                {
155
+                    int rr = new BLL.T_Sys_LoginLogs().Add(new Model.T_Sys_LoginLogs()
156
+                    {
157
+                        F_LoginName = "飞书登录",
158
+                        F_LoginId = -1,
159
+                        F_Result = "登录失败:Code-" + code  + ";" ,
160
+                        F_LoginIP = Common.DTRequest.GetIP(),
161
+                        F_Hostname = Common.DTRequest.GetIP(),
162
+                        F_LoginDate = DateTime.Now,
163
+                        F_Remark = "",
164
+                        F_State = 0
165
+                    });
166
+                    return Error("用户不存在,请重新登录");
167
+                }
168
+
169
+        }
170
+
100 171
         public ActionResult Logout(string token = "")
101 172
         {
102 173
             int userId = CurrentUser.UserData.F_UserId;

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

@@ -77,6 +77,7 @@
77 77
     <Compile Include="DirFileHelper.cs" />
78 78
     <Compile Include="EncryptHelper.cs" />
79 79
     <Compile Include="Extend\ExtLinq.cs" />
80
+    <Compile Include="FeiShuiHelper.cs" />
80 81
     <Compile Include="FileUp.cs" />
81 82
     <Compile Include="Linq\PredicateExtensionses.cs" />
82 83
     <Compile Include="NPOI\Ification.cs" />

+ 358 - 0
codegit/CallCenterCommon/CallCenter.Utility/FeiShuiHelper.cs

@@ -0,0 +1,358 @@
1
+using Newtonsoft.Json;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.IO;
5
+using System.Linq;
6
+using System.Net;
7
+using System.Net.Http;
8
+using System.Net.Http.Headers;
9
+using System.Text;
10
+
11
+namespace CallCenter.Utility
12
+{
13
+    public  class FeiShuiHelper
14
+    {
15
+        static  string app_id = Configs.GetValue("FeiShui_AppId");
16
+        static  string app_secret = Configs.GetValue("FeiShui_AppSecret");
17
+        //获取tenant_access_token
18
+        private static string GetTenantAccessToken()
19
+        {
20
+            string result = string.Empty;
21
+            var param = new
22
+            {
23
+                app_id = app_id,
24
+                app_secret = app_secret,
25
+               
26
+            };
27
+            var strresult = HttpMethods.HttpPost("https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal", param.ToJson(),"application/json; charset=utf-8");
28
+            if (!string.IsNullOrEmpty(strresult))
29
+            {
30
+                var resultobj = strresult.ToJObject();
31
+                if (resultobj["code"].ToString() != "0")
32
+                {
33
+                    LogFactory.GetLogger("tenant_access_token").Error(strresult);
34
+                    result = resultobj["msg"].ToString();
35
+                }
36
+                else
37
+                {
38
+                    result = resultobj["tenant_access_token"].ToString();
39
+                }
40
+            }
41
+            return result;
42
+        }
43
+        //获取user_access_token
44
+        private static string GetUserAccessToken(string code)
45
+        {
46
+            string result = string.Empty;
47
+            var param = new
48
+            {
49
+                grant_type = "authorization_code",
50
+                client_id = app_id,
51
+                client_secret=app_secret,
52
+                code= code
53
+
54
+            };
55
+            var strresult = HttpMethods.HttpPost("https://open.feishu.cn/open-apis/authen/v2/oauth/token", param.ToJson(), "application/json; charset=utf-8");
56
+            if (!string.IsNullOrEmpty(strresult))
57
+            {
58
+                var resultobj = strresult.ToJObject();
59
+                if (resultobj["code"].ToString() != "0")
60
+                {
61
+                    LogFactory.GetLogger("error").Error(strresult);
62
+                    result = resultobj["error"].ToString();
63
+                }
64
+                else
65
+                {
66
+                    result = resultobj["access_token"].ToString();
67
+                }
68
+            }
69
+            return result;
70
+        }
71
+        //通过手机号获取用户id
72
+        private static string GetUserid(string mobile)
73
+        {
74
+            string result = string.Empty;
75
+
76
+            //Dictionary<string, object> param = new Dictionary<string, object>();
77
+            //param.Add("mobiles", new string[] { mobile });
78
+            //param.Add("include_resigned", true);
79
+            
80
+            var postData = new { mobiles = new string[] { mobile }, include_resigned = true };
81
+            var strresult = SendPostRequest
82
+         ("https://open.feishu.cn/open-apis/contact/v3/users/batch_get_id?user_id_type=user_id", postData);
83
+            if (!string.IsNullOrEmpty(strresult))
84
+            {
85
+                generalResult<userslist> resultobj = JsonConvert.
86
+                    DeserializeObject<generalResult<userslist>>(strresult);
87
+                if (resultobj.code != "0")
88
+                {
89
+                    LogFactory.GetLogger("GetUserid").Error(resultobj.msg);
90
+                    result = resultobj.msg;
91
+                }
92
+                else
93
+                {
94
+                   if (resultobj.data!=null&& resultobj.data.user_list.Count>0)
95
+                    result = resultobj.data.user_list[0].user_id;
96
+                }
97
+            }
98
+            return result;
99
+        }
100
+        //发送消息
101
+        public static string SendMsg(string mobile,string msg)
102
+        {
103
+            string userid = GetUserid(mobile);
104
+            if (string.IsNullOrEmpty(mobile))
105
+                return "";
106
+            Guid guid = Guid.NewGuid();
107
+            string uuid = guid.ToString();
108
+            string result = string.Empty;
109
+            //Dictionary<string, object> param = new Dictionary<string, object>();
110
+            //param.Add("receive_id", userid);
111
+            //param.Add("msg_type", "text");
112
+            //param.Add( "content", "{\"text\":\"" + msg + "\"}");
113
+            //param.Add("uuid", uuid);
114
+
115
+            var postData = new { receive_id = userid, msg_type = "post",
116
+                content = "{\"zh_cn\":{\"title\":\""+ msg + "\",\"content\":[[{\"tag\":\"text\",\"text\":\"地址 :\"},{\"tag\":\"a\",\"href\":\"http://www.feishu.cn\",\"text\":\"超链接\"}]]}}",
117
+                uuid = uuid,
118
+            };
119
+            var strresult = SendPostRequest
120
+         ("https://open.feishu.cn/open-apis/im/v1/messages?receive_id_type=user_id", postData);
121
+            if (!string.IsNullOrEmpty(strresult))
122
+            {
123
+                var resultobj = strresult.ToJObject();
124
+                if (resultobj["code"].ToString() != "0")
125
+                {
126
+                    LogFactory.GetLogger("SendMsg").Error(strresult);
127
+                    result = resultobj["msg"].ToString();
128
+                }
129
+                else
130
+                {
131
+                    result =  resultobj.ToJson() ;
132
+                }
133
+            }
134
+            return result;
135
+        }
136
+
137
+        //获取单个用户
138
+        public static string GetUser(string code)
139
+        {
140
+            string token = GetUserAccessToken(code);
141
+           
142
+            Guid guid = Guid.NewGuid();
143
+            string uuid = guid.ToString();
144
+            string result = string.Empty;
145
+            var strresult = SendGetRequest("https://open.feishu.cn/open-apis/authen/v1/user_info",token);
146
+            if (!string.IsNullOrEmpty(strresult))
147
+            {
148
+                generalResult<user> resultobj = JsonConvert.DeserializeObject<generalResult<user>>(strresult);
149
+                if (resultobj.code != "0")
150
+                {
151
+                    LogFactory.GetLogger("GetUser").Error(resultobj.msg);
152
+                    result = resultobj.msg;
153
+                }
154
+                else
155
+                {
156
+                    if (resultobj.data != null )
157
+                        result = resultobj.data.mobile;
158
+                }
159
+            }
160
+            return result;
161
+        }
162
+        public static string SendGetRequest(string url, string authToken)
163
+        {
164
+            // 创建请求对象
165
+            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
166
+            request.Method = "GET";
167
+            request.ContentType = "application/json; charset=utf-8"; // 设置 Content-Type
168
+            request.Headers.Add("Authorization", $"Bearer {authToken}");
169
+
170
+            // 如果需要忽略 SSL 证书验证(仅测试环境使用)
171
+            // ServicePointManager.ServerCertificateValidationCallback += 
172
+            //     (sender, certificate, chain, sslPolicyErrors) => true;
173
+
174
+            try
175
+            {
176
+                // 获取响应
177
+                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
178
+                using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
179
+                {
180
+                    return reader.ReadToEnd();
181
+                }
182
+            }
183
+            catch (WebException ex)
184
+            {
185
+                // 处理错误响应
186
+                if (ex.Response is HttpWebResponse errorResponse)
187
+                {
188
+                    using (Stream errorStream = errorResponse.GetResponseStream())
189
+                    using (StreamReader reader = new StreamReader(errorStream, Encoding.UTF8))
190
+                    {
191
+                        string errorContent = reader.ReadToEnd();
192
+                        throw new Exception($"HTTP Error {(int)errorResponse.StatusCode}: {errorContent}");
193
+                    }
194
+                }
195
+                throw;
196
+            }
197
+        }
198
+    
199
+    public static string HttpGet(string url, string token)
200
+        {
201
+            ServicePointManager.Expect100Continue = true;
202
+            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
203
+            ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
204
+            HttpClient client = new HttpClient();
205
+            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json; charset=utf-8"));
206
+            client.DefaultRequestHeaders.Authorization = new
207
+                AuthenticationHeaderValue
208
+                ("Bearer", token);
209
+            var result = client.GetAsync(url).Result.Content.ReadAsStringAsync().Result;
210
+
211
+            return result;
212
+        }
213
+        public static string SendPostRequest(string url, object data)
214
+        {
215
+            string authToken = GetTenantAccessToken();
216
+            // 创建请求对象
217
+            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
218
+            request.Method = "POST";
219
+            request.ContentType = "application/json; charset=utf-8";
220
+
221
+            // 添加 Authorization 头
222
+            request.Headers.Add("Authorization", $"Bearer {authToken}");
223
+
224
+            // 如果需要忽略 SSL 证书验证(仅测试环境使用)
225
+            // ServicePointManager.ServerCertificateValidationCallback += 
226
+            //     (sender, certificate, chain, sslPolicyErrors) => true;
227
+
228
+            try
229
+            {
230
+                // 序列化数据为 JSON
231
+                string json = JsonConvert.SerializeObject(data);
232
+                byte[] postData = Encoding.UTF8.GetBytes(json);
233
+
234
+                // 写入请求体
235
+                request.ContentLength = postData.Length;
236
+                using (Stream stream = request.GetRequestStream())
237
+                {
238
+                    stream.Write(postData, 0, postData.Length);
239
+                }
240
+
241
+                // 获取响应
242
+                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
243
+                using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
244
+                {
245
+                    return reader.ReadToEnd();
246
+                }
247
+            }
248
+            catch (WebException ex)
249
+            {
250
+                // 处理错误响应
251
+                if (ex.Response is HttpWebResponse errorResponse)
252
+                {
253
+                    using (Stream errorStream = errorResponse.GetResponseStream())
254
+                    using (StreamReader reader = new StreamReader(errorStream, Encoding.UTF8))
255
+                    {
256
+                        string errorContent = reader.ReadToEnd();
257
+                        throw new Exception($"HTTP Error {(int)errorResponse.StatusCode}: {errorContent}");
258
+                    }
259
+                }
260
+                throw;
261
+            }
262
+        }
263
+    
264
+    public static string HttpPost(string url, Dictionary<string, object> dic)
265
+        {
266
+            string result = ""; string token = GetTenantAccessToken();
267
+            try
268
+            {
269
+                // 创建 HttpWebRequest 对象
270
+                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
271
+                // 设置请求方法为 POST
272
+                request.Method = "POST";
273
+                // 设置 Content-Type
274
+                request.ContentType = "application/json; charset=utf-8";
275
+                // 设置 Authorization 头部
276
+                request.Headers.Add("Authorization", token);
277
+                var d = JsonConvert.SerializeObject(dic);
278
+                // 将请求体数据转换为字节数组
279
+                byte[] requestBodyBytes = Encoding.UTF8.GetBytes(d);
280
+                // 设置请求体的长度
281
+                request.ContentLength = requestBodyBytes.Length;
282
+
283
+                // 获取请求流
284
+                using (Stream requestStream = request.GetRequestStream())
285
+                {
286
+                    // 将请求体数据写入请求流
287
+                    requestStream.Write(requestBodyBytes, 0, requestBodyBytes.Length);
288
+                }
289
+
290
+                // 发送请求并获取响应
291
+                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
292
+                {
293
+                    // 检查响应状态码
294
+                    if (response.StatusCode == HttpStatusCode.OK)
295
+                    {
296
+                        // 获取响应流
297
+                        using (Stream responseStream = response.GetResponseStream())
298
+                        {
299
+                            if (responseStream != null)
300
+                            {
301
+                                // 创建 StreamReader 用于读取响应流
302
+                                using (StreamReader reader = new StreamReader(responseStream, Encoding.UTF8))
303
+                                {
304
+                                    // 读取响应内容
305
+                                    string responseBody = reader.ReadToEnd();
306
+                                    Console.WriteLine("请求成功,响应内容:");
307
+                                    return responseBody;
308
+                                }
309
+                            }
310
+                        }
311
+                    }
312
+                    else
313
+                    {
314
+                        return $"请求失败,状态码:{response.StatusCode}";
315
+                    }
316
+                }
317
+            }
318
+            catch (WebException ex)
319
+            {
320
+                if (ex.Status == WebExceptionStatus.ProtocolError)
321
+                {
322
+                    HttpWebResponse errorResponse = (HttpWebResponse)ex.Response;
323
+                    return $"请求失败,状态码:{errorResponse.StatusCode}";
324
+                }
325
+                else
326
+                {
327
+                    return $"发生网络异常:{ex.Message}";
328
+                    
329
+                }
330
+            }
331
+            catch (Exception ex)
332
+            {
333
+                return $"发生异常:{ex.Message}";
334
+            }
335
+
336
+            return result;
337
+        }
338
+        private class generalResult<T> where T : class
339
+        {
340
+            public string code { get; set; }
341
+            public string msg { get; set; }
342
+            public T data { get; set; }
343
+        }
344
+        private class userlist
345
+        {
346
+            public string user_id { get; set; }
347
+        }
348
+        private class userslist
349
+        {
350
+            public List<userlist> user_list { get; set; }
351
+        }
352
+        private class user
353
+        {
354
+            public string mobile { get; set; }
355
+        }
356
+        
357
+    }
358
+}

+ 13 - 6
codegit/CallCenterCommon/CallCenter.Utility/Http/HttpMethods.cs

@@ -19,7 +19,8 @@ namespace CallCenter.Utility
19 19
         /// <param name="url">URL.</param>
20 20
         /// <param name="param">POST的数据</param>
21 21
         /// <returns></returns>
22
-        public static string HttpPost(string url, string param = null)
22
+        public static string HttpPost(string url, string param = null, string contentType = "application/x-www-form-urlencoded"
23
+            )
23 24
         {
24 25
             HttpWebRequest request;
25 26
 
@@ -35,20 +36,21 @@ namespace CallCenter.Utility
35 36
                 request = WebRequest.Create(url) as HttpWebRequest;
36 37
             }
37 38
 
39
+
38 40
             request.Method = "POST";
39
-            request.ContentType = "application/x-www-form-urlencoded";
41
+            request.ContentType = contentType;
40 42
             request.Accept = "*/*";
41 43
             request.Timeout = 15000;
42 44
             request.AllowAutoRedirect = false;
43 45
 
44
-
45
-
46 46
             StreamWriter requestStream = null;
47 47
             WebResponse response = null;
48 48
             string responseStr = null;
49 49
 
50 50
             try
51 51
             {
52
+                LogFactory.GetLogger("HttpPost").Debug(url + "\r\n" + param + "\r\n");
53
+
52 54
                 requestStream = new StreamWriter(request.GetRequestStream());
53 55
                 requestStream.Write(param);
54 56
                 requestStream.Close();
@@ -60,10 +62,12 @@ namespace CallCenter.Utility
60 62
                     responseStr = reader.ReadToEnd();
61 63
                     reader.Close();
62 64
                 }
65
+
66
+                LogFactory.GetLogger("HttpPost").Debug(url + "\r\n" + param + "\r\n" + responseStr);
63 67
             }
64
-            catch (Exception)
68
+            catch (Exception ex)
65 69
             {
66
-                throw;
70
+                LogFactory.GetLogger("HttpPost").Error(url + "\r\n" + param + "\r\n" + ex.ToJson() + responseStr);
67 71
             }
68 72
             finally
69 73
             {
@@ -80,6 +84,9 @@ namespace CallCenter.Utility
80 84
         {
81 85
             return true; //总是接受  
82 86
         }
87
+
88
+
89
+       
83 90
         public static string BuildRequest(string strUrl, Dictionary<string, string> dicPara, string fileName)
84 91
         {
85 92
             string contentType = "image/jpeg";

+ 2 - 1
codegit/CallCenterCommon/CallCenter.Utility/ImageUpload.cs

@@ -682,8 +682,9 @@ namespace CallCenter.Utility
682 682
                 _Error = 0;
683 683
                 return;
684 684
             }
685
-            catch
685
+            catch(Exception E)
686 686
             {
687
+                LogFactory.GetLogger("").Error(E.ToJson());
687 688
                 _Error = 4;
688 689
                 return;
689 690
             }