|
@@ -0,0 +1,201 @@
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using TEAMModelOS.Models;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using System.Text.Json;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+using Azure.Cosmos;
|
|
|
+using System.Text;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using Microsoft.Extensions.Options;
|
|
|
+using Azure.Messaging.ServiceBus;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
+using HTEXLib.COMM.Helpers;
|
|
|
+using TEAMModelOS.SDK;
|
|
|
+using System.IdentityModel.Tokens.Jwt;
|
|
|
+using TEAMModelOS.Services;
|
|
|
+using TEAMModelOS.SDK.Models.Service;
|
|
|
+using System.IO;
|
|
|
+using System.Dynamic;
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
+using Azure.Storage.Blobs.Models;
|
|
|
+using static TEAMModelOS.SDK.Models.Teacher;
|
|
|
+using System.Web;
|
|
|
+using static TEAMModelOS.Controllers.FixDataController;
|
|
|
+using static TEAMModelOS.SDK.SchoolService;
|
|
|
+using Microsoft.AspNetCore.Hosting;
|
|
|
+using Microsoft.Azure.Cosmos.Table;
|
|
|
+using System.Net.Http;
|
|
|
+using TEAMModelOS.SDK.Context.Attributes.Azure;
|
|
|
+
|
|
|
+namespace TEAMModelOS.Controllers.Third.LePei
|
|
|
+{
|
|
|
+ [ApiController]
|
|
|
+ public class LePeiController : ControllerBase
|
|
|
+ {
|
|
|
+ private readonly SnowflakeId _snowflakeId;
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ private readonly Option _option;
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
+ private readonly AzureServiceBusFactory _serviceBus;
|
|
|
+ private readonly AzureRedisFactory _azureRedis;
|
|
|
+ private readonly CoreAPIHttpService _coreAPIHttpService;
|
|
|
+ public readonly string type = "scsyxpt";
|
|
|
+ public readonly IHttpClientFactory _httpClientFactory;
|
|
|
+
|
|
|
+ public IConfiguration _configuration { get; set; }
|
|
|
+ public LePeiController(IWebHostEnvironment environment, AzureCosmosFactory azureCosmos, SnowflakeId snowflakeId, DingDing dingDing, IOptionsSnapshot<Option> option, AzureStorageFactory azureStorage,
|
|
|
+ AzureRedisFactory azureRedis, AzureServiceBusFactory serviceBus, IConfiguration configuration, CoreAPIHttpService coreAPIHttpService, IHttpClientFactory httpClientFactory)
|
|
|
+ {
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
+ _snowflakeId = snowflakeId;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _option = option?.Value;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
+ _serviceBus = serviceBus;
|
|
|
+ _configuration = configuration;
|
|
|
+ _azureRedis = azureRedis;
|
|
|
+ _coreAPIHttpService = coreAPIHttpService;
|
|
|
+ _httpClientFactory = httpClientFactory;
|
|
|
+ }
|
|
|
+ [HttpPost("{path}/lepei-sso")]
|
|
|
+ [AllowAnonymous]
|
|
|
+ public async Task<IActionResult> Sso(LPSSO sso, string path) {
|
|
|
+ string HostName = HttpContext.GetHostName();
|
|
|
+ if (!string.IsNullOrWhiteSpace(_option.HostName))
|
|
|
+ {
|
|
|
+ HostName = _option.HostName;
|
|
|
+ }
|
|
|
+ if (path.Equals("xinjin"))
|
|
|
+ {
|
|
|
+ if (!_option.Location.Contains("Dep"))
|
|
|
+ {
|
|
|
+ HostName = "www.teammodel.cn";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var rurl = new StringBuilder($"https://{HostName}/sso");
|
|
|
+ var table = _azureStorage.GetCloudTableClient().GetTableReference("ScYxpt");
|
|
|
+ List<LPConfig> configs = await table.FindListByDict<LPConfig>(new Dictionary<string, object>() { { "PartitionKey", $"LPConfig-{sso.appId}" }, { Constant.RowKey,path } });
|
|
|
+ if (configs.Any())
|
|
|
+ {
|
|
|
+ LPConfig config = configs[0];
|
|
|
+ string data = AESHelper.Decryptor(sso.encryptData, config.secretKey, config.secretKey.Substring(0, 16));
|
|
|
+ LPSSOEncryptData encryptData = data.ToObject<LPSSOEncryptData>();
|
|
|
+ List<LPTeacher> teachers = await table.FindListByDict<LPTeacher>(new Dictionary<string, object>() { { "PartitionKey", $"LPTeacher-{encryptData.schoolId}" }, { Constant.RowKey, encryptData.userId } });
|
|
|
+ if (teachers.Any())
|
|
|
+ {
|
|
|
+ LPTeacher teacher = teachers[0];
|
|
|
+ if (!string.IsNullOrWhiteSpace(teacher.tmdid))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ int status = 2;//手机号未注册
|
|
|
+ string param =string.Empty;
|
|
|
+ string enurl=string.Empty;
|
|
|
+ if (!string.IsNullOrWhiteSpace(encryptData.mobile)) {
|
|
|
+ //未绑定,尝试用手机号进行关联
|
|
|
+ var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", encryptData.mobile } }, _option.Location, _configuration);
|
|
|
+
|
|
|
+ if (coreUser != null)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ enurl = $"status={status}¶m={HttpUtility.UrlEncode(new { msg = $"教师编号为:{encryptData.userId}未绑定" , }.ToJsonString(), Encoding.UTF8)}";
|
|
|
+ return Redirect(rurl.Append($"?{enurl}").ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ //未配置 {path}项目
|
|
|
+ string enurl = $"status=1¶m={HttpUtility.UrlEncode(new { msg =$"未配置{path}项目" }.ToJsonString(), Encoding.UTF8)}";
|
|
|
+ return Redirect(rurl.Append($"?{enurl}").ToString());
|
|
|
+ }
|
|
|
+ return Ok();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public class LPSSO {
|
|
|
+ public string appId { get; set; }
|
|
|
+ public string schoolId { get; set; }
|
|
|
+ public string encryptData { get; set; }
|
|
|
+ }
|
|
|
+ public class LPSSOEncryptData
|
|
|
+ {
|
|
|
+ public string appId { get; set; }
|
|
|
+ public string schoolId { get; set; }
|
|
|
+ public string userId { get; set; }
|
|
|
+ public string mobile { get; set; }
|
|
|
+ }
|
|
|
+ [TableName(Name = "ScYxpt")]
|
|
|
+ public class LPTeacher :TableEntity
|
|
|
+ {
|
|
|
+ /// <summary>
|
|
|
+ /// PartitionKey = "LPTeacher-{schoolId}"
|
|
|
+ /// RowKey = $"{userId}"
|
|
|
+ /// </summary>
|
|
|
+ public string userId { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 乐陪对应的学校id
|
|
|
+ /// </summary>
|
|
|
+ public string schoolId { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 醍摩豆对应的学校编码
|
|
|
+ /// </summary>
|
|
|
+ public string schoolCode { get; set; }
|
|
|
+ public string mobile { get; set; }
|
|
|
+ public string tmdid { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// {path}/lepei-sso 中的path
|
|
|
+ /// </summary>
|
|
|
+ public string path { get; set; }
|
|
|
+ }
|
|
|
+ [TableName(Name = "ScYxpt")]
|
|
|
+ public class LPSchool : TableEntity
|
|
|
+ {
|
|
|
+ public LPSchool()
|
|
|
+ {
|
|
|
+ PartitionKey = "LPSchool";
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// PartitionKey = "LPSchool"
|
|
|
+ /// RowKey = $"{schoolId学校id}"
|
|
|
+ /// </summary>
|
|
|
+ public string schoolId { get; set; }
|
|
|
+ public string schoolName { get; set; }
|
|
|
+ /// <summary>
|
|
|
+ /// 醍摩豆对应的学校编码
|
|
|
+ /// </summary>
|
|
|
+ public string schoolCode { get; set; }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// {path}/lepei-sso 中的path
|
|
|
+ /// </summary>
|
|
|
+ public string path { get; set; }
|
|
|
+ }
|
|
|
+ [TableName(Name = "ScYxpt")]
|
|
|
+ public class LPConfig : TableEntity
|
|
|
+ {
|
|
|
+ public LPConfig (){
|
|
|
+ PartitionKey = "LPConfig-{appId}";
|
|
|
+ }
|
|
|
+ /// <summary>
|
|
|
+ /// pk="LPConfig"
|
|
|
+ /// rk=$"{path}"
|
|
|
+ /// </summary>
|
|
|
+ public string path { get; set; }
|
|
|
+ public string appId { get; set;}
|
|
|
+ public string secretKey { get; set; }
|
|
|
+ }
|
|
|
+}
|