Commit 460e78dd authored by 黄奎's avatar 黄奎

页面修改

parent 7b46a13c
......@@ -73,5 +73,13 @@ namespace Edu.Cache
/// </summary>
public static string GZH_ZYSH_Key = "GZH_ZYSHToken_Key_";
/// <summary>
/// AppletB2B_Login_1(用户id)
/// </summary>
public static string AppletB2B_Login_Info_
{
get { return "AppletB2B_Login_"; }
}
}
}
using Edu.CacheManager.Base;
using Edu.Common;
using Edu.Common.API;
using Edu.Common.Enum;
using Edu.Common.Enum.Customer;
using Edu.Model.CacheModel;
using Edu.Repository.Customer;
using Edu.Repository.User;
using System;
using System.Linq;
......@@ -176,8 +180,85 @@ namespace Edu.Cache.User
/// <param name="Id"></param>
public static void ClearUserLoginCache(object Id)
{
string cacheKey = Cache.CacheKey.User_Login_Key + Id.ToString();
string cacheKey = CacheKey.User_Login_Key + Id.ToString();
redis.KeyDelete(cacheKey);
}
/// <summary>
/// 同业
/// </summary>
private static readonly RB_CustomerRepository customerRepository = new RB_CustomerRepository();
/// <summary>
/// 获取同于用户登录信息
/// </summary>
/// <param name="CustomerId"></param>
/// <returns></returns>
public static AppletCustomerInfo GetAppletCustomerLoginInfo(object CustomerId)
{
if (CustomerId != null)
{
string cacheKey = CacheKey.AppletB2B_Login_Info_ + CustomerId.ToString();
AppletCustomerInfo userInfo = null;
try
{
userInfo = redis.StringGet<AppletCustomerInfo>(cacheKey);
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "GetAppletCustomerLoginInfo");
}
if (userInfo == null)
{
Int32.TryParse(CustomerId.ToString(), out int NewUserId);
if (NewUserId > 0)
{
string token = "";
var umodel = customerRepository.GetEntity(NewUserId);
if (umodel != null && umodel.CustomerState == CustomerStateEnum.Normal)
{
userInfo = new AppletCustomerInfo
{
MallBaseId = umodel.MallBaseId,
MallName = "",
Mobile = umodel.ContactNumber,
CustomerId = NewUserId,
CustomerName = umodel.CustomerName,
OpenId = umodel.OpenId,
Photo = umodel.WeChatPhoto,
Source = umodel.CustomerSourceType,
CustomerToken = token,
Blacklist = 0,
GroupId = umodel.Group_Id,
IsAdmin = 0,
AdminId = 0
};
AppletCustomerSet(CacheKey.AppletB2B_Login_Info_ + CustomerId, userInfo, Config.JwtExpirTime);
}
}
}
return userInfo;
}
return null;
}
/// <summary>
/// 设置同业用户缓存
/// </summary>
/// <param name="cacheKey"></param>
/// <param name="model"></param>
/// <param name="JwtExpirTime"></param>
public static void AppletCustomerSet(string cacheKey, AppletCustomerInfo model, int JwtExpirTime)
{
try
{
TimeSpan ts = GetExpirTime(JwtExpirTime);
redis.StringSet<AppletCustomerInfo>(cacheKey, model, ts);
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "AppletCustomerSet缓存设置失败");
}
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Text;
namespace Edu.Common.API
{
/// <summary>
/// 小程序同业信息缓存
/// </summary>
public class AppletCustomerInfo
{
/// <summary>
/// 教育集团
/// </summary>
public int GroupId
{
get;
set;
}
/// <summary>
/// 小程序ID
/// </summary>
public int MallBaseId { get; set; }
/// <summary>
/// 同业id
/// </summary>
public int CustomerId { get; set; }
/// <summary>
/// 唯一码
/// </summary>
public string OpenId
{
get;
set;
}
/// <summary>
/// 名称
/// </summary>
public string CustomerName
{
get;
set;
}
/// <summary>
/// 手机号码
/// </summary>
public string Mobile
{
get;
set;
}
/// <summary>
/// 头像
/// </summary>
public string Photo { get; set; }
/// <summary>
/// 来源 1微信 2支付宝
/// </summary>
public int Source
{
get;
set;
}
/// <summary>
/// 商城名称
/// </summary>
public string MallName
{
get;
set;
}
/// <summary>
/// token
/// </summary>
public string CustomerToken { get; set; }
/// <summary>
/// 是否加入了黑名单 1是
/// </summary>
public int? Blacklist { get; set; }
/// <summary>
/// 是否管理员 1是
/// </summary>
public int IsAdmin { get; set; }
/// <summary>
/// 小程序管理员编号
/// </summary>
public int AdminId { get; set; }
}
}
......@@ -14,6 +14,12 @@
/// 用户ID
/// </summary>
public string Uid { get; set; }
/// <summary>
/// 客户编号
/// </summary>
public string CustomerId { get; set; }
/// <summary>
/// 请求消息
/// </summary>
......@@ -34,6 +40,11 @@
/// </summary>
public string Token { get; set; }
/// <summary>
/// 同业小程序用户Token
/// </summary>
public string B2BToken { get; set; }
/// <summary>
/// 客户端版本
/// </summary>
......
......@@ -29,7 +29,8 @@
/// <summary>
/// Mall用户TokenKey
/// </summary>
public const string JWT_Mall_User_Key = "userInfo";
public const string JWT_Mall_Customer_Key = "mall_userInfo";
/// <summary>
/// app学生用户TokenKey
/// </summary>
......
......@@ -185,6 +185,11 @@ namespace Edu.Model.Entity.Customer
/// <summary>
/// 头像
/// </summary>
public string WeChatPhoto { get; set; }
public string WeChatPhoto { get; set; }
/// <summary>
/// 小程序ID
/// </summary>
public int MallBaseId { get; set; }
}
}
\ No newline at end of file
......@@ -5,11 +5,11 @@ using VT.FW.DB;
namespace Edu.Model.Entity.Customer
{
/// <summary>
/// 同业客户任务实体类
/// 任务实体类
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Customer_Task
public class RB_Task
{
/// <summary>
/// 主键编号
......
......@@ -7,11 +7,11 @@ using VT.FW.DB;
namespace Edu.Model.Entity.Customer
{
/// <summary>
/// 同业客户任务详情实体类
/// 任务详情实体类
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_Customer_TaskDetails
public class RB_TaskDetails
{
/// <summary>
/// 任务详情编号
......
......@@ -226,5 +226,12 @@ namespace Edu.Model.Entity.Sell
/// 学员毕业时间
/// </summary>
public DateTime? GraduationTime { get; set; }
/// <summary>
/// 续费状态 1正常 2续费
/// </summary>
public int RenewState { get; set; }
}
}
......@@ -9,7 +9,7 @@ namespace Edu.Model.ViewModel.Customer
/// <summary>
/// 同业客户任务详情扩展实体类
/// </summary>
public class RB_Customer_TaskDetails_Extend : RB_Customer_TaskDetails
public class RB_TaskDetails_Extend : RB_TaskDetails
{
/// <summary>
/// 任务编号【逗号分割】
......
......@@ -8,7 +8,7 @@ namespace Edu.Model.ViewModel.Customer
/// <summary>
/// 同业客户任务扩展实体类
/// </summary>
public class RB_Customer_Task_Extend : RB_Customer_Task
public class RB_Task_Extend : RB_Task
{
/// <summary>
/// 创建人
......@@ -18,7 +18,7 @@ namespace Edu.Model.ViewModel.Customer
/// <summary>
/// 任务详情列表
/// </summary>
public List<RB_Customer_TaskDetails_Extend> DetailsList { get; set; }
public List<RB_TaskDetails_Extend> DetailsList { get; set; }
/// <summary>
/// 任务开始时间
......
......@@ -19,12 +19,12 @@ namespace Edu.Module.Customer
/// <summary>
/// 任务仓储层对象
/// </summary>
private readonly RB_Customer_TaskRepository customer_TaskRepository = new RB_Customer_TaskRepository();
private readonly RB_TaskRepository customer_TaskRepository = new RB_TaskRepository();
/// <summary>
/// 任务详情仓储层对象
/// </summary>
private readonly RB_Customer_TaskDetailsRepository detailsRepository = new RB_Customer_TaskDetailsRepository();
private readonly RB_TaskDetailsRepository detailsRepository = new RB_TaskDetailsRepository();
/// <summary>
/// 课程仓储层对象
......@@ -49,16 +49,16 @@ namespace Edu.Module.Customer
/// <param name="rowsCount"></param>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Customer_Task_Extend> GetCustomerTaskPageModule(int pageIndex, int pageSize, out long rowsCount, RB_Customer_Task_Extend query)
public List<RB_Task_Extend> GetTaskPageModule(int pageIndex, int pageSize, out long rowsCount, RB_Task_Extend query)
{
var list = customer_TaskRepository.GetCustomerTaskPageRepository(pageIndex, pageSize, out rowsCount, query);
var list = customer_TaskRepository.GetTaskPageRepository(pageIndex, pageSize, out rowsCount, query);
if (list != null && list.Count > 0)
{
string Ids = string.Join(",", list.Select(qitem => qitem.Id));
var detailsList = new List<RB_Customer_TaskDetails_Extend>();
var detailsList = new List<RB_TaskDetails_Extend>();
if (!string.IsNullOrEmpty(Ids))
{
detailsList = detailsRepository.GetCustomerTaskDetailsListRepository(new RB_Customer_TaskDetails_Extend()
detailsList = detailsRepository.GetTaskDetailsListRepository(new RB_TaskDetails_Extend()
{
QTaskIds = Ids
});
......@@ -76,7 +76,7 @@ namespace Edu.Module.Customer
/// 处理子任务
/// </summary>
/// <param name="detailsList"></param>
private void ParsingSubTaskTarget(List<RB_Customer_TaskDetails_Extend> detailsList)
private void ParsingSubTaskTarget(List<RB_TaskDetails_Extend> detailsList)
{
if (detailsList != null && detailsList.Count > 0)
{
......@@ -163,24 +163,24 @@ namespace Edu.Module.Customer
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool SetCustomerTaskModule(RB_Customer_Task_Extend model)
public bool SetCustomerTaskModule(RB_Task_Extend model)
{
bool flag = false;
if (model.Id > 0)
{
Dictionary<string, object> fileds = new Dictionary<string, object>()
{
{nameof(RB_Customer_Task_Extend.TaskName),model.TaskName },
{nameof(RB_Customer_Task_Extend.TaskSubTitle),model.TaskSubTitle },
{nameof(RB_Customer_Task_Extend.TaskImage),model.TaskImage },
{nameof(RB_Customer_Task_Extend.TaskStartTime),model.TaskStartTime },
{nameof(RB_Customer_Task_Extend.TaskEndTime),model.TaskEndTime },
{nameof(RB_Customer_Task_Extend.TaskDesc),model.TaskDesc },
{nameof(RB_Customer_Task_Extend.UpdateBy),model.UpdateBy },
{nameof(RB_Customer_Task_Extend.UpdateTime),model.UpdateTime },
{nameof(RB_Customer_Task_Extend.ExchangeEndTime),model.ExchangeEndTime },
{nameof(RB_Task_Extend.TaskName),model.TaskName },
{nameof(RB_Task_Extend.TaskSubTitle),model.TaskSubTitle },
{nameof(RB_Task_Extend.TaskImage),model.TaskImage },
{nameof(RB_Task_Extend.TaskStartTime),model.TaskStartTime },
{nameof(RB_Task_Extend.TaskEndTime),model.TaskEndTime },
{nameof(RB_Task_Extend.TaskDesc),model.TaskDesc },
{nameof(RB_Task_Extend.UpdateBy),model.UpdateBy },
{nameof(RB_Task_Extend.UpdateTime),model.UpdateTime },
{nameof(RB_Task_Extend.ExchangeEndTime),model.ExchangeEndTime },
};
flag = customer_TaskRepository.Update(fileds, new WhereHelper(nameof(RB_Customer_Task_Extend.Id), model.Id));
flag = customer_TaskRepository.Update(fileds, new WhereHelper(nameof(RB_Task_Extend.Id), model.Id));
}
else
{
......@@ -192,7 +192,7 @@ namespace Edu.Module.Customer
if (model.DetailsList != null && model.DetailsList.Count > 0)
{
var oldList = detailsRepository.GetCustomerTaskDetailsListRepository(new RB_Customer_TaskDetails_Extend() {
var oldList = detailsRepository.GetTaskDetailsListRepository(new RB_TaskDetails_Extend() {
TaskId = model.Id
});
//以前没有任务详情信息【直接新增】
......@@ -234,17 +234,17 @@ namespace Edu.Module.Customer
{
Dictionary<string, object> subFileds = new Dictionary<string, object>()
{
{nameof(RB_Customer_TaskDetails_Extend.TaskId),item.TaskId },
{nameof(RB_Customer_TaskDetails_Extend.DetailsName),item.DetailsName },
{nameof(RB_Customer_TaskDetails_Extend.TaskType),item.TaskType },
{nameof(RB_Customer_TaskDetails_Extend.TargetId),item.TargetId },
{nameof(RB_Customer_TaskDetails_Extend.TaskFinishType),item.TaskFinishType },
{nameof(RB_Customer_TaskDetails_Extend.TaskFinishValue),item.TaskFinishValue },
{nameof(RB_Customer_TaskDetails_Extend.TaskKudo),item.TaskKudo },
{nameof(RB_Customer_TaskDetails_Extend.TaskKudoImg),item.TaskKudoImg },
{nameof(RB_Customer_TaskDetails_Extend.KudoDescription),item.KudoDescription },
{nameof(RB_TaskDetails_Extend.TaskId),item.TaskId },
{nameof(RB_TaskDetails_Extend.DetailsName),item.DetailsName },
{nameof(RB_TaskDetails_Extend.TaskType),item.TaskType },
{nameof(RB_TaskDetails_Extend.TargetId),item.TargetId },
{nameof(RB_TaskDetails_Extend.TaskFinishType),item.TaskFinishType },
{nameof(RB_TaskDetails_Extend.TaskFinishValue),item.TaskFinishValue },
{nameof(RB_TaskDetails_Extend.TaskKudo),item.TaskKudo },
{nameof(RB_TaskDetails_Extend.TaskKudoImg),item.TaskKudoImg },
{nameof(RB_TaskDetails_Extend.KudoDescription),item.KudoDescription },
};
detailsRepository.Update(subFileds,new WhereHelper(nameof(RB_Customer_TaskDetails_Extend.DetailId),item.DetailId));
detailsRepository.Update(subFileds,new WhereHelper(nameof(RB_TaskDetails_Extend.DetailId),item.DetailId));
}
}
}
......@@ -265,9 +265,9 @@ namespace Edu.Module.Customer
{
Dictionary<string, object> fileds = new Dictionary<string, object>()
{
{nameof(RB_Customer_Task_Extend.Status),(int)DateStateEnum.Delete},
{nameof(RB_Task_Extend.Status),(int)DateStateEnum.Delete},
};
var flag = customer_TaskRepository.Update(fileds, new WhereHelper(nameof(RB_Customer_Task_Extend.Id), Id));
var flag = customer_TaskRepository.Update(fileds, new WhereHelper(nameof(RB_Task_Extend.Id), Id));
return flag;
}
......@@ -277,12 +277,12 @@ namespace Edu.Module.Customer
/// </summary>
/// <param name="CustomerId"></param>
/// <returns></returns>
public RB_Customer_Task_Extend GetCustomerTaskModule(object Id)
public RB_Task_Extend GetCustomerTaskModule(object Id)
{
var extModel = customer_TaskRepository.GetEntity<RB_Customer_Task_Extend>(Id);
var extModel = customer_TaskRepository.GetEntity<RB_Task_Extend>(Id);
if (extModel != null)
{
var detailsList = detailsRepository.GetCustomerTaskDetailsListRepository(new RB_Customer_TaskDetails_Extend()
var detailsList = detailsRepository.GetTaskDetailsListRepository(new RB_TaskDetails_Extend()
{
TaskId = extModel.Id
});
......
......@@ -10,33 +10,33 @@ namespace Edu.Repository.Customer
/// <summary>
/// 同业客户任务详情仓储层
/// </summary>
public class RB_Customer_TaskDetailsRepository : BaseRepository<RB_Customer_TaskDetails>
public class RB_TaskDetailsRepository : BaseRepository<RB_TaskDetails>
{
/// <summary>
/// 获取任务详情列表
/// </summary>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Customer_TaskDetails_Extend> GetCustomerTaskDetailsListRepository(RB_Customer_TaskDetails_Extend query)
public List<RB_TaskDetails_Extend> GetTaskDetailsListRepository(RB_TaskDetails_Extend query)
{
StringBuilder builder = new StringBuilder();
builder.AppendFormat(@"
SELECT A.*
FROM RB_Customer_TaskDetails AS A
FROM RB_TaskDetails AS A
WHERE 1=1
");
if (query != null)
{
if (query.TaskId > 0)
{
builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Customer_TaskDetails_Extend.TaskId), query.TaskId);
builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_TaskDetails_Extend.TaskId), query.TaskId);
}
if (!string.IsNullOrEmpty(query.QTaskIds))
{
builder.AppendFormat(@" AND A.{0} IN({1}) ", nameof(RB_Customer_TaskDetails_Extend.TaskId), query.QTaskIds);
builder.AppendFormat(@" AND A.{0} IN({1}) ", nameof(RB_TaskDetails_Extend.TaskId), query.QTaskIds);
}
}
return Get<RB_Customer_TaskDetails_Extend>(builder.ToString()).ToList();
return Get<RB_TaskDetails_Extend>(builder.ToString()).ToList();
}
......@@ -47,7 +47,7 @@ WHERE 1=1
/// <returns></returns>
public bool DeleteByTaskIdRepository(int TaskId)
{
string sql = string.Format(" DELETE FROM RB_Customer_TaskDetails WHERE TaskId IN({0}) ", TaskId);
string sql = string.Format(" DELETE FROM RB_TaskDetails WHERE TaskId IN({0}) ", TaskId);
return base.Execute(sql) > 0;
}
}
......
......@@ -12,7 +12,7 @@ namespace Edu.Repository.Customer
/// <summary>
/// 同业客户任务仓储层
/// </summary>
public class RB_Customer_TaskRepository : BaseRepository<RB_Customer_Task>
public class RB_TaskRepository : BaseRepository<RB_Task>
{
/// <summary>
/// 获取任务分页列表
......@@ -22,29 +22,29 @@ namespace Edu.Repository.Customer
/// <param name="rowsCount"></param>
/// <param name="query"></param>
/// <returns></returns>
public List<RB_Customer_Task_Extend> GetCustomerTaskPageRepository(int pageIndex, int pageSize, out long rowsCount, RB_Customer_Task_Extend query)
public List<RB_Task_Extend> GetTaskPageRepository(int pageIndex, int pageSize, out long rowsCount, RB_Task_Extend query)
{
var parameters = new DynamicParameters();
StringBuilder builder = new StringBuilder();
builder.AppendFormat(@"
SELECT A.*
FROM RB_Customer_Task AS A
FROM RB_Task AS A
WHERE 1=1
");
builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Customer_Task_Extend.Status), (int)DateStateEnum.Normal);
builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Task_Extend.Status), (int)DateStateEnum.Normal);
if (query != null)
{
if (query.Group_Id > 0)
{
builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Customer_Task_Extend.Group_Id), query.Group_Id);
builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Task_Extend.Group_Id), query.Group_Id);
}
if (!string.IsNullOrEmpty(query.TaskName))
{
builder.AppendFormat(" AND A.{0} LIKE @TaskName ", nameof(RB_Customer_Task_Extend.TaskName));
builder.AppendFormat(" AND A.{0} LIKE @TaskName ", nameof(RB_Task_Extend.TaskName));
parameters.Add("TaskName", "%" + query.TaskName.Trim() + "%");
}
}
return GetPage<RB_Customer_Task_Extend>(pageIndex, pageSize, out rowsCount, builder.ToString(), parameters).ToList();
return GetPage<RB_Task_Extend>(pageIndex, pageSize, out rowsCount, builder.ToString(), parameters).ToList();
}
}
}
......@@ -43,6 +43,11 @@ namespace Edu.WebApi.Controllers
JObject parms = JObject.Parse(Request.HttpContext.Items[GlobalKey.TokenUserInfo].ToString());
requestParm.Uid = parms.GetStringValue("uid");
}
if (Request.HttpContext.Items[GlobalKey.JWT_Mall_Customer_Key] != null)
{
JObject parms = JObject.Parse(Request.HttpContext.Items[GlobalKey.JWT_Mall_Customer_Key].ToString());
requestParm.CustomerId = parms.GetStringValue("uid");
}
}
#endregion
//根据token 获取uid
......@@ -103,5 +108,18 @@ namespace Edu.WebApi.Controllers
}
return flag;
}
/// <summary>
/// 获取同业用户缓存
/// </summary>
public AppletCustomerInfo AppletCustomerInfo
{
get
{
var parm = this.RequestParm;
AppletCustomerInfo userInfo = UserReidsCache.GetAppletCustomerLoginInfo(parm.CustomerId);
return userInfo;
}
}
}
}
\ No newline at end of file
......@@ -172,12 +172,12 @@ namespace Edu.WebApi.Controllers.Customer
public ApiResult GetCustomerTaskPage()
{
var pageModel = JsonHelper.DeserializeObject<ResultPageModel>(RequestParm.Msg.ToString());
var query = new RB_Customer_Task_Extend()
var query = new RB_Task_Extend()
{
Group_Id = base.UserInfo.Group_Id,
TaskName = base.ParmJObj.GetStringValue("TaskName"),
};
var list = taskModule.GetCustomerTaskPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
var list = taskModule.GetTaskPageModule(pageModel.PageIndex, pageModel.PageSize, out long rowsCount, query);
foreach (var item in list)
{
if (item.CreateBy > 0)
......@@ -197,7 +197,7 @@ namespace Edu.WebApi.Controllers.Customer
[HttpPost]
public ApiResult SetCustomerTask()
{
var model = new RB_Customer_Task_Extend()
var model = new RB_Task_Extend()
{
Id = base.ParmJObj.GetInt("Id"),
TaskName = base.ParmJObj.GetStringValue("TaskName"),
......@@ -221,7 +221,7 @@ namespace Edu.WebApi.Controllers.Customer
model.UpdateTime = DateTime.Now;
model.Group_Id = base.UserInfo.Group_Id;
model.School_Id = base.UserInfo.School_Id;
model.DetailsList = new List<RB_Customer_TaskDetails_Extend>();
model.DetailsList = new List<RB_TaskDetails_Extend>();
string details = base.ParmJObj.GetStringValue("DetailsList");
if (!string.IsNullOrEmpty(details))
{
......@@ -243,7 +243,7 @@ namespace Edu.WebApi.Controllers.Customer
{
imgKudoList = JsonHelper.DeserializeObject<List<string>>(taskKudoImageList);
}
model.DetailsList.Add(new RB_Customer_TaskDetails_Extend()
model.DetailsList.Add(new RB_TaskDetails_Extend()
{
DetailId = jobj.GetInt("DetailId"),
TaskId = jobj.GetInt("TaskId"),
......
......@@ -28,8 +28,9 @@ namespace Edu.WebApi.Filter
public override void OnActionExecuting(ActionExecutingContext actionContext)
{
string token = "";
string customerToken = "";
//请求参数
DoApiMonitorLog(actionContext, ref token);
DoApiMonitorLog(actionContext, ref token,ref customerToken);
bool isCheckToken = true;
var endpoint = actionContext.HttpContext.Features.Get<IEndpointFeature>()?.Endpoint;
if (endpoint != null && endpoint.Metadata.GetMetadata<AllowAnonymousAttribute>() != null)
......@@ -40,7 +41,7 @@ namespace Edu.WebApi.Filter
//Token校验
if (isCheckToken)
{
JWTValidat(actionContext, token);
JWTValidat(actionContext, token, customerToken);
}
#region 验证表单重复提交
......@@ -86,7 +87,7 @@ namespace Edu.WebApi.Filter
/// <param name="actionContext"></param>
/// <param name="token"></param>
/// <returns></returns>
private JObject DoApiMonitorLog(ActionExecutingContext actionContext, ref string token)
private JObject DoApiMonitorLog(ActionExecutingContext actionContext, ref string token,ref string customerToken)
{
JObject parm = new JObject();
var request = actionContext.HttpContext.Request;
......@@ -112,6 +113,7 @@ namespace Edu.WebApi.Filter
Common.Plugin.LogHelper.Write(ex, string.Format("DoApiMonitorLog:{0}", responseData));
}
token = headers["token"].ToString();
customerToken = headers["B2BToken"].ToString();
}
#endregion
return parm;
......@@ -122,7 +124,7 @@ namespace Edu.WebApi.Filter
/// </summary>
/// <param name="actionContext"></param>
/// <param name="token"></param>
private static void JWTValidat(ActionExecutingContext actionContext, string token)
private static void JWTValidat(ActionExecutingContext actionContext, string token,string customerToken)
{
if (!string.IsNullOrEmpty(token))
{
......@@ -133,7 +135,7 @@ namespace Edu.WebApi.Filter
var tokenUser = Common.Plugin.JsonHelper.DeserializeObject<EduUserInfoToken>(jwtJson[Common.GlobalKey.JWT_User_Key].ToString());
if (tokenUser != null)
{
var cacheUser = UserReidsCache.GetUserLoginInfo(tokenUser.uid,apiRequestFromEnum: tokenUser.requestFrom);
var cacheUser = UserReidsCache.GetUserLoginInfo(tokenUser.uid, apiRequestFromEnum: tokenUser.requestFrom);
if (Common.Config.IsOnline && cacheUser.ApiRequestFromEnum == tokenUser.requestFrom && (cacheUser.Token != token || string.IsNullOrWhiteSpace(cacheUser.Token)))
{
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(
......@@ -185,6 +187,68 @@ namespace Edu.WebApi.Filter
});
}
}
else if (!string.IsNullOrEmpty(customerToken))
{
//解析token,校验是否失效
try
{
JObject jwtJson = WebApiTokenHelper.AnalysisToken(customerToken, isCustomer: true);
JObject customerInfo = JObject.Parse(jwtJson[Common.GlobalKey.JWT_Mall_Customer_Key].ToString());
string customerId= customerInfo.GetStringValue("uid");
if (!string.IsNullOrEmpty(customerId))
{
var cacheCustomer = UserReidsCache.GetAppletCustomerLoginInfo(customerId);
if (Common.Config.IsOnline && (cacheCustomer.CustomerToken != customerToken || string.IsNullOrWhiteSpace(cacheCustomer.CustomerToken)))
{
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(
new ApiResult
{
Code = (int)ResultCode.TokenOverdue,
Message = "用户凭证失效,请重新登录0",
Data = null
});
}
else
{
actionContext.HttpContext.Items[Common.GlobalKey.JWT_Mall_Customer_Key] = jwtJson[Common.GlobalKey.JWT_Mall_Customer_Key];
}
}
}
catch (SignatureVerificationException sve)
{
string message = sve.Message;
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(
new ApiResult
{
Code = (int)ResultCode.TokenOverdue,
Message = "用户凭证失效,请重新登录1",
Data = null
});
}
catch (ArgumentException ae)
{
string message = ae.Message;
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(
new ApiResult
{
Code = (int)ResultCode.TokenIllegal,
Message = "用户凭证失效,请重新登录2",
Data = null
});
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "JWTValidat3");
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(
HttpStatusCode.OK,
new ApiResult
{
Code = (int)ResultCode.TokenIllegal,
Message = "用户凭证失效,请重新登录3",
Data = null
});
}
}
else
{
actionContext.Result = new Microsoft.AspNetCore.Mvc.JsonResult(
......@@ -195,6 +259,8 @@ namespace Edu.WebApi.Filter
Data = null
});
}
}
}
}
\ No newline at end of file
......@@ -44,14 +44,18 @@ namespace Edu.WebApi.Helper
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
public static JObject AnalysisToken(string token)
public static JObject AnalysisToken(string token,bool isCustomer=false)
{
IJsonSerializer serializer = new JsonNetSerializer();
IDateTimeProvider provider = new UtcDateTimeProvider();
IJwtValidator validator = new JwtValidator(serializer, provider);
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtDecoder decoder = new JwtDecoder(serializer, validator, urlEncoder);
string secret = Common.Config.JwtSecretKey;
string secret = Common.Config.JwtSecretKey; ;
if (isCustomer)
{
secret = Common.Config.MallJwtSecretKey;
}
//token为之前生成的字符串
var json = decoder.Decode(token, secret, verify: true);
JObject jwtJson = JObject.Parse(json);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment