Example #1
0
        /// <summary>
        /// 验证并返回请求对象
        /// </summary>
        /// <param name="baseRequest"></param>
        /// <param name="data"></param>
        /// <param name="signdata"></param>
        /// <returns></returns>
        protected VerifyResult Verify(out BaseRequest baseRequest, string data = null, string signdata = null)
        {
            var verifyResult = new VerifyResult {
                IsPass = true
            };
            HttpMessage httpMessage;

            //报文验证
            if (!Base64Verify(out httpMessage, out baseRequest, data, signdata))
            {
                return(VerifyResult.CreateVerifyResult(false, EnumPlatform.EResponseCode.解析报文错误));
            }
            //未传入SourceID,忽略此请求
            if (string.IsNullOrEmpty(baseRequest.SourceID))
            {
                return(VerifyResult.CreateVerifyResult(false, EnumPlatform.EResponseCode.存在此机构));
            }
            //机构号验证
            if (!SourceIdVerify(baseRequest))
            {
                return(VerifyResult.CreateVerifyResult(false, EnumPlatform.EResponseCode.存在此机构));
            }
            //验签
            if (!SignVerify(httpMessage, baseRequest.SourceID))
            {
                return(VerifyResult.CreateVerifyResult(false, EnumPlatform.EResponseCode.验证签名失败));
            }

            return(GetRequest(httpMessage.data, baseRequest.BizCode, out baseRequest));
        }
Example #2
0
        /// <summary>
        /// 获取request对象
        /// </summary>
        /// <param name="requestStr"></param>
        /// <param name="bizCode"></param>
        /// <param name="baseRequest"></param>
        /// <returns></returns>
        protected VerifyResult GetRequest(string requestStr, string bizCode, out BaseRequest baseRequest)
        {
            baseRequest = null;
            switch (bizCode)
            {
            case "1006":
                baseRequest = JsonUtils.Deserialize <BaseRequest>(requestStr);
                break;

            default:
                return(VerifyResult.CreateVerifyResult(false, EnumPlatform.EResponseCode.无效交易类型));
            }
            return(ModelVerify(baseRequest));
        }
Example #3
0
        /// <summary>
        /// 验证RequestData
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        protected VerifyResult ModelVerify(BaseRequest t)
        {
            var  verifyResult = new VerifyResult();
            var  context      = new ValidationContext(t, null, null);
            var  results      = new List <ValidationResult>();
            bool isValid      = Validator.TryValidateObject(t, context, results);
            var  errorMsg     = new StringBuilder();

            if (!isValid)
            {
                for (int i = 0; i < results.Count; i++)
                {
                    ValidationResult r = results[i];
                    errorMsg.Append(String.Format("{0}、{1}。\r\n", i + 1, r.ErrorMessage));
                }
                return(VerifyResult.CreateVerifyResult(false, EnumPlatform.EResponseCode.参数不正确, errorMsg.ToString()));
            }
            return(VerifyResult.CreateVerifyResult(true, EnumPlatform.EResponseCode.成功受理了请求));
        }