Commit b064bf4c authored by 黄奎's avatar 黄奎

页面修改

parent d774bc62
...@@ -86,6 +86,61 @@ namespace Mall.CacheManager.User ...@@ -86,6 +86,61 @@ namespace Mall.CacheManager.User
/// </summary> /// </summary>
private static readonly Repository.User.RB_Login_LogRepository login_LogRepository = new Repository.User.RB_Login_LogRepository(); private static readonly Repository.User.RB_Login_LogRepository login_LogRepository = new Repository.User.RB_Login_LogRepository();
/// <summary>
/// 缓存用户OpenId
/// </summary>
/// <param name="TenantId">商户Id</param>
/// <returns></returns>
public static void SetMiniAppUsetOpenId(string cacheKey, MiniAppUserCache cacheModel)
{
try
{
TimeSpan ts = GetExpirTime(Config.JwtExpirTime);
redis.StringSet<MiniAppUserCache>(cacheKey, cacheModel, ts);
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "SetMiniAppUsetOpenId");
}
}
/// <summary>
/// 获取缓存用户OpenId
/// </summary>
/// <param name="TenantId">商户Id</param>
/// <returns></returns>
public static MiniAppUserCache GetMiniAppUsetOpenId(string cacheKey)
{
MiniAppUserCache miniAppUserCache = null;
try
{
miniAppUserCache = redis.StringGet<MiniAppUserCache>(cacheKey);
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "SetMiniAppUsetOpenId");
}
return miniAppUserCache;
}
/// <summary>
/// 删除OpenId缓存
/// </summary>
/// <param name="TenantId">商户Id</param>
/// <returns></returns>
public static void DeleteMiniAppUsetOpenId(string cacheKey)
{
try
{
redis.KeyDelete(cacheKey);
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "DeleteMiniAppUsetOpenId");
}
}
/// <summary> /// <summary>
/// 获取用户登录信息 /// 获取用户登录信息
/// </summary> /// </summary>
......
...@@ -158,4 +158,12 @@ namespace Mall.Common ...@@ -158,4 +158,12 @@ namespace Mall.Common
public int ERPGroupId { get; set; } public int ERPGroupId { get; set; }
} }
public class MiniAppUserCache
{
/// <summary>
/// 用户OpenId
/// </summary>
public string UserOpenId { get; set; }
}
} }
...@@ -47,7 +47,7 @@ namespace Mall.Common.Plugin ...@@ -47,7 +47,7 @@ namespace Mall.Common.Plugin
{ {
//请求路径 //请求路径
string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + AppId + "&secret=" + AppSecret + "&js_code=" + Code + "&grant_type=authorization_code"; string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + AppId + "&secret=" + AppSecret + "&js_code=" + Code + "&grant_type=authorization_code";
result= Common.Plugin.HttpHelper.HttpGet(url); result = Common.Plugin.HttpHelper.HttpGet(url);
if (result != null && !string.IsNullOrEmpty(result)) if (result != null && !string.IsNullOrEmpty(result))
{ {
JObject jObj = JObject.Parse(result); JObject jObj = JObject.Parse(result);
...@@ -66,6 +66,40 @@ namespace Mall.Common.Plugin ...@@ -66,6 +66,40 @@ namespace Mall.Common.Plugin
return openid; return openid;
} }
/// <summary>
/// 验证OpenId是否有效
/// </summary>
/// <param name="AppId"></param>
/// <param name="AppSecret"></param>
/// <param name="OpenId"></param>
/// <returns></returns>
public static int ValidateOpenId(string AppId, string AppSecret,string OpenId)
{
string result = "";
string access_token = "";
try
{
//请求路径
string url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", AppId, AppSecret);
result = Common.Plugin.HttpHelper.HttpGet(url);
if (result != null && !string.IsNullOrEmpty(result))
{
JObject jObj = JObject.Parse(result);
access_token = jObj["access_token"].ToString();
}
if (!string.IsNullOrWhiteSpace(access_token))
{
string TestUrl = string.Format("https://api.weixin.qq.com/sns/auth?access_token={0}&openid={1}", access_token, OpenId);
result = Common.Plugin.HttpHelper.HttpGet(TestUrl);
}
}
catch (Exception ex)
{
Common.Plugin.LogHelper.Write(ex, "GetWeChatAccessToken:result=" + result);
}
return 1;
}
/// <summary> /// <summary>
/// 获取微信订阅消息模板 /// 获取微信订阅消息模板
/// </summary> /// </summary>
......
...@@ -566,6 +566,7 @@ namespace Mall.WebApi.Controllers.Education ...@@ -566,6 +566,7 @@ namespace Mall.WebApi.Controllers.Education
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
[RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)]
public ApiResult GetEducationStartUpModel(object requestMsg) public ApiResult GetEducationStartUpModel(object requestMsg)
{ {
var parms = JsonConvert.DeserializeObject<RequestParm>(requestMsg.ToString()); var parms = JsonConvert.DeserializeObject<RequestParm>(requestMsg.ToString());
......
...@@ -4,6 +4,7 @@ using System.Linq; ...@@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dnc.Api.Throttle; using Dnc.Api.Throttle;
using Mall.CacheManager.User; using Mall.CacheManager.User;
using Mall.Common;
using Mall.Common.API; using Mall.Common.API;
using Mall.Common.Plugin; using Mall.Common.Plugin;
using Mall.Model.Entity.BaseSetUp; using Mall.Model.Entity.BaseSetUp;
...@@ -481,7 +482,8 @@ namespace Mall.WebApi.Controllers.MallBase ...@@ -481,7 +482,8 @@ namespace Mall.WebApi.Controllers.MallBase
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
[HttpPost] [HttpPost]
[AllowAnonymous] [RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)] [AllowAnonymous]
[RateValve(Policy = Policy.Ip, Limit = 10, Duration = 60)]
public ApiResult GetAppConfig() public ApiResult GetAppConfig()
{ {
string MiniAppId = ""; string MiniAppId = "";
...@@ -713,8 +715,16 @@ namespace Mall.WebApi.Controllers.MallBase ...@@ -713,8 +715,16 @@ namespace Mall.WebApi.Controllers.MallBase
{ {
openId = Common.Plugin.WeiXinHelper.GetWeChatOpenId(miniProgram.MiniAppId, miniProgram.MiniAppSecret, code); openId = Common.Plugin.WeiXinHelper.GetWeChatOpenId(miniProgram.MiniAppId, miniProgram.MiniAppSecret, code);
} }
//string newOpenId = "oyEzY5J8llEXYMeC2O7Y06g2SO4M";
//Common.Plugin.WeiXinHelper.GetWeChat(miniProgram.MiniAppId, miniProgram.MiniAppSecret, newOpenId);
} }
return ApiResult.Success(data: openId); var newGuid = Guid.NewGuid().ToString();
var miniAppUserCache = new MiniAppUserCache()
{
UserOpenId= openId
};
UserReidsCache.SetMiniAppUsetOpenId(newGuid, miniAppUserCache);
return ApiResult.Success(data: newGuid);
} }
/// <summary> /// <summary>
......
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