/// <summary> /// 验证 /// </summary> protected void Validate() { //var _interfaceAccount = interfaceAccountRep.GetInterfaceAccount(new InterfaceAccount() { MerchantCode = model.MerchantId }); var _interfaceAccount = interfaceAccount.GetModel(i => i.MerchantCode == model.MerchantId).FirstOrDefault(); if (_interfaceAccount == null) { throw new MerchantException("MerchantCode"); } var aesAddress = _interfaceAccount.CertAddress.Split('|')[1]; if (PlatformID.Win32NT != Environment.OSVersion.Platform) { //aesAddress = "/home/dev/" + aesAddress.Substring(3).Replace('\\', '/'); aesAddress = "/app/CGT.Api/" + aesAddress.Substring(15).Replace('\\', '/'); } //解密data var json = Encrpty.AESDecrypt(model.Data, Encrpty.RSADecrypt(model.EncryptKey, aesAddress, _interfaceAccount.CertPassword)); // 反序列化Json为参数对象 this.Parameter = JsonConvert.DeserializeObject <P>(json); //验证sign if (!this.Parameter.Sign.Equals(GetMySign(_interfaceAccount.UserKey))) { throw new ApiSignException("Sign"); } //验证数据 if (!this.Parameter.IsValid) { throw new ValidationException("IsValid", this.Parameter.GetRuleViolationMessages()); } }
/// <summary> /// 验证 /// </summary> protected virtual void Validate() { //lock (lockobject) { var interfaceAccount = new InterfaceAccount() { MerchantCode = model.MerchantId }; var _interfaceAccount = interfaceAccountRep.GetInterfaceAccount(interfaceAccount); //获取userRSA地址 var aesAddress = _interfaceAccount.CertAddress.Split('|')[1]; string AesKey = ""; try { AesKey = Encrpty.RSADecrypt(model.EncryptKey, aesAddress, _interfaceAccount.CertPassword); } catch (Exception ex) { LoggerFactory.Instance.Logger_Debug(model.EncryptKey + "|" + aesAddress + "|" + _interfaceAccount.CertPassword + "|" + ex.Message, "RSADecryptError"); var exstr = new RSADecryptException(); throw new RSADecryptException(Common.ServiceCommon.GetExMessage(exstr.ErrorCode, "RSA解密失败!")); } //解密data var json = Encrpty.AESDecrypt(model.Data, AesKey); // 反序列化Json为参数对象 this.Parameter = JsonConvert.DeserializeObject <P>(json); string MySign = GetMySign(_interfaceAccount.UserKey); //验证sign if (!this.Parameter.Sign.Equals(MySign)) { var ex = new ApiSignException(); throw new ApiSignException(Common.ServiceCommon.GetExMessage(ex.ErrorCode, "签名验证失败!")); } //验证数据 if (!this.Parameter.IsValid) { var ex = new ValidationException(); throw new ValidationException(Common.ServiceCommon.GetExMessage(ex.ErrorCode, this.Parameter.GetRuleViolationMessages())); } //} }