|
@@ -53,6 +53,89 @@ namespace TEAMModelOS.Controllers
|
|
|
_coreAPIHttpService = coreAPIHttpService;
|
|
|
}
|
|
|
[HttpPost("sendsms/pin")]
|
|
|
+ public async Task<IActionResult> SendSmsPinCode(JsonElement request)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (!request.TryGetProperty("area", out JsonElement _area)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("to", out JsonElement _to)) return BadRequest();
|
|
|
+ if (!request.TryGetProperty("lang", out JsonElement _lang)) return BadRequest();
|
|
|
+ request.TryGetProperty("HasUser", out JsonElement _HasUser);
|
|
|
+ string code=$"{_area}{_to}";
|
|
|
+ int exp = 120;
|
|
|
+
|
|
|
+ string key = $"Random:Code:PinCode-{_area}{_to}";
|
|
|
+ bool exist = await _azureRedis.GetRedisClient(8).KeyExistsAsync(key);
|
|
|
+ if (!exist)
|
|
|
+ {
|
|
|
+ //不存在则发送请求。
|
|
|
+
|
|
|
+ Dictionary<string, object> dict = null;
|
|
|
+ if (_HasUser.ValueKind.Equals(JsonValueKind.True) || _HasUser.ValueKind.Equals(JsonValueKind.False))
|
|
|
+ {
|
|
|
+ dict = new Dictionary<string, object> { { "country", $"{_area}" }, { "to", $"{_to}" }, { "lang", $"{_lang}" }, { "HasUser", _HasUser } };
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ dict = new Dictionary<string, object> { { "country", $"{_area}" }, { "to", $"{_to}" }, { "lang", $"{_lang}" } };
|
|
|
+ }
|
|
|
+ var httpStatusCode = await _coreAPIHttpService.SendSmsPin(dict, _option.Location, _configuration, _dingDing);
|
|
|
+ if (httpStatusCode.Equals(HttpStatusCode.OK))
|
|
|
+ {
|
|
|
+ var Expire = DateTime.UtcNow.AddSeconds(exp);
|
|
|
+ //send=1 表示已发送
|
|
|
+ await _azureRedis.GetRedisClient(8).StringSetAsync(key, new { code = code, send = 1, Expire = Expire.Ticks }.ToJsonString());
|
|
|
+ _azureRedis.GetRedisClient(8).KeyExpire(key, Expire);
|
|
|
+ return Ok(new { send = 1 });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //检查当前key是否已经发送了.
|
|
|
+ RedisValue value = await _azureRedis.GetRedisClient(8).StringGetAsync(key);
|
|
|
+ JsonElement element = value.ToString().ToObject<JsonElement>();
|
|
|
+ int send = 0;
|
|
|
+ if (element.TryGetProperty("send", out JsonElement _send))
|
|
|
+ {
|
|
|
+ if (_send.ValueKind.Equals(JsonValueKind.Number))
|
|
|
+ {
|
|
|
+ if (int.Parse($"{_send}") == 1)
|
|
|
+ {
|
|
|
+ send = 1;
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (int.Parse($"{_send}") == 0)
|
|
|
+ {
|
|
|
+ send = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (send == 0)
|
|
|
+ {
|
|
|
+ await _azureRedis.GetRedisClient(8).KeyDeleteAsync(key);
|
|
|
+ return Ok(new { send = 0 });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ TimeSpan? timeSpan = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync(key);
|
|
|
+ if (timeSpan != null && timeSpan.HasValue)
|
|
|
+ {
|
|
|
+ int seconds = timeSpan.Value.Seconds;
|
|
|
+ return Ok(new { send = 1 });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return Ok(new { send = 0 });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ [HttpPost("sendsms/pin-code")]
|
|
|
public async Task<IActionResult> SendSmsPin(JsonElement request) {
|
|
|
|
|
|
if (!request.TryGetProperty("area", out JsonElement _area)) return BadRequest();
|