Files
KJD_WebService/Store.Framework/Base/ApiControllerBase.cs
T
chfei fa03add754 增加同步物流模块
修改现有架构,改为分模块( 简易版)
2026-09-22 17:52:42 +08:00

59 lines
1.4 KiB
C#

using KJD_Web.Utils;
using Newtonsoft.Json;
using Store.Framework.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using System.Web.Http.Controllers;
namespace Store.Framework.Base;
public abstract class ApiControllerBase : ApiController
{
protected bool ValidateSign(SignRequestBase request, bool isUserLogin = false)
{
if (request == null || string.IsNullOrEmpty(request.time) || string.IsNullOrEmpty(request.code))
{
return false;
}
int time;
if (!int.TryParse(request.time, out time))
{
return false;
}
if (request.code != EncrypUtil.Encryption(time))
{
return false;
}
if (!isUserLogin && string.IsNullOrWhiteSpace(request.UserName))
{
return false;
}
return true;
}
private bool IsAllowAnonymous(HttpActionContext context)
{
// Action 上
if (context.ActionDescriptor.GetCustomAttributes<AllowAnonymousAttribute>().Any())
return true;
// Controller 上
if (context.ControllerContext.ControllerDescriptor.ControllerType
.GetCustomAttributes(typeof(AllowAnonymousAttribute), true).Any())
return true;
return false;
}
private async Task<HttpResponseMessage> OkResponseAsync(object content)
{
IHttpActionResult result = Ok(content);
return await result.ExecuteAsync(CancellationToken.None);
}
}