|
|
@ -34,13 +34,15 @@ namespace _24Hour.Controllers |
|
|
|
private readonly IConfiguration _configuration; |
|
|
|
private readonly IConfiguration _configuration; |
|
|
|
private readonly SqlSugarClient _db;//Êý¾Ý¿â |
|
|
|
private readonly SqlSugarClient _db;//Êý¾Ý¿â |
|
|
|
private readonly WriteSysLog _logs;//²Ù×÷ÈÕÖ¾ |
|
|
|
private readonly WriteSysLog _logs;//²Ù×÷ÈÕÖ¾ |
|
|
|
private readonly ILogger<LoginController> _logger;//日志 |
|
|
|
private readonly ILogger<LoginController> _logger;//日志 |
|
|
|
|
|
|
|
private readonly WechatMessagerClient wechatMessagerClient; |
|
|
|
Result ret = new Result(); |
|
|
|
Result ret = new Result(); |
|
|
|
public LoginController(ILogger<LoginController> logger, SqlSugarClient db, IConfiguration configuration) |
|
|
|
public LoginController(ILogger<LoginController> logger, SqlSugarClient db, IConfiguration configuration, WechatMessagerClient _wechatMessagerClient) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_logger = logger; |
|
|
|
_logger = logger; |
|
|
|
_db = db; |
|
|
|
_db = db; |
|
|
|
_configuration = configuration; |
|
|
|
_configuration = configuration; |
|
|
|
|
|
|
|
this.wechatMessagerClient = _wechatMessagerClient; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
[HttpPost] |
|
|
@ -313,9 +315,9 @@ namespace _24Hour.Controllers |
|
|
|
public async Task<Result> WeChatLoginByCode(string code) |
|
|
|
public async Task<Result> WeChatLoginByCode(string code) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var opendata = await GetOpenId(code); |
|
|
|
var opendata = await GetOpenId(code); |
|
|
|
if (opendata.IsSucceed==true) |
|
|
|
if (opendata.IsSucceed == true) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return WeChatLogin(opendata.result); |
|
|
|
return await WeChatLogin(opendata.result); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
@ -335,20 +337,32 @@ namespace _24Hour.Controllers |
|
|
|
{ |
|
|
|
{ |
|
|
|
var date = await _db.Queryable<App_Sys_UserModel>().Where(q => q.IsDeleted == 0 && q.isdeactivate == 0 && q.wechatId == openId).FirstAsync(); |
|
|
|
var date = await _db.Queryable<App_Sys_UserModel>().Where(q => q.IsDeleted == 0 && q.isdeactivate == 0 && q.wechatId == openId).FirstAsync(); |
|
|
|
if (date != null) |
|
|
|
if (date != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//if (date.usertype == 1 && date.audit == null) |
|
|
|
//if (date.usertype == 1 && date.audit == null) |
|
|
|
//{ |
|
|
|
//{ |
|
|
|
// ret.IsSucceed = false; |
|
|
|
// ret.IsSucceed = false; |
|
|
|
// ret.Message = "账号审核中!"; |
|
|
|
// ret.Message = "账号审核中!"; |
|
|
|
// return ret; |
|
|
|
// return ret; |
|
|
|
//} |
|
|
|
//} |
|
|
|
//else if (date.usertype == 1 && date.audit == 1) |
|
|
|
//else if (date.usertype == 1 && date.audit == 1) |
|
|
|
//{ |
|
|
|
//{ |
|
|
|
// ret.IsSucceed = false; |
|
|
|
// ret.IsSucceed = false; |
|
|
|
// ret.Message = $"账号审核未通过,原因:{date.describe}!"; |
|
|
|
// ret.Message = $"账号审核未通过,原因:{date.describe}!"; |
|
|
|
// return ret; |
|
|
|
// return ret; |
|
|
|
//} |
|
|
|
//} |
|
|
|
//else |
|
|
|
//else |
|
|
|
|
|
|
|
if (date.identity == "律师" && date.audit == 1) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ret.IsSucceed = false; |
|
|
|
|
|
|
|
ret.Message = $"用户信息审核未通过,原因:{date.describe},请重新注册!"; |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (date.identity == "律师" && date.audit == 2) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ret.IsSucceed = false; |
|
|
|
|
|
|
|
ret.Message = "用户信息审核中!"; |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
if (date.usertype == 0 && date.becurrent == 1) |
|
|
|
if (date.usertype == 0 && date.becurrent == 1) |
|
|
|
{ |
|
|
|
{ |
|
|
|
ret.IsSucceed = false; |
|
|
|
ret.IsSucceed = false; |
|
|
@ -386,7 +400,8 @@ namespace _24Hour.Controllers |
|
|
|
identity = date.identity, |
|
|
|
identity = date.identity, |
|
|
|
usertype = date.usertype, |
|
|
|
usertype = date.usertype, |
|
|
|
unitCode = date.unitCode, |
|
|
|
unitCode = date.unitCode, |
|
|
|
token = tokenString |
|
|
|
token = tokenString, |
|
|
|
|
|
|
|
openId = date.wechatId |
|
|
|
}; |
|
|
|
}; |
|
|
|
#endregion |
|
|
|
#endregion |
|
|
|
ret.IsSucceed = true; |
|
|
|
ret.IsSucceed = true; |
|
|
@ -394,7 +409,7 @@ namespace _24Hour.Controllers |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
ret.IsSucceed = false; |
|
|
|
ret.IsSucceed = false; |
|
|
|
ret.Message = "微信未授权!"; |
|
|
|
ret.Message = "微信未授权,请先注册账号!"; |
|
|
|
} |
|
|
|
} |
|
|
|
return ret; |
|
|
|
return ret; |
|
|
|
} |
|
|
|
} |
|
|
@ -410,6 +425,12 @@ namespace _24Hour.Controllers |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
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 = "当前微信已与其他账号绑定"; |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var data = await _db.Queryable<App_Sys_UserModel>().Where(q => q.phone == UserModel.phone && q.IsDeleted == 0).FirstAsync(); |
|
|
|
var data = await _db.Queryable<App_Sys_UserModel>().Where(q => q.phone == UserModel.phone && q.IsDeleted == 0).FirstAsync(); |
|
|
|
if (UserModel.identity == "ÂÉʦ") |
|
|
|
if (UserModel.identity == "ÂÉʦ") |
|
|
@ -618,29 +639,7 @@ namespace _24Hour.Controllers |
|
|
|
/// <param name="code"></param> |
|
|
|
/// <param name="code"></param> |
|
|
|
/// <returns></returns> |
|
|
|
/// <returns></returns> |
|
|
|
[HttpGet("getOpenid")] |
|
|
|
[HttpGet("getOpenid")] |
|
|
|
public async Task<Result> GetOpenId(string code) |
|
|
|
public Task<Result> GetOpenId(string code) => wechatMessagerClient.GetOpenId(code); |
|
|
|
{ |
|
|
|
|
|
|
|
var opendata = HttpHelper.Get($"https://api.weixin.qq.com/sns/jscode2session?appid={appid}&secret={secid}&js_code={code}&grant_type=authorization_code"); |
|
|
|
|
|
|
|
var data = JsonConvert.DeserializeAnonymousType(opendata, new |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
openid=default(string), |
|
|
|
|
|
|
|
session_key = default(string), |
|
|
|
|
|
|
|
unionid = default(string), |
|
|
|
|
|
|
|
errcode = default(int), |
|
|
|
|
|
|
|
errmsg = default(string), |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if (data.errcode==0) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ret.IsSucceed = true; |
|
|
|
|
|
|
|
ret.result = data.openid; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ret.IsSucceed = false; |
|
|
|
|
|
|
|
ret.Message = data.errmsg; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return ret; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|