|
@@ -1,22 +1,26 @@
|
|
|
-using AppFramework.Common.Exceptions;
|
|
|
+using System;
|
|
|
+using AppFramework.Common.Exceptions;
|
|
|
using AppFramework.Common.Mapper;
|
|
|
using AppFramework.JsonRpc.Driver;
|
|
|
-using WingUserModule.Entity;
|
|
|
-using WingUserModule.Processor;
|
|
|
-using WingSessionModule.Entity;
|
|
|
-using WingSessionModule.Service;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Collections.Concurrent;
|
|
|
using System.Threading.Tasks;
|
|
|
-using UnifiedLog.Service;
|
|
|
+using UnifiedLogModule.Service;
|
|
|
using WingCloudMongoDB.Repositories.DO;
|
|
|
using WingCloudMongoDB.Service;
|
|
|
+using WingSessionModule.Entity;
|
|
|
+using WingSMSModule.Service;
|
|
|
+using WingUserModule.Entity;
|
|
|
+using WingUserModule.Processor;
|
|
|
|
|
|
namespace WingUserModule.Service
|
|
|
{
|
|
|
public class LoginService : BaseRpcService, ILoginService
|
|
|
{
|
|
|
private IUserDBService _userServiceProxy;
|
|
|
- private ISessionService _sessionServiceProxy;
|
|
|
private IServerLogService _serverLogService;
|
|
|
+ private ISMSService _smsService;
|
|
|
+ private ConcurrentDictionary<string, VerifyCodeInfo> _mobileVerifyCodes = new ConcurrentDictionary<string, VerifyCodeInfo>();
|
|
|
|
|
|
/// <summary>
|
|
|
/// Init service
|
|
@@ -24,8 +28,8 @@ namespace WingUserModule.Service
|
|
|
public override void InitService()
|
|
|
{
|
|
|
_userServiceProxy = GetProxy<IUserDBService>();
|
|
|
- _sessionServiceProxy = GetProxy<ISessionService>();
|
|
|
_serverLogService = GetProxy<IServerLogService>();
|
|
|
+ _smsService = GetProxy<ISMSService>();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -63,7 +67,48 @@ namespace WingUserModule.Service
|
|
|
}
|
|
|
var userInfoDO = userInfo.MappingTo<UserInfoDO>();
|
|
|
await _userServiceProxy.InsertUserAsync(userInfoDO, string.Empty);
|
|
|
- return true;
|
|
|
+ return await Task.FromResult(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<dynamic> CheckVerificationCode(string userPhone, string verifyCode)
|
|
|
+ {
|
|
|
+ var mobileVerifyCode = GetVerifyCode(userPhone);
|
|
|
+ if (mobileVerifyCode != null && mobileVerifyCode.VerifyCode == verifyCode && !mobileVerifyCode.IsOverdue)
|
|
|
+ {
|
|
|
+ return await Task.FromResult(true);
|
|
|
+ }
|
|
|
+ return await Task.FromResult(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<dynamic> GetVerificationCode(string userPhone)
|
|
|
+ {
|
|
|
+ var validMinutes = 10;
|
|
|
+ var verifyCode = GetVerifyCode(userPhone, validMinutes);
|
|
|
+ return await _smsService.SendMessage(new List<string>{ userPhone },"1017793",new List<string>{ verifyCode });
|
|
|
+ }
|
|
|
+
|
|
|
+ private string GetVerifyCode(string userPhone, int validMinutes)
|
|
|
+ {
|
|
|
+ if (_mobileVerifyCodes.ContainsKey(userPhone))
|
|
|
+ {
|
|
|
+ _mobileVerifyCodes.TryRemove(userPhone, out _);
|
|
|
+ }
|
|
|
+ var mobileVerifyCode = _mobileVerifyCodes.GetOrAdd(userPhone, new VerifyCodeInfo
|
|
|
+ {
|
|
|
+ VerifyCode = new Random().Next(1000, 9999).ToString(),
|
|
|
+ ValidMinutes = validMinutes,
|
|
|
+ CreateTime = DateTime.Now,
|
|
|
+ });
|
|
|
+ return mobileVerifyCode.VerifyCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ private VerifyCodeInfo GetVerifyCode(string userPhone)
|
|
|
+ {
|
|
|
+ if (_mobileVerifyCodes.ContainsKey(userPhone))
|
|
|
+ {
|
|
|
+ return _mobileVerifyCodes[userPhone];
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
}
|