|
@@ -93,7 +93,7 @@ namespace TEAMModelBI.Controllers
|
|
|
OapiGettokenRequest tokenRequest = new() { Appkey = appKey, Appsecret = appSecret };
|
|
|
tokenRequest.SetHttpMethod("Get");
|
|
|
OapiGettokenResponse tokenRespone = tokenClient.Execute(tokenRequest);
|
|
|
- if (tokenRespone.IsError) return BadRequest();
|
|
|
+ if (tokenRespone.IsError) return BadRequest();
|
|
|
|
|
|
string access_token = tokenRespone.AccessToken;
|
|
|
//获取临时授权码 获取授权用户的个人信息
|
|
@@ -101,7 +101,7 @@ namespace TEAMModelBI.Controllers
|
|
|
OapiSnsGetuserinfoBycodeRequest req = new() { TmpAuthCode = $"{LoginTempCode}" }; //通过扫描二维码,跳转到指定的Url后,向Url中追加Code临时授权码
|
|
|
OapiSnsGetuserinfoBycodeResponse response = clientinfo.Execute(req, appKey, appSecret);
|
|
|
|
|
|
- if (response.Errcode.Equals(40078))
|
|
|
+ if (response.Errcode.Equals(40078))
|
|
|
{
|
|
|
return Ok(new { state = 0, message = $"state:{response.Errcode};Err{response.Errmsg}/临时授权码过期请重新扫码" });
|
|
|
}
|
|
@@ -110,7 +110,7 @@ namespace TEAMModelBI.Controllers
|
|
|
IDingTalkClient client2 = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/user/getbyunionid"); //userid地址
|
|
|
OapiUserGetbyunionidRequest byunionidRequest = new() { Unionid = unionid };
|
|
|
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 });
|
|
|
}
|
|
@@ -147,7 +147,7 @@ namespace TEAMModelBI.Controllers
|
|
|
{
|
|
|
ddUserInfos.Add(item);
|
|
|
}
|
|
|
- foreach (var item in ddUserInfos)
|
|
|
+ foreach (var item in ddUserInfos)
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(item.tmdId))
|
|
|
{
|
|
@@ -158,7 +158,7 @@ namespace TEAMModelBI.Controllers
|
|
|
//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(), item.RowKey?.ToString(), item.name?.ToString(), item.avatar?.ToString(), _option.JwtSecretKey, scope: "assist", Website: "BI", roles: roles?.ToArray(), permissions: permissions?.ToArray(), expire:3);
|
|
|
+ id_token = JwtAuth.CreateAuthTokenBI(_option.HostName, item.tmdId?.ToString(), item.tmdName?.ToString(), item.picture?.ToString(), item.RowKey?.ToString(), item.name?.ToString(), item.avatar?.ToString(), _option.JwtSecretKey, scope: "assist", Website: "BI", 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);
|
|
|
}
|
|
@@ -172,7 +172,7 @@ namespace TEAMModelBI.Controllers
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- DingDingUserInfo dingDingUserInfo = new ()
|
|
|
+ DingDingUserInfo dingDingUserInfo = new()
|
|
|
{
|
|
|
PartitionKey = divide,
|
|
|
RowKey = v2GetResponse.Result.Userid,
|
|
@@ -194,7 +194,7 @@ namespace TEAMModelBI.Controllers
|
|
|
picture = "",
|
|
|
roles = "",
|
|
|
permissions = "",
|
|
|
- };
|
|
|
+ };
|
|
|
await table.Save<DingDingUserInfo>(dingDingUserInfo);
|
|
|
|
|
|
return Ok(new { state = 400, ddUserId = dingDingUserInfo });
|
|
@@ -213,55 +213,77 @@ namespace TEAMModelBI.Controllers
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[AuthToken(Roles = "assist")]
|
|
|
- [HttpPost("binguser")]
|
|
|
- public async Task<IActionResult> BindUser(JsonElement jsonElement)
|
|
|
+ [HttpPost("set-bind")]
|
|
|
+ public async Task<IActionResult> BindUser(JsonElement jsonElement)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- if (!jsonElement.TryGetProperty("mobile", out JsonElement moile)) return BadRequest();
|
|
|
if (!jsonElement.TryGetProperty("partitionKey", out JsonElement partitionKey)) return BadRequest();
|
|
|
if (!jsonElement.TryGetProperty("rowKey", out JsonElement userId)) return BadRequest();
|
|
|
+ jsonElement.TryGetProperty("id_token", out JsonElement idtoken);
|
|
|
+ jsonElement.TryGetProperty("mobile", out JsonElement moile);
|
|
|
|
|
|
HttpClient httpClient = _http.CreateClient();
|
|
|
string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
|
|
|
- HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, moile);
|
|
|
+ var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
|
|
|
+ var tempUser = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "RowKey", $"{userId}" } });
|
|
|
|
|
|
- if (responseMessage.StatusCode == HttpStatusCode.OK)
|
|
|
+ var id_token = "";
|
|
|
+ var auth_token = "";
|
|
|
+ List<DingDingUserInfo> ddUserInfos = new();
|
|
|
+ List<string> roles = new();//角色列表
|
|
|
+ List<string> permissions = new();//权限列表
|
|
|
+
|
|
|
+ foreach (var itemUser in tempUser)
|
|
|
{
|
|
|
- var table = _azureStorage.GetCloudTableClient().GetTableReference("BIDDUserInfo");
|
|
|
- var temp = await responseMessage.Content.ReadAsStringAsync();
|
|
|
- if (temp.Length > 0)
|
|
|
+ if (!string.IsNullOrEmpty($"{idtoken}"))
|
|
|
{
|
|
|
- List<DingDingUserInfo> ddUserInfos = new();
|
|
|
- List<JsonElement> itemjson = temp.ToObject<List<JsonElement>>();
|
|
|
- var tempUser = await table.FindListByDict<DingDingUserInfo>(new Dictionary<string, object> { { "PartitionKey", $"{partitionKey}" }, { "RowKey", $"{userId}" } });
|
|
|
- foreach (var item in itemjson)
|
|
|
+ JwtSecurityToken jwt = new JwtSecurityToken($"{idtoken}");
|
|
|
+ var tmdId = jwt.Payload.Sub;
|
|
|
+ jwt.Payload.TryGetValue("name", out object tmdName);
|
|
|
+ jwt.Payload.TryGetValue("picture", out object picture);
|
|
|
+
|
|
|
+ itemUser.tmdId = tmdId;
|
|
|
+ itemUser.tmdName = $"{tmdName}";
|
|
|
+ itemUser.tmdMobile = itemUser.mobile;
|
|
|
+ itemUser.picture = $"{picture}";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty($"{moile}"))
|
|
|
+ {
|
|
|
+ HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, moile);
|
|
|
+ if (responseMessage.StatusCode == HttpStatusCode.OK)
|
|
|
{
|
|
|
- foreach (var itemUser in tempUser)
|
|
|
+ var temp = await responseMessage.Content.ReadAsStringAsync();
|
|
|
+ if (temp.Length > 0)
|
|
|
{
|
|
|
- var tmdId = item.GetProperty("id").ToString();
|
|
|
- var tmdName = item.GetProperty("name").ToString();
|
|
|
- itemUser.tmdId = tmdId;
|
|
|
- itemUser.tmdName = tmdName;
|
|
|
- itemUser.tmdMobile = item.GetProperty("mobile").ToString();
|
|
|
- itemUser.picture = item.GetProperty("picture").ToString();
|
|
|
- itemUser.mail = item.GetProperty("mail").ToString();
|
|
|
-
|
|
|
- //保存操作记录
|
|
|
- await _azureStorage.SaveBILog("tabledd-update", $"{tmdName}【{tmdId}】醍摩豆账号和{itemUser.name}【{itemUser.RowKey}】钉钉账户绑定成功", _dingDing, httpContext: HttpContext);
|
|
|
-
|
|
|
- ddUserInfos.Add(itemUser);
|
|
|
+ List<JsonElement> itemjson = temp.ToObject<List<JsonElement>>();
|
|
|
+ foreach (var item in itemjson)
|
|
|
+ {
|
|
|
+ itemUser.tmdId = item.GetProperty("id").ToString();
|
|
|
+ itemUser.tmdName = item.GetProperty("name").ToString();
|
|
|
+ itemUser.tmdMobile = item.GetProperty("mobile").ToString();
|
|
|
+ itemUser.picture = item.GetProperty("picture").ToString();
|
|
|
+ itemUser.mail = item.GetProperty("mail").ToString();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- var dingDingUserInfos = await table.UpdateAll(ddUserInfos);
|
|
|
+ roles = !string.IsNullOrEmpty($"{itemUser.roles}") ? new List<string>(itemUser.roles.Split(",")) : new List<string>();
|
|
|
|
|
|
+ //保存操作记录
|
|
|
+ await _azureStorage.SaveBILog("tabledd-update", $"{itemUser.tmdName}【{itemUser.tmdId}】醍摩豆账号和{itemUser.name}【{itemUser.RowKey}】钉钉账户绑定成功", _dingDing, httpContext: HttpContext);
|
|
|
|
|
|
- return Ok(new { state = 200, ddUsers = dingDingUserInfos });
|
|
|
- }
|
|
|
- else return Ok(new { state = 400, message = "该手机没有注册提莫信息" });
|
|
|
+ auth_token = JwtAuth.CreateAuthTokenBI(_option.HostName, itemUser.tmdId?.ToString(), itemUser.tmdName?.ToString(), itemUser.picture?.ToString(), itemUser.RowKey?.ToString(), itemUser.name?.ToString(), itemUser.avatar?.ToString(), _option.JwtSecretKey, scope: "assist", Website: "BI", roles: roles?.ToArray(), permissions: permissions?.ToArray(), expire: 3);
|
|
|
}
|
|
|
- else return Ok(new { state = responseMessage.StatusCode });
|
|
|
+
|
|
|
+ ddUserInfos = await table.UpdateAll(ddUserInfos);
|
|
|
+
|
|
|
+ //blob 访问权限
|
|
|
+ var (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, id_token, auth_token, roles, osblob_uri, osblob_sas });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -354,7 +376,7 @@ namespace TEAMModelBI.Controllers
|
|
|
await _dingDing.SendBotMsg($"BI,{_option.Location} /common/login/get-ddinfo \n {ex.Message}{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
return BadRequest();
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
public record DingDingbinds
|
|
|
{
|
|
@@ -386,6 +408,6 @@ namespace TEAMModelBI.Controllers
|
|
|
public string userid { get; set; }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|