|
@@ -86,7 +86,7 @@ namespace TEAMModelBI.Controllers
|
|
string divide = _configuration["CustomParam:SiteScope"];
|
|
string divide = _configuration["CustomParam:SiteScope"];
|
|
if (string.IsNullOrWhiteSpace(appKey) || string.IsNullOrWhiteSpace(appSecret))
|
|
if (string.IsNullOrWhiteSpace(appKey) || string.IsNullOrWhiteSpace(appSecret))
|
|
{
|
|
{
|
|
- return Ok(new { state = 0, message = "请检查配置钉钉的信息" });
|
|
|
|
|
|
+ return Ok(new { state = 0, msg = "请检查配置钉钉的信息" });
|
|
}
|
|
}
|
|
//自己传的code
|
|
//自己传的code
|
|
if (!jsonElement.TryGetProperty("code", out JsonElement LoginTempCode)) return BadRequest();
|
|
if (!jsonElement.TryGetProperty("code", out JsonElement LoginTempCode)) return BadRequest();
|
|
@@ -106,7 +106,7 @@ namespace TEAMModelBI.Controllers
|
|
|
|
|
|
if (response.Errcode.Equals(40078))
|
|
if (response.Errcode.Equals(40078))
|
|
{
|
|
{
|
|
- return Ok(new { state = 0, message = $"state:{response.Errcode};Err{response.Errmsg}/临时授权码过期请重新扫码" });
|
|
|
|
|
|
+ return Ok(new { state = 0, msg = $"state:{response.Errcode};Err{response.Errmsg}/临时授权码过期请重新扫码" });
|
|
}
|
|
}
|
|
|
|
|
|
string unionid = response.UserInfo.Unionid;
|
|
string unionid = response.UserInfo.Unionid;
|
|
@@ -115,7 +115,7 @@ namespace TEAMModelBI.Controllers
|
|
OapiUserGetbyunionidResponse byunionidResponse = client2.Execute(byunionidRequest, access_token);
|
|
OapiUserGetbyunionidResponse byunionidResponse = client2.Execute(byunionidRequest, access_token);
|
|
if (byunionidResponse.IsError || byunionidResponse.Errcode == 60121)
|
|
if (byunionidResponse.IsError || byunionidResponse.Errcode == 60121)
|
|
{
|
|
{
|
|
- return Ok(new { state = 0, message = byunionidResponse.Errmsg });
|
|
|
|
|
|
+ return Ok(new { state = 0, msg = byunionidResponse.Errmsg });
|
|
}
|
|
}
|
|
// 根据userId获取用户信息
|
|
// 根据userId获取用户信息
|
|
string userid = byunionidResponse.Result.Userid;
|
|
string userid = byunionidResponse.Result.Userid;
|
|
@@ -130,52 +130,73 @@ namespace TEAMModelBI.Controllers
|
|
OapiV2UserGetResponse v2GetResponse = client3.Execute(v2GetRequest, access_token);
|
|
OapiV2UserGetResponse v2GetResponse = client3.Execute(v2GetRequest, access_token);
|
|
if (v2GetResponse.IsError)
|
|
if (v2GetResponse.IsError)
|
|
{
|
|
{
|
|
- return Ok(new { state = 0, message = "扫码登录失败" });
|
|
|
|
|
|
+ return Ok(new { state = 0, msg = "扫码登录失败" });
|
|
}
|
|
}
|
|
|
|
|
|
var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
|
|
var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
|
|
|
|
+ var id_token = "";
|
|
|
|
+ string osblob_uri = null, osblob_sas = null;
|
|
|
|
+ List<string> roles = new();//角色列表
|
|
|
|
+ List<string> permissions = new();//权限列表
|
|
|
|
+
|
|
List<DingDingUserInfo> ddusers = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object>() { { "RowKey", $"{v2GetResponse.Result.Userid}" }, { "unionId", $"{v2GetResponse.Result.Unionid}" } });
|
|
List<DingDingUserInfo> ddusers = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object>() { { "RowKey", $"{v2GetResponse.Result.Userid}" }, { "unionId", $"{v2GetResponse.Result.Unionid}" } });
|
|
|
|
|
|
|
|
+
|
|
if (ddusers.Count > 0)
|
|
if (ddusers.Count > 0)
|
|
{
|
|
{
|
|
- List<DingDingUserInfo> ddUserInfos = new List<DingDingUserInfo>();
|
|
|
|
-
|
|
|
|
- var id_token = "";
|
|
|
|
- string osblob_uri = null, osblob_sas = null;
|
|
|
|
-
|
|
|
|
- List<string> roles = new();//角色列表
|
|
|
|
- List<string> permissions = new List<string>();//权限列表
|
|
|
|
|
|
+ List<DingDingUserInfo> saveInfo = new();
|
|
|
|
+ StringBuilder strMsg = new();
|
|
|
|
|
|
foreach (var item in ddusers)
|
|
foreach (var item in ddusers)
|
|
{
|
|
{
|
|
- ddUserInfos.Add(item);
|
|
|
|
- }
|
|
|
|
- foreach (var item in ddUserInfos)
|
|
|
|
- {
|
|
|
|
- if (!string.IsNullOrEmpty(item.tmdId))
|
|
|
|
|
|
+ if (string.IsNullOrEmpty(item.tmdId))
|
|
{
|
|
{
|
|
- roles = !string.IsNullOrEmpty($"{item.roles}") ? new List<string>(item.roles.Split(",")) : new List<string>();
|
|
|
|
- permissions = !string.IsNullOrEmpty($"{item.permissions}") ? new List<string>(item.permissions.Split(",")) : new List<string>();
|
|
|
|
|
|
+ HttpClient httpClient = _http.CreateClient();
|
|
|
|
+ string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
|
|
|
|
|
|
- ///在IES5 添加
|
|
|
|
- //id_token = JwtAuthExtension.CreateAuthToken(_option.HostName, item.tmdId?.ToString(), item.tmdName?.ToString(), item.picture?.ToString(), _option.JwtSecretKey, Website: "BI", scope: $"assist", roles: roles?.ToArray(), permissions: permissions?.ToArray(), ddsub: item.RowKey?.ToString());
|
|
|
|
-
|
|
|
|
- //自己写的
|
|
|
|
- id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, item.tmdId?.ToString(), item.tmdName?.ToString(), item.picture?.ToString(), _option.JwtSecretKey, scope: "assist", Website: "BI", item.RowKey?.ToString(), item.name?.ToString(), item.avatar?.ToString(), roles: roles?.ToArray(), permissions: permissions?.ToArray(), expire: 3);
|
|
|
|
|
|
+ List<string> mobiles = new() { $"{ item.mobile}" };
|
|
|
|
+ HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, mobiles);
|
|
|
|
+ if (responseMessage.StatusCode == HttpStatusCode.OK)
|
|
|
|
+ {
|
|
|
|
+ string temp = responseMessage.Content.ReadAsStringAsync().Result;
|
|
|
|
+ List<JsonElement> json_id = temp.ToObject<List<JsonElement>>();
|
|
|
|
+ if (json_id.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ foreach (var tmd in json_id)
|
|
|
|
+ {
|
|
|
|
+ item.tmdId = tmd.GetProperty("id").ToString();
|
|
|
|
+ item.tmdName = tmd.GetProperty("name").ToString();
|
|
|
|
+ item.tmdMobile = tmd.GetProperty("mobile").ToString();
|
|
|
|
+ item.picture = tmd.GetProperty("picture").ToString();
|
|
|
|
+ item.mail = tmd.GetProperty("mail").ToString();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
|
|
|
|
+ }
|
|
|
|
|
|
- (osblob_uri, osblob_sas) = roles.Contains("assist") ? _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete) : _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- return Ok(new { state = 201, ddUserInfos });
|
|
|
|
|
|
+ strMsg.Append($"{item.tmdName}【{item.tmdId}】醍摩豆账号和{item.name}【{item.RowKey}】钉钉账户绑定成功");
|
|
}
|
|
}
|
|
|
|
+ saveInfo.Add(item);
|
|
|
|
+
|
|
|
|
+ roles = !string.IsNullOrEmpty($"{item.roles}") ? new List<string>(item.roles.Split(",")) : new List<string>();
|
|
|
|
+ permissions = !string.IsNullOrEmpty($"{item.permissions}") ? new List<string>(item.permissions.Split(",")) : new List<string>();
|
|
|
|
+
|
|
|
|
+ //自己写的
|
|
|
|
+ id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, item.tmdId?.ToString(), item.tmdName?.ToString(), item.picture?.ToString(), _option.JwtSecretKey, scope: "assist", Website: "BI", item.RowKey?.ToString(), item.name?.ToString(), item.avatar?.ToString(), roles: roles?.ToArray(), permissions: permissions?.ToArray(), expire: 3);
|
|
|
|
+
|
|
|
|
+ (osblob_uri, osblob_sas) = roles.Contains("assist") ? _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete) : _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
|
|
|
|
+ }
|
|
|
|
+ if (saveInfo.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ ddusers = await table.UpdateAll<DingDingUserInfo>(saveInfo);
|
|
|
|
+ //保存操作记录
|
|
|
|
+ await _azureStorage.SaveBILog("tabledd-update", strMsg?.ToString(), _dingDing, httpContext: HttpContext);
|
|
}
|
|
}
|
|
|
|
|
|
- return Ok(new { state = 200, ddUserInfos, id_token, roles, permissions, osblob_uri, osblob_sas });
|
|
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- DingDingUserInfo dingDingUserInfo = new()
|
|
|
|
|
|
+ DingDingUserInfo ddUserInfo = new()
|
|
{
|
|
{
|
|
PartitionKey = divide,
|
|
PartitionKey = divide,
|
|
RowKey = v2GetResponse.Result.Userid,
|
|
RowKey = v2GetResponse.Result.Userid,
|
|
@@ -190,18 +211,52 @@ namespace TEAMModelBI.Controllers
|
|
depts = string.Join(",", v2GetResponse.Result.DeptIdList.ToArray()),
|
|
depts = string.Join(",", v2GetResponse.Result.DeptIdList.ToArray()),
|
|
avatar = v2GetResponse.Result.Avatar,
|
|
avatar = v2GetResponse.Result.Avatar,
|
|
isAdmin = v2GetResponse.Result.Admin,
|
|
isAdmin = v2GetResponse.Result.Admin,
|
|
- tmdId = "",
|
|
|
|
- tmdName = "",
|
|
|
|
- tmdMobile = "",
|
|
|
|
- mail = "",
|
|
|
|
- picture = "",
|
|
|
|
- roles = "",
|
|
|
|
- permissions = "",
|
|
|
|
|
|
+ roles = "assist",
|
|
|
|
+ permissions = "abilitystandard-read,batcharea-read,batchschool-read,orgusers-read"
|
|
};
|
|
};
|
|
- await table.Save<DingDingUserInfo>(dingDingUserInfo);
|
|
|
|
|
|
|
|
- return Ok(new { state = 400, ddUserId = dingDingUserInfo });
|
|
|
|
|
|
+ if (!string.IsNullOrEmpty($"{ddUserInfo.mobile}"))
|
|
|
|
+ {
|
|
|
|
+ HttpClient httpClient = _http.CreateClient();
|
|
|
|
+ string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
|
|
|
|
+
|
|
|
|
+ List<string> mobiles = new() { $"{ ddUserInfo.mobile}" };
|
|
|
|
+ HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, mobiles);
|
|
|
|
+ if (responseMessage.StatusCode == HttpStatusCode.OK)
|
|
|
|
+ {
|
|
|
|
+ string temp = responseMessage.Content.ReadAsStringAsync().Result;
|
|
|
|
+ List<JsonElement> json_id = temp.ToObject<List<JsonElement>>();
|
|
|
|
+ if (json_id.Count > 0)
|
|
|
|
+ {
|
|
|
|
+ foreach (var tmd in json_id)
|
|
|
|
+ {
|
|
|
|
+ ddUserInfo.tmdId = tmd.GetProperty("id").ToString();
|
|
|
|
+ ddUserInfo.tmdName = tmd.GetProperty("name").ToString();
|
|
|
|
+ ddUserInfo.tmdMobile = tmd.GetProperty("mobile").ToString();
|
|
|
|
+ ddUserInfo.picture = tmd.GetProperty("picture").ToString();
|
|
|
|
+ ddUserInfo.mail = tmd.GetProperty("mail").ToString();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else return Ok(new { state = 404, msg = "依据钉钉手机号未找到醍摩豆账号!" });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else return Ok(new { state = 404, msg = "钉钉手机号为空" });
|
|
|
|
+
|
|
|
|
+ ddUserInfo = await table.Save<DingDingUserInfo>(ddUserInfo);
|
|
|
|
+
|
|
|
|
+ //保存操作记录
|
|
|
|
+ await _azureStorage.SaveBILog("tabledd-update", $"{ddUserInfo.tmdName}【{ddUserInfo.tmdId}】醍摩豆账号和{ddUserInfo.name}【{ddUserInfo.RowKey}】钉钉账户绑定成功", _dingDing, httpContext: HttpContext);
|
|
|
|
+
|
|
|
|
+ roles = !string.IsNullOrEmpty($"{ddUserInfo.roles}") ? new List<string>(ddUserInfo.roles.Split(",")) : new List<string>();
|
|
|
|
+ permissions = !string.IsNullOrEmpty($"{ddUserInfo.permissions}") ? new List<string>(ddUserInfo.permissions.Split(",")) : new List<string>();
|
|
|
|
+
|
|
|
|
+ //自己写的
|
|
|
|
+ id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, ddUserInfo.tmdId?.ToString(), ddUserInfo.tmdName?.ToString(), ddUserInfo.picture?.ToString(), _option.JwtSecretKey, scope: "assist", Website: "BI", ddUserInfo.RowKey?.ToString(), ddUserInfo.name?.ToString(), ddUserInfo.avatar?.ToString(), roles: roles?.ToArray(), permissions: permissions?.ToArray(), expire: 3);
|
|
|
|
+
|
|
|
|
+ (osblob_uri, osblob_sas) = roles.Contains("assist") ? _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete) : _azureStorage.GetBlobContainerSAS("teammodelos", BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return Ok(new { state = 200, ddUserInfos = ddusers, id_token, roles, permissions, osblob_uri, osblob_sas });
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
{
|
|
{
|
|
@@ -274,7 +329,7 @@ namespace TEAMModelBI.Controllers
|
|
else return Ok(new { state = 404, msg = "手机号未找到醍摩豆账户" });
|
|
else return Ok(new { state = 404, msg = "手机号未找到醍摩豆账户" });
|
|
}
|
|
}
|
|
|
|
|
|
- if (string.IsNullOrEmpty($"{mobile}") && string.IsNullOrEmpty($"{idtoken}"))
|
|
|
|
|
|
+ if (string.IsNullOrEmpty($"{mobile}") && string.IsNullOrEmpty($"{idtoken}"))
|
|
return Ok(new { state = 400, msg = "mobile、idtoken参数错误" });
|
|
return Ok(new { state = 400, msg = "mobile、idtoken参数错误" });
|
|
else
|
|
else
|
|
{
|
|
{
|
|
@@ -371,8 +426,6 @@ namespace TEAMModelBI.Controllers
|
|
}
|
|
}
|
|
else return Ok(new { state = responseMessage.StatusCode });
|
|
else return Ok(new { state = responseMessage.StatusCode });
|
|
}
|
|
}
|
|
- ////在IES5 的基础上增加参数
|
|
|
|
- //id_token = JwtAuthExtension.CreateAuthToken(_option.HostName, itemUser.tmdId?.ToString(), itemUser.tmdName?.ToString(), itemUser.picture?.ToString(), _option.JwtSecretKey,Website: "BI", scope: $"assist", roles: roles?.ToArray(), permissions: permissions?.ToArray(), ddsub: itemUser.RowKey?.ToString());
|
|
|
|
//自己写的
|
|
//自己写的
|
|
id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, itemUser.tmdId?.ToString(), itemUser.tmdName?.ToString(), itemUser.picture?.ToString(), _option.JwtSecretKey, scope: "assist", Website: "BI", itemUser.RowKey?.ToString(), itemUser.name?.ToString(), itemUser.avatar?.ToString(), roles: roles?.ToArray(), permissions: permissions?.ToArray(), expire: 3);
|
|
id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, itemUser.tmdId?.ToString(), itemUser.tmdName?.ToString(), itemUser.picture?.ToString(), _option.JwtSecretKey, scope: "assist", Website: "BI", itemUser.RowKey?.ToString(), itemUser.name?.ToString(), itemUser.avatar?.ToString(), roles: roles?.ToArray(), permissions: permissions?.ToArray(), expire: 3);
|
|
}
|
|
}
|
|
@@ -411,7 +464,7 @@ namespace TEAMModelBI.Controllers
|
|
Company company = new();
|
|
Company company = new();
|
|
List<Company> companies = new();
|
|
List<Company> companies = new();
|
|
string id_token = "";
|
|
string id_token = "";
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryIterator<Company>(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Company") }))
|
|
|
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryIterator<Company>(queryText: sqlTxt.ToString(), requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Company") }))
|
|
{
|
|
{
|
|
companies.Add(item);
|
|
companies.Add(item);
|
|
}
|
|
}
|
|
@@ -441,7 +494,7 @@ namespace TEAMModelBI.Controllers
|
|
/// <param name="jsonElement"></param>
|
|
/// <param name="jsonElement"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
[HttpPost("set-registered")]
|
|
[HttpPost("set-registered")]
|
|
- public async Task<IActionResult> SetRegistered(JsonElement jsonElement)
|
|
|
|
|
|
+ public async Task<IActionResult> SetRegistered(JsonElement jsonElement)
|
|
{
|
|
{
|
|
if (!jsonElement.TryGetProperty("name", out JsonElement name)) return BadRequest();
|
|
if (!jsonElement.TryGetProperty("name", out JsonElement name)) return BadRequest();
|
|
if (!jsonElement.TryGetProperty("credit", out JsonElement credit)) return BadRequest();
|
|
if (!jsonElement.TryGetProperty("credit", out JsonElement credit)) return BadRequest();
|
|
@@ -452,7 +505,7 @@ namespace TEAMModelBI.Controllers
|
|
string salt = Utils.CreatSaltString(8);
|
|
string salt = Utils.CreatSaltString(8);
|
|
|
|
|
|
string sqltxt = $"select value(c) from c where c.mobile='{mobile}'";
|
|
string sqltxt = $"select value(c) from c where c.mobile='{mobile}'";
|
|
- await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryStreamIterator(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Company") }))
|
|
|
|
|
|
+ await foreach (var item in cosmosClient.GetContainer("TEAMModelOS", "Normal").GetItemQueryStreamIterator(queryText: sqltxt, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey("Company") }))
|
|
{
|
|
{
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
@@ -491,7 +544,6 @@ namespace TEAMModelBI.Controllers
|
|
return Ok(new { state = 200, company });
|
|
return Ok(new { state = 200, company });
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
public record DingDingbinds
|
|
public record DingDingbinds
|
|
{
|
|
{
|
|
public string type { get; set; }
|
|
public string type { get; set; }
|
|
@@ -522,6 +574,5 @@ namespace TEAMModelBI.Controllers
|
|
public string userid { get; set; }
|
|
public string userid { get; set; }
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|