Commit 905acc38 authored by liudong1993's avatar liudong1993

1

parent eebb84bd
...@@ -57,12 +57,14 @@ namespace Mall.WebApi.Controllers.User ...@@ -57,12 +57,14 @@ namespace Mall.WebApi.Controllers.User
[RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)] [RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)]
public ApiResult Login(object requestMsg) public ApiResult Login(object requestMsg)
{ {
var lObj = JObject.Parse(requestMsg.ToString()); var lObj = JObject.Parse(requestMsg.ToString());
var requestParm = new RequestParm() var requestParm = new RequestParm()
{ {
TenantId = lObj.GetInt("TenantId"), TenantId = lObj.GetInt("TenantId"),
MallBaseId = lObj.GetInt("MallBaseId"), MallBaseId = lObj.GetInt("MallBaseId"),
msg=lObj.GetStringValue("msg") token = lObj.GetStringValue("token"),
msg = lObj.GetStringValue("msg")
}; };
JObject parms = JObject.Parse(requestParm.msg.ToString()); JObject parms = JObject.Parse(requestParm.msg.ToString());
RB_Member_User_Extend demodel = new RB_Member_User_Extend() RB_Member_User_Extend demodel = new RB_Member_User_Extend()
...@@ -97,6 +99,7 @@ namespace Mall.WebApi.Controllers.User ...@@ -97,6 +99,7 @@ namespace Mall.WebApi.Controllers.User
return ApiResult.ParamIsNull("请传递唯一码"); return ApiResult.ParamIsNull("请传递唯一码");
} }
int LoginUserId = 0;
var opcache = UserReidsCache.GetMiniAppUsetOpenId(demodel.OpenId); var opcache = UserReidsCache.GetMiniAppUsetOpenId(demodel.OpenId);
if (opcache != null && !string.IsNullOrEmpty(opcache.UserOpenId)) if (opcache != null && !string.IsNullOrEmpty(opcache.UserOpenId))
{ {
...@@ -104,7 +107,22 @@ namespace Mall.WebApi.Controllers.User ...@@ -104,7 +107,22 @@ namespace Mall.WebApi.Controllers.User
demodel.OpenId = opcache.UserOpenId; demodel.OpenId = opcache.UserOpenId;
} }
else { else {
return ApiResult.ParamIsNull("未获取到唯一码,请刷新后再试"); if (string.IsNullOrEmpty(requestParm.token))
{
return ApiResult.ParamIsNull("请传递唯一码");
}
else {
LoginUserId = JWTValidatGetUserId(requestParm.token);
if (LoginUserId <= 0) {
return ApiResult.ParamIsNull("请传递唯一码");
}
var loginModel = UserReidsCache.GetAppletUserLoginInfo(LoginUserId);
demodel.OpenId = loginModel?.OpenId ?? "";
if (string.IsNullOrEmpty(demodel.OpenId))
{
return ApiResult.ParamIsNull("请传递唯一码");
}
}
} }
Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend couponResult = new Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend(); Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend couponResult = new Model.Extend.MarketingCenter.RB_DiscountCoupon_Extend();
...@@ -463,7 +481,39 @@ namespace Mall.WebApi.Controllers.User ...@@ -463,7 +481,39 @@ namespace Mall.WebApi.Controllers.User
/// <summary>
/// token校验
/// </summary>
/// <param name="actionContext"></param>
/// <param name="token"></param>
private int JWTValidatGetUserId( string token)
{
int UserID = 0;
if (!string.IsNullOrEmpty(token))
{
//解析token,校验是否失效
try
{
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 = Config.JwtSecretKey;
var json = decoder.Decode(token, secret, verify: true);//token为之前生成的字符串
JObject jwtJson = JObject.Parse(json);
string userInfo = jwtJson["mall_userInfo"].ToString();
JObject parms = JObject.Parse(userInfo);
UserID = parms.GetInt("uid", 0);
}
catch (Exception)
{
}
}
return UserID;
}
......
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