Ejemplo n.º 1
0
        private IActionResult Failure(String appId, Int32 errorCode, String errorMessage = null)
        {
            var resp = new GatewayCommonResponse()
            {
                Status  = errorCode,
                Msg     = errorMessage.HasValue() ? errorMessage : ErrorCodeDescriptor.GetDescription(errorCode),
                Content = new { AppId = appId }
            };

            String callResultStatus = CallResultStatus.ERROR.ToString();

            var respContent = JsonUtil.SerializeObject(resp.Content);

            if (!respContent.Success)
            {
                resp.Status = ErrorCode.SERIALIZE_FAILED;
                resp.Msg    = ErrorCodeDescriptor.GetDescription(resp.Status);
                return(this.Json(resp, callResultStatus));
            }

            var signResult = CryptoHelper.MakeSign(respContent.Value, KeyConfig.CPICommonPrivateKey, PrivateKeyFormat.PKCS8, HashAlgorithmName.SHA1);

            if (!signResult.Success)
            {
                _logger.Error(TraceType.API.ToString(), CallResultStatus.ERROR.ToString(), $"{_typeFullName}.Failure()", "CryptoHelper.MakeSign(...)", "生成签名失败", signResult.FirstException);

                resp.Status = ErrorCode.SIGN_FAILED;
                resp.Msg    = ErrorCodeDescriptor.GetDescription(resp.Status);
                return(this.Json(resp, callResultStatus));
            }

            resp.Sign = signResult.Value;
            return(this.Json(resp, callResultStatus));
        }
Ejemplo n.º 2
0
        private IActionResult Success(String appId, Object value)
        {
            var resp = new GatewayCommonResponse()
            {
                Status  = ErrorCode.SUCCESS,
                Content = value
            };

            String callResultStatus = CallResultStatus.OK.ToString();

            var signContent = JsonUtil.SerializeObject(resp.Content);

            if (!signContent.Success)
            {
                resp.Status  = ErrorCode.SERIALIZE_FAILED;
                resp.Msg     = ErrorCodeDescriptor.GetDescription(resp.Status);
                resp.Content = new { AppId = appId };
                return(this.Json(resp, callResultStatus));
            }

            var signResult = CryptoHelper.MakeSign(signContent.Value, KeyConfig.CPICommonPrivateKey, PrivateKeyFormat.PKCS8, HashAlgorithmName.SHA1);

            if (!signResult.Success)
            {
                _logger.Error(TraceType.API.ToString(), CallResultStatus.ERROR.ToString(), $"{this.GetType().FullName}:Success()", "CryptoHelper.MakeSign(...)", "生成签名失败", signResult.FirstException);

                resp.Status  = ErrorCode.SIGN_FAILED;
                resp.Msg     = ErrorCodeDescriptor.GetDescription(resp.Status);
                resp.Content = new { AppId = appId };
                return(this.Json(resp, callResultStatus));
            }

            resp.Sign = signResult.Value;
            return(this.Json(resp, callResultStatus));
        }
Ejemplo n.º 3
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseDeveloperExceptionPage();
            app.UseStaticFiles();
            app.UseMvc();

            GlobalConfig.Environment = Configuration["Environment"];
            ErrorCodeDescriptor.AddErrorCodeTypes(typeof(ErrorCode));
            XDI.Run();
        }