Exemple #1
0
        public async Task <JsonResult> Post([FromBody] AuthorizationCodeModel data)
        {
            var parameters =
                $"grant_type=authorization_code&code={data.code}&state={data.state}&redirect_uri={data.redirect_uri}&client_id={AppSettings.ClientId}&client_secret={AppSettings.ClientSecret}";
            var result = await Task.FromResult(WebUtils.DoPost(AppSettings.TokenEndpoint, parameters)); //得到令牌

            var resdata = JsonConvert.DeserializeObject <dynamic>(result);

            if (resdata.access_token == null)
            {
                return(Json(ResponseResult.Execute("10027", "授权码已不存在或已过期")));
            }
            string access_token  = resdata.access_token;
            int    expires_in    = resdata.expires_in;
            string token_type    = resdata.token_type;
            string refresh_token = resdata.refresh_token;

            if (string.IsNullOrEmpty(access_token))
            {
                return(Json(ResponseResult.Execute("10009", "任务过多,系统繁忙")));
            }
            _memoryCache.Set(access_token, DateTime.Now.AddSeconds(expires_in), TimeSpan.FromSeconds(expires_in));    //令牌写入缓存

            return(Json(ResponseResult.Execute(new { access_token, token_type, expires_in, refresh_token })));
        }
Exemple #2
0
        public async Task <JsonResult> Get()
        {
            //var a=_cache.Get<Base_UserEntity>("test");
            bool r = await _cache.AddAsync("test", "ichnb");

            return(Json(ResponseResult.Execute(r)));
            //return new string[] { "value1", "value2" };
        }
        public async Task <JsonResult> Get()
        {
            //bool r=  await _baseUserRepository.BatchSetOpenIdAsync(); //同步openid
            //int total = 0;
            var list = await _baseUserRepository.FindListAsync(t => true, "realname", true, 10, 1);

            return(Json(ResponseResult.Execute(list)));
            //return new string[] { "value1", "value2" };
        }
Exemple #4
0
 public IActionResult UpdateOrderState(string orderId, int state)
 {
     return((IActionResult)Json(ResponseResult.Execute(new
     {
         code = 0,
         message = "success",
         messageType = MessageType.success
     })));
 }
Exemple #5
0
 public IActionResult OrderProcess(string orderId)
 {
     return((IActionResult)Json(ResponseResult.Execute(new
     {
         code = 0,
         message = "success",
         messageType = MessageType.success
     })));
 }
Exemple #6
0
 public IActionResult OrderList()
 {
     return((IActionResult)Json(ResponseResult.Execute(new
     {
         code = 0,
         message = "success",
         messageType = MessageType.success
     })));
 }
Exemple #7
0
        public IActionResult GetOrderCount(int logisticsType, string goodsId, int state)
        {
            int orderCount = 0;

            return((IActionResult)Json(ResponseResult.Execute(new
            {
                data = orderCount,
                code = 0,
                message = "success",
                messageType = MessageType.success
            })));
        }
Exemple #8
0
        public async Task <IActionResult> Post([FromBody] AuthorizationCodeModel data)
        {
            var(error, result) = await _client.GetToken(data.code, data.state, data.redirect_uri);

            return(!string.IsNullOrEmpty(error)
                ? Ok(ResponseResult.Execute("10027", error))
                : (IActionResult)Json(ResponseResult.Execute(new
            {
                access_token = result.AccessToken,
                token_type = result.TokenType,
                expires_in = result.ExpiresIn,
                refresh_token = result.RefreshToken
            })));
        }
        public async Task <IActionResult> Post()
        {
            if (!HttpContext.User.HasClaim(c => c.Type == ClaimTypes.Authentication))
            {
                return(Json(ResponseResult.Execute("10008", "参数错误,请参考API文档")));
            }

            var clamin = HttpContext.User.FindFirst(c => c.Type == ClaimTypes.Authentication);

            if (!string.IsNullOrEmpty(clamin.Value))
            {
                DateTime expireTime;
                if (_memoryCache.TryGetValue(clamin.Value, out expireTime))
                {
                    var parameters = $"access_token={clamin.Value}";
                    var result     = await WebUtils.DoPostAsync(AppSettings.UserInfoEndpoint, parameters, "utf-8"); //得到用户信息

                    var data     = JsonConvert.DeserializeObject <dynamic>(result);
                    var userdata = data.data;
                    if (data.code == "0" && null != userdata)
                    {
                        //判断是否是内部员工
                        string openid  = userdata.openid;
                        bool   isExist = await _baseUserRepository.ExistAsync(c => c.OpenId == openid && c.EnabledMark == 1 && c.DeleteMark == 0);

                        if (isExist)
                        {
                            var user = new UserInfoModel
                            {
                                cellphone = userdata.cellphone,
                                email     = userdata.email,
                                figureurl = userdata.figureurl,
                                nickname  = userdata.nickname,
                                openid    = userdata.openid,
                                sex       = userdata.sex
                            };
                            _memoryCache.Set(clamin.Value, user, expireTime - DateTime.Now);
                            return(Json(ResponseResult.Execute(user)));
                        }
                        return(Json(ResponseResult.Execute("20001", "用户不存在")));
                    }
                    return(Json(ResponseResult.Execute("10009", "任务过多,系统繁忙")));
                }
            }
            return(Json(ResponseResult.Execute("10026", "令牌不存在或已过期")));
        }
        public static IApplicationBuilder UseCustomerExceptionHandler(this IApplicationBuilder app)
        {
            return(app.UseExceptionHandler(errorApp =>
            {
                // Normally you'd use MVC or similar to render a nice page.
                errorApp.Run(async context =>
                {
                    context.Response.StatusCode = 501;
                    context.Response.ContentType = "application/json";

                    var error = context.Features.Get <IExceptionHandlerFeature>();

                    if (error != null)
                    {
                        //if (error.Error is NotImplementedException)
                        //{//TODO:自定义返回异常信息
                        //    string log = JsonConvert.SerializeObject(ResponseResult.Execute(error.Error)); //真实日志信息
                        //    string text=JsonConvert.SerializeObject(ResponseResult.Execute("自定义返回内容"));
                        //    await context.Response.WriteAsync(text);
                        //}
                        if (error.Error is TimeoutException)
                        { //TODO:自定义返回异常信息
                            string text = JsonConvert.SerializeObject(ResponseResult.Execute("10010", "任务超时"));
                            await context.Response.WriteAsync(text);
                        }
                        else if (error.Error is StewardException)
                        {
                            var ex = error.Error as StewardException;
                            string text = JsonConvert.SerializeObject(ResponseResult.Execute(ex.Code, ex.Message));
                            await context.Response.WriteAsync(text);
                        }
                        else
                        {
                            string text = JsonConvert.SerializeObject(ResponseResult.Execute("10001", "系统错误"));
                            await context.Response.WriteAsync(text);
                        }
                        //TODO:异步记录日志
                    }
                });
            }));
        }
 public override void OnResultExecuting(ResultExecutingContext context)
 {
     //根据实际需求进行具体实现
     if (context.Result is ObjectResult)
     {
         var objectResult = context.Result as ObjectResult;
         context.Result = objectResult.Value == null ? new JsonResult(ResponseResult.Execute("404", "Not Found")) : new JsonResult(ResponseResult.Execute(objectResult.Value));
     }
     else if (context.Result is EmptyResult)
     {
         context.Result = new JsonResult(ResponseResult.Execute("404", "Not Found"));
     }
     else if (context.Result is ContentResult)
     {
         context.Result = new JsonResult(ResponseResult.Execute((context.Result as ContentResult).Content));
     }
     else if (context.Result is StatusCodeResult)
     {
         context.Result = new JsonResult(ResponseResult.Execute((context.Result as StatusCodeResult).StatusCode.ToString(), ""));
     }
     base.OnResultExecuting(context);
 }