123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- using Microsoft.AspNetCore.Http;
- 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 Microsoft.Extensions.Options;
- using Microsoft.Extensions.Configuration;
- using System.Text.Json;
- using System.Net.Http;
- using TEAMModelOS.SDK.Extension;
- using System.Text;
- using System.Net;
- using System.Net.Http.Json;
- using TEAMModelOS.SDK;
- using TEAMModelBI.Filter;
- using Microsoft.AspNetCore.Authorization;
- using Azure.Storage.Sas;
- using TEAMModelOS.SDK.Context.Constant;
- namespace TEAMModelBI.Controllers.BIServer
- {
- [Route("biservers")]
- [ApiController]
- public class BiServersController : ControllerBase
- {
- //钉钉信息发送
- private readonly DingDing _dingDing;
- //数据库连接
- public AzureCosmosFactory _azureCosmos;
- //文件容器
- private readonly AzureStorageFactory _azureStorage;
- private readonly Option _option;
- //读取配置信息
- private readonly IConfiguration _configuration;
- private readonly IHttpClientFactory httpClient;
- private readonly CoreAPIHttpService _coreAPIHttpService;
- public BiServersController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, IHttpClientFactory http, CoreAPIHttpService coreAPIHttpService)
- {
- _azureCosmos = azureCosmos;
- _azureStorage = azureStorage;
- _dingDing = dingDing;
- _option = option?.Value;
- _configuration = configuration;
- httpClient = http;
- _coreAPIHttpService = coreAPIHttpService;
- }
- /// <summary>
- /// 通过手机号、醍摩豆账户、邮箱查询信息 //已对接
- /// </summary>
- /// <param name="request"></param>
- /// <returns></returns>
- [AuthToken(Roles = "admin,rdc,assist,sales")]
- [HttpPost("get-coreinfo")]
- public async Task<IActionResult> GetCoreInfo(JsonElement jsonElement)
- {
- try
- {
- var content = new StringContent(jsonElement.ToString(), Encoding.UTF8, "application/json");
- string json = await _coreAPIHttpService.GetUserInfos(content);
- return Ok(new { state = 200, infos = json.ToObject<JsonElement>() });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI, {_option} /biservers/get-coreinfo \n {ex.Message}\n{ex.StackTrace} ", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 依据手机号查询醍摩豆基础信息 //需要
- /// </summary>
- /// <param name="jsonElment"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-userinfo")]
- public async Task<IActionResult> SendMobileGetUserIfo(JsonElement jsonElment)
- {
- try
- {
- if (!jsonElment.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
- var coreUser = await _coreAPIHttpService.GetUserInfo(new Dictionary<string, string> { { "key", $"{mobile}" } }, _option.Location, _configuration);
- if (coreUser.id != null)
- return Ok(new { state = 200, coreUser });
- else return Ok(new { state = 404, msg = "未找到改账户" });
- //HttpClient IHttpClientFactory = _http.CreateClient();
- //string url = _configuration.GetValue<string>("HaBookAuth:CoreId:userinfo");
- //HttpResponseMessage responseMessage = await httpClient.PostAsJsonAsync(url, jsonElment);
- //List<userInfo> userInfos = new List<userInfo>();
- //if (responseMessage.StatusCode == HttpStatusCode.OK)
- //{
- // string temp = responseMessage.Content.ReadAsStringAsync().Result;
- // List<JsonElement> json_id = temp.ToObject<List<JsonElement>>();
- // foreach (var item in json_id)
- // {
- // userInfo userInfo = new userInfo();
- // userInfo.tmdid = item.GetProperty("id").ToString();
- // userInfo.tmdname = item.GetProperty("name").ToString();
- // userInfo.mobile = item.GetProperty("mobile").ToString();
- // userInfos.Add(userInfo);
- // }
- // return Ok(new { state = 200, userInfos });
- //}
- //else return Ok(new { responseMessage.StatusCode });
- }
- catch (Exception ex)
- {
- await _dingDing.SendBotMsg($"BI, {_option} /biservers/get-userinfo \n {ex.Message}\n{ex.StackTrace} ", GroupNames.成都开发測試群組);
- return BadRequest();
- }
- }
- /// <summary>
- /// 发送验证码
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("send-sms")]
- public async Task<IActionResult> send_sms(JsonElement jsonElement)
- {
- try
- {
- if (!jsonElement.TryGetProperty("country", out JsonElement country)) return BadRequest();
- if (!jsonElement.TryGetProperty("to", out JsonElement to)) return BadRequest();
- if (!jsonElement.TryGetProperty("lang", out JsonElement lang)) return BadRequest();
- if (!jsonElement.TryGetProperty("HasUser", out JsonElement HasUser)) return BadRequest();
- string smsurl = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
-
- HttpResponseMessage responseMessage = await httpClient.CreateClient().PostAsJsonAsync($"{smsurl}/service/sandsms/pin", jsonElement);
- if (responseMessage.StatusCode == HttpStatusCode.OK)
- {
- string str_json = await responseMessage.Content.ReadAsStringAsync();
- if (string.IsNullOrEmpty($"{str_json}"))
- {
- return Ok(new { state = 200, message = "发送成功" });
- }
- else
- {
- return Ok(str_json);
- }
- }
- else
- {
- return Ok(new { state = 0, message = "发送失败!" });
- }
- }
- catch (Exception ex)
- {
- return Ok(new { state = 0, message = $"发送失败!{ex.Message}\n{ex.StackTrace}" });
- }
- }
- /// <summary>
- /// 验证码和手机的验证
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("verfiypin")]
- public async Task<IActionResult> VerifiyPIN(JsonElement jsonElement)
- {
- try
- {
- if (!jsonElement.TryGetProperty("mobile", out JsonElement mobile)) return BadRequest();
- if (!jsonElement.TryGetProperty("Authorization_Pin", out JsonElement sms)) return BadRequest();
- string smsurl = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
-
- var temp_job = new { Authorization_Pin = sms };
- HttpResponseMessage responseMessage = await httpClient.CreateClient().PostAsJsonAsync($"{smsurl}/service/verifiy/pin", temp_job);
- if (responseMessage.StatusCode == HttpStatusCode.OK)
- {
- string responseBody = await responseMessage.Content.ReadAsStringAsync();
- var json = responseBody.ToObject<JsonElement>();
- json.TryGetProperty("resule", out JsonElement jsone);
- if (!string.IsNullOrEmpty($"{jsone}"))
- {
- string[] mobules = $"{jsone}".Split("-");
- string temp_mobile = mobules.Length >= 2 ? mobules[1] : mobules[0];
- if (mobile.ToString().Equals(temp_mobile))
- {
- return Ok(new { state = 200, message = "手机号和验证码验证都过了" });
- }
- else
- {
- return Ok(new { state = 5, message = "手机号码不正确" });
- }
- }
- else
- {
- return Ok(json);
- }
- }
- else
- {
- return Ok(new { state = 0, message = "发送状态错误" });
- }
- }
- catch (Exception ex)
- {
- return Ok(new { state = 0, message = $"发送状态错误{ex.Message}\n{ex.StackTrace}" });
- }
- }
- /// <summary>
- /// 获取blob容器key
- /// </summary>
- /// <param name="jsonElement"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-cntrkey")]
- public async Task<IActionResult> GetCntrKey(JsonElement jsonElement)
- {
- if (!jsonElement.TryGetProperty("cntr", out JsonElement cntr)) return BadRequest();
- string osblob_uri = null, osblob_sas = null;
- if (string.IsNullOrEmpty($"{cntr}"))
- return Ok(new { state = RespondCode.ParamsError, msg = "容器不能为空!" });
- (osblob_uri, osblob_sas) = _azureStorage.GetBlobContainerSAS($"{cntr}", BlobContainerSasPermissions.Write | BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List | BlobContainerSasPermissions.Delete);
- return Ok(new { state = RespondCode.Ok, osblob_uri, osblob_sas });
- }
- public record userInfo
- {
- public string mobile { get; set; }
- public string tmdid { get; set; }
- public string tmdname { get; set; }
- }
- }
- }
|