123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using TEAMModelOS.SDK.DI;
- using TEAMModelOS.SDK;
- using TEAMModelOS.Models;
- using Microsoft.Extensions.Configuration;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using Microsoft.AspNetCore.Authorization;
- using System.Threading.Tasks;
- using TEAMModelOS.Controllers.Third.LePei;
- using Microsoft.Azure.Amqp.Encoding;
- using System;
- using TEAMModelOS.SDK.Extension;
- using System.Text.Json;
- using System.Web;
- using System.Text;
- using System.Net.Http;
- using System.Net.Http.Json;
- using Azure.Core;
- using Microsoft.Azure.Cosmos;
- namespace TEAMModelOS.Controllers.Third.XunFeiJYY
- {
- /// <summary>
- /// 讯飞教育云
- /// </summary>
- [ProducesResponseType(StatusCodes.Status200OK)]
- [ProducesResponseType(StatusCodes.Status400BadRequest)]
- [ApiController]
- [Route("xunfei-jjy")]
- public class XunFeilJYYController : ControllerBase
- {
- private static readonly string authurl = "http://www.jyyun.com/sso-oauth";
- private static readonly string authorize = "authorize";
- private static readonly string getOpenId = "getOpenId";
- private static readonly string getUserInfo = "getUserInfo";
- private static readonly string url= "https://open.jyyun.com";
- private static readonly string getUserByUserId = "getUserByUserId";
- private static readonly string appid = "ea4e44e1dea54caba7b06bdea72970fa";
- private static readonly string appsecret = "bb79a189fb9c22e9ae1a62b279a112c0";
- private static readonly string apikey = "305C300D06092A864886F70D0101010500034B003048024100C362EAB80DDFD682367592DD8274A40A9FE9F37DDEC56AC8E0FBE4A5A6D9F6FDAAA495460821CA94EF4A955B582822D7BB289142F2C562FC04DA2D3B940C3D730203010001";
- private static readonly string testuserid = "fbc284072a40da84adbe206f721b3285bc5101240c006447328c7afa3b7ae20d122a14a73144eea261756cce3e83c3f6ef940d9e8d823c7c";
- private static readonly string testschlid = "fbc284072a40da841b643aa367013eb18a1d351ed46b0feb15f629530e2f3c1137ae30823af5c69d3b88ef0fa3c761efee102032fc5d2a5a";
- private readonly AzureCosmosFactory _azureCosmos;
- private readonly DingDing _dingDing;
- private readonly Option _option;
- private readonly AzureStorageFactory _azureStorage;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- private readonly IWebHostEnvironment _environment;
- private readonly IConfiguration _configuration;
- private readonly ILogger<XunFeilJYYController> _logger;
- private readonly IHttpClientFactory _httpClientFactory;
- public XunFeilJYYController(ILogger<XunFeilJYYController> logger, IConfiguration configuration, IWebHostEnvironment environment,
- CoreAPIHttpService coreAPIHttpService, AzureStorageFactory azureStorage, DingDing dingDing, AzureCosmosFactory azureCosmos, IOptionsSnapshot<Option> option)
- {
- _logger = logger;
- _configuration = configuration;
- _environment = environment;
- _coreAPIHttpService = coreAPIHttpService;
- _azureStorage = azureStorage;
- _dingDing = dingDing;
- _azureCosmos = azureCosmos;
- _option = option?.Value;
- }
- [HttpPost("gen-sso")]
- [AllowAnonymous]
- public async Task<IActionResult> GenSso(JsonElement json )
- {
- json.TryGetProperty("p", out var p);
- if ($"{p}".Equals("xunfei-jjy-sso"))
- {
- string HostName = HttpContext.GetHostName();
- if (!string.IsNullOrWhiteSpace(_option.HostName))
- {
- HostName = _option.HostName;
- }
- string xunfei_url = $"{authurl}/{authorize}?appkey={appid}&redirectUri={HttpUtility.UrlEncode($"https://{HostName}/xunfei-jjy/sso", Encoding.UTF8)}&state={DateTimeOffset.Now.ToUnixTimeMilliseconds()}&display=web";
- return Ok(new { xunfei_url, code = 200 });
- }
- else
- {
- return Ok(new { code = 400, msg = "参数错误" });
- }
- }
- [HttpGet("sso")]
- [AllowAnonymous]
- public async Task<IActionResult> Sso([FromQuery]string accesstoken,[FromQuery]string state)
- {
- //前端缓存accesstoken,用于做免登录验证。直接获取用户的Token .
- var httpClient= _httpClientFactory.CreateClient();
- HttpResponseMessage response_getOpenId = await httpClient.PostAsJsonAsync($"{authurl}/{getOpenId}",new { appkey= appid , appsecret= appsecret, accessToken= accesstoken });
- if (response_getOpenId.IsSuccessStatusCode)
- {
- var result = await response_getOpenId.Content.ReadAsStringAsync();
- var resultData= result.ToObject<JsonElement>();
- if (resultData.TryGetProperty("data", out JsonElement data))
- {
-
- }
- }
- return Ok(new { code = 200 });
- }
- }
- }
|