CrazyIter_Bin 3 роки тому
батько
коміт
7b00586c6f

+ 38 - 1
TEAMModelFunction/ScsApisHttpTrigger.cs

@@ -61,7 +61,6 @@ namespace TEAMModelFunction
             //parameterMap.Add("ProjectItemID", "22");
             parameterMap.Add("PXID", pxid);
             ScsResult result = new ScsResult { code = Code, title = "5.3.1.3通过项目编号获取学员测评能力项V2" };
-
             try
             {
                 result = await _thirdApisService.Post(config.url, Code, config.passKey, config.privateKey, parameterMap);
@@ -81,5 +80,43 @@ namespace TEAMModelFunction
                 return new OkObjectResult(abilityNos);
             }
         }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="req"></param>
+        /// <param name="log"></param>
+        /// <returns></returns>
+        [FunctionName("GetSingleTeacherByProject")]
+        public async Task<IActionResult> GetSingleTeacherByProject([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log)
+        {
+            ScTeacher teacher=null;
+            string data = await new StreamReader(req.Body).ReadToEndAsync();
+            JsonElement accessConfig = data.ToObject<JsonElement>().GetProperty("accessConfig");
+            JsonElement pxid = data.ToObject<JsonElement>().GetProperty("pxid");
+            JsonElement tid = data.ToObject<JsonElement>().GetProperty("tid");
+            ScAccessConfig config = $"{accessConfig}".ToObject<ScAccessConfig>();
+            Code = "GetSingleTeacherByProject";
+            parameterMap = new Dictionary<string, object>();
+            parameterMap.Add("TrainComID", config.trainComID);
+            parameterMap.Add("Pxid", $"{pxid}");
+            parameterMap.Add("Tid", $"{tid}");
+            ScsResult result = new ScsResult { code = Code, title = "5.3.1.11获取跳转学员信息,用于sso单点,后端验证。" };
+            try
+            {
+                ///{“result”:true,”reason”:null,”content”:”{“PXID”:””,”TID”:””,”TeacherName”:””,”ProjectTitle”:””,”ProjectItemTitle”:””,”CityName”:””,
+                ///”DisName”:””,”SchoolName”:””,”Sex”:””,”PXXK”:””,”PXXD”:””,”TeacherXK”:””,”TeacherXD”:””,”Email”:””}”,”pagecount”:1}
+                result = await _thirdApisService.Post(config.url, Code, config.passKey, config.privateKey, parameterMap);
+                if (result.result)
+                {
+                      teacher = result.content.ToObject<ScTeacher>();
+                }
+                return new OkObjectResult(teacher);
+            }
+            catch (Exception ex)
+            {
+                await _dingDing.SendBotMsg($"IES5.ScApisService:GetSingleTeacherByProject\n{ex.Message}{ex.StackTrace}\n{result.ToJsonString()}", GroupNames.成都开发測試群組);
+                return new OkObjectResult(teacher);
+            }
+        }
     }
 }

+ 80 - 0
TEAMModelOS.SDK/DI/HttpTrigger/HttpTrigger.cs

@@ -0,0 +1,80 @@
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Net.Http;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using System.Security.Cryptography;
+using System.Net.Http.Json;
+using System.Text.Json;
+using System.IO;
+using TEAMModelOS.SDK.Extension;
+using System.Net;
+
+namespace TEAMModelOS.SDK.DI
+{
+    public class HttpTrigger
+    {
+        private readonly HttpClient _httpClient;
+
+        public HttpTrigger(HttpClient httpClient)
+        {
+            _httpClient = httpClient;
+        }
+        // <summary>
+        /// 请求信息
+        /// </summary>
+        /// <param name="robotUrl">釘釘Robot發送Url</param>
+        /// <param name="secret">加簽密鑰</param>
+        /// <param name="msg">發送訊息</param>
+        /// <returns></returns>
+        public async Task<(int status,string json)> RequestHttpTrigger(object data, string location,string url)
+        {
+            var keys = HttpTriggerUrl.HttpTrigger地址.GetDescriptionText().Split(',');
+            string domain = "";
+            if (location.Equals("China-Dep"))
+            {
+                domain = keys[1];
+            }
+            else if (location.Equals("China-Test"))
+            {
+                domain = keys[1];
+            }
+            else if (location.Equals("China"))
+            {
+                domain = keys[2];
+            }
+            else if (location.Equals("Global-Dep"))
+            {
+                domain = keys[4];
+            }
+            else if (location.Equals("Global-Test"))
+            {
+                domain = keys[4];
+            }
+            else if (location.Equals("Global"))
+            {
+                domain = keys[5];
+            }
+            HttpResponseMessage responseMessage =await _httpClient.PostAsJsonAsync($"https://{domain}/api/{url}", data);
+            if (responseMessage.StatusCode == HttpStatusCode.OK)
+            {
+                string Content= await responseMessage.Content.ReadAsStringAsync();
+                return (200, Content);
+            }
+            else
+            {
+                string Content = await responseMessage.Content?.ReadAsStringAsync();
+                return (500, Content);
+            }
+        }
+    }
+    public enum HttpTriggerUrl
+    {
+        [Description("localhost:7071,teammodelosfunction-test.chinacloudsites.cn,teammodelosfunction.chinacloudsites.cn,teammodelosfunction.chinacloudsites.cn,teammodelosfunction.chinacloudsites.cn")]
+        HttpTrigger地址,
+
+    }
+}

+ 21 - 4
TEAMModelOS.SDK/Models/Service/Third/ScApisService.cs

@@ -14,19 +14,19 @@ namespace TEAMModelOS.SDK
     {
         public static string Code { get; set; }
         public static Dictionary<string, object> parameterMap = null;
-        public static async Task<List<string>> GetDiagnosisListByProject_V2( string setting,  string PXID) {
-            ScAccessConfig config = setting.ToObject<ScAccessConfig>();
+        public static async Task<List<string>> GetDiagnosisListByProject_V2(ScConfig scconfig, ThirdApisService _thirdApisService) {
+            ScAccessConfig config = scconfig.accessConfig.ToObject<ScAccessConfig>();
             List<string> abilityNos = null;
             Code = "GetDiagnosisListByProject_V2";
             parameterMap = new Dictionary<string, object>();
             parameterMap.Add("TrainComID", config.trainComID);
             //parameterMap.Add("ProjectID", "22");
             //parameterMap.Add("ProjectItemID", "22");
-            parameterMap.Add("PXID", PXID);
+            parameterMap.Add("PXID", scconfig.pxid);
             ScsResult result = new ScsResult {code=Code,title= "5.3.1.3通过项目编号获取学员测评能力项V2" };
 
             try {
-               // result = await _thirdApisService.Post(config.url, Code, config.passKey, config.privateKey, parameterMap);
+                result = await _thirdApisService.Post(config.url, Code, config.passKey, config.privateKey, parameterMap);
                 if (result.result)
                 {
                     List<ScDiagnosis> diagnoses = result.content.ToObject<List<ScDiagnosis>>();
@@ -42,12 +42,29 @@ namespace TEAMModelOS.SDK
             }
         }
     }
+    public class ScConfig
+    {
+        public string accessConfig { get; set; }
+        public string pxid { get; set; }
+    }
     public class ScDiagnosis
     {
         public string diagnosisName { get; set; }
         public string DiagnosisDicNum { get; set; }
         public string ID { get; set; }
     }
+    public class ScTeacher
+    {
+        public string PXID { get; set; }
+        public string TID { get; set; }
+        public string TeacherName { get; set; }
+        public string SchoolID { get; set; }
+        public string SchoolName { get; set; }
+        public string ProjectID { get; set; }
+        public string ProjectItemID { get; set; }
+        public string ProjectTitle { get; set; }
+        public string ProjectItemTitle { get; set; }
+    }
     public class ScAccessConfig
     {
         public string passKey { get; set; }

+ 6 - 3
TEAMModelOS.SDK/Models/Service/Third/ThirdService.cs

@@ -41,13 +41,16 @@ namespace TEAMModelOS.SDK.Models
                 return (setting.accessConfig,area,setting);
             }
         }
-        public static async Task<List<Ability>> GetDiagnosisList(CosmosClient client, string standard,DingDing dingDing,  AreaSetting setting, ThirdApisService _thirdApisService,string PXID) {
-            List<string> abilityNos = null ;
+        public static async Task<List<Ability>> GetDiagnosisList(CosmosClient client, string standard,DingDing dingDing,  AreaSetting setting, ThirdApisService _thirdApisService, HashSet<string> pxids) {
+            List<string> abilityNos = new List<string>() ;
             var config= setting.accessConfig.ToObject<JsonElement>();
             config.TryGetProperty("config", out JsonElement _config);
             if ($"{_config}".Equals("scsyxpt"))
             {
-             //  abilityNos = await ScApisService.GetDiagnosisListByProject_V2(new { accessConfig = setting.accessConfig, pxid = PXID }.ToJsonString());
+                foreach (var pxid in pxids) {
+                     var   abilityNoslsit = await ScApisService.GetDiagnosisListByProject_V2(new ScConfig { accessConfig = setting.accessConfig, pxid = pxid }, _thirdApisService);
+                    abilityNos.AddRange(abilityNoslsit);
+                }
             }
             //获取能力点
             List<Ability> abilities = null;

+ 3 - 2
TEAMModelOS/Controllers/Research/AbilityStatisticsController.cs

@@ -1592,8 +1592,9 @@ namespace TEAMModelOS.Controllers.Research
                 (string accessConfig, Area area, AreaSetting setting) =  await ThirdService.GetAccessConfig(client, $"{standard}");
                 //未对接其他平台。有对接其他平台则必修。
                 if (!string.IsNullOrEmpty(accessConfig)) {
-
-                    var abilitys = await ThirdService.GetDiagnosisList(client, $"{standard}", _dingDing, setting,   _thirdApisService,   $"PXID");
+                    Teacher teacher = await _azureCosmos.GetCosmosClient().GetContainer("TEAMModelOS", "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
+                    HashSet<string> pxid= teacher.binds.SelectMany(x => x.pxid).ToHashSet();
+                    var abilitys = await ThirdService.GetDiagnosisList(client, $"{standard}", _dingDing, setting,   _thirdApisService, pxid);
                     if (abilitys != null)
                     {
                         abilitys.ForEach(x => { x.currency = 1; });

+ 229 - 210
TEAMModelOS/Controllers/Third/ScController.cs

@@ -36,7 +36,7 @@ namespace TEAMModelOS.Controllers.Third
     [ProducesResponseType(StatusCodes.Status200OK)]
     [ProducesResponseType(StatusCodes.Status400BadRequest)]
     //[Authorize(Roles = "IES5")]
-    [Route("sc")]
+    //[Route("")]
     //[Route("api/[controller]")]
     [ApiController]
     public class ScController : ControllerBase
@@ -51,6 +51,7 @@ namespace TEAMModelOS.Controllers.Third
         private readonly CoreAPIHttpService _accountHttpService;
         private readonly ThirdApisService _scsApisService;
         public readonly string type = "scsyxpt";
+        private readonly HttpTrigger _httpTrigger;
         /// <summary>
         /// 机构安全码
         /// </summary>
@@ -69,7 +70,7 @@ namespace TEAMModelOS.Controllers.Third
         public   string _sc_url;
         public IConfiguration _configuration { get; set; }
         public ScController(AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
-          AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IConfiguration configuration, CoreAPIHttpService accountHttpService, ThirdApisService scsApisService)
+          AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IConfiguration configuration, CoreAPIHttpService accountHttpService, ThirdApisService scsApisService, HttpTrigger httpTrigger)
         {
             _azureCosmos = azureCosmos;
             _snowflakeId = snowflakeId;
@@ -85,6 +86,210 @@ namespace TEAMModelOS.Controllers.Third
             _sc_trainComID = _configuration.GetValue<string>("Third:scsyxpt:trainComID");
             _sc_privateKey = _configuration.GetValue<string>("Third:scsyxpt:privateKey");
             _sc_url = _configuration.GetValue<string>("Third:scsyxpt:url");
+            _httpTrigger = httpTrigger;
+        }
+       
+       
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [ProducesDefaultResponseType]
+        [HttpPost("sc/bind")]
+        [AllowAnonymous]
+        public async Task<IActionResult> Bind(SSO sso) {
+            try 
+            {
+                Teacher teacher = null;
+                if (string.IsNullOrEmpty(sso.id_token)) {
+                    return Ok(new
+                    {
+                        location = _option.Location,
+                        status = 2,
+                    });
+                }
+                var jwt = new JwtSecurityToken(sso.id_token);
+                if (!jwt.Payload.Iss.Equals("account.teammodel", StringComparison.OrdinalIgnoreCase)) return BadRequest();
+                var id = jwt.Payload.Sub;
+                jwt.Payload.TryGetValue("name", out object name);
+                jwt.Payload.TryGetValue("picture", out object picture);
+                var client = _azureCosmos.GetCosmosClient();
+                teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
+                //先检查绑定的平台是否已经被绑定
+                //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
+                ScSSO scsso= sso.param.ToObject<ScSSO>();
+                string sql = $"SELECT distinct value(c) FROM c join A1 in  c.binds where  A1.webid='{scsso.Webid}' and A1.tid='{scsso.tid}'";
+                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sql,
+                    requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+                {
+                    teacher = item;
+                    break;
+                }
+                if (teacher != null)
+                {
+                    if (teacher.id.Equals(id))
+                    {
+                        var bind = teacher.binds.Find(x => x.source.Equals($"{scsso.Webid}") && x.userid.Equals($"{scsso.tid}"));
+                        if (bind == null)
+                        {
+                            teacher.binds=new List<Teacher.ThirdBind> { new Teacher.ThirdBind { pxid = new HashSet<string> { $"{scsso.Pxid}" }, userid = $"{scsso.tid}", source = $"{scsso.Webid}", type = type } };
+                            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
+                        }
+                        else
+						{
+                            if (bind.pxid != null)
+                            {
+                                if (bind.pxid.Add(scsso.Pxid))
+                                {
+                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
+                                }
+                            }
+                            else {
+                                bind.pxid = new HashSet<string> { scsso.Pxid };
+                                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
+                            }
+                           
+                        }
+                    }
+                    else {
+                        return Ok(new
+                        {
+                            location = _option.Location,
+                            //账号已被别的醍摩豆id绑定
+                            status = 3,
+                            tmdid = teacher.id,
+                            name=teacher.name,
+                            tid = scsso.tid
+                        }) ;
+                    }
+                }
+                else {
+                    teacher = new Teacher
+                    {
+                        id = id,
+                        pk = "Base",
+                        code = "Base",
+                        name = name?.ToString(),
+                        picture = picture?.ToString(),
+                        //创建账号并第一次登录IES5则默认赠送1G
+                        size = 1,
+                        defaultSchool = null,
+                        schools = new List<Teacher.TeacherSchool>(),
+                        binds= new List<Teacher.ThirdBind> { new Teacher.ThirdBind { pxid = new HashSet<string> { $"{scsso.Pxid}" }, userid = $"{scsso.tid}", source = $"{scsso.Webid}", type = type } }
+                    };
+                    var container = _azureStorage.GetBlobContainerClient(id);
+                    await container.CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
+                    teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
+                }
+                return Ok(new
+                {
+                    location = _option.Location,
+                    status = 200,
+                });
+                
+            } catch (Exception  ) {
+                return Ok(new
+                {
+                    location = _option.Location,
+                    status = 2,
+                });
+            }
+
+        }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+
+        [HttpGet("{path}/sso")]
+        [AllowAnonymous]
+        public async Task<IActionResult> Sso([FromQuery] ScSSO sso,string path)
+        {
+            if (path.Equals("sc"))
+            {
+                path = $"scpjx";
+            }
+            else {
+                path = $"sc{path}";
+            }
+            var rurl = new StringBuilder($"https://{_option.HostName}/sso");
+            string parmas = $"Pxid={sso.Pxid}&Webid={sso.Webid}&tid={sso.tid}&time={sso.time}";
+            if (Md5Hash.GetMd5String(parmas).Equals($"{sso.Encrypt}"))
+            {
+                //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
+              
+                long ssotime = long.Parse($"{sso.time}");
+                long nowtime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
+                if (nowtime - ssotime > 60 * 10)//10分钟有效期
+                {
+                    //  return Ok(new { status = 2, msg = "登录超时!" });
+                }
+            }
+            else
+            {
+                return Redirect(rurl.Append($"?status=1").ToString());
+            }
+            Dictionary<string, object> dict = new Dictionary<string, object> { { "pxid",sso.Pxid },{ "tid",sso.tid} };
+            (int status,string json ) =await  _httpTrigger.RequestHttpTrigger(dict, _option.Location, "GetSingleTeacherByProject");
+            Teacher teacher = null;
+            //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
+            //string sql = $"SELECT distinct value(c) FROM c join A1 in  c.binds where A1.pxid='{sso.Pxid}' and A1.webid='{sso.Webid}' and A1.tid='{sso.tid}'";
+            string sql = $"SELECT distinct value(c) FROM c join A1 in  c.binds where  A1.source='{sso.Webid}' and A1.userid='{sso.tid}'";
+            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sql,
+                requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
+            {
+                teacher = item;
+                break;
+            }
+            if (teacher == null)
+            {
+                return Redirect(rurl.Append($"?status=4&param={sso.ToJsonString()}&type={type}&bindurl=sc/bind").ToString());
+            }
+            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 _accountHttpService.Implicit(clientID, clientSecret, location, $"{url}/oauth2/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)
+                {
+                    implicit_token = content.ToObject<TmdidImplicit>();
+                    var bind = teacher.binds.Find(x => x.userid.Equals(sso.tid) && x.source.Equals(sso.Webid));
+                    if (bind != null) {
+                        if (bind.pxid != null)
+                        {
+                            if (bind.pxid.Add(sso.Pxid))
+                            {
+                                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
+                            }
+                        }
+                        else {
+                            bind.pxid = new HashSet<string> { sso.Pxid };
+                            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
+                        }
+                    }
+                    return Redirect(rurl.Append($"?status=200&id_token={implicit_token.id_token}&access_token={implicit_token.access_token}&expires_in={implicit_token.expires_in}&token_type={implicit_token.token_type}").ToString());
+                }
+                else {
+                    //绑定失效
+                    if (teacher.binds.IsNotEmpty()) {
+                        teacher.binds.RemoveAll(x => x.userid.Equals(sso.tid) && x.source.Equals(sso.Webid));
+                        await  _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher,teacher.id,new PartitionKey(teacher.code));
+                    }
+                    return Redirect(rurl.Append($"?status=4&param={sso.ToJsonString()}&type={type}&bindurl=sc/bind").ToString());
+                }
+            }
         }
         /// <summary>
         ///
@@ -92,20 +297,21 @@ namespace TEAMModelOS.Controllers.Third
         /// <param name="json"></param>
         /// <returns></returns>
         [ProducesDefaultResponseType]
-        [HttpPost("get-list")]
+        [HttpPost("sc/get-list")]
         [AllowAnonymous]
-        public async Task<IActionResult> GetProjectList(JsonElement json) {
+        public async Task<IActionResult> GetProjectList(JsonElement json)
+        {
 
             // 5.3.1.1获取项目列表
             string trainComID = _sc_trainComID;
             string Code = "GetProjectInfoByTrainComID";
             Dictionary<string, object> parameterMap = new Dictionary<string, object>();
             parameterMap.Add("TrainComID", _sc_trainComID);
-            ScsResult GetProjectInfoByTrainComID = await _scsApisService.Post(_sc_url, Code, _sc_passKey,_sc_privateKey, parameterMap);
+            ScsResult GetProjectInfoByTrainComID = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
             GetProjectInfoByTrainComID.code = Code;
             GetProjectInfoByTrainComID.title = "5.3.1.1获取项目列表";
 
-          
+
             // 5.3.1.2获取学员名单,暂不对接。
             Code = "GetTeachersListByProject";
             parameterMap = new Dictionary<string, object>();
@@ -143,7 +349,8 @@ namespace TEAMModelOS.Controllers.Third
 
             ScsResult UpdateTeacherSituation = null;
             // 5.3.1.4学员培训基本情况回写
-            try {
+            try
+            {
                 Code = "UpdateTeacherSituation";
                 parameterMap = new Dictionary<string, object>();
                 parameterMap.Add("TrainComID", trainComID);
@@ -156,7 +363,8 @@ namespace TEAMModelOS.Controllers.Third
                 UpdateTeacherSituation = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
                 UpdateTeacherSituation.code = Code;
                 UpdateTeacherSituation.title = "5.3.1.4学员培训基本情况回写";
-            } catch (Exception ex) { }
+            }
+            catch (Exception ex) { }
             ScsResult UpdateTeacherDiagnosis = null;
             try
             {
@@ -185,7 +393,8 @@ namespace TEAMModelOS.Controllers.Third
                 UpdateTeacherDiagnosis.code = Code;
                 UpdateTeacherDiagnosis.title = "5.3.1.5学员能力点测评结果回写";
             }
-            catch (Exception ex) { 
+            catch (Exception ex)
+            {
             }
 
 
@@ -256,8 +465,8 @@ namespace TEAMModelOS.Controllers.Third
             try
             { // 5.3.1.12学员培训基本情况批量回写
                 Code = "UpdateTeacherListSituation";
-              
-              
+
+
                 parameterContent.Add("TrainComID", trainComID);
                 parameterContent.Add("List", list);
                 // {"TrainComID":"39","List":[{"ResearchText":"","ComPassed":1,"PXID":"35455","CourseHour":"50.0","TID":"411105","TeacherName":"付绍令"}]}
@@ -376,11 +585,12 @@ namespace TEAMModelOS.Controllers.Third
                     pfiles.Add(pfileMap);
                     list.Add(parameterMapData);
                 }
-                 UpdateTeacherListDiagnosis = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterContent);
+                UpdateTeacherListDiagnosis = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterContent);
                 UpdateTeacherListDiagnosis.code = Code;
                 UpdateTeacherListDiagnosis.title = "5.3.1.13学员能力点测评结果批量回写";
             }
-            catch (Exception ex) { 
+            catch (Exception ex)
+            {
             }
 
 
@@ -402,7 +612,8 @@ namespace TEAMModelOS.Controllers.Third
                 UploadSBTARPDF.code = Code;
                 UploadSBTARPDF.title = "5.3.1.14学员校本研修PDF回写";
             }
-            catch (Exception ex) { 
+            catch (Exception ex)
+            {
             }
 
             ScsResult UploadSBTARPDFList = null;
@@ -455,10 +666,11 @@ namespace TEAMModelOS.Controllers.Third
                 parameterMap.Add("fileSize", "247767");
                 parameterMap.Add("md5", "9c3da8c5c07c2c660cd73c01f56d7fca");
                 parameterMap.Add("fileType", "mp4");
-                 UploadKTSL = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
+                UploadKTSL = await _scsApisService.Post(_sc_url, Code, _sc_passKey, _sc_privateKey, parameterMap);
                 UploadKTSL.code = Code;
                 UploadKTSL.title = "5.3.1.16学员课堂实录回写";
-            } catch (Exception ex) { }
+            }
+            catch (Exception ex) { }
             ScsResult UploadKTSLList = null;
             try
             {
@@ -558,203 +770,10 @@ namespace TEAMModelOS.Controllers.Third
                 GetProjectDiagnosis,
                 GetSchoolDiagnosis
             });
-            
-            //return Ok(GetProjectInfoByTrainComID);
-        }
-
-       
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
-        [ProducesDefaultResponseType]
-        [HttpPost("bind")]
-        [AllowAnonymous]
-        public async Task<IActionResult> Bind(SSO sso) {
-            try 
-            {
-                Teacher teacher = null;
-                if (string.IsNullOrEmpty(sso.id_token)) {
-                    return Ok(new
-                    {
-                        location = _option.Location,
-                        status = 2,
-                    });
-                }
-                var jwt = new JwtSecurityToken(sso.id_token);
-                if (!jwt.Payload.Iss.Equals("account.teammodel", StringComparison.OrdinalIgnoreCase)) return BadRequest();
-                var id = jwt.Payload.Sub;
-                jwt.Payload.TryGetValue("name", out object name);
-                jwt.Payload.TryGetValue("picture", out object picture);
-                var client = _azureCosmos.GetCosmosClient();
-                teacher = await client.GetContainer(Constant.TEAMModelOS, "Teacher").ReadItemAsync<Teacher>(id, new PartitionKey("Base"));
-                //先检查绑定的平台是否已经被绑定
-                //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
-                ScSSO scsso= sso.param.ToObject<ScSSO>();
-                string sql = $"SELECT distinct value(c) FROM c join A1 in  c.binds where  A1.webid='{scsso.Webid}' and A1.tid='{scsso.tid}'";
-                await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sql,
-                    requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-                {
-                    teacher = item;
-                    break;
-                }
-                if (teacher != null)
-                {
-                    if (teacher.id.Equals(id))
-                    {
-                        var bind = teacher.binds.Find(x => x.source.Equals($"{scsso.Webid}") && x.userid.Equals($"{scsso.tid}"));
-                        if (bind == null)
-                        {
-                            teacher.binds=new List<Teacher.ThirdBind> { new Teacher.ThirdBind { pxid = new HashSet<string> { $"{scsso.Pxid}" }, userid = $"{scsso.tid}", source = $"{scsso.Webid}", type = type } };
-                            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
-                        }
-                        else
-						{
-                            if (bind.pxid != null)
-                            {
-                                if (bind.pxid.Add(scsso.Pxid))
-                                {
-                                    await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
-                                }
-                            }
-                            else {
-                                bind.pxid = new HashSet<string> { scsso.Pxid };
-                                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
-                            }
-                           
-                        }
-                    }
-                    else {
-                        return Ok(new
-                        {
-                            location = _option.Location,
-                            //账号已被别的醍摩豆id绑定
-                            status = 3,
-                            tmdid = teacher.id,
-                            name=teacher.name,
-                            tid = scsso.tid
-                        }) ;
-                    }
-                }
-                else {
-                    teacher = new Teacher
-                    {
-                        id = id,
-                        pk = "Base",
-                        code = "Base",
-                        name = name?.ToString(),
-                        picture = picture?.ToString(),
-                        //创建账号并第一次登录IES5则默认赠送1G
-                        size = 1,
-                        defaultSchool = null,
-                        schools = new List<Teacher.TeacherSchool>(),
-                        binds= new List<Teacher.ThirdBind> { new Teacher.ThirdBind { pxid = new HashSet<string> { $"{scsso.Pxid}" }, userid = $"{scsso.tid}", source = $"{scsso.Webid}", type = type } }
-                    };
-                    var container = _azureStorage.GetBlobContainerClient(id);
-                    await container.CreateIfNotExistsAsync(PublicAccessType.None); //嘗試創建Teacher私有容器,如存在則不做任何事,保障容器一定存在
-                    teacher = await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").CreateItemAsync<Teacher>(teacher, new PartitionKey("Base"));
-                }
-                return Ok(new
-                {
-                    location = _option.Location,
-                    status = 200,
-                });
-                
-            } catch (Exception  ) {
-                return Ok(new
-                {
-                    location = _option.Location,
-                    status = 2,
-                });
-            }
 
+            //return Ok(GetProjectInfoByTrainComID);
         }
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="request"></param>
-        /// <returns></returns>
 
-        [HttpGet("sso")]
-        [AllowAnonymous]
-        public async Task<IActionResult> Sso([FromQuery] ScSSO sso)
-        {
-            var rurl = new StringBuilder($"https://{_option.HostName}/sso");
-            string parmas = $"Pxid={sso.Pxid}&Webid={sso.Webid}&tid={sso.tid}&time={sso.time}";
-            if (Md5Hash.GetMd5String(parmas).Equals($"{sso.Encrypt}"))
-            {
-                //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
-              
-                long ssotime = long.Parse($"{sso.time}");
-                long nowtime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
-                if (nowtime - ssotime > 60 * 10)//10分钟有效期
-                {
-                    //  return Ok(new { status = 2, msg = "登录超时!" });
-                }
-            }
-            else
-            {
-                return Redirect(rurl.Append($"?status=1").ToString());
-            }
-            Teacher teacher = null;
-            //四川研训平台跳转隐式登录/或者绑定IES平台接入规范
-            //string sql = $"SELECT distinct value(c) FROM c join A1 in  c.binds where A1.pxid='{sso.Pxid}' and A1.webid='{sso.Webid}' and A1.tid='{sso.tid}'";
-            string sql = $"SELECT distinct value(c) FROM c join A1 in  c.binds where  A1.source='{sso.Webid}' and A1.userid='{sso.tid}'";
-            await foreach (var item in _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").GetItemQueryIterator<Teacher>(queryText: sql,
-                requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Base") }))
-            {
-                teacher = item;
-                break;
-            }
-            if (teacher == null)
-            {
-                return Redirect(rurl.Append($"?status=4&param={sso.ToJsonString()}&type={type}&bindurl=sc/bind").ToString());
-            }
-            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 _accountHttpService.Implicit(clientID, clientSecret, location, $"{url}/oauth2/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)
-                {
-                    implicit_token = content.ToObject<TmdidImplicit>();
-                    var bind = teacher.binds.Find(x => x.userid.Equals(sso.tid) && x.source.Equals(sso.Webid));
-                    if (bind != null) {
-                        if (bind.pxid != null)
-                        {
-                            if (bind.pxid.Add(sso.Pxid))
-                            {
-                                await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
-                            }
-                        }
-                        else {
-                            bind.pxid = new HashSet<string> { sso.Pxid };
-                            await _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher, teacher.id, new PartitionKey(teacher.code));
-                        }
-                    }
-                    return Redirect(rurl.Append($"?status=200&id_token={implicit_token.id_token}&access_token={implicit_token.access_token}&expires_in={implicit_token.expires_in}&token_type={implicit_token.token_type}").ToString());
-                }
-                else {
-                    //绑定失效
-                    if (teacher.binds.IsNotEmpty()) {
-                        teacher.binds.RemoveAll(x => x.userid.Equals(sso.tid) && x.source.Equals(sso.Webid));
-                        await  _azureCosmos.GetCosmosClient().GetContainer(Constant.TEAMModelOS, "Teacher").ReplaceItemAsync<Teacher>(teacher,teacher.id,new PartitionKey(teacher.code));
-                    }
-                    return Redirect(rurl.Append($"?status=4&param={sso.ToJsonString()}&type={type}&bindurl=sc/bind").ToString());
-                }
-            }
-        }
         public record ScSSO{
             public string Webid { get; set; }
             public string Pxid { get; set; }

+ 1 - 0
TEAMModelOS/Startup.cs

@@ -107,6 +107,7 @@ namespace TEAMModelOS
             services.AddHttpClient<NotificationService>();
             services.AddHttpClient<CoreAPIHttpService>();
             services.AddHttpClient<ThirdApisService>();
+            services.AddHttpClient<HttpTrigger>();
             services.AddMemoryCache();
             services.AddSpaStaticFiles(opt => opt.RootPath = "ClientApp/dist");
             services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = false; });