zhoufan 4 years ago
parent
commit
84fa0ca0bd

+ 60 - 0
RMYY_CallCenter_Api.Utility/Helper/DingTalkHelper.cs

@@ -0,0 +1,60 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Threading.Tasks;
6
+
7
+namespace RMYY_CallCenter_Api.Utility.Helper
8
+{
9
+    public class DingTalkHelper
10
+    {        
11
+        /// <summary>
12
+        /// 获取AccessToken
13
+        /// </summary>
14
+        /// <returns></returns>
15
+        public static string GetAccessToken()
16
+        {
17
+            var accesstoken = RedisHelper.StringGet("DingTalkToken").ToString();
18
+            if (string.IsNullOrEmpty(accesstoken))
19
+            {
20
+                string result = HttpHelper.HttpGet(string.Format("https://oapi.dingtalk.com/gettoken?appkey={0}&appsecret={1}", ConfigHelper.GetValue("DingTalk_AppKey"), ConfigHelper.GetValue("DingTalk_AppSecret")));
21
+                var resultobj = result.ToJObject();
22
+                if (resultobj["errcode"].ToString() == "0")
23
+                {
24
+                    accesstoken = resultobj["access_token"].ToString();
25
+                    string cachetime = ConfigHelper.GetValue("DingTalk_TokenCacheTime");
26
+                    RedisHelper.StringSet("DingTalkToken", accesstoken, new TimeSpan(0, 0, cachetime.ToInt()));
27
+                }
28
+            }
29
+
30
+            return accesstoken;
31
+        }
32
+
33
+        /// <summary>
34
+        /// 发送模板消息
35
+        /// </summary>
36
+        /// <param name="userids"></param>
37
+        /// <param name="deptids"></param>
38
+        /// <param name="msgjson"></param>
39
+        /// <param name="templateid"></param>
40
+        /// <returns></returns>
41
+        public static string SendByTemplate(string userids, string deptids, string msgjson, string templateid)
42
+        {
43
+            string result = string.Empty;
44
+            var param = new
45
+            {
46
+                agent_id = "948060598",
47
+                template_id = "e27a9eed42b34a14a2xxxx",
48
+                data = "{\"name\":\"淘宝6\",\"name2\":\"http://www.taobao.com\"}",
49
+                dept_id_list = "421897262"
50
+            };
51
+            var strresult = HttpHelper.HttpPost(string.Format("https://oapi.dingtalk.com/topapi/message/corpconversation/sendbytemplate?access_token={0}", GetAccessToken()), param.ToJson());
52
+            var resultobj = strresult.ToJObject();
53
+            if (resultobj["errcode"].ToString() != "0")
54
+            {
55
+                result = resultobj["errmsg"].ToString();
56
+            }
57
+            return result;
58
+        }
59
+    }
60
+}

+ 8 - 17
RMYY_CallCenter_Api.Utility/Helper/HttpHelper.cs

@@ -19,7 +19,7 @@ namespace RMYY_CallCenter_Api.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, string jwt = null, string contenttype = "application/x-www-form-urlencoded")
22
+        public static string HttpPost(string url, string param = null, string contenttype = "application/x-www-form-urlencoded")
23 23
         {
24 24
             HttpWebRequest request;
25 25
 
@@ -34,10 +34,7 @@ namespace RMYY_CallCenter_Api.Utility
34 34
             {
35 35
                 request = WebRequest.Create(url) as HttpWebRequest;
36 36
             }
37
-            if (!string.IsNullOrEmpty(jwt))
38
-            {
39
-                request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + jwt);
40
-            }
37
+
41 38
             request.Method = "POST";
42 39
             request.ContentType = contenttype;
43 40
             request.Accept = "*/*";
@@ -68,7 +65,7 @@ namespace RMYY_CallCenter_Api.Utility
68 65
             catch (Exception ex)
69 66
             {
70 67
                 responseStr = null;
71
-                LogHelper.Error("post请求失败,url:" + url + ",参数:" + (param?.ToJson() ?? ""), ex);
68
+                LogHelper.Error("post请求失败,url:" + url + ",参数:" + (param ?? ""), ex);
72 69
             }
73 70
             finally
74 71
             {
@@ -93,7 +90,7 @@ namespace RMYY_CallCenter_Api.Utility
93 90
         /// </summary>
94 91
         /// <param name="url">URL.</param>
95 92
         /// <returns></returns>
96
-        public static string HttpGet(string url, string jwt = null)
93
+        public static string HttpGet(string url)
97 94
         {
98 95
             HttpWebRequest request;
99 96
 
@@ -108,10 +105,7 @@ namespace RMYY_CallCenter_Api.Utility
108 105
             {
109 106
                 request = WebRequest.Create(url) as HttpWebRequest;
110 107
             }
111
-            if (!string.IsNullOrEmpty(jwt))
112
-            {
113
-                request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + jwt);
114
-            }
108
+
115 109
             request.Method = "GET";
116 110
             //request.ContentType = "application/x-www-form-urlencoded";
117 111
             request.Accept = "*/*";
@@ -195,7 +189,7 @@ namespace RMYY_CallCenter_Api.Utility
195 189
         /// </summary>
196 190
         /// <param name="url">URL.</param>
197 191
         /// <returns></returns>
198
-        public static string HttpPut(string url, string param = null, string jwt = null, string contenttype = "application/x-www-form-urlencoded")
192
+        public static string HttpPut(string url, string param = null, string contenttype = "application/x-www-form-urlencoded")
199 193
         {
200 194
             HttpWebRequest request;
201 195
 
@@ -210,10 +204,7 @@ namespace RMYY_CallCenter_Api.Utility
210 204
             {
211 205
                 request = WebRequest.Create(url) as HttpWebRequest;
212 206
             }
213
-            if (!string.IsNullOrEmpty(jwt))
214
-            {
215
-                request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + jwt);
216
-            }
207
+
217 208
             request.Method = "PUT";
218 209
             request.ContentType = contenttype;
219 210
             request.Accept = "*/*";
@@ -246,7 +237,7 @@ namespace RMYY_CallCenter_Api.Utility
246 237
             {
247 238
                 responseStr = null;
248 239
 
249
-                LogHelper.Error("put请求失败,url:" + url + ",参数:" + (param?.ToJson() ?? ""), ex);
240
+                LogHelper.Error("put请求失败,url:" + url + ",参数:" + (param ?? ""), ex);
250 241
             }
251 242
             finally
252 243
             {

+ 1 - 0
RMYY_CallCenter_Api.Utility/RMYY_CallCenter_Api.Utility.csproj

@@ -70,6 +70,7 @@
70 70
     <Compile Include="Extention\Object.cs" />
71 71
     <Compile Include="Extention\String.cs" />
72 72
     <Compile Include="Helper\CacheHelper.cs" />
73
+    <Compile Include="Helper\DingTalkHelper.cs" />
73 74
     <Compile Include="Helper\HttpHelper.cs" />
74 75
     <Compile Include="Helper\LogHelper.cs" />
75 76
     <Compile Include="Helper\NPOIHelper.cs" />

+ 4 - 0
RMYY_CallCenter_Api/Configs/system.config

@@ -23,6 +23,10 @@
23 23
   <!-- ================== 5:Redis配置 ================== -->
24 24
   <add key="Redis_Server" value="192.168.8.20"/>
25 25
   <add key="Redis_Port" value="6379"/>
26
+  <!-- ================== 6:DingTalk配置 ================== -->
27
+  <add key="DingTalk_AppKey" value="ding77tk1okpuoxhitxs"/>
28
+  <add key="DingTalk_AppSecret" value="lrV9pt51pjxUY00qCkPdoZ-393can29IujDFdlR9SZnechH_pSG1Tl1maWocWrDB"/>
29
+  <add key="DingTalk_TokenCacheTime" value="7200"/>
26 30
   <!-- ================== 8:外呼前缀配置 ================== -->
27 31
   <!--外呼外地前缀-->
28 32
   <add key="CallOutWPre" value="0" />

+ 0 - 1
RMYY_CallCenter_Api/Controllers/IndexController.cs

@@ -46,7 +46,6 @@ namespace RMYY_CallCenter_Api.Controllers
46 46
 
47 47
                 CacheHelper.Insert("RoleMenus_" + User.F_RoleId, dt, 10);
48 48
 
49
-
50 49
                 return Success("成功", dt);
51 50
             }
52 51
         }

+ 0 - 2
RMYY_CallCenter_Api/Controllers/System/DepartmentController.cs

@@ -111,8 +111,6 @@ namespace RMYY_CallCenter_Api.Controllers.System
111 111
                     dModel.F_Sort = sort;
112 112
                     dModel.F_DeptCode = code;
113 113
                     dModel.F_DeptName = name;
114
-                    dModel.F_Sort = sort;
115
-                    dModel.F_DeptName = name;
116 114
                     dModel.F_State = 1;
117 115
 
118 116
                     if (departmentBLL.Update(dModel))

+ 24 - 28
RMYY_CallCenter_Api/Web.config

@@ -5,17 +5,17 @@
5 5
   -->
6 6
 <configuration>
7 7
   <appSettings>
8
-    <add key="webpages:Version" value="3.0.0.0"/>
9
-    <add key="webpages:Enabled" value="false"/>
10
-    <add key="ClientValidationEnabled" value="true"/>
11
-    <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
8
+    <add key="webpages:Version" value="3.0.0.0" />
9
+    <add key="webpages:Enabled" value="false" />
10
+    <add key="ClientValidationEnabled" value="true" />
11
+    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
12 12
   </appSettings>
13 13
   <connectionStrings>
14
-    <add name="ConnectionString" connectionString="Data Source=192.168.1.37;User ID=sa;pwd=hykj@800100;Initial Catalog=RMYY_CallCenter;"/>
14
+    <add name="ConnectionString" connectionString="Data Source=192.168.1.37;User ID=sa;pwd=hykj@800100;Initial Catalog=RMYY_CallCenter;" />
15 15
   </connectionStrings>
16 16
   <system.web>
17
-    <compilation debug="true" targetFramework="4.5"/>
18
-    <httpRuntime targetFramework="4.5"/>
17
+    <compilation debug="true" targetFramework="4.5" />
18
+    <httpRuntime targetFramework="4.5" />
19 19
   </system.web>
20 20
   <system.webServer>
21 21
     <staticContent>
@@ -30,48 +30,44 @@
30 30
       </customHeaders>
31 31
     </httpProtocol>
32 32
     <!--cors 支持跨域 end-->
33
-    <validation validateIntegratedModeConfiguration="false"/>
33
+    <validation validateIntegratedModeConfiguration="false" />
34 34
   </system.webServer>
35 35
   <runtime>
36 36
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
37 37
       <dependentAssembly>
38
-        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f"/>
39
-        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2"/>
38
+        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
39
+        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
40 40
       </dependentAssembly>
41 41
       <dependentAssembly>
42
-        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed"/>
43
-        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0"/>
42
+        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
43
+        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
44 44
       </dependentAssembly>
45 45
       <dependentAssembly>
46
-        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
47
-        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
46
+        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
47
+        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
48 48
       </dependentAssembly>
49 49
       <dependentAssembly>
50
-        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
51
-        <bindingRedirect oldVersion="1.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930"/>
50
+        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
51
+        <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
52 52
       </dependentAssembly>
53 53
       <dependentAssembly>
54
-        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
55
-        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
54
+        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
55
+        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
56 56
       </dependentAssembly>
57 57
       <dependentAssembly>
58
-        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
59
-        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
58
+        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
59
+        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
60 60
       </dependentAssembly>
61 61
       <dependentAssembly>
62
-        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
63
-        <bindingRedirect oldVersion="1.0.0.0-5.2.4.0" newVersion="5.2.4.0"/>
62
+        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
63
+        <bindingRedirect oldVersion="1.0.0.0-5.2.4.0" newVersion="5.2.4.0" />
64 64
       </dependentAssembly>
65 65
     </assemblyBinding>
66 66
   </runtime>
67 67
   <system.codedom>
68 68
     <compilers>
69
-      <compiler language="c#;cs;csharp" extension=".cs"
70
-        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
71
-        warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
72
-      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
73
-        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
74
-        warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
69
+      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
70
+      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
75 71
     </compilers>
76 72
   </system.codedom>
77 73
 </configuration>