Procházet zdrojové kódy

处理代码逻辑。

CrazyIter_Bin před 2 roky
rodič
revize
0dac7a95be

+ 1 - 1
TEAMModelOS.SDK/DI/CoreAPI/CoreAPIHttpService.cs

@@ -56,7 +56,7 @@ namespace TEAMModelOS.SDK
         /// <param name="url"></param>
         /// <param name="data"></param>
         /// <returns></returns>
-        public async Task<HttpStatusCode> SendSmsPin(Dictionary<string, string> data, string location, IConfiguration _configuration, DI.DingDing _dingDing)
+        public async Task<HttpStatusCode> SendSmsPin(Dictionary<string, object> data, string location, IConfiguration _configuration, DI.DingDing _dingDing)
 
         {
             try {

+ 30 - 17
TEAMModelOS/Controllers/System/CoreController.cs

@@ -90,7 +90,16 @@ namespace TEAMModelOS.Controllers
                 {
                     //不存在则发送请求。
                     // 如果是idtoken获取的code ,则不存在可以重新发送。
-                    var httpStatusCode = await _coreAPIHttpService.SendSmsPin(new Dictionary<string, string> { { "country", $"{_area}" }, { "to", $"{_to}" }, { "lang", $"{_lang}" } }, _option.Location, _configuration, _dingDing);
+                    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(60);
@@ -143,14 +152,14 @@ namespace TEAMModelOS.Controllers
                     }
                     if (send == 1)
                     {
-                        DateTime? dateTime=  await _azureRedis.GetRedisClient(8).KeyExpireTimeAsync(key);
-                        if (dateTime != null && dateTime.HasValue) {
-                           var dis=  dateTime.Value - DateTime.UtcNow;
-                           int expire =  dis.Seconds;
-                            return Ok(new { random, send = 1, expire = expire });
+                        TimeSpan? timeSpan=  await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync(key);
+                        if (timeSpan != null && timeSpan.HasValue) {
+                            int seconds = timeSpan.Value.Seconds;
+                           return Ok(new { random, send = 1, expire = seconds });
                         }
                         else{
                             random = $"{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
+                            key= $"Random:Code:Pin-{random}";
                             //最新的保持5分钟
                             var Expire = DateTime.UtcNow.AddSeconds(60);
                             await _azureRedis.GetRedisClient(8).StringSetAsync(key, new { code = random, send = 0, Expire = 0 }.ToJsonString());
@@ -160,16 +169,21 @@ namespace TEAMModelOS.Controllers
                         
                     }
                     else {
-                        var httpStatusCode = await _coreAPIHttpService.SendSmsPin(new Dictionary<string, string> { { "country", $"{_area}" }, { "to", $"{_to}" }, { "lang", $"{_lang}" } }, _option.Location, _configuration, _dingDing);
+                        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))
                         {
-                            await _azureRedis.GetRedisClient(8).KeyDeleteAsync(key);
-                            random = $"{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
-                            //重新生成新的
-                            key = $"Random:Code:Pin-{random}";
                             //最新的保持1分钟
                             var Expire = DateTime.UtcNow.AddSeconds(60);
-                            await _azureRedis.GetRedisClient(8).StringSetAsync(key, new { code = random, send = 0, Expire = 0 }.ToJsonString());
+                            await _azureRedis.GetRedisClient(8).StringSetAsync(key, new { code = random, send = 1, Expire = 60 }.ToJsonString());
                             _azureRedis.GetRedisClient(8).KeyExpire(key, Expire);
                             return Ok(new { random, send = 1, expire = 60 });
                         }
@@ -209,12 +223,11 @@ namespace TEAMModelOS.Controllers
                         return Ok(new { random, send = 0, expire = 0 });
                     }
                     else {
-                        DateTime? dateTime = await _azureRedis.GetRedisClient(8).KeyExpireTimeAsync(key);
-                        if (dateTime != null && dateTime.HasValue)
+                        TimeSpan? timeSpan = await _azureRedis.GetRedisClient(8).KeyTimeToLiveAsync(key);
+                        if (timeSpan != null && timeSpan.HasValue)
                         {
-                            var dis = dateTime.Value - DateTime.UtcNow;
-                            int expire = dis.Seconds;
-                            return Ok(new { random, send = 1, expire = expire });
+                            int seconds = timeSpan.Value.Seconds;
+                            return Ok(new { random, send = 1, expire = seconds });
                         }
                         else {
                             return Ok(new { random, send = 0, expire = 0 });