|
|
@ -15,6 +15,8 @@ using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using UAParser;
|
|
|
|
using UAParser;
|
|
|
|
|
|
|
|
using Furion.RemoteRequest.Extensions;
|
|
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Core.Service;
|
|
|
|
namespace Myshipping.Core.Service;
|
|
|
|
|
|
|
|
|
|
|
@ -298,4 +300,77 @@ public class AuthService : IAuthService, IDynamicApiController, ITransient
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return await Task.FromResult(_captchaHandle.CheckCode(input));
|
|
|
|
return await Task.FromResult(_captchaHandle.CheckCode(input));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 使用跳转code登录
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <param name="code"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
|
|
[HttpPost("/loginWithCode")]
|
|
|
|
|
|
|
|
public async Task<string> LoginWithCode(string code)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var djyAuthUrl = App.GetConfig<string>("DjyAuthUrl");
|
|
|
|
|
|
|
|
if (!djyAuthUrl.EndsWith("/"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
djyAuthUrl += "/";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var loginUrl = djyAuthUrl + "user/login";
|
|
|
|
|
|
|
|
var infoUrl = djyAuthUrl + "user/info";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//跳转登录
|
|
|
|
|
|
|
|
var result = await loginUrl
|
|
|
|
|
|
|
|
.SetBody(new { code }, "application/json")
|
|
|
|
|
|
|
|
.PostAsStringAsync();
|
|
|
|
|
|
|
|
var jRtn = JObject.Parse(result);
|
|
|
|
|
|
|
|
if (jRtn.GetIntValue("code") == 200)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var jData = jRtn.GetJObjectValue("data");
|
|
|
|
|
|
|
|
var token = jData.GetStringValue("token");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var headers = new Dictionary<string, object>();
|
|
|
|
|
|
|
|
headers.Add("Authorization", $"Bearer {token}");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取登录信息
|
|
|
|
|
|
|
|
result = await infoUrl
|
|
|
|
|
|
|
|
.SetHeaders(headers)
|
|
|
|
|
|
|
|
.GetAsStringAsync();
|
|
|
|
|
|
|
|
jRtn = JObject.Parse(result);
|
|
|
|
|
|
|
|
if (jRtn.GetIntValue("code") == 200)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
jData = jRtn.GetJObjectValue("data");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dic = new Dictionary<string, object>();
|
|
|
|
|
|
|
|
foreach (var prop in jData.Properties())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dic.Add(prop.Name, jData[prop.Name]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var accessToken = JWTEncryption.Encrypt(dic);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置Swagger自动登录
|
|
|
|
|
|
|
|
_httpContextAccessor.HttpContext.SigninToSwagger(accessToken);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 生成刷新Token令牌
|
|
|
|
|
|
|
|
var refreshToken = JWTEncryption.GenerateRefreshToken(accessToken, 30);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 设置刷新Token令牌
|
|
|
|
|
|
|
|
_httpContextAccessor.HttpContext.Response.Headers["x-access-token"] = refreshToken;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return accessToken;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah(jRtn.GetStringValue("message"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
throw Oops.Bah(jRtn.GetStringValue("message"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|