/// <summary>
        /// 返回信息
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        private ExecResult <TResult> ParseResponse(string response)
        {
            var result = new ExecResult <TResult>();
            var view   = JsonConvert.DeserializeObject <ResponseSignView>(response);

            if (!string.IsNullOrWhiteSpace(view.data))
            {
                var signresponse = Encrpty.AESDecrypt(view.data, JsonConfig.JsonRead("aesKey", "Installment"));
                var responseView = JsonConvert.DeserializeObject <ResponseView>(signresponse);
                if (responseView.result == "100" || responseView.result == "200")
                {
                    Collection.DDD.Logger.LoggerFactory.Instance.Logger_Info(string.Format("response:{0},data:{1}", response, responseView.data), "InstallmentService");
                    result.Result = JsonConvert.DeserializeObject <TResult>(responseView.data);
                }
                else
                {
                    result.Success = false;
                    result.Message = responseView.errorMessage;
                }
            }
            else
            {
                result.Success = false;
                result.Message = view.sign;
            }
            return(result);
        }
示例#2
0
        /// <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());
            }
        }
示例#3
0
        /// <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()));
            }
            //}
        }