Commit a1727541 authored by 吴春's avatar 吴春

1

parent b7ee1d44
......@@ -162,5 +162,24 @@ namespace Edu.Common.Plugin
}
return result;
}
/// <summary>
/// 获取请求数据
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static string HttpClientGet(string url)
{
HttpClient httpClient = new HttpClient();
HttpResponseMessage res = httpClient.GetAsync(url).Result;
if (res.IsSuccessStatusCode)
{
Task<string> t = res.Content.ReadAsStringAsync();
return t.Result;
}
return string.Empty;
}
}
}
\ No newline at end of file
......@@ -118,6 +118,11 @@ namespace Edu.Common.Plugin
return userInfo;
}
/// <summary>
/// 获取微信授权手机号码
/// </summary>
......@@ -223,4 +228,55 @@ namespace Edu.Common.Plugin
public string phoneNumber { get; set; }
}
#region 微信登录获取返回的access_token (通过 code 获取access_token
/// <summary>
/// 通过 code 获取access_token
/// </summary>
public class GetTokenByCode
{
/// <summary>
/// refresh_token
/// </summary>
public string access_token { get; set; }
/// <summary>
/// access_token接口调用凭证超时时间,单位(秒)
/// </summary>
public string expires_in { get; set; }
/// <summary>
/// 用户刷新access_token
/// </summary>
public string refresh_token { get; set; }
/// <summary>
/// 授权用户唯一标识
/// </summary>
public string openid { get; set; }
/// <summary>
/// 用户授权的作用域,使用逗号(,)分隔
/// </summary>
public string scope { get; set; }
/// <summary>
/// 当且仅当该网站应用已获得该用户的 userinfo 授权时,才会出现该字段。
/// </summary>
public string unionid { get; set; }
/// <summary>
/// 错误状态码
/// </summary>
public string errcode { get; set; }
/// <summary>
/// 错误提示信息
/// </summary>
public string errmsg { get; set; }
}
#endregion
}
\ No newline at end of file
......@@ -24,7 +24,8 @@ namespace Edu.Module.User
/// </summary>
/// <param name="empId"></param>
/// <returns></returns>
public Employee_ViewModel GetEmployeeInfo(int empId) {
public Employee_ViewModel GetEmployeeInfo(int empId)
{
return accountRepository.GetEmployeeInfo(empId);
}
......@@ -102,8 +103,11 @@ namespace Edu.Module.User
Dictionary<string, object> fileds = new Dictionary<string, object>()
{
{nameof(RB_Account_ViewModel.OpenId),model.OpenId.Trim() },
{nameof(RB_Account_ViewModel.UnionId),model.UnionId.Trim() }
};
if (!string.IsNullOrWhiteSpace(model.UnionId))
{
fileds.Add(nameof(RB_Account_ViewModel.UnionId), model.UnionId.Trim());
}
flag = accountRepository.Update(fileds, new WhereHelper(nameof(RB_Account_ViewModel.Id), model.Id));
}
return flag;
......
......@@ -426,5 +426,53 @@ namespace Edu.WebApi.Controllers.Applet
}
}
#endregion
#region 根据openid 绑定用户的账号信息
/// <summary>
/// 取消预约
/// </summary>
/// <returns></returns>
[HttpPost]
public ApiResult GetOpenIdBindAccount()
{
var userInfo = base.AppletUserInfo;
string openId = ParmJObj.GetStringValue("OpenId");
if (string.IsNullOrWhiteSpace(openId))
{
return ApiResult.ParamIsNull("请传递OpenId");
}
var model = accountModule.GetStudentExt(new RB_Account_ViewModel()
{
Id = userInfo.Id,
AccountId = userInfo.AccountId,
AccountType = Common.Enum.User.AccountTypeEnum.Student
})?.FirstOrDefault();
if (!string.IsNullOrWhiteSpace(model.OpenId))
{
return ApiResult.Failed("账户已绑定微信信息,请勿重复操作");
}
var modelOpenId = accountModule.GetStudentExt(new RB_Account_ViewModel()
{
OpenId = openId.Trim(),
AccountType = Common.Enum.User.AccountTypeEnum.Student
})?.FirstOrDefault();
if ((modelOpenId?.Id ?? 0) > 0)
{
return ApiResult.Failed("微信信息已绑定账户,请勿重复操作");
}
model.OpenId = openId;
model.UnionId = "";
var flag = accountModule.UpdateAccountUnionId(model);
if (flag)
{
return ApiResult.Success();
}
else
{
return ApiResult.Failed("绑定失败");
}
}
#endregion
}
}
......@@ -23,6 +23,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Senparc.Weixin.MP.AdvancedAPIs;
namespace Edu.WebApi.Controllers.APP
{
......@@ -68,7 +69,7 @@ namespace Edu.WebApi.Controllers.APP
}
else if (model.Status == Common.Enum.DateStateEnum.Delete)
{
return ApiResult.Failed(message: $"此账号【{ account }】已禁用", new { Error = 2 });
return ApiResult.Failed(message: $"此账号【{account}】已禁用", new { Error = 2 });
}
else if (model.ActivationStatus == 0)
{
......@@ -125,7 +126,7 @@ namespace Edu.WebApi.Controllers.APP
}
if (model.Status == Common.Enum.DateStateEnum.Delete)
{
return ApiResult.Failed(message: $"此账号【{ account }】已禁用", new { Error = 2 });
return ApiResult.Failed(message: $"此账号【{account}】已禁用", new { Error = 2 });
}
//判断学员是否退学
......@@ -169,7 +170,7 @@ namespace Edu.WebApi.Controllers.APP
//{
// return ApiResult.Failed(message: "用户不存在", new { Error = -1 });
//}
IUserInfoToken mallUserInfo = new ErpTokenUserInfo { uid = (umodel?.Id??0).ToString(), requestFrom = Common.Enum.ApiRequestFromEnum.MallMiniProgram };
IUserInfoToken mallUserInfo = new ErpTokenUserInfo { uid = (umodel?.Id ?? 0).ToString(), requestFrom = Common.Enum.ApiRequestFromEnum.MallMiniProgram };
#region JWT
IDateTimeProvider provider = new UtcDateTimeProvider();
var now = provider.GetNow().AddMinutes(-1);
......@@ -204,7 +205,7 @@ namespace Edu.WebApi.Controllers.APP
TeacherName = studentModel.TeacherName,
CourseName = studentModel.CourseName,
StuSex = studentModel.StuSex,
StuBirth = studentModel.StuBirth.HasValue ? studentModel.StuBirth.Value.ToString("yyyy-MM-dd") : "",
StuBirth = studentModel.StuBirth.HasValue ? studentModel.StuBirth.Value.ToString("yyyy-MM-dd") : "",
ClassScrollType = studentModel.ClassScrollType,
Token = token,
GroupLogo = model.GroupLogo,
......@@ -262,7 +263,8 @@ namespace Edu.WebApi.Controllers.APP
}
else
{
if (model == null && IsVisitor == 1) {
if (model == null && IsVisitor == 1)
{
int GroupId = 100000;//默认
int CreateBy = 1;//默认管理员
//游客登录 注册游客信息
......@@ -315,7 +317,7 @@ namespace Edu.WebApi.Controllers.APP
}
if (model.Status == Common.Enum.DateStateEnum.Delete)
{
return ApiResult.Failed(message: $"此账号【{ account }】已禁用", new { Error = 2 });
return ApiResult.Failed(message: $"此账号【{account}】已禁用", new { Error = 2 });
}
//判断学员是否退学
......@@ -358,7 +360,7 @@ namespace Edu.WebApi.Controllers.APP
//{
// return ApiResult.Failed(message: "用户不存在", new { Error = -1 });
//}
IUserInfoToken mallUserInfo = new ErpTokenUserInfo { uid = (umodel?.Id??0).ToString(), requestFrom = Common.Enum.ApiRequestFromEnum.MallMiniProgram };
IUserInfoToken mallUserInfo = new ErpTokenUserInfo { uid = (umodel?.Id ?? 0).ToString(), requestFrom = Common.Enum.ApiRequestFromEnum.MallMiniProgram };
#region JWT
IDateTimeProvider provider = new UtcDateTimeProvider();
var now = provider.GetNow().AddMinutes(-1);
......@@ -419,6 +421,193 @@ namespace Edu.WebApi.Controllers.APP
}
}
/// <summary>
/// 根据OpenId一键登录
/// </summary>
/// <returns></returns>
[HttpGet]
[HttpPost]
[AllowAnonymous]
public ApiResult LoginByOpenId()
{
JObject jobj = JObject.Parse(RequestParm.Msg.ToString());
string UnionId = jobj.GetStringValue("UnionId");
string OpenId = jobj.GetStringValue("OpenId");
int IsVisitor = jobj.GetInt("IsVisitor", 0);// 1是游客登录
string WeChatName = jobj.GetStringValue("WeChatName");
string WeChatPhoto = jobj.GetStringValue("WeChatPhoto");
var model = accountModule.GetStudentExt(new RB_Account_ViewModel()
{
OpenId = OpenId.Trim(),
AccountType = Common.Enum.User.AccountTypeEnum.Student
})?.FirstOrDefault();
if (model == null && IsVisitor == 0)
{
return ApiResult.Failed(message: "手机号码登录失败、跳转至账号登录", new { Error = -1 });
}
else
{
if (model == null && IsVisitor == 1)
{
int GroupId = 100000;//默认
int CreateBy = 1;//默认管理员
//游客登录 注册游客信息
studentModule.SetStudentModule(new RB_Student_ViewModel()
{
StuId = 0,
StuName = WeChatName,
StuTel = "",
StuIcon = WeChatPhoto,
StuSex = 0,
StuBirth = null,
ProviceId = 0,
CityId = 0,
AreaId = 0,
Group_Id = GroupId,
School_Id = 0,
Status = 0,
CreateBy = CreateBy,
CreateTime = DateTime.Now,
UpdateBy = CreateBy,
UpdateTime = DateTime.Now,
IsDisable = 1,
StuStatus = 0,
CreateType = Common.Enum.User.StuCreateTypeEnum.EmployeeInput,
StuStage = 1,
StuChannel = 0,
PlatformName = "",
StuType = 0,
StuRealMobile = ""
});
//再次获取学生信息
model = accountModule.GetStudentExt(new RB_Account_ViewModel() { OpenId = OpenId, AccountType = Common.Enum.User.AccountTypeEnum.Student })?.FirstOrDefault();
}
if (model == null)
{
return ApiResult.Failed(message: "游客注册失败", new { Error = -2 });
}
if (!string.IsNullOrEmpty(model.OpenId))//UnionId是否为空,为空则绑定手机号与UnionId
{
if (OpenId != model.OpenId)
{
//return ApiResult.Failed("手机号与绑定的微信账户不一致", new { Error = 0 });
}
}
else
{
model.UnionId = UnionId;
model.OpenId = OpenId;
var flag = accountModule.UpdateAccountUnionId(model);
}
if (model.Status == Common.Enum.DateStateEnum.Delete)
{
return ApiResult.Failed(message: $"此账号【{model.Account}】已禁用", new { Error = 2 });
}
//判断学员是否退学
var studentList = studentModule.GetStudentInfoModule(model.AccountId, model.Group_Id);
//if (studentList == null || !studentList.Any())
//{
// return ApiResult.Failed(message: $"很抱歉,由于你已经退学,无法继续使用本系统", new { Error = 3 });
//}
RB_Student_ViewModel studentModel = new RB_Student_ViewModel();
if (studentList.Any())
{
studentModel = studentList.Where(x => x.ClassStatus == 2).FirstOrDefault();
if (studentModel == null || studentModel.StuId == 0)
{
studentModel = new RB_Student_ViewModel();
studentModel = studentList.Where(x => x.ClassStatus == 1).FirstOrDefault();
if (studentModel == null || studentModel.StuId == 0)
{
studentModel = new RB_Student_ViewModel();
studentModel = studentList.Where(x => x.ClassStatus == 3).FirstOrDefault();
}
}
}
//生成教育token
EduUserInfoToken eduUserInfo = new EduUserInfoToken()
{
requestFrom = Common.Enum.ApiRequestFromEnum.AppletStudent,
uid = model.Id.ToString()
};
string token = WebApiTokenHelper.CreateToken(Common.GlobalKey.JWT_User_Key, eduUserInfo);
//上传配置
var uploadConfig = publicModule.GetFileStoreList(new Model.Public.RB_File_Store() { Group_Id = model.Group_Id, IsDefault = 1 })?.FirstOrDefault();
#region 获取甲鹤小程序端token
//查询用户信息
var umodel = studentModule.GetMemberUserEntityModule(new RB_Member_User_Extend() { TenantId = Convert.ToInt32(Config.JHTenantId), MallBaseId = Convert.ToInt32(Config.JHMallBaseId), Source = 1, OpenId = Config.JHMallUserOpenId });
//if (umodel == null)
//{
// return ApiResult.Failed(message: "用户不存在", new { Error = -1 });
//}
IUserInfoToken mallUserInfo = new ErpTokenUserInfo { uid = (umodel?.Id ?? 0).ToString(), requestFrom = Common.Enum.ApiRequestFromEnum.MallMiniProgram };
#region JWT
IDateTimeProvider provider = new UtcDateTimeProvider();
var now = provider.GetNow().AddMinutes(-1);
var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); // or use JwtValidator.UnixEpoch
var secondsSinceEpoch = Math.Round((now - unixEpoch).TotalSeconds);
var payload = new Dictionary<string, object>
{
{"iat",secondsSinceEpoch },
{"exp",secondsSinceEpoch + Config.JwtExpirTime},
{"mall_userInfo",mallUserInfo }
};
IJwtAlgorithm algorithm = new HMACSHA256Algorithm();
IJsonSerializer serializer = new JsonNetSerializer();
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder);
string secret = Config.JwtSecretKey;
string mallUserToken = encoder.Encode(payload, secret);
#endregion
#endregion
AppletStudentInfo obj = new AppletStudentInfo
{
Id = model.Id,
AccountType = model.AccountType,
Group_Id = model.Group_Id,
GroupName = model.GroupName,
School_Id = studentModel.SId,
AccountId = model.AccountId,
AccountName = model.AccountName,
SchoolName = studentModel.SName,
TeacherName = studentModel.TeacherName,
CourseName = studentModel.CourseName,
StuSex = studentModel.StuSex,
StuBirth = studentModel.StuBirth.HasValue ? studentModel.StuBirth.Value.ToString("yyyy-MM-dd") : "",
ClassScrollType = studentModel.ClassScrollType,
Token = token,
GroupLogo = model.GroupLogo,
UserIcon = model.UserIcon,
MallToken = mallUserToken,
ApiRequestFromEnum = Common.Enum.ApiRequestFromEnum.AppletStudent,
JHMallBaseId = Config.JHMallBaseId,
JHTenantId = Config.JHTenantId,
JHMallUserId = model?.Id ?? 0,
JHMallUserOpenId = Config.JHMallUserOpenId,
UploadConfig = new
{
uploadConfig?.Bucket,
uploadConfig?.StoreType,
uploadConfig?.Region,
uploadConfig?.CustomDomain,
uploadConfig?.SecretKey,
uploadConfig?.SecretId,
uploadConfig?.UploadDomain
}
};
Cache.User.AppletStudentReidsCache.UserInfoSet(Cache.CacheKey.AppletStudent_Login_Key + model.Id, obj, Common.Config.JwtExpirTime);
return ApiResult.Success(data: obj);
}
}
#region 小程序获取手机号码
/// <summary>
/// 获取手机号码
......@@ -445,7 +634,7 @@ namespace Edu.WebApi.Controllers.APP
}
catch
{
Common.Plugin.LogHelper.Write("GetGuestWeiXinMobile:1"+Common.Plugin.JsonHelper.Serialize(res));
Common.Plugin.LogHelper.Write("GetGuestWeiXinMobile:1" + Common.Plugin.JsonHelper.Serialize(res));
try
{
res = Common.Plugin.WeChatHelper.GetWechatMobile(encryptedData, code, iv);
......@@ -455,7 +644,7 @@ namespace Edu.WebApi.Controllers.APP
Common.Plugin.LogHelper.Write("GetGuestWeiXinMobile:2" + Common.Plugin.JsonHelper.Serialize(res));
}
}
if (res.phoneNumber== null||string.IsNullOrEmpty(res.phoneNumber))
if (res.phoneNumber == null || string.IsNullOrEmpty(res.phoneNumber))
{
Thread.Sleep(10);
try
......@@ -469,7 +658,7 @@ namespace Edu.WebApi.Controllers.APP
{
res = Common.Plugin.WeChatHelper.GetWechatMobile(encryptedData, code, iv);
}
catch
catch
{
Common.Plugin.LogHelper.Write("GetGuestWeiXinMobile:4" + Common.Plugin.JsonHelper.Serialize(res));
}
......@@ -515,6 +704,307 @@ namespace Edu.WebApi.Controllers.APP
return ApiResult.Success(data: userinfo);
}
/// <summary>
/// 获取用户信息
/// </summary>
/// <returns></returns>
[HttpGet]
[HttpPost]
[AllowAnonymous]
public ApiResult GetWeChatUserInfo()
{
JObject parms = JObject.Parse(RequestParm.Msg.ToString());
string code = parms.GetStringValue("Code");
string Appid = Common.Config.WeChatAccountAppId;
var Secret = Common.Config.WeChatAccountAppSecret;
if (string.IsNullOrEmpty(code))
{
return ApiResult.ParamIsNull();
}
string url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + Appid + "&secret=" + Secret + "&code=" + code + "&grant_type=authorization_code";
string type = "utf-8";
GetUsersHelper GetUsersHelper = new GetUsersHelper();
string wenXinResult = string.Empty;
JObject jo = null;
GetTokenByCode res = new GetTokenByCode();
try
{
wenXinResult = GetUsersHelper.GetUrltoHtml(url, type);//获取微信服务器返回字符串
jo = (JObject)JsonConvert.DeserializeObject(wenXinResult);//将字符串转换为json格式
LogHelper.WriteInfo(wenXinResult);
//微信服务器验证成功
res.access_token = jo["access_token"].ToString();//获取到了access_token
//res.expires_in = jo["expires_in"].ToString();
//res.refresh_token = jo["refresh_token"].ToString();//获取到了refresh_token
res.openid = jo["openid"].ToString();//获取到了openid
//res.scope = jo["scope"].ToString();
//res.unionid = jo["unionid"].ToString();
if (string.IsNullOrWhiteSpace(res.openid))
{
return ApiResult.Failed("获取Token失败");
}
string error = "";
if (jo.Property("errcode") != null)//是否存在
{
error = jo["errcode"].ToString();
}
if (!string.IsNullOrWhiteSpace(error))
{
return ApiResult.Failed(jo["errmsg"].ToString());
}
//将用户的token保存起方便后面用
try
{
string userInfoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" + res.access_token + "&openid=" + res.openid;
string userInfoResult = HttpHelper.HttpClientGet(userInfoUrl);
JObject userInfoJ = (JObject)JsonConvert.DeserializeObject(userInfoResult);//将字符串转换为json格式
if (userInfoJ.Property("errcode") != null)//是否存在
{
error = userInfoJ["errcode"].ToString();
}
if (!string.IsNullOrWhiteSpace(error))
{
return ApiResult.Failed(userInfoJ["errmsg"].ToString());
}
string unionid = "";
if (userInfoJ.Property("unionid") != null)//是否存在
{
unionid = userInfoJ["unionid"].ToString();
}
string OpenId = "";
if (userInfoJ.Property("openid") != null)//是否存在
{
OpenId = userInfoJ["openid"].ToString();
}
string nickname = "";
if (userInfoJ.Property("nickname") != null)//是否存在
{
nickname = userInfoJ["nickname"].ToString();
}
int Sex = 0;
if (userInfoJ.Property("sex") != null && !string.IsNullOrWhiteSpace(userInfoJ["sex"].ToString()))
{
Sex = Convert.ToInt32(userInfoJ["sex"].ToString());
}
string Photo = "";
if (userInfoJ.Property("headimgurl") != null)//是否存在
{
Photo = userInfoJ["headimgurl"].ToString();
}
return ApiResult.Success(data: new { unionid, OpenId, nickname, Sex, Photo });
}
catch (Exception ex)
{
return ApiResult.Failed("获取用户信息失败");
}
}
catch (Exception ex)
{
return ApiResult.Failed("获取用户信息失败");
}
}
/// <summary>
/// 注册学员信息 学员注册:账号,密码,姓名,OpenId(非必填)
/// </summary>
/// <returns></returns>
[HttpGet]
[HttpPost]
[AllowAnonymous]
public ApiResult GetRegisterStu()
{
JObject jobj = JObject.Parse(RequestParm.Msg.ToString());
string account = jobj.GetStringValue("Account").Trim();
string password = jobj.GetStringValue("Password").Trim();
string openId = jobj.GetStringValue("OpenId");
string WeChatPhoto = jobj.GetStringValue("WeChatPhoto");
string name = jobj.GetStringValue("Name").Trim();
if (string.IsNullOrEmpty(account))
{
return ApiResult.Failed(message: "请输入账号", new { Error = -1 });
}
if (string.IsNullOrEmpty(password))
{
return ApiResult.Failed(message: "请输入密码", new { Error = -1 });
}
if (!string.IsNullOrWhiteSpace(openId))
{
var modelOpenId = accountModule.GetStudentExt(new RB_Account_ViewModel()
{
OpenId = openId.Trim(),
AccountType = Common.Enum.User.AccountTypeEnum.Student
})?.FirstOrDefault();
if ((modelOpenId?.Id ?? 0) > 0)
{
return ApiResult.Failed("OpenId已绑定账户,快去登录吧");
}
}
var modelOld = accountModule.GetStudentExt(new RB_Account_ViewModel()
{
Account = account.Trim(),
AccountType = Common.Enum.User.AccountTypeEnum.Student
})?.FirstOrDefault();
if ((modelOld?.Id ?? 0) > 0)
{
return ApiResult.Failed(message: "用户已存在", new { Error = -1 });
}
if (password != "Viitto!@#123")
{
password = Common.DES.Encrypt(password);
}
int GroupId = 100000;//默认
int CreateBy = 1;//默认管理员
studentModule.SetStudentModule(new RB_Student_ViewModel()
{
StuId = 0,
StuName = name,
StuTel = account,
StuIcon = WeChatPhoto,
StuSex = 0,
StuBirth = null,
ProviceId = 0,
CityId = 0,
AreaId = 0,
Group_Id = GroupId,
School_Id = 0,
Status = 0,
CreateBy = CreateBy,
CreateTime = DateTime.Now,
UpdateBy = CreateBy,
UpdateTime = DateTime.Now,
IsDisable = 1,
StuStatus = 0,
CreateType = Common.Enum.User.StuCreateTypeEnum.EmployeeInput,
StuStage = 1,
StuChannel = 0,
PlatformName = "",
StuType = 0,
StuRealMobile = account,
});
//再次获取学生信息
var model = accountModule.GetStudentExt(new RB_Account_ViewModel() { Account = account.Trim(), AccountType = Common.Enum.User.AccountTypeEnum.Student })?.FirstOrDefault();
if ((model?.Id ?? 0) > 0)
{
model.UnionId = "";
model.OpenId = openId;
model.ActivationStatus = 1;
var flag = accountModule.SetResetPwdAndAtatus(model, password);
//判断学员是否退学
var studentList = studentModule.GetStudentInfoModule(model.AccountId, model.Group_Id);
//if (studentList == null || !studentList.Any())
//{
// return ApiResult.Failed(message: $"很抱歉,由于你已经退学,无法继续使用本系统", new { Error = 3 });
//}
RB_Student_ViewModel studentModel = new RB_Student_ViewModel();
if (studentList.Any())
{
studentModel = studentList.Where(x => x.ClassStatus == 2).FirstOrDefault();
if (studentModel == null || studentModel.StuId == 0)
{
studentModel = new RB_Student_ViewModel();
studentModel = studentList.Where(x => x.ClassStatus == 1).FirstOrDefault();
if (studentModel == null || studentModel.StuId == 0)
{
studentModel = new RB_Student_ViewModel();
studentModel = studentList.Where(x => x.ClassStatus == 3).FirstOrDefault();
}
}
}
//生成教育token
EduUserInfoToken eduUserInfo = new EduUserInfoToken()
{
requestFrom = Common.Enum.ApiRequestFromEnum.AppletStudent,
uid = model.Id.ToString()
};
string token = WebApiTokenHelper.CreateToken(Common.GlobalKey.JWT_User_Key, eduUserInfo);
//上传配置
var uploadConfig = publicModule.GetFileStoreList(new Model.Public.RB_File_Store() { Group_Id = model.Group_Id, IsDefault = 1 })?.FirstOrDefault();
#region 获取甲鹤小程序端token
//查询用户信息
var umodel = studentModule.GetMemberUserEntityModule(new RB_Member_User_Extend() { TenantId = Convert.ToInt32(Config.JHTenantId), MallBaseId = Convert.ToInt32(Config.JHMallBaseId), Source = 1, OpenId = Config.JHMallUserOpenId });
//if (umodel == null)
//{
// return ApiResult.Failed(message: "用户不存在", new { Error = -1 });
//}
IUserInfoToken mallUserInfo = new ErpTokenUserInfo { uid = (umodel?.Id ?? 0).ToString(), requestFrom = Common.Enum.ApiRequestFromEnum.MallMiniProgram };
#region JWT
IDateTimeProvider provider = new UtcDateTimeProvider();
var now = provider.GetNow().AddMinutes(-1);
var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); // or use JwtValidator.UnixEpoch
var secondsSinceEpoch = Math.Round((now - unixEpoch).TotalSeconds);
var payload = new Dictionary<string, object>
{
{"iat",secondsSinceEpoch },
{"exp",secondsSinceEpoch + Config.JwtExpirTime},
{"mall_userInfo",mallUserInfo }
};
IJwtAlgorithm algorithm = new HMACSHA256Algorithm();
IJsonSerializer serializer = new JsonNetSerializer();
IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder();
IJwtEncoder encoder = new JwtEncoder(algorithm, serializer, urlEncoder);
string secret = Config.JwtSecretKey;
string mallUserToken = encoder.Encode(payload, secret);
#endregion
#endregion
AppletStudentInfo obj = new AppletStudentInfo
{
Id = model.Id,
AccountType = model.AccountType,
Group_Id = model.Group_Id,
GroupName = model.GroupName,
School_Id = studentModel.SId,
AccountId = model.AccountId,
AccountName = model.AccountName,
SchoolName = studentModel.SName,
TeacherName = studentModel.TeacherName,
CourseName = studentModel.CourseName,
StuSex = studentModel.StuSex,
StuBirth = studentModel.StuBirth.HasValue ? studentModel.StuBirth.Value.ToString("yyyy-MM-dd") : "",
ClassScrollType = studentModel.ClassScrollType,
Token = token,
GroupLogo = model.GroupLogo,
UserIcon = model.UserIcon,
MallToken = mallUserToken,
ApiRequestFromEnum = Common.Enum.ApiRequestFromEnum.AppletStudent,
JHMallBaseId = Config.JHMallBaseId,
JHTenantId = Config.JHTenantId,
JHMallUserId = model?.Id ?? 0,
JHMallUserOpenId = Config.JHMallUserOpenId,
UploadConfig = new
{
uploadConfig?.Bucket,
uploadConfig?.StoreType,
uploadConfig?.Region,
uploadConfig?.CustomDomain,
uploadConfig?.SecretKey,
uploadConfig?.SecretId,
uploadConfig?.UploadDomain
}
};
Cache.User.AppletStudentReidsCache.UserInfoSet(Cache.CacheKey.AppletStudent_Login_Key + model.Id, obj, Common.Config.JwtExpirTime);
return ApiResult.Success(data: obj);
}
else
{
return ApiResult.Failed("注册失败");
}
}
#endregion
}
}
......@@ -46,8 +46,8 @@
"JHTenantId": "15",
"JHMallBaseId": "5",
"JHMallUserOpenId": "oshxs5I-6uR1J91Rs3QVyi2rJIm4",
"WeChatAccountAppId": "wx7c2cedaebbfca211",
"WeChatAccountAppSecret": "6fd676c7f599bc2783fab6ae6c7a12d4",
"WeChatAccountAppId": "wx17ed4ce5c80be02c",
"WeChatAccountAppSecret": "2d777c2ed4627423bace16f2428b2169",
"Notice_BaseKey": "Notice_BaseKey",
"QYWeiChatToken": "b3e0ebf63301f80cb8e741cf72fdaf3c",
"QYWeiChatEncodingAESKey": "ODRjOGEwYWQxNWJkNDRkMTg2NGJiOWY1ZTE4LCE0NmY",
......
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