123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- 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 HTEXLib.COMM.Helpers;
- using System.Net.Http.Json;
- namespace TEAMModelBI.Controllers.BIServer
- {
- [Route("biservers")]
- [ApiController]
- public class BiServersController : ControllerBase
- {
- //钉钉信息发送
- private readonly DingDing _dingDing;
- //数据库连接
- public AzureCosmosFactory _azureCosmos;
- private readonly Option _option;
- //读取配置信息
- private readonly IConfiguration _configuration;
- private readonly IHttpClientFactory _http;
- public BiServersController(AzureCosmosFactory azureCosmos, DingDing dingDing, IOptionsSnapshot<Option> option, IConfiguration configuration, IHttpClientFactory http)
- {
- _azureCosmos = azureCosmos;
- _dingDing = dingDing;
- _option = option?.Value;
- _configuration = configuration;
- _http = http;
- }
- /// <summary>
- /// 依据手机号查询醍摩豆基础信息
- /// </summary>
- /// <param name="jsonElment"></param>
- /// <returns></returns>
- [ProducesDefaultResponseType]
- [HttpPost("get-mobileuserinfo")]
- public async Task<IActionResult> SendMobileGetUserIfo(JsonElement jsonElment)
- {
- try
- {
- HttpClient httpClient = _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-mobileuserinfo \n {ex.Message} {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");
- HttpClient httpClient = _http.CreateClient();
- HttpResponseMessage responseMessage = await httpClient.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}" });
- }
- }
- /// <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");
- HttpClient httpClient = _http.CreateClient();
- var temp_job = new { Authorization_Pin = sms };
- HttpResponseMessage responseMessage = await httpClient.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}" });
- }
- }
- public record userInfo
- {
- public string mobile { get; set; }
- public string tmdid { get; set; }
- public string tmdname { get; set; }
- }
- }
- }
|