20210917 与五环OA单点登陆
This commit is contained in:
		
							parent
							
								
									01cef410fd
								
							
						
					
					
						commit
						738a601386
					
				|  | @ -62,6 +62,11 @@ namespace BLL | ||||||
|         /// 微信订阅模板ID |         /// 微信订阅模板ID | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         public const string WX_TemplateID = "hKFrcahyXEjGSrLM4qBPpjXAkFldnrqxU_mARd1IF4o"; |         public const string WX_TemplateID = "hKFrcahyXEjGSrLM4qBPpjXAkFldnrqxU_mARd1IF4o"; | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// 五环OA 私钥 | ||||||
|  |         /// </summary> | ||||||
|  |         public const string OAPrivateKey_CWCEC = "<RSAKeyValue><Modulus>nq6pYDFkcrpzVtMrLbf2dvDPs2FDo5yeDub6YCnl0hXov3MVEVMbVe3NCnC5Thl3dwm14yI9/vNIGdH5M4getAkMnkG8tNA60NPjtHUzyoZSpVYCUOmB30s5vx+4IBkPh8R4ynkJYyUxkl61/0h6y7A86qz4jNivxAKt2a0vQxk=AQABy/DiC9r3AfTlJzuwk2BBT3X2YpVN0LE/lUIHJs64GW2siQow/k9BRcPOkBwLuVOp/YrwYPCh/XGLxjukqxCjNw==xzA32jeRGMthXVbkmn0YvFKV6O9IS7Toee2cRN8x1qRPwwnN5yOq7lunMcZyWLfCimsKmYwRe9Uw5fHMPScULw==DIzRTEt4Qd2RMH3i2t7khgBLXjuz4zDVKdk7WW8FM0Nlh7Vh2HSGHsXy8zlWm1wDrP+c1UpZnaAcKuHGu2Q1tw==jFW3dAHkM0DPFzDqHMH4FG5m+dbj65rIk2bJy2got93J6FLXA3sIqahfMl1rIIBPCrCBpk6d3s4EBm2GBKustw==ux8JAVqXtCjtaNgahpa0AK73tp+kGEkHyvt/hzp8C8LmXicNGNZtgDDHHLwxN+Lzp3z6ThfzY44oQtymljRu1g==Ye2Oj9PLltYkKhgmFI/sZZjVxXEoKgeUr8OyDrisoUtuGQCvpsJwI0affGr2oREsXeU7P9I5CmcfPvgLX9cIgsAtOcDMM81Hs6WhfbkryjyFj1CfKTI9gYZnApPInYYMew8wvUX23K6Hq+rIyHxMnSAhLvoqXor4KVQj6QRtdOU=</D></RSAKeyValue>"; | ||||||
|         #endregion |         #endregion | ||||||
| 
 | 
 | ||||||
|         #region 按钮描述 |         #region 按钮描述 | ||||||
|  |  | ||||||
|  | @ -1131,6 +1131,16 @@ namespace BLL | ||||||
|             } |             } | ||||||
|             return value; |             return value; | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// 时间戳转日期 | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="timestamp"></param> | ||||||
|  |         /// <returns></returns> | ||||||
|  |         public static DateTime IntToDateTime(int timestamp) | ||||||
|  |         { | ||||||
|  |             return TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddSeconds(timestamp); | ||||||
|  |         }        | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -38,6 +38,32 @@ namespace BLL | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         ///  OA ÓòÕ˺ŵǽ | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="account"></param> | ||||||
|  |         /// <param name="password"></param> | ||||||
|  |         /// <param name="rememberMe"></param> | ||||||
|  |         /// <param name="page"></param> | ||||||
|  |         /// <returns></returns> | ||||||
|  |         public static bool UserLogOn_OA(string account, bool rememberMe, System.Web.UI.Page page) | ||||||
|  |         { | ||||||
|  |             List<Sys_User> x = (from y in Funs.DB.Sys_User | ||||||
|  |                                 where y.Account == account && y.IsPost == true  | ||||||
|  |                                 select y).ToList(); | ||||||
|  |             if (x.Any()) | ||||||
|  |             { | ||||||
|  |                 string accValue = HttpUtility.UrlEncode(account); | ||||||
|  |                 FormsAuthentication.SetAuthCookie(accValue, false); | ||||||
|  |                 page.Session[SessionName.CurrUser] = x.First(); | ||||||
|  |                 return true; | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |                 return false; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         /// <summary> |         /// <summary> | ||||||
|         /// 用户登录成功方法 |         /// 用户登录成功方法 | ||||||
|         /// </summary> |         /// </summary> | ||||||
|  |  | ||||||
|  | @ -1 +1,33 @@ | ||||||
|  |  | ||||||
|  | 错误信息开始=====> | ||||||
|  | 错误类型:FormatException | ||||||
|  | 错误信息:输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字符,或者填充字符间包含非法字符。 | ||||||
|  | 错误堆栈: | ||||||
|  |    在 System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength) | ||||||
|  |    在 System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength) | ||||||
|  |    在 System.Convert.FromBase64String(String s) | ||||||
|  |    在 System.Security.Cryptography.RSA.FromXmlString(String xmlString) | ||||||
|  |    在 FineUIPro.Web.Login.RSADecrypt(String privatekey, String content) 位置 D:\CWCEC\SGGL_CWCEC\SGGL\FineUIPro.Web\Login.aspx.cs:行号 161 | ||||||
|  |    在 FineUIPro.Web.Login.Page_Load(Object sender, EventArgs e) 位置 D:\CWCEC\SGGL_CWCEC\SGGL\FineUIPro.Web\Login.aspx.cs:行号 74 | ||||||
|  |    在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) | ||||||
|  |    在 System.EventHandler.Invoke(Object sender, EventArgs e) | ||||||
|  |    在 System.Web.UI.Control.OnLoad(EventArgs e) | ||||||
|  |    在 System.Web.UI.Control.LoadRecursive() | ||||||
|  |    在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) | ||||||
|  | 出错时间:09/17/2021 14:54:20 | ||||||
|  | 出错文件:http://localhost:8118/Login.aspx?data=****&database=userName=sysgly×pan=1256015312 | ||||||
|  | IP地址:::1 | ||||||
|  | 
 | ||||||
|  | 出错时间:09/17/2021 14:54:20 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 错误信息开始=====> | ||||||
|  | 错误类型:FormatException | ||||||
|  | 错误信息:该字符串未被识别为有效的 DateTime。 | ||||||
|  | 错误堆栈: | ||||||
|  |    在 System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles) | ||||||
|  |    在 System.DateTime.Parse(String s) | ||||||
|  |    在 BLL.Funs.GetNewDateTime(String time) 位置 D:\CWCEC\SGGL_CWCEC\SGGL\BLL\Common\Funs.cs:行号 554 | ||||||
|  | 出错时间:09/17/2021 14:56:12 | ||||||
|  | 出错时间:09/17/2021 14:56:12 | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -4,6 +4,8 @@ | ||||||
|     using System; |     using System; | ||||||
|     using System.Configuration; |     using System.Configuration; | ||||||
|     using System.Linq; |     using System.Linq; | ||||||
|  |     using System.Security.Cryptography; | ||||||
|  |     using System.Text; | ||||||
|     using System.Web; |     using System.Web; | ||||||
|     using System.Web.Services; |     using System.Web.Services; | ||||||
| 
 | 
 | ||||||
|  | @ -65,6 +67,32 @@ | ||||||
|         { |         { | ||||||
|             if (!IsPostBack) |             if (!IsPostBack) | ||||||
|             { |             { | ||||||
|  |                 string userdata = Request.Params["basedata"]; | ||||||
|  |                 if (!string.IsNullOrEmpty(userdata)) | ||||||
|  |                 { | ||||||
|  |                     string result = RSADecrypt(Const.OAPrivateKey_CWCEC, userdata); //经过RSA解密后获得的域登录名+时间戳 | ||||||
|  |                     if (!string.IsNullOrEmpty(result)) | ||||||
|  |                     { | ||||||
|  |                         var value = Funs.GetStrListByStr(result, '|'); | ||||||
|  |                         if (value.Count > 1) | ||||||
|  |                         { | ||||||
|  |                             var userValues = Funs.GetStrListByStr(value[0], '='); | ||||||
|  |                             var timespan = Funs.GetStrListByStr(value[1], '='); | ||||||
|  |                             if (userValues.Count > 1 && timespan.Count > 1) | ||||||
|  |                             { | ||||||
|  |                                 DateTime? dateTimeS = Funs.IntToDateTime(Funs.GetNewIntOrZero(timespan[1])); | ||||||
|  |                                 if (dateTimeS.HasValue && DateTime.Now.AddSeconds(-30) < dateTimeS) | ||||||
|  |                                 { | ||||||
|  |                                     if (LoginService.UserLogOn_OA(userValues[1], true, this.Page)) | ||||||
|  |                                     { | ||||||
|  |                                         string url = getUrl(); | ||||||
|  |                                         Response.Redirect(url); | ||||||
|  |                                     } | ||||||
|  |                                 } | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         #endregion |         #endregion | ||||||
|  | @ -80,28 +108,59 @@ | ||||||
|             string url = ""; |             string url = ""; | ||||||
|             if (LoginService.UserLogOn(user, pwd, true, this.Page)) |             if (LoginService.UserLogOn(user, pwd, true, this.Page)) | ||||||
|             { |             { | ||||||
|               this.CurrUser.RoleType = RoleService.GetRoleTypeByRoleId(this.CurrUser.RoleId); |                 url = getUrl(); | ||||||
|                 if (!this.CurrUser.LastIsOffice.HasValue) |  | ||||||
|                 { |  | ||||||
|                     this.CurrUser.LastIsOffice = this.CurrUser.IsOffice; |  | ||||||
|                 } |  | ||||||
|                 if (this.CurrUser.LastIsOffice == true) |  | ||||||
|                 { |  | ||||||
|                     this.CurrUser.LoginProjectId = null; |  | ||||||
|                     ////本部菜单 |  | ||||||
|                     url = "index.aspx"; |  | ||||||
|                 } |  | ||||||
|                 else |  | ||||||
|                 { |  | ||||||
|                     this.CurrUser.LoginProjectId = this.CurrUser.LastProjectId; |  | ||||||
|                     //// 项目菜单 |  | ||||||
|                     url = "indexProject.aspx?projectId=" + this.CurrUser.LastProjectId; |  | ||||||
|                 } |  | ||||||
| 
 |  | ||||||
|                 LogService.AddSys_Log(this.CurrUser, this.CurrUser.UserName, this.CurrUser.UserId, Const.UserMenuId, Const.BtnLogin); |  | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             return url; |             return url; | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         ///  获取跳转页面 | ||||||
|  |         /// </summary> | ||||||
|  |         /// <returns></returns> | ||||||
|  |         private string getUrl() | ||||||
|  |         { | ||||||
|  |             string url = ""; | ||||||
|  |             this.CurrUser.RoleType = RoleService.GetRoleTypeByRoleId(this.CurrUser.RoleId); | ||||||
|  |             if (!this.CurrUser.LastIsOffice.HasValue) | ||||||
|  |             { | ||||||
|  |                 this.CurrUser.LastIsOffice = this.CurrUser.IsOffice; | ||||||
|  |             } | ||||||
|  |             if (this.CurrUser.LastIsOffice == true) | ||||||
|  |             { | ||||||
|  |                 this.CurrUser.LoginProjectId = null; | ||||||
|  |                 ////本部菜单 | ||||||
|  |                 url = "index.aspx"; | ||||||
|  |             } | ||||||
|  |             else | ||||||
|  |             { | ||||||
|  |                 this.CurrUser.LoginProjectId = this.CurrUser.LastProjectId; | ||||||
|  |                 //// 项目菜单 | ||||||
|  |                 url = "indexProject.aspx?projectId=" + this.CurrUser.LastProjectId; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             LogService.AddSys_Log(this.CurrUser, this.CurrUser.UserName, this.CurrUser.UserId, Const.UserMenuId, Const.BtnLogin); | ||||||
|  | 
 | ||||||
|  |             return url; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |         /// <summary> | ||||||
|  |         /// <summary> | ||||||
|  |         /// 用私钥对数据进行RSA解密 | ||||||
|  |         /// </summary> | ||||||
|  |         /// <param name="privatekey"></param> | ||||||
|  |         /// <param name="content"></param> | ||||||
|  |         /// <returns></returns> | ||||||
|  |         public static string RSADecrypt(string privatekey, string content) | ||||||
|  |         { | ||||||
|  | 
 | ||||||
|  |             RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); | ||||||
|  |             byte[] cipherbytes; | ||||||
|  |             rsa.FromXmlString(privatekey); | ||||||
|  |             //对参数content进行两次base64解密 | ||||||
|  |             cipherbytes = rsa.Decrypt(Convert.FromBase64String(Encoding.UTF8.GetString(Convert.FromBase64String(content))), false); | ||||||
|  |             return Encoding.UTF8.GetString(cipherbytes); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -0,0 +1,7 @@ | ||||||
|  | publickey  | ||||||
|  | 
 | ||||||
|  | <RSAKeyValue><Modulus>rnq6pYDFkcrpzVtMrLbf2dvDPs2FDo5yeDub6YCnl0hXov3MVEVMbVe3NCnC5Thl3dwm14yI9/vNIGdH5M4getAkMnkG8tNA60NPjtHUzyoZSpVYCUOmB30s5vx+4IBkPh8R4ynkJYyUxkl61/0h6y7A86qz4jNivxAKt2a0vQxk=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | privatekey:<RSAKeyValue><Modulus>nq6pYDFkcrpzVtMrLbf2dvDPs2FDo5yeDub6YCnl0hXov3MVEVMbVe3NCnC5Thl3dwm14yI9/vNIGdH5M4getAkMnkG8tNA60NPjtHUzyoZSpVYCUOmB30s5vx+4IBkPh8R4ynkJYyUxkl61/0h6y7A86qz4jNivxAKt2a0vQxk=AQAB | ||||||
|  | y/DiC9r3AfTlJzuwk2BBT3X2YpVN0LE/lUIHJs64GW2siQow/k9BRcPOkBwLuVOp/YrwYPCh/XGLxjukqxCjNw==xzA32jeRGMthXVbkmn0YvFKV6O9IS7Toee2cRN8x1qRPwwnN5yOq7lunMcZyWLfCimsKmYwRe9Uw5fHMPScULw==DIzRTEt4Qd2RMH3i2t7khgBLXjuz4zDVKdk7WW8FM0Nlh7Vh2HSGHsXy8zlWm1wDrP+c1UpZnaAcKuHGu2Q1tw==jFW3dAHkM0DPFzDqHMH4FG5m+dbj65rIk2bJy2got93J6FLXA3sIqahfMl1rIIBPCrCBpk6d3s4EBm2GBKustw==ux8JAVqXtCjtaNgahpa0AK73tp+kGEkHyvt/hzp8C8LmXicNGNZtgDDHHLwxN+Lzp3z6ThfzY44oQtymljRu1g==Ye2Oj9PLltYkKhgmFI/sZZjVxXEoKgeUr8OyDrisoUtuGQCvpsJwI0affGr2oREsXeU7P9I5CmcfPvgLX9cIgsAtOcDMM81Hs6WhfbkryjyFj1CfKTI9gYZnApPInYYMew8wvUX23K6Hq+rIyHxMnSAhLvoqXor4KVQj6QRtdOU=</D></RSAKeyValue> | ||||||
|  | @ -0,0 +1,38 @@ | ||||||
|  |  单点登录的方式 | ||||||
|  |   五环系统点击链接:https://zhgd.cwcec.com/Login.html?data=****&basedata=**** | ||||||
|  |   免登录进入智慧工地的系统 | ||||||
|  |  data参数说明 | ||||||
|  |      data字符串是用户名和时间戳用RSA公钥加密后的字符串。例如: | ||||||
|  |      userName=zhangsan×pan=1256015312用公钥加密后生成**** | ||||||
|  |  basedata参数说明 | ||||||
|  |   basedata字符串是用户名和时间戳用RSA公钥加密后再用Base64加密一次 | ||||||
|  |   生成的加密字符串。例如: | ||||||
|  |   userName=zhangsan×pan=1256015312用公钥加密后再用Base64加密 | ||||||
|  |   为了解决有的解密过程中出现"+"或者"="这样的特殊字符。推荐截取basedata的 | ||||||
|  |   字符串解密。 | ||||||
|  |       | ||||||
|  |  解密方式 | ||||||
|  |   data或者basedata都是用公钥进行RSA加密,需要用我们提供的私钥对加密文件进行解密,判断用户名是否在系统中并且当前时间-时间戳<30秒钟,才能登录到系统中,否则需要输入账号密码 | ||||||
|  | 三、.net解密的函数参考 | ||||||
|  | string userdata = context.Request["database"].ToString(); | ||||||
|  | string privatekey = ****(我们会提供) | ||||||
|  | string result = RSADecrypt(privatekey, userdata); //经过RSA解密后获得的域登录名+时间戳 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | /// <summary> | ||||||
|  | /// <summary> | ||||||
|  | /// 用私钥对数据进行RSA解密 | ||||||
|  | /// </summary> | ||||||
|  | /// <param name="privatekey"></param> | ||||||
|  | /// <param name="content"></param> | ||||||
|  | /// <returns></returns> | ||||||
|  | public static string RSADecrypt(string privatekey, string content) | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  | RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); | ||||||
|  | byte[] cipherbytes; | ||||||
|  | rsa.FromXmlString(privatekey); | ||||||
|  | //对参数content进行两次base64解密 | ||||||
|  | cipherbytes = rsa.Decrypt(Convert.FromBase64String(Encoding.UTF8.GetString(Convert.FromBase64String(content))), false); | ||||||
|  | return Encoding.UTF8.GetString(cipherbytes); | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue