CrazyIter_Bin 3 yıl önce
ebeveyn
işleme
42022b3c76

+ 93 - 9
TEAMModelOS.SDK/DI/CoreAPI/CoreAPIHttpService.cs

@@ -1,3 +1,4 @@
+using Microsoft.Extensions.Configuration;
 using System;
 using System.Collections.Generic;
 using System.Net;
@@ -26,8 +27,14 @@ namespace TEAMModelOS.SDK.Models.Service
         /// <param name="url"></param>
         /// <param name="data"></param>
         /// <returns></returns>
-        public async Task<(int code ,string content)> Implicit(string clientID, string clientSecret, string location, string url,Dictionary<string,string> data)
+        public async Task<TmdidImplicit> Implicit( Dictionary<string,string> data,string location, IConfiguration _configuration)
+
         {
+            var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
+            url = "https://api2-rc.teammodel.cn";
+            url = $"{url}/oauth2/implicit";
+            var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
+            var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
             if (location.Contains("China"))
             {
                 location = "China";
@@ -47,15 +54,23 @@ namespace TEAMModelOS.SDK.Models.Service
             if (responseMessage.StatusCode == HttpStatusCode.OK)
             {
                 string content=await responseMessage.Content.ReadAsStringAsync();
-                return (200,content);
+                if (!string.IsNullOrEmpty(content))
+                {
+                    TmdidImplicit tmdidImplicit = content.ToObject<TmdidImplicit>();
+                    return tmdidImplicit;
+                }
+                else
+                {
+                    return null;
+                }
             }
             else if (responseMessage.StatusCode == HttpStatusCode.Unauthorized)
             {
-                return (401,null);
+                return null;
             }
             else
             {
-                return (500,null);
+                return null;
             }
         }
         /// <summary>
@@ -67,8 +82,13 @@ namespace TEAMModelOS.SDK.Models.Service
         /// <param name="url"></param>
         /// <param name="data"></param>
         /// <returns></returns>
-        public async Task<(int code, string content)> GetUserInfo(string clientID, string clientSecret, string location, string url, Dictionary<string, string> data)
+        public async Task<CoreUser> GetUserInfo(Dictionary<string, string> data, string location, IConfiguration _configuration)
         {
+            var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
+            url = "https://api2-rc.teammodel.cn";
+            url = $"{url}/oauth2/getuserinfo";
+            var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
+            var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
             if (location.Contains("China"))
             {
                 location = "China";
@@ -88,16 +108,80 @@ namespace TEAMModelOS.SDK.Models.Service
             if (responseMessage.StatusCode == HttpStatusCode.OK)
             {
                 string content = await responseMessage.Content.ReadAsStringAsync();
-                return (200, content);
+                if (!string.IsNullOrEmpty(content))
+                {
+                    CoreUserInfo coreUserInfo = content.ToObject<CoreUserInfo>();
+                    if (coreUserInfo != null)
+                    {
+                        bool isActivate = !string.IsNullOrWhiteSpace(coreUserInfo.password) || !string.IsNullOrWhiteSpace(coreUserInfo.passwordOld);
+                        CoreUser coreUser = new CoreUser
+                        {
+                            isActivate = isActivate,
+                            id = coreUserInfo.id,
+                            vid = coreUserInfo.vid,
+                            mail = coreUserInfo.mail,
+                            mobile = coreUserInfo.mobile,
+                            name = coreUserInfo.name,
+                            picture = coreUserInfo.picture,
+                            habook = coreUserInfo.habook,
+                            wechat = coreUserInfo.wechat,
+                            facebook = coreUserInfo.facebook,
+                            google = coreUserInfo.google,
+                            ding = coreUserInfo.ding,
+                            apple = coreUserInfo.apple,
+                        };
+                        return coreUser;
+                    }
+                    else
+                    {
+                        return null;
+                    }
+                }
+                else {
+                    return null;
+                }
             }
             else if (responseMessage.StatusCode == HttpStatusCode.Unauthorized)
             {
-                return (401, null);
+                return null;
             }
             else
             {
-                return (500, null);
+                return null;
             }
         }
-    } 
+    }
+    public class TmdidImplicit
+    {
+            public string id_token { get; set; }
+    public string access_token { get; set; }
+    public string expires_in { get; set; }
+    public string token_type { get; set; }
+}
+public class CoreUser
+    {
+        public string id { get; set; }
+        public string vid { get; set; }
+        public string mail { get; set; }
+        public string mobile { get; set; }
+        public string name { get; set; }
+        public string picture { get; set; }
+        public string habook { get; set; }
+        public string wechat { get; set; }
+        public string facebook { get; set; }
+        public string google { get; set; }
+        public string ding { get; set; }
+        public string apple { get; set; }
+        public bool isActivate { get; set; }
+    }
+    public class CoreUserInfo : CoreUser
+    {
+        public string area { get; set; }
+        public string country { get; set; }
+        public string type { get; set; }
+        public string password { get; set; }
+        public string salt { get; set; }
+        public string passwordOld { get; set; }
+        public string saltOld { get; set; }
+    }
 }

+ 3 - 7
TEAMModelOS.SDK/Models/Service/Third/ScYxptModel.cs

@@ -79,6 +79,7 @@ namespace TEAMModelOS.SDK.Models
         public string Mobile { get; set; }
         public string Email { get; set; }
         public string tmdid { get; set; }
+        public string areaId { get; set; }
     }
     public class ScAccessConfig : AccessConfig
     {
@@ -220,12 +221,7 @@ namespace TEAMModelOS.SDK.Models
         public string type { get; set; }
         public string param { get; set; }
         public string id_token { get; set; }
+        public string mobile { get; set; }
     }
-    public class TmdidImplicit
-    {
-        public string id_token { get; set; }
-        public string access_token { get; set; }
-        public string expires_in { get; set; }
-        public string token_type { get; set; }
-    }
+    
 }

+ 6 - 65
TEAMModelOS/Controllers/Teacher/InitController.cs

@@ -63,76 +63,17 @@ namespace TEAMModelOS.Controllers
 
         public async Task<IActionResult> GetUserInfo(JsonElement request) {
             if (!request.TryGetProperty("key", out JsonElement key)) return BadRequest();
-            var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
-            var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
-            var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
+           
             var location = _option.Location;
             //https://api2-rc.teammodel.cn
-            url = "https://api2-rc.teammodel.cn";
-            (int code, string content) = await _coreAPIHttpService.GetUserInfo(clientID, clientSecret, location, $"{url}/oauth2/GetUserInfo",
-                new Dictionary<string, string>()
+           CoreUser core = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string>()
                 {      { "key",$"{key}" }
-                });
-            if (code == 200 && !string.IsNullOrEmpty(content))
-            {
-                CoreUserInfo coreUserInfo = content.ToObject<CoreUserInfo>();
-                if (coreUserInfo != null)
-                {
-                    bool isActivate = !string.IsNullOrWhiteSpace(coreUserInfo.password) || !string.IsNullOrWhiteSpace(coreUserInfo.passwordOld);
-                    CoreUser coreUser = new CoreUser
-                    {
-                        isActivate = isActivate,
-                        id = coreUserInfo.id,
-                        vid = coreUserInfo.vid,
-                        mail = coreUserInfo.mail,
-                        mobile = coreUserInfo.mobile,
-                        name = coreUserInfo.name,
-                        picture = coreUserInfo.picture,
-                        habook = coreUserInfo.habook,
-                        wechat = coreUserInfo.wechat,
-                        facebook = coreUserInfo.facebook,
-                        google = coreUserInfo.google,
-                        ding = coreUserInfo.ding,
-                        apple = coreUserInfo.apple,
-                    };
-                    return Ok(new { coreUser });
-                }
-                else {
-                    return Ok(new { error = 404, msg = "未请求到数据" });
-                }
-            }
-            else {
-                return Ok(new { error= 404, msg="未请求到数据"});
-            }
+                }, location,_configuration
+               );
+            return Ok(new { coreUser = core });
            
         }
-        public record CoreUser {
-            public string id { get; set; }
-            public string vid { get; set; }
-            public string mail { get; set; }
-            public string mobile { get; set; } 
-            public string name { get; set; }
-            public string picture { get; set; }
-            public string habook { get; set; }
-            public string wechat { get; set; }
-            public string facebook { get; set; }
-            public string google { get; set; }
-            public string ding { get; set; }
-            public string apple { get; set; }
-            public bool isActivate { get; set; }
-
-
-        }
-        public record CoreUserInfo : CoreUser
-        {
-            public string area { get; set; }
-            public string country { get; set; }
-            public string type { get; set; }
-            public string password { get; set; }
-            public string salt { get; set; }
-            public string passwordOld { get; set; }
-            public string saltOld { get; set; }
-        }
+        
 
 
         /// <summary>

+ 29 - 13
TEAMModelOS/Controllers/Third/ScController.cs

@@ -299,8 +299,6 @@ namespace TEAMModelOS.Controllers.Third
                 };
                 try
                 {
-                    
-
                     await client.GetContainer(Constant.TEAMModelOS, "School").CreateItemAsync<School>(school, new PartitionKey(school.code));
                     schoolsScucess.Add(school);
                 }
@@ -314,12 +312,30 @@ namespace TEAMModelOS.Controllers.Third
                     schoolsfailed.Add(school);
                 }
             }
-
+            //省平台获取到的学生。
+            List<ScTeacher> teachers = new();
             // 5.3.1.2获取学员名单
             (status, json) = await _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetTeachersListByProject");
             if (status == 200)
             {
-                List<ScTeacher> teachers = json.ToObject<List<ScTeacher>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
+                teachers = json.ToObject<List<ScTeacher>>(new JsonSerializerOptions { PropertyNameCaseInsensitive = false });
+                if (teachers.IsNotEmpty()) {
+                    teachers.ForEach(x => {
+                        x.RowKey = $"{x.PXID}";
+                        x.PartitionKey = "ScTeacher";
+                        x.areaId = $"{areaId}";
+                    });
+                    var areaTeacher = await _azureStorage.FindListByDict<ScSchool>(new Dictionary<string, object>() { { "PartitionKey", $"ScTeacher" }, { "areaId", $"{areaId}" } });
+                    if (areaTeacher.IsNotEmpty())
+                    {
+                       // areaTeacher
+                    }
+                    else
+                    {
+                        teachers= await _azureStorage.SaveAll(teachers);
+                    }
+                }
+                
             }
             return Ok(new {
                 projects, msg=$"Table中已经有:{tbschools.Count}个学校,省平台获取到:{schools.Count}个学校,本次保存有:{saveschools?.Count},没有被保存的学校:{unsave.Count},创建失败的学校有:{schoolsfailed.Count()},创建成功的的学校有:{schoolsScucess.Count()}",
@@ -500,13 +516,17 @@ namespace TEAMModelOS.Controllers.Third
             try 
             {
                 Teacher teacher = null;
-                if (string.IsNullOrEmpty(sso.id_token)) {
+                if (string.IsNullOrEmpty(sso.id_token) && string.IsNullOrEmpty(sso.mobile)) {
                     return Ok(new
                     {
                         location = _option.Location,
                         status = 2,
                     });
                 }
+                if (string.IsNullOrEmpty(sso.id_token) && !string.IsNullOrEmpty(sso.mobile)) { 
+                    
+                }
+
                 JwtSecurityToken jwt = null;
                 try {
                     jwt = new JwtSecurityToken(sso.id_token);
@@ -838,24 +858,20 @@ namespace TEAMModelOS.Controllers.Third
                 }
                 else
                 {
-                    var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
                     var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
-                    var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
                     var location = _option.Location;
-                    (int code, string content) = await _coreAPIHttpService.Implicit(clientID, clientSecret, location, $"{url}/oauth2/implicit",
+                    TmdidImplicit implicit_token = await _coreAPIHttpService.Implicit(  
                         new Dictionary<string, string>()
                         {
                         { "grant_type", "implicit" },
                         { "client_id",clientID },
                         { "account",teacher.id },
                         { "nonce",Guid.NewGuid().ToString()}
-                        });
-                    TmdidImplicit implicit_token = new TmdidImplicit();
-                    if (!string.IsNullOrEmpty(content) && code == 200)
+                        },location,_configuration);
+                    if (implicit_token!=null)
                     {
-                        implicit_token = content.ToObject<TmdidImplicit>();
                         if (string.IsNullOrEmpty(implicit_token.id_token)) {
-                            await _dingDing.SendBotMsg($"OS,隐式登录获得信息为空:{_option.Location}-\n{scsso.ToJsonString()} \npath:{path}\n{content}", GroupNames.成都开发測試群組);
+                            await _dingDing.SendBotMsg($"OS,隐式登录获得信息为空:{_option.Location}-\n{scsso.ToJsonString()} \npath:{path}\n{implicit_token.ToJsonString()}", GroupNames.成都开发測試群組);
                             return Redirect(rurl.Append($"?status=1").ToString());
                         }
                         var bind = teacher.binds.Find(x => x.userid.Equals(sso.tid));

+ 2 - 9
TEAMModelOS/Controllers/XTest/TestController.cs

@@ -588,15 +588,8 @@ namespace TEAMModelOS.Controllers
         [HttpPost("get-data")]
         public async Task<IActionResult> GetData(JsonElement request)
         {
-            var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
-            var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
-            var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
-            var location = _option.Location;
-            (int code, string content) = await _coreAPIHttpService.GetUserInfo(clientID, clientSecret, location, $"{url}/oauth2/getuserinfo",
-                new Dictionary<string, string>()
-                {      { "key", request.GetProperty("key").ToString() }
-                });
-            return Ok(content);
+           
+            return Ok();
         }
     }