24小时一体机服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

748 lines
30 KiB

using _24Hour.Model;
using com.sun.org.apache.bcel.@internal.generic;
using com.sun.xml.@internal.ws.api.model;
using Elight.Entity;
using Elight.Logic;
using Elight.Logic.SystemModel;
using Elight.Utility;
using Elight.Utility.Code;
using Elight.Utility.Encrypt;
using Elight.Utility.Extensions;
using Elight.Utility.logs;
using java.security;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
using SqlSugar;
using System.IdentityModel.Tokens.Jwt;
using System.Runtime.Serialization;
using System.Security.Claims;
using System.Text;
namespace _24Hour.Controllers
{
/// <summary>
/// <EFBFBD><EFBFBD>¼
/// </summary>
// [HiddenApi]
[ApiController]
[Route("api/APP")]
public class LoginController : ControllerBase
{
private readonly IConfiguration _configuration;
private readonly SqlSugarClient _db;//<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>
private readonly WriteSysLog _logs;//<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־
private readonly ILogger<LoginController> _logger;//<EFBFBD><EFBFBD>־
private readonly WechatMessagerClient wechatMessagerClient;
Result ret = new Result();
public LoginController(ILogger<LoginController> logger, SqlSugarClient db, IConfiguration configuration, WechatMessagerClient _wechatMessagerClient)
{
_logger = logger;
_db = db;
_configuration = configuration;
this.wechatMessagerClient = _wechatMessagerClient;
2 years ago
}
[HttpPost]
[Route("LoginDefault")]
[CustomCorsActionFilterAttribute]
public async Task<Result> LoginDefault()
{
var Passmd5 = Md5.Encrypt32("jcy@123456").ToLower();
var date = await _db.Queryable<App_Sys_UserModel>().Where(x => x.phone == "admin" && x.IsDeleted == 0).FirstAsync();
2 years ago
if (date == null)
{
ret.IsSucceed = false;
ret.Message = "<EFBFBD>˺Ų<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD>ᣡ";
return ret;
}
if (Passmd5 != date.Password)
{
ret.IsSucceed = false;
ret.Message = "<EFBFBD>˺Ż<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
return ret;
}
if (!string.IsNullOrEmpty(date.department))
{
var dept = await _db.Queryable<App_Sys_DepartModel>().Where(x => x.Id == date.department && x.IsDelete == 0).FirstAsync();
if (dept != null)
2 years ago
{
date.departmentName = dept.departname;
2 years ago
}
}
#region jwt<EFBFBD><EFBFBD><EFBFBD><EFBFBD>token
var tokenHandler = new JwtSecurityTokenHandler();
var claims = new Claim[]
{
new Claim(ClaimTypes.UserData,JsonConvert.SerializeObject(date)),
};
var key = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_configuration.GetSection("JwtConfiguration:Jwtkey").Value));
var signingCredentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
//Token
var jwttoken = new JwtSecurityToken(
issuer: _configuration.GetSection("JwtConfiguration:Issuer").Value,
audience: _configuration.GetSection("JwtConfiguration:Audience").Value,
claims: claims,
notBefore: DateTime.Now,
expires: DateTime.Now.AddDays(1),
signingCredentials: signingCredentials
);
//var token = new JwtSecurityTokenHandler().CreateToken(jwttoken);
var tokenString = new JwtSecurityTokenHandler().WriteToken(jwttoken);
ret.IsSucceed = true;
2 years ago
ret.result = new
{
Id = date.Id,
name = date.name,
sex = date.sex,
phone = date.phone,
photo = date.photo,
duties = date.duties,
identity = date.identity,
openId = date.wechatId,
2 years ago
unitCode = date.unitCode,
department = date.department,
departmentName = date.departmentName,
token = tokenString
};
#endregion
ret.IsSucceed = true;
2 years ago
return ret;
}
2 years ago
/// <summary>
/// ϵͳ<EFBFBD><EFBFBD>¼
/// </summary>
/// <param name="login"></param>
/// <returns></returns>
[HttpPost]
[Route("SystemLogin")]
[CustomCorsActionFilterAttribute]
public async Task<Result> SystemLogin(UserLogin login)
{
try
{
var Passmd5 = Md5.Encrypt32(login.Password).ToLower();
var date = await _db.Queryable<App_Sys_UserModel>().Where(x => x.phone == login.phone && x.IsDeleted == 0).FirstAsync();
if (date == null)
{
ret.IsSucceed = false;
ret.Message = "<EFBFBD>˺Ų<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD>ᣡ";
return ret;
}
if (Passmd5 != date.Password)
{
ret.IsSucceed = false;
ret.Message = "<EFBFBD>˺Ż<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
return ret;
}
if (!string.IsNullOrEmpty(date.department))
{
var dept = await _db.Queryable<App_Sys_DepartModel>().Where(x => x.Id == date.department && x.IsDelete == 0).FirstAsync();
if (dept != null)
{
date.departmentName = dept.departname;
}
}
#region jwt<EFBFBD><EFBFBD><EFBFBD><EFBFBD>token
var tokenHandler = new JwtSecurityTokenHandler();
var claims = new Claim[]
{
new Claim(ClaimTypes.UserData,JsonConvert.SerializeObject(date)),
};
var key = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_configuration.GetSection("JwtConfiguration:Jwtkey").Value));
var signingCredentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
//Token
var jwttoken = new JwtSecurityToken(
issuer: _configuration.GetSection("JwtConfiguration:Issuer").Value,
audience: _configuration.GetSection("JwtConfiguration:Audience").Value,
claims: claims,
notBefore: DateTime.Now,
expires: DateTime.Now.AddDays(1),
signingCredentials: signingCredentials
);
//var token = new JwtSecurityTokenHandler().CreateToken(jwttoken);
var tokenString = new JwtSecurityTokenHandler().WriteToken(jwttoken);
var Unitdate = await _db.Queryable<App_Sys_UnitModel>().FirstAsync(x => x.unitCode == date.unitCode);
ret.IsSucceed = true;
ret.result = new
{
Id = date.Id,
name = date.name,
sex = date.sex,
phone = date.phone,
photo = date.photo,
duties = date.duties,
identity = date.identity,
openId = date.wechatId,
unitCode = date.unitCode,
unitname = Unitdate?.unitname,
department = date.department,
departmentName = date.departmentName,
token = tokenString
};
#endregion
}
catch (Exception ex)
{
ret.IsSucceed = false;
ret.Message = $"{ex.Message}";
LogService.WriteLog(ex, "<EFBFBD><EFBFBD>¼");
}
return ret;
}
/// <summary>
/// app--<EFBFBD><EFBFBD>¼
/// </summary>
/// <param name="login"></param>
/// <returns></returns>
[HttpPost]
[Route("Login")]
[CustomCorsActionFilterAttribute]
public async Task<Result> Login(UserLogin login)
{
try
{
var Passmd5 = Md5.Encrypt32(login.Password).ToLower();
var date = await _db.Queryable<App_Sys_UserModel>().Where(x => x.phone == login.phone && x.IsDeleted == 0).FirstAsync();
if (date == null)
{
ret.IsSucceed = false;
ret.Message = "<EFBFBD>˺Ų<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD>ᣡ";
return ret;
}
if (date.identity == "<EFBFBD><EFBFBD>ʦ" && date.audit == 1)
{
ret.IsSucceed = false;
ret.Message = $"<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>δͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>{date.describe}<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD>ᣡ";
return ret;
}
else if (date.identity == "<EFBFBD><EFBFBD>ʦ" && date.audit == 2)
{
ret.IsSucceed = false;
ret.Message = "<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>";
return ret;
}
if (Passmd5 != date.Password)
{
ret.IsSucceed = false;
ret.Message = "<EFBFBD>˺Ż<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
return ret;
}
//else if (date.usertype == 1 && date.audit == null)
//{
// ret.IsSucceed = false;
// ret.Message = "<EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>";
// return ret;
//}
//else if (date.usertype == 1 && date.audit == 1)
//{
// ret.IsSucceed = false;
// ret.Message = $"<EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>{date.describe}<EFBFBD><EFBFBD>";
// return ret;
//}
else if (date.usertype == 0 && date.becurrent == 1)
{
ret.IsSucceed = false;
ret.Message = $"<EFBFBD>˺<EFBFBD>δ<EFBFBD><EFBFBD>Ȩ<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>";
return ret;
}
if (!string.IsNullOrEmpty(date.department))
{
var dept = await _db.Queryable<App_Sys_DepartModel>().Where(x => x.Id == date.department && x.IsDelete == 0).FirstAsync();
if (dept != null)
{
date.departmentName = dept.departname;
}
}
#region jwt<EFBFBD><EFBFBD><EFBFBD><EFBFBD>token
var tokenHandler = new JwtSecurityTokenHandler();
var claims = new Claim[]
{
new Claim(ClaimTypes.UserData,JsonConvert.SerializeObject(date)),
};
var key = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_configuration.GetSection("JwtConfiguration:Jwtkey").Value));
var signingCredentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
//Token
var jwttoken = new JwtSecurityToken(
issuer: _configuration.GetSection("JwtConfiguration:Issuer").Value,
audience: _configuration.GetSection("JwtConfiguration:Audience").Value,
claims: claims,
notBefore: DateTime.Now,
expires: DateTime.Now.AddDays(1),
signingCredentials: signingCredentials
);
//var token = new JwtSecurityTokenHandler().CreateToken(jwttoken);
var tokenString = new JwtSecurityTokenHandler().WriteToken(jwttoken);
ret.result = new
{
Id = date.Id,
name = date.name,
sex = date.sex,
phone = date.phone,
photo = date.photo,
duties = date.duties,
identity = date.identity,
openId = date.wechatId,
usertype = date.usertype,
unitCode = date.unitCode,
department = date.department,
departmentName = date.departmentName,
token = tokenString
};
#endregion
ret.IsSucceed = true;
}
catch (Exception ex)
{
ret.IsSucceed = false;
ret.Message = $"{ex.Message}";
LogService.WriteLog(ex, "<EFBFBD><EFBFBD>¼");
}
return ret;
}
/// <summary>
/// ΢<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Code <EFBFBD><EFBFBD>½
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
[HttpGet]
[Route("WeChatLoginCode")]
public async Task<Result> WeChatLoginByCode(string code)
{
var opendata = await GetOpenId(code);
if (opendata.IsSucceed == true)
{
return await WeChatLogin(opendata.result);
}
else
{
return opendata;
}
}
/// <summary>
/// ΢<EFBFBD>Ź<EFBFBD><EFBFBD>ں<EFBFBD>Code <EFBFBD><EFBFBD>½
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
[HttpGet]
[Route("WeChatLoginByGzhCode")]
public async Task<Result> WeChatLoginByGzhCode(string code)
{
var opendata = await GetGzhOpenId(code);
if (opendata.IsSucceed == true)
{
return await WeChatLogin(opendata.result);
}
else
{
return opendata;
}
}
///// <summary>
///// <EFBFBD><EFBFBD>ȡ΢<EFBFBD>Ź<EFBFBD><EFBFBD>ں<EFBFBD>Code
///// </summary>
///// <param name="code"></param>
///// <returns></returns>
//[HttpGet]
//[Route("GetCode")]
//public async Task<Result> GetCode(string code,string state)
//{
// var opendata = await GetGzhOpenId(code);
// if (opendata.IsSucceed == true)
// {
// return await WeChatLogin(opendata.result);
// }
// else
// {
// return opendata;
// }
//}
/// <summary>
/// ΢<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD>¼
/// </summary>
/// <param name="openId"></param>
/// <returns></returns>
[HttpGet]
[Route("WeChatLogin")]
public async Task<Result> WeChatLogin(string openId)
{
var date = await _db.Queryable<App_Sys_UserModel>()
.Where(q => q.IsDeleted == 0 && q.wechatId == openId)
.OrderByDescending(x => x.createtime)
.FirstAsync();
if (date != null)
{
if (date.identity == "<EFBFBD><EFBFBD>ʦ" && date.audit == 1)
{
ret.IsSucceed = false;
ret.Message = $"<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>δͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>{date.describe}<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD>ᣡ";
return ret;
}
else if (date.identity == "<EFBFBD><EFBFBD>ʦ" && date.audit == 2)
{
ret.IsSucceed = false;
ret.Message = "<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>";
return ret;
}
if (date.isdeactivate == 1)
{
ret.IsSucceed = false;
ret.Message = "<EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><EFBFBD>ѱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>";
return ret;
}
if (date.usertype == 0 && date.becurrent == 1)
{
ret.IsSucceed = false;
ret.Message = $"<EFBFBD>˺<EFBFBD>δ<EFBFBD><EFBFBD>Ȩ<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>";
return ret;
}
#region jwt<EFBFBD><EFBFBD><EFBFBD><EFBFBD>token
var tokenHandler = new JwtSecurityTokenHandler();
var claims = new Claim[]
{
new Claim(ClaimTypes.UserData,JsonConvert.SerializeObject(date)),
};
var key = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_configuration.GetSection("JwtConfiguration:Jwtkey").Value));
var signingCredentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
//Token
var jwttoken = new JwtSecurityToken(
issuer: _configuration.GetSection("JwtConfiguration:Issuer").Value,
audience: _configuration.GetSection("JwtConfiguration:Audience").Value,
claims: claims,
notBefore: DateTime.Now,
expires: DateTime.Now.AddDays(1),
signingCredentials: signingCredentials
);
//var token = new JwtSecurityTokenHandler().CreateToken(jwttoken);
var tokenString = new JwtSecurityTokenHandler().WriteToken(jwttoken);
ret.result = new
{
Id = date.Id,
name = date.name,
sex = date.sex,
phone = date.phone,
photo = date.photo,
duties = date.duties,
identity = date.identity,
usertype = date.usertype,
unitCode = date.unitCode,
token = tokenString,
openId = date.wechatId,
departmentPhoto = date.departmentPhoto,
identityphoto = date.identityphoto,
cardIdphoto = date.cardIdphoto
};
#endregion
ret.IsSucceed = true;
}
else
{
ret.IsSucceed = false;
ret.Message = <EFBFBD><EFBFBD>δ<EFBFBD><EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD>˺ţ<EFBFBD>";
}
return ret;
}
/// <summary>
/// APP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
[HttpPost]
[Route("AddUser1")]
public async Task<Result> AddUser1(App_Sys_UserModel UserModel)
{
try
{
_logger.LogInformation(UserModel.ConvertToJsonStr());
//if (string.IsNullOrEmpty(UserModel.wechatId) && await _db.Queryable<App_Sys_UserModel>().AnyAsync(x => x.wechatId == UserModel.wechatId && x.IsDeleted == 0))
//{
// ret.IsSucceed = false;
// ret.Message = "<EFBFBD><EFBFBD>ǰ΢<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺Ű<EFBFBD><EFBFBD><EFBFBD>";
// return ret;
//}
if (string.IsNullOrEmpty(UserModel.wechatId) == false)
{
if (await _db.Queryable<App_Sys_UserModel>().AnyAsync(x => x.wechatId == UserModel.wechatId && x.IsDeleted == 0 && x.audit != 1 && x.isdeactivate == 0))
{
ret.IsSucceed = false;
ret.Message = "<EFBFBD><EFBFBD>ǰ΢<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺Ű<EFBFBD><EFBFBD><EFBFBD>";
return ret;
}
}
var data = await _db.Queryable<App_Sys_UserModel>().Where(q => q.phone == UserModel.phone && q.IsDeleted == 0).FirstAsync();
if (UserModel.identity == "<EFBFBD><EFBFBD>ʦ")
{
if (data != null && (data.identity != "<EFBFBD><EFBFBD>ʦ" || data.audit == 0))
{
ret.IsSucceed = false;
ret.Message = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><EFBFBD>ڣ<EFBFBD>";
return ret;
}
else if (data != null && data.audit == 2)
{
ret.IsSucceed = false;
ret.Message = "<EFBFBD>˺<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>";
return ret;
}
2 years ago
if (data != null && data.audit == 1)
{
_db.BeginTran();
data.audit = 2;
data.describe = "";
data.photo = "/CaseFile/resource/headicon.png";
data.name = UserModel.name;
data.sex = UserModel.sex;
data.phone = UserModel.phone;
data.cardId = UserModel.cardId;
data.identitycardId = UserModel.identitycardId;
data.departmentName = UserModel.departmentName;
data.Password = Elight.Utility.Encrypt.Md5.Encrypt32($"{UserModel.Password}").ToLower();
data.cardIdphoto = UserModel.cardIdphoto;
data.identityphoto = UserModel.identityphoto;
data.departmentPhoto = UserModel.departmentPhoto;
var num = await _db.Updateable(data).IgnoreColumns(true).ExecuteCommandAsync();
_db.CommitTran();
if (num > 0)
{
ret.IsSucceed = true;
ret.result = "<EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD>,<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>";
}
}
else
{
_db.BeginTran();
UserModel.Id = Guid.NewGuid().ToString();
UserModel.usertype = 1;
UserModel.audit = 2;
if (string.IsNullOrEmpty(UserModel.photo))
{
UserModel.photo = "/CaseFile/resource/headicon.png";
}
//Ĭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UserModel.Password = Elight.Utility.Encrypt.Md5.Encrypt32($"{UserModel.Password}").ToLower();
var num = await _db.Insertable(UserModel).ExecuteCommandAsync();
_db.CommitTran();
if (num > 0)
{
ret.IsSucceed = true;
ret.result = "<EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD>";
}
}
}
else
{
if (data != null)
{
ret.IsSucceed = false;
ret.Message = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><EFBFBD>ڣ<EFBFBD>";
return ret;
}
_db.BeginTran();
UserModel.Id = Guid.NewGuid().ToString();
UserModel.usertype = 1;
//Ĭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
UserModel.Password = Elight.Utility.Encrypt.Md5.Encrypt32($"{UserModel.Password}").ToLower();
if (string.IsNullOrEmpty(UserModel.photo))
{
UserModel.photo = "/CaseFile/resource/headicon.png";
}
var num = await _db.Insertable(UserModel).ExecuteCommandAsync();
_db.CommitTran();
if (num > 0)
{
ret.IsSucceed = true;
ret.result = "<EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD>";
}
}
}
catch (System.Exception ex)
{
_db.RollbackTran();
ret.IsSucceed = false;
ret.Message = ex.Message;
}
return ret;
}
/// <summary>
/// <EFBFBD><EFBFBD>λlist<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
[HttpPost]
[Route("QueryUnitlist")]
public async Task<Result> QueryUnitlist(App_Sys_UnitInput Unitdata)
{
var list = await _db.Queryable<App_Sys_UnitModel>()
.WhereIF(!Unitdata.unitCode.IsNull(), q => q.unitCode.Contains(Unitdata.unitCode))
.WhereIF(!Unitdata.unitname.IsNull(), q => q.unitname.Contains(Unitdata.unitname))
.WhereIF(!Unitdata.unitjc.IsNull(), q => q.unitjc.Contains(Unitdata.unitjc))
.Where(q => q.IsDelete == 0).ToListAsync();
ret.IsSucceed = true;
ret.result = list;
return ret;
}
/// <summary>
/// <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
/// </summary>
/// <param name="Sendingdata"></param>
/// <returns></returns>
[HttpGet]
[Route("getrtsp")]
public async Task<Result> getrtsp(string str)
{
ret.IsSucceed = true;
ret.result = $"{_configuration.GetSection($"Videoaddress:{str}").Value}";
return ret;
}
[HttpGet]
[Route("cardIdLogin")]
public async Task<Result> cardIdLogin(string cardId, string name)
{
var date = await _db.Queryable<App_Sys_UserModel>().Where(q => q.IsDeleted == 0 && q.cardId == cardId && q.name == name).FirstAsync();
if (date != null)
{
//if (date.usertype == 1 && date.audit == null)
// {
// ret.IsSucceed = false;
// ret.Message = "<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>";
// return ret;
// }
// else if (date.usertype == 1 && date.audit == 1)
// {
// ret.IsSucceed = false;
// ret.Message = $"<EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>{date.describe}<EFBFBD><EFBFBD>";
// return ret;
// }
// else
if (date.usertype == 0 && date.becurrent == 1 && date.isdeactivate == 1)
{
ret.IsSucceed = false;
ret.Message = $"<EFBFBD>û<EFBFBD>δ<EFBFBD><EFBFBD>Ȩ<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>";
return ret;
}
#region jwt<EFBFBD><EFBFBD><EFBFBD><EFBFBD>token
var tokenHandler = new JwtSecurityTokenHandler();
var claims = new Claim[]
{
new Claim(ClaimTypes.UserData,JsonConvert.SerializeObject(date)),
};
var key = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_configuration.GetSection("JwtConfiguration:Jwtkey").Value));
var signingCredentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
//Token
var jwttoken = new JwtSecurityToken(
issuer: _configuration.GetSection("JwtConfiguration:Issuer").Value,
audience: _configuration.GetSection("JwtConfiguration:Audience").Value,
claims: claims,
notBefore: DateTime.Now,
expires: DateTime.Now.AddDays(1),
signingCredentials: signingCredentials
);
//var token = new JwtSecurityTokenHandler().CreateToken(jwttoken);
var tokenString = new JwtSecurityTokenHandler().WriteToken(jwttoken);
ret.result = new
{
Id = date.Id,
name = date.name,
sex = date.sex,
phone = date.phone,
photo = date.photo,
duties = date.duties,
identity = date.identity,
openId = date.wechatId,
usertype = date.usertype,
unitCode = date.unitCode,
token = tokenString
};
#endregion
ret.IsSucceed = true;
}
else
{
var datea = await _db.Queryable<App_Sys_UserModel>().Where(q => q.IsDeleted == 0 && q.cardId == cardId).FirstAsync();
if (datea == null)
{
var unitcode = _configuration.GetSection("CaseTwenty:UnitCode").Value;
var UserModel = new App_Sys_UserModel();
_db.BeginTran();
UserModel.Id = Guid.NewGuid().ToString();
UserModel.cardId = cardId;
UserModel.name = name;
UserModel.usertype = 1;
UserModel.unitCode = unitcode;
string cardIdpwa = UserModel.cardId.Substring(UserModel.cardId.Length - 6);
//Ĭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤<EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
UserModel.Password = Elight.Utility.Encrypt.Md5.Encrypt32($"{cardIdpwa}").ToLower();
var num = await _db.Insertable(UserModel).ExecuteCommandAsync();
_db.CommitTran();
if (num > 0)
{
ret.IsSucceed = true;
ret.result = "<EFBFBD><EFBFBD><EFBFBD>ӳɹ<EFBFBD>";
}
}
else
{
ret.IsSucceed = false;
ret.Message = $"<EFBFBD>û<EFBFBD>δ<EFBFBD><EFBFBD>Ȩ<EFBFBD>޷<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>";
return ret;
}
}
return ret;
}
/// <summary>
/// С<EFBFBD><EFBFBD><EFBFBD><EFBFBD>AppID
/// </summary>
private const string appid = "wx48108a0c98a3dab0";
/// <summary>
/// С<EFBFBD><EFBFBD><EFBFBD><EFBFBD>secretID
/// </summary>
private const string secid = "e752e4fba67526eca21313a18c96a58f";
/// <summary>
/// <EFBFBD><EFBFBD>ȡ΢<EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD>openid
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
[HttpGet("getOpenid")]
public Task<Result> GetOpenId(string code) => wechatMessagerClient.GetOpenId(code);
/// <summary>
/// <EFBFBD><EFBFBD>ȡ΢<EFBFBD>Ź<EFBFBD><EFBFBD>ں<EFBFBD>openid
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
[HttpGet("GetGzhOpenId")]
public Task<Result> GetGzhOpenId(string code) => wechatMessagerClient.GetGzhOpenId(code);
}
public class UserLogin
{
[DataMember]
public string phone { get; set; }
/// <summary>
/// <EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
[DataMember]
public string Password { get; set; }
}
}