AuthController.cs 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  1. 
  2. using Flurl.Http.Configuration;
  3. using Microsoft.AspNetCore.SignalR;
  4. using Microsoft.EntityFrameworkCore.Metadata.Internal;
  5. using NPOI.SS.Formula.Functions;
  6. using OASystem.API.OAMethodLib;
  7. using OASystem.API.OAMethodLib.Hotmail;
  8. using OASystem.API.OAMethodLib.Hub.HubClients;
  9. using OASystem.API.OAMethodLib.Hub.Hubs;
  10. using OASystem.API.OAMethodLib.QiYeWeChatAPI;
  11. using OASystem.Domain.AesEncryption;
  12. using OASystem.Domain.Attributes;
  13. using OASystem.Domain.Dtos.UserDto;
  14. using OASystem.Domain.Entities.Customer;
  15. using OASystem.Domain.Entities.Groups;
  16. using OASystem.Infrastructure.Repositories.Login;
  17. using System.IdentityModel.Tokens.Jwt;
  18. using System.Text.Json;
  19. using static OASystem.API.OAMethodLib.Hotmail.HotmailService;
  20. using static OASystem.API.OAMethodLib.JWTHelper;
  21. namespace OASystem.API.Controllers
  22. {
  23. /// <summary>
  24. /// 鉴权相关
  25. /// </summary>
  26. [Route("api/")]
  27. public class AuthController : ControllerBase
  28. {
  29. private readonly IMapper _mapper;
  30. private readonly IConfiguration _config;
  31. private readonly LoginRepository _loginRep;
  32. private readonly MessageRepository _message;
  33. private readonly SystemMenuPermissionRepository _sysMenuPermRep;
  34. private readonly MessageRepository _messageRep;
  35. private readonly IQiYeWeChatApiService _qiYeWeChatApiService;
  36. private readonly IHubContext<ChatHub, IChatClient> _hubContext;
  37. private readonly DeviceTokenRepository _deviceTokenRep;
  38. private readonly HotmailService _hotmailService;
  39. private readonly System.Net.Http.IHttpClientFactory _httpClientFactory;
  40. /// <summary>
  41. ///
  42. /// </summary>
  43. /// <param name="config"></param>
  44. /// <param name="loginRep"></param>
  45. /// <param name="mapper"></param>
  46. /// <param name="message"></param>
  47. /// <param name="sysMenuPermRep"></param>
  48. /// <param name="qiYeWeChatApiService"></param>
  49. /// <param name="messageRep"></param>
  50. /// <param name="deviceRep"></param>
  51. /// <param name="hubContext"></param>
  52. /// <param name="hotmailService"></param>
  53. /// <param name="httpClientFactory"></param>
  54. public AuthController(
  55. IConfiguration config,
  56. LoginRepository loginRep,
  57. IMapper mapper,
  58. MessageRepository message,
  59. SystemMenuPermissionRepository sysMenuPermRep,
  60. IQiYeWeChatApiService qiYeWeChatApiService,
  61. MessageRepository messageRep,
  62. DeviceTokenRepository deviceRep,
  63. IHubContext<ChatHub,IChatClient> hubContext,
  64. HotmailService hotmailService,
  65. System.Net.Http.IHttpClientFactory httpClientFactory)
  66. {
  67. _config = config;
  68. _loginRep = loginRep;
  69. _mapper = mapper;
  70. _message = message;
  71. _sysMenuPermRep = sysMenuPermRep;
  72. _qiYeWeChatApiService = qiYeWeChatApiService;
  73. _messageRep = messageRep;
  74. _deviceTokenRep = deviceRep;
  75. _hubContext = hubContext;
  76. _hotmailService = hotmailService;
  77. _httpClientFactory = httpClientFactory;
  78. }
  79. /// <summary>
  80. /// 用户登录
  81. /// </summary>
  82. /// <param name="dto"></param>
  83. /// <returns></returns>
  84. [Route("login")]
  85. [HttpPost]
  86. [ApiLog("Login", OperationEnum.Login)]
  87. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  88. public async Task<IActionResult> LoginAsync(LoginDto dto)
  89. {
  90. if (string.IsNullOrWhiteSpace(dto.Number) || string.IsNullOrWhiteSpace(dto.Password))
  91. {
  92. return Ok(JsonView(false, "账号或密码不能为空!!"));
  93. }
  94. #region 校验用户信息
  95. var userData = _loginRep.Login(dto).Result;
  96. if (userData.Code != 0) return Ok(JsonView(false, userData.Msg));
  97. #endregion
  98. #region 限制销售部门 除gyy外可登录
  99. var userInfo = userData.Data as UserLoginInfoView;
  100. if (userInfo == null) return Ok(JsonView(false, userData.Msg));
  101. if (userInfo.DepName.Contains("市场部"))
  102. {
  103. var noLoginAuth = _config.GetSection("NoLoginAuth").Get<List<string>>();
  104. if (noLoginAuth.Any())
  105. {
  106. if (noLoginAuth.Contains(userInfo.CnName)) return Ok(JsonView(false, "NO ACCESS!!"));
  107. }
  108. //其他市场部人员 限制登录时间段
  109. var currentDateTime = DateTime.Now;
  110. var startTime = DateTime.Parse(_config["ApiAccessTime:StartTime"]);
  111. var endTime = DateTime.Parse(_config["ApiAccessTime:EndTime"]);
  112. if (currentDateTime < startTime && currentDateTime > endTime) return Ok(JsonView(false, "NO ACCESS!!"));
  113. }
  114. #endregion
  115. Result authData = null;
  116. string uName = string.Empty,
  117. role = string.Empty,
  118. depName = string.Empty;
  119. int uId = 0;
  120. int unReadCount = 0;
  121. int announcementUnReadCount = 0;
  122. if (userData.Data != null)
  123. {
  124. uId = (userData.Data as UserLoginInfoView).UserId;
  125. uName = (userData.Data as UserLoginInfoView).CnName;
  126. depName = (userData.Data as UserLoginInfoView).DepName;
  127. role = (userData.Data as UserLoginInfoView).JobName;
  128. authData = _sysMenuPermRep.QueryMenuLoad(uId, dto.PortType);
  129. unReadCount = await _messageRep.GetUnReadCount(uId);
  130. announcementUnReadCount = await _messageRep.GetAnnouncementUnReadCount(uId);
  131. }
  132. //_hubContext.Login(uId, uName);
  133. var view = new LoginView
  134. {
  135. UserInfo = userData?.Data,
  136. AuthData = authData?.Data,
  137. UnReadCount = unReadCount,
  138. AnnouncementUnReadCount = announcementUnReadCount
  139. };
  140. DateTime createZebraTime = DateTime.Now;
  141. string authorId = dto.Number + "Token";
  142. string authorToken = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>(authorId);//string 取
  143. if (authorToken != null)
  144. {
  145. #region 解析出过期时间
  146. var jwtHandler = new JwtSecurityTokenHandler();
  147. JwtSecurityToken securityToken = jwtHandler.ReadJwtToken(authorToken);
  148. DateTime expDt = (securityToken.Payload[JwtRegisteredClaimNames.Exp] ?? 0).GetInt().GetTimeSpmpToDate();
  149. #endregion
  150. if (expDt >= createZebraTime) //超时重新获取token
  151. {
  152. authorToken = await JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Department = depName, Role = role }); //
  153. }
  154. view.Expires = expDt;
  155. view.Token = authorToken;
  156. }
  157. else
  158. {
  159. view.Expires = createZebraTime.AddMinutes(30);
  160. //view.Token = await GeneralMethod.GetToken(_config, dto.Number, uId, uName, createZebraTime); //JwtHelper
  161. view.Token = await JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Department = depName, Role = role }); //
  162. TimeSpan ts = view.Expires.AddMinutes(-1) - createZebraTime; //设置redis 过期时间 比 jwt 时间 快一分钟
  163. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>(authorId, view.Token, ts);//string 存
  164. }
  165. //#region 添加登录用户上线信息
  166. //_hubContext.SignalRLogin(uId);
  167. //#endregion
  168. #region 测试添加系统消息
  169. //await _message.AddMsg(new MessageDto()
  170. //{
  171. // Type = 1,
  172. // IssuerId = 208,
  173. // Title = "测试添加消息标题",
  174. // Content = "消息体测试",
  175. // ReleaseTime = DateTime.Now,
  176. // UIdList = new List<int> {
  177. // 5,
  178. // 208,
  179. // 219
  180. // }
  181. //});
  182. #endregion
  183. return Ok(JsonView(view));
  184. }
  185. /// <summary>
  186. /// 移动端用户登录
  187. /// </summary>
  188. /// <param name="dto"></param>
  189. /// <returns></returns>
  190. [Route("MobileLogin")]
  191. [HttpPost]
  192. [ApiLog("Login", OperationEnum.Login)]
  193. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  194. public async Task<IActionResult> MobileLoginAsync(LoginDto dto)
  195. {
  196. if (string.IsNullOrWhiteSpace(dto.Number) || string.IsNullOrWhiteSpace(dto.Password))
  197. {
  198. return Ok(JsonView(false, "账号或密码不能为空!!"));
  199. }
  200. #region 校验用户信息
  201. var userData = _loginRep.Login(dto).Result;
  202. if (userData.Code != 0) return Ok(JsonView(false, userData.Msg));
  203. #endregion
  204. Result authData = null;
  205. string uName = string.Empty;
  206. string role = string.Empty;
  207. int uId = 0;
  208. int unReadCount = 0;
  209. int announcementUnReadCount = 0;
  210. if (userData.Data != null)
  211. {
  212. uId = (userData.Data as UserLoginInfoView).UserId;
  213. uName = (userData.Data as UserLoginInfoView).CnName;
  214. role = (userData.Data as UserLoginInfoView).JobName;
  215. authData = _sysMenuPermRep.MobileMenuLoad(uId, dto.PortType);
  216. unReadCount = await _messageRep.GetUnReadCount(uId);
  217. announcementUnReadCount = await _messageRep.GetAnnouncementUnReadCount(uId);
  218. }
  219. //_hubContext.Login(uId, uName);
  220. var view = new LoginView
  221. {
  222. UserInfo = userData?.Data,
  223. AuthData = authData?.Data,
  224. UnReadCount = unReadCount,
  225. AnnouncementUnReadCount = announcementUnReadCount
  226. };
  227. DateTime createZebraTime = DateTime.Now;
  228. string authorId = dto.Number + "Token";
  229. string authorToken = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>(authorId);//string 取
  230. if (authorToken != null)
  231. {
  232. #region 解析出过期时间
  233. var jwtHandler = new JwtSecurityTokenHandler();
  234. JwtSecurityToken securityToken = jwtHandler.ReadJwtToken(authorToken);
  235. DateTime expDt = (securityToken.Payload[JwtRegisteredClaimNames.Exp] ?? 0).GetInt().GetTimeSpmpToDate();
  236. #endregion
  237. if (expDt >= createZebraTime) //超时重新获取token
  238. {
  239. authorToken = await JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Role = role }); //
  240. }
  241. view.Expires = expDt;
  242. view.Token = authorToken;
  243. }
  244. else
  245. {
  246. view.Expires = createZebraTime.AddMinutes(30);
  247. //view.Token = await GeneralMethod.GetToken(_config, dto.Number, uId, uName, createZebraTime); //JwtHelper
  248. view.Token = await JwtHelper.IssueJwtAsync(new TokenModelJwt() { UserId = uId, UserName = uName, Role = role }); //
  249. TimeSpan ts = view.Expires.AddMinutes(-1) - createZebraTime; //设置redis 过期时间 比 jwt 时间 快一分钟
  250. await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>(authorId, view.Token, ts);//string 存
  251. }
  252. //#region 添加登录用户上线信息
  253. //_hubContext.SignalRLogin(uId);
  254. //#endregion
  255. #region 测试添加系统消息
  256. //await _message.AddMsg(new MessageDto()
  257. //{
  258. // Type = 1,
  259. // IssuerId = 208,
  260. // Title = "测试添加消息标题",
  261. // Content = "消息体测试",
  262. // ReleaseTime = DateTime.Now,
  263. // UIdList = new List<int> {
  264. // 5,
  265. // 208,
  266. // 219
  267. // }
  268. //});
  269. #endregion
  270. return Ok(JsonView(view));
  271. }
  272. /// <summary>
  273. /// 申请注册 数据Data
  274. /// </summary>
  275. /// <returns></returns>
  276. //[Authorize]
  277. [HttpPost]
  278. [Route("register/daraSource")]
  279. public async Task<IActionResult> RegisterDataSource()
  280. {
  281. string sql = string.Format(@"Select sc.Id CompanyId,sc.CompanyName,sd.Id DepId,sd.DepName,sjp.Id JobId,sjp.JobName From Sys_Company sc
  282. Left Join Sys_Department sd On sd.IsDel = 0 And sc.Id = sd.CompanyId
  283. Left Join Sys_JobPost sjp On sjp.IsDel = 0 And sjp.DepId = sd.Id
  284. Where sc.IsDel = 0");
  285. var companyDetails = _loginRep._sqlSugar.SqlQueryable<CompanyDetailsView>(sql).ToList();
  286. var detailsView1 = new List<CompanyDetailsView1>();
  287. if (companyDetails.Count > 0)
  288. {
  289. var companyDetails1 = companyDetails.GroupBy(it => it.CompanyId).Select(it => it.First()).ToList();
  290. detailsView1 = companyDetails1.Select(it =>
  291. {
  292. var itemCompany = new CompanyDetailsView1();
  293. var depDetailsView = new List<DepDetailsView>();
  294. var companyDetails2 = companyDetails.GroupBy(it => it.DepId).Select(it => it.First()).ToList();
  295. //部门
  296. depDetailsView = companyDetails2.Where(depIt => depIt.CompanyId == it.CompanyId).Select(depIt =>
  297. {
  298. var depDetails = new DepDetailsView();
  299. var jobDetails = new List<JobDetailsView>();
  300. //岗位
  301. jobDetails = companyDetails.Where(jobIt => jobIt.DepId == depIt.DepId).Select(jobIt =>
  302. {
  303. var jobDetail = new JobDetailsView()
  304. {
  305. JobId = jobIt.JobId,
  306. JobName = jobIt.JobName,
  307. };
  308. return jobDetail;
  309. }).ToList();
  310. depDetails.DepId = depIt.DepId;
  311. depDetails.DepName = depIt.DepName;
  312. depDetails.SubJob = jobDetails;
  313. return depDetails;
  314. }).ToList();
  315. itemCompany.CompanyId = it.CompanyId;
  316. itemCompany.CompanyName = it.CompanyName;
  317. itemCompany.SubDep = depDetailsView;
  318. return itemCompany;
  319. }).ToList();
  320. }
  321. return Ok(new { Code = 200, Msg = "查询成功!", Data = detailsView1 });
  322. }
  323. /// <summary>
  324. /// 申请注册
  325. /// </summary>
  326. /// <param name="dto"></param>
  327. /// <returns></returns>
  328. //[Authorize]
  329. [HttpPost]
  330. [Route("register")]
  331. public async Task<IActionResult> Register(RegisterDto dto)
  332. {
  333. #region 企业微信添加员工
  334. //string lastName = dto.CnName.Substring(0, 1);
  335. //string lastNamePy = string.Empty;
  336. //if (PinyinHelper.IsChinese(Convert.ToChar(lastName)))
  337. //{
  338. // lastNamePy = PinyinHelper.GetPinyin(lastName);
  339. //}
  340. //string userId = string.Format("{0}.{1}", dto.EnName, lastNamePy.ToLower());
  341. //Create_Request request = new Create_Request()
  342. //{
  343. // userid = userId,
  344. // name = dto.CnName,
  345. // mobile = dto.Phone,
  346. // department = new List<long>() { dto.DepId },
  347. // position = dto.JobPostId.ToString(),
  348. // gender = dto.Sex == 0 ? 1 : dto.Sex == 1 ? 2 : 1,
  349. // biz_mail = dto.Email
  350. //};
  351. //var qiYeWeChatCreateData = await _qiYeWeChatApiServic.CreateAsync(request);
  352. #endregion
  353. var userData = _loginRep.Register(dto);
  354. if (userData.Result.Code != 0)
  355. {
  356. return Ok(JsonView(false, userData.Result.Msg));
  357. }
  358. return Ok(JsonView(true, userData.Result.Msg));
  359. }
  360. /// <summary>
  361. /// 修改密码
  362. /// </summary>
  363. /// <param name="dto"></param>
  364. /// <returns></returns>
  365. [Authorize]
  366. [HttpPost]
  367. [Route("UpdPassword")]
  368. public async Task<IActionResult> UpdateUserPassword(UpdateDto dto)
  369. {
  370. //Result result = new Result();
  371. //var httpContext = HttpContext.User.Claims.FirstOrDefault(it => it.Type == ClaimTypes.Name)?.Value;
  372. //Sys_Users sys_Users = _mapper.Map<Sys_Users>(dto);
  373. var _view = await _loginRep.ChangePassword(dto.UserId, dto.Password);
  374. if (_view.Code == 0) return Ok(JsonView(true, "操作成功!"));
  375. return Ok(JsonView(false, _view.Msg));
  376. }
  377. /// <summary>
  378. /// 保存deviceToken
  379. /// </summary>
  380. /// <param name="dto"></param>
  381. /// <returns></returns>
  382. [HttpPost("SaveDeviceToken")]
  383. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  384. public async Task<IActionResult> SaveDeviceToken(SaveDeviceToken dto)
  385. {
  386. var view = await _deviceTokenRep.SaveToken(dto);
  387. if (view.Code == 0) return Ok(JsonView(true, "操作成功!"));
  388. return Ok(JsonView(false, view.Msg));
  389. }
  390. /// <summary>
  391. /// 获取deviceToken
  392. /// </summary>
  393. /// <param name="dto"></param>
  394. /// <returns></returns>
  395. [HttpPost("GetDeviceToken")]
  396. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  397. public async Task<IActionResult> GetDeviceToken(GetDeviceToken dto)
  398. {
  399. var view = await _deviceTokenRep.GetToken(dto.account);
  400. if (view.Code == 0) return Ok(JsonView(true, "操作成功!", view.Data));
  401. return Ok(JsonView(false, view.Msg));
  402. }
  403. #region microsoft 鉴权验证
  404. /// <summary>
  405. /// microsoft - hotmail 鉴权验证
  406. /// </summary>
  407. /// <returns></returns>
  408. [HttpGet("microsoft/auth/verify/{currUserId}")]
  409. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  410. public async Task<IActionResult> MicrosoftHotmailPrepareAuth(int currUserId)
  411. {
  412. var (code, message) = await _hotmailService.PrepareAuth(currUserId);
  413. return code switch
  414. {
  415. // 无需授权
  416. 0 => Ok(JsonView(true, "已通过验证", new { isAuth = false })),
  417. // 需要跳转授权 (1)
  418. 1 => Ok(JsonView(true, "请点击链接进行 Auth 验证!", new { isAuth = true, url = message })),
  419. //1 => Redirect(message),
  420. // 配置错误或异常 (-1)
  421. _ => Ok(JsonView(false, message))
  422. };
  423. }
  424. /// <summary>
  425. /// microsoft auth 回调
  426. /// </summary>
  427. /// <param name="code"></param>
  428. /// <param name="state"></param>
  429. /// <returns></returns>
  430. [HttpGet("microsoft/auth/callback")]
  431. public async Task<IActionResult> HandleCallback([FromQuery] string code, [FromQuery] string state)
  432. {
  433. if (string.IsNullOrEmpty(code)) return BadRequest("授权码无效");
  434. // 1. 状态与配置校验
  435. if (!int.TryParse(state, out int userId)) return BadRequest("非法的 state 标识");
  436. var config = await _hotmailService.GetUserMailConfig(userId);
  437. if (config == null) return BadRequest("对应配置信息不存在");
  438. try
  439. {
  440. // 2. 换取令牌 (使用严格的参数清洗)
  441. var httpClient = _httpClientFactory.CreateClient();
  442. var tokenRequest = new Dictionary<string, string>
  443. {
  444. { "client_id", config.ClientId.Trim() },
  445. { "client_secret", config.ClientSecret.Trim() },
  446. { "code", code },
  447. { "redirect_uri", config.RedirectUri.Trim() }, // 确保与 PrepareAuth 阶段完全一致
  448. { "grant_type", "authorization_code" },
  449. // 换取时再次明确 scope
  450. { "scope", "offline_access Mail.Read Mail.Send User.Read" }
  451. };
  452. var response = await httpClient.PostAsync("https://login.microsoftonline.com/common/oauth2/v2.0/token", new FormUrlEncodedContent(tokenRequest));
  453. var responseContent = await response.Content.ReadAsStringAsync();
  454. if (!response.IsSuccessStatusCode) return BadRequest($"令牌交换失败: {responseContent}");
  455. var root = JsonDocument.Parse(responseContent).RootElement;
  456. // 3. 提取令牌 (准则:确保 refresh_token 存在)
  457. var accessToken = root.GetProperty("access_token").GetString()!;
  458. var refreshToken = root.TryGetProperty("refresh_token", out var rt) ? rt.GetString()! : null;
  459. var expiresIn = root.GetProperty("expires_in").GetInt32();
  460. if (string.IsNullOrEmpty(refreshToken))
  461. return BadRequest("未能获取长效刷新令牌,请检查 offline_access 权限。");
  462. // 4. 获取用户信息
  463. string userEmail = await GetEmailFromGraphApiAsync(accessToken);
  464. // 5. 缓存 (准则 2 & 3)
  465. var userToken = new UserToken
  466. {
  467. Email = userEmail,
  468. AccessToken = accessToken,
  469. RefreshToken = refreshToken,
  470. ExpiresAt = DateTime.UtcNow.AddSeconds(expiresIn),
  471. Source = "Microsoft_Graph" // 准则 3: 增加标识
  472. };
  473. // Redis 缓存 (用于 API 快速调用)
  474. var redisKey = HotmailService.GetRedisKey(userEmail);
  475. await RedisRepository.RedisFactory.CreateRedisRepository()
  476. .StringSetAsync(redisKey, userToken, TimeSpan.FromDays(90));
  477. // 6. 返回结果
  478. return Ok(new
  479. {
  480. status = "Success",
  481. account = userEmail,
  482. expiresInSeconds = expiresIn,
  483. source = userToken.Source
  484. });
  485. }
  486. catch (Exception ex)
  487. {
  488. // _logger.LogError(ex, "Callback processing failed");
  489. return StatusCode(500, "回调失败,请检查控制台日志");
  490. }
  491. }
  492. private async Task<string> GetEmailFromGraphApiAsync(string accessToken)
  493. {
  494. // 1. 使用 HttpClientFactory 获取预设或独立的 Client
  495. var httpClient = _httpClientFactory.CreateClient("MicrosoftGraph");
  496. // 2. 构造请求头
  497. var request = new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/v1.0/me");
  498. request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
  499. // 3. 发送请求并确保成功
  500. var response = await httpClient.SendAsync(request);
  501. if (!response.IsSuccessStatusCode)
  502. {
  503. var errorContent = await response.Content.ReadAsStringAsync();
  504. throw new Exception($"Graph API 身份验证失败: {response.StatusCode}, {errorContent}");
  505. }
  506. // 4. 安全解析 JSON
  507. using var doc = await JsonDocument.ParseAsync(await response.Content.ReadAsStreamAsync());
  508. var root = doc.RootElement;
  509. // 优先序:mail (邮箱) > userPrincipalName (登录名)
  510. string? email = null;
  511. if (root.TryGetProperty("mail", out var mailProp))
  512. email = mailProp.GetString();
  513. if (string.IsNullOrEmpty(email) && root.TryGetProperty("userPrincipalName", out var upnProp))
  514. email = upnProp.GetString();
  515. if (string.IsNullOrWhiteSpace(email))
  516. throw new Exception("Graph API 返回结果中缺失有效的身份标识 (mail/upn)");
  517. return email.Trim().ToLower(); // 准则:归一化存储,避免大小写导致的缓存失效
  518. }
  519. #endregion
  520. /// <summary>
  521. /// 测试auth
  522. /// </summary>
  523. /// <param name="dto"></param>
  524. /// <returns></returns>
  525. [OASystemAuthentication]
  526. [HttpPost("TestToken")]
  527. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  528. public async Task<IActionResult> TestToken(LoginDto dto)
  529. {
  530. string authorId = dto.Number + "Token";
  531. // 从Redis里面取数据
  532. //string userToken = _redis.StringGet(authorId);
  533. string userToken = "";
  534. var view = new LoginView
  535. {
  536. Token = authorId + ":" + userToken
  537. };
  538. return Ok(JsonView(view));
  539. }
  540. /// <summary>
  541. /// 限流测试
  542. /// </summary>
  543. /// <returns></returns>
  544. [HttpGet("rate-test")]
  545. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  546. public IActionResult RateTest()
  547. {
  548. return Ok(JsonView(true, $"限流测试 - IP:{HttpContext.Connection.RemoteIpAddress?.ToString()}", null, GetRequestCount()));
  549. }
  550. private static int _requestCount = 0;
  551. private int GetRequestCount()
  552. {
  553. return ++_requestCount;
  554. }
  555. ///// <summary>
  556. ///// 员工信息 迁移
  557. ///// Old OA To New OA
  558. ///// </summary>
  559. ///// <returns></returns>
  560. //[HttpPost("UpdateUserDataOldOAToNewOA")]
  561. //[ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  562. //public async Task<IActionResult> UpdateUserDataOldOAToNewOA()
  563. //{
  564. // dynamic view = null;
  565. // try
  566. // {
  567. // var _sqlSuar = _loginRep._sqlSugar;
  568. // var oldOaUsersData = await _sqlSuar.Queryable<OA2014UsersView>().AS("OA2014.dbo.Users").ToListAsync();
  569. // var newOaCompanyData = await _sqlSuar.Queryable<Sys_Company>().ToListAsync();
  570. // var newOaDepartmentData = await _sqlSuar.Queryable<Sys_Department>().ToListAsync();
  571. // var newOaJobPostData = await _sqlSuar.Queryable<Sys_JobPost>().ToListAsync();
  572. // List<Sys_Users> newOaUserDatas = new List<Sys_Users>();
  573. // foreach (var oldUser in oldOaUsersData)
  574. // {
  575. // int depId = 0, postId = 0;
  576. // #region 处理部门岗位
  577. // int did = oldUser.Did;
  578. // string post = oldUser.Post;
  579. // switch (did)
  580. // {
  581. // case 1 : //信息部
  582. // depId = 2;
  583. // if (post.Equals("信息部经理")) postId = 4;
  584. // else if (post.Equals("美工")) { depId = 5; postId = 18; }
  585. // else if(post.Equals("网络推广")) postId = 46;
  586. // else if (post.Equals("软件开发")) postId = 5;
  587. // else if (post.Equals("平面设计师")) { depId = 5; postId = 18; }
  588. // else if (post.Equals("平面设计")) { depId = 5; postId = 18; }
  589. // else if (post.Equals("平面设计师")) { depId = 5; postId = 18; }
  590. // else if (post.Equals("软件工程师")) postId = 5;
  591. // else if (post.Equals("OP操作")) { depId = 7; postId = 28; }
  592. // else if (post.Equals("软件工程师.")) postId = 5;
  593. // else if (post.Equals(".net工程师")) postId = 5;
  594. // else if (post.Equals("安卓开发工程师")) postId = 7;
  595. // else if (post.Equals("web前端")) postId = 6;
  596. // else if (post.Equals("Web后端开发")) postId = 5;
  597. // break;
  598. // case 2 : //财务部
  599. // depId=3;
  600. // if (post.Equals("主管")) postId = 47;
  601. // else if (post.Equals("财务总监")) { postId = 9; }
  602. // else if (post.Equals("会计")) { postId = 10; }
  603. // else if (post.Equals("财务经理")) { postId = 47; }
  604. // else if (post.Equals("财务助理")) { postId = 50; }
  605. // else if (post.Equals("出纳")) { postId = 48; }
  606. // else { postId = 10; }
  607. // break;
  608. // case 3: //人事部
  609. // depId = 4;
  610. // if (post.Equals("主管")) postId = 51;
  611. // else if (post.Equals("人事部主管")) { postId = 51; }
  612. // else if (post.Equals("人事行政主管")) { postId = 51; }
  613. // else if (post.Equals("行政人事助理")) { postId = 52; }
  614. // else if (post.Equals("人事助理")) { postId = 52; }
  615. // else if (post.Equals("人事主管")) { postId = 51; }
  616. // else if (post.Equals("行政人事专员")) { postId = 12; }
  617. // else if (post.Equals("行政司机")) { postId = 14; }
  618. // else if (post.Equals("司机")) { postId = 14; }
  619. // else if (post.Equals("统筹执行")) { postId = 12; }
  620. // else if (post.Equals("培训专员")) { postId = 13; }
  621. // else if (post.Equals("人事经理")) { postId = 11; }
  622. // else if (post.Equals("前台")) { postId = 33; }
  623. // else if (post.Equals("人事行政经理")) { postId = 11; }
  624. // else if (post.Equals("人事部经理")) { postId = 11; }
  625. // else if (post.Equals("人事专员")) { postId = 12; }
  626. // else if (post.Equals("人事经理")) { postId = 11; }
  627. // else postId = 12;
  628. // break;
  629. // case 4: //国交部
  630. // //22 7 主管
  631. // //23 7 计调
  632. // //24 7 机票
  633. // //25 7 酒店
  634. // //26 7 签证
  635. // //27 7 商邀
  636. // //28 7 OP
  637. // //32 7 经理
  638. // depId = 7;
  639. // if (post.Equals("酒店")) postId = 25;
  640. // else if (post.Equals("经理")) { postId = 32; }
  641. // else if (post.Equals("OP专员")) { postId = 28; }
  642. // else if (post.Equals("酒店预订")) { postId = 25; }
  643. // else if (post.Equals("商务邀请")) { postId = 27; }
  644. // else if (post.Equals("-")) { postId = 0; }
  645. // else if (post.Equals("签证专员")) { postId = 26; }
  646. // else if (post.Equals("OP操作")) { postId = 28; }
  647. // else if (post.Equals("司机")) { postId = 14; }
  648. // else if (post.Equals("国际交流部经理")) { postId = 32; }
  649. // else if (post.Equals("机票酒店")) { postId = 24; }
  650. // else if (post.Equals("签证")) { postId = 26; }
  651. // else if (post.Equals("票房")) { postId = 24; }
  652. // else if (post.Equals("票务专员")) { postId = 24; }
  653. // else if (post.Equals("酒店/机票")) { postId = 24; }
  654. // else if (post.Equals("OP")) { postId = 28; }
  655. // else if (post.Equals("主管")) { postId = 22; }
  656. // else if (post.Equals("订票专员")) { postId = 24; }
  657. // else if (post.Equals("机票")) { postId = 24; }
  658. // else if (post.Equals("国交部经理")) { postId = 32; }
  659. // else if (post.Equals("计调")) { postId = 23; }
  660. // else if (post.Equals("票务")) { postId = 24; }
  661. // else if (post.Equals("国交部主管")) { postId = 22; }
  662. // else if (post.Equals("暂无")) { postId = 22; }
  663. // else if (post.Equals("初级OP")) { postId = 28; }
  664. // else if (post.Equals("计调")) { postId = 23; }
  665. // else { postId = 0; }
  666. // break;
  667. // case 5: //会展部
  668. // //15 5 经理
  669. // //16 5 文案策划
  670. // //17 5 活动执行
  671. // //18 5 平面设计师
  672. // //19 5 3D设计师
  673. // depId = 5;
  674. // if (post.Equals("-")) postId = 16;
  675. // break;
  676. // case 6: //市场销售部
  677. // //20 6 经理
  678. // //21 6 市场专员
  679. // //53 6 主管
  680. // depId = 6;
  681. // if (post.Equals("主管")) postId = 53;
  682. // else if (post.Equals("-")) postId = 21;
  683. // else if (post.Equals("销售总监")) postId = 53;
  684. // else if (post.Equals("市场专员")) postId = 21;
  685. // else if (post.Equals("销售专员")) postId = 54;
  686. // else if (post.Equals("市场助理")) postId = 55;
  687. // else if (post.Equals("销售")) postId = 54;
  688. // break;
  689. // case 99: //总经办
  690. // //1 1 总经理
  691. // //2 1 副总经理
  692. // //3 1 总经理助理
  693. // depId = 1;
  694. // if (post.Equals("总经理")) postId = 1;
  695. // else if (post.Equals("副总")) postId = 2;
  696. // break;
  697. // case 107: //会议会展策划部
  698. // //15 5 经理
  699. // //16 5 文案策划
  700. // //17 5 活动执行
  701. // //18 5 平面设计师
  702. // //19 5 3D设计师
  703. // //56 5 销售
  704. // //46 5 网络推广
  705. // //57 5 市场推广
  706. // depId = 5;
  707. // if (post.Equals("销售")) postId = 56;
  708. // else if (post.Equals("策划执行")) postId = 16;
  709. // else if (post.Equals("策活动划")) postId = 16;
  710. // else if (post.Equals("活动执行")) postId = 17;
  711. // else if (post.Equals("网络媒介推广")) postId = 46;
  712. // else if (post.Equals("媒介主任")) postId = 46;
  713. // else if (post.Equals("公关部经理")) postId = 15;
  714. // else if (post.Equals("项目执行")) postId = 17;
  715. // else if (post.Equals("市场推广")) postId = 57;
  716. // else if (post.Equals("策划")) postId = 16;
  717. // else if (post.Equals("3D设计师")) postId = 19;
  718. // else if (post.Equals("平面设计")) postId = 18;
  719. // else if (post.Equals("设计")) postId = 18;
  720. // else if (post.Equals("活动策划")) postId = 16;
  721. // else if (post.Equals("活动策划执行")) postId = 17;
  722. // else if (post.Equals("高级活动策划")) postId = 16;
  723. // else postId = 0;
  724. // break;
  725. // case 115:
  726. // if (post.Equals("系统管理员")) { depId = 9; postId = 31; }
  727. // else if (post.Equals("后勤专员")) { depId = 5; postId = 58; }
  728. // break;
  729. // case 287: //会展部
  730. // //59 2 17 经理
  731. // //60 2 17 主管
  732. // //61 2 17 会展专员
  733. // //62 2 17 会展销售
  734. // //63 2 17 会展策划
  735. // //64 2 17 招商专员
  736. // //65 2 17 媒介专员
  737. // depId = 17;
  738. // if (post.Equals("会展部经理")) postId = 59;
  739. // else if (post.Equals("会展专员")) postId = 61;
  740. // else if (post.Equals("会展销售")) postId = 62;
  741. // else if (post.Equals("招商招展")) postId = 63;
  742. // else if (post.Equals("会展部主管")) postId = 60;
  743. // else if (post.Equals("媒介专员")) postId = 65;
  744. // else if (post.Equals("会展策划")) postId = 63;
  745. // else if (post.Equals("招商专员")) postId = 64;
  746. // else postId = 61;
  747. // break;
  748. // case 304: //总经理助理
  749. // //1 1 总经理
  750. // //2 1 副总经理
  751. // //3 1 总经理助理
  752. // depId = 1;
  753. // postId = 3;
  754. // break;
  755. // case 323: //海外游学部
  756. // //66 3 19 游学顾问
  757. // depId = 19;
  758. // postId = 66;
  759. // break;
  760. // case 335: //会议会展策划部
  761. // //15 5 经理
  762. // //16 5 文案策划
  763. // //17 5 活动执行
  764. // //18 5 平面设计师
  765. // //19 5 3D设计师
  766. // //56 5 销售
  767. // //46 5 网络推广
  768. // //57 5 市场推广
  769. // //67 5 策划主管
  770. // depId = 5;
  771. // if (post.Equals("会展专员")) { depId = 17; postId = 61; }
  772. // else if (post.Equals("策划执行")) postId = 16;
  773. // else if (post.Equals("策划主管")) postId = 67;
  774. // else if (post.Equals("策划")) postId = 16;
  775. // else if (post.Equals("文案")) postId = 16;
  776. // else if (post.Equals("策划执行")) postId = 17;
  777. // else if (post.Equals("执行专员 ")) postId = 17;
  778. // break;
  779. // case 761://项目部
  780. // //20 6 经理
  781. // //21 6 市场专员
  782. // //53 6 主管
  783. // if (post.Equals("销售主管")) { depId = 6; postId = 20; }
  784. // else if (post.Equals("场站经理")) { depId = 6; postId = 53; }
  785. // else if (post.Equals("暂无")) { depId = 5; postId = 58; }
  786. // else
  787. // {
  788. // if (oldUser.CnName.Equals("许婷"))
  789. // {
  790. // depId = 5; postId = 16;
  791. // }
  792. // else if (oldUser.CnName.Equals("陈雪"))
  793. // {
  794. // depId = 5; postId = 17;
  795. // }
  796. // }
  797. // break;
  798. // default:
  799. // break;
  800. // }
  801. // #endregion
  802. // string idCrad = string.Empty;
  803. // string idCradNumber = string.Empty;
  804. // DateTime? birthday = null;
  805. // if (!string.IsNullOrEmpty(oldUser.IDCard))
  806. // {
  807. // idCrad = oldUser.IDCard.Trim();
  808. // #region 处理身份证Number 出生日期
  809. // if (idCrad.ValidateIdNumber())
  810. // {
  811. // idCradNumber = idCrad.ToString();
  812. // string birthDate = idCrad.Substring(6, 8); // 提取从第6位开始的8个字符,即出生日期部分
  813. // birthday = new DateTime(int.Parse(birthDate.Substring(0, 4)), int.Parse(birthDate.Substring(4, 2)), int.Parse(birthDate.Substring(6, 2)));
  814. // }
  815. // #endregion
  816. // }
  817. // DateTime? startWorkDate = null;
  818. // #region 判断是否是日期格式的字符串
  819. // string format = "yyyy-MM-dd"; // 日期格式
  820. // DateTime date;
  821. // bool isParsed = DateTime.TryParseExact(oldUser.StartWorkDate, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out date);
  822. // if (isParsed)
  823. // {
  824. // startWorkDate = date;
  825. // }
  826. // #endregion
  827. // int education = 0;
  828. // #region 处理学历
  829. // if (!string.IsNullOrEmpty(oldUser.Education))
  830. // {
  831. // //0 未设置 1 小学、2 初中、3 高中、4 专科、5 本科、6 研究生
  832. // if (oldUser.Education.Equals("本科")) education = 5;
  833. // else if (oldUser.Education.Equals("大学专科")) education = 4;
  834. // else if (oldUser.Education.Equals("大专")) education = 4;
  835. // else if (oldUser.Education.Equals("全日制本科")) education = 5;
  836. // else if (oldUser.Education.Equals("硕士")) education = 6;
  837. // else if (oldUser.Education.Equals("硕士研究生")) education = 6;
  838. // else if (oldUser.Education.Equals("学士")) education = 6;
  839. // else if (oldUser.Education.Equals("研究生")) education = 6;
  840. // else if (oldUser.Education.Equals("专科")) education = 4;
  841. // }
  842. // #endregion
  843. // int theOrAdultEducation = 0;
  844. // #region 处理统招/成人
  845. // if (!string.IsNullOrEmpty(oldUser.TheOrAdultEducation))
  846. // {
  847. // //0 未设置 1 成教 2 统招 3 留学
  848. // if (oldUser.TheOrAdultEducation.Equals("成教")) theOrAdultEducation = 1;
  849. // if (oldUser.TheOrAdultEducation.Equals("自考")) theOrAdultEducation = 1;
  850. // else if (oldUser.TheOrAdultEducation.Equals("统招")) theOrAdultEducation = 2;
  851. // else if (oldUser.TheOrAdultEducation.Equals("留学")) theOrAdultEducation = 3;
  852. // }
  853. // #endregion
  854. // Sys_Users user = new Sys_Users()
  855. // {
  856. // Id = oldUser.Id,
  857. // CnName = oldUser.CnName,
  858. // EnName = oldUser.EnName,
  859. // Number = oldUser.Number,
  860. // CompanyId = 2,
  861. // DepId = depId,
  862. // JobPostId = postId,
  863. // Password = oldUser.Password,
  864. // Sex = oldUser.Sex,
  865. // Ext = oldUser.Ext,
  866. // Phone = oldUser.Phone,
  867. // UrgentPhone = oldUser.UrgentPhone,
  868. // Email = oldUser.Email,
  869. // Address = oldUser.Address,
  870. // Edate = oldUser.Edate,
  871. // Rdate = oldUser.Rdate,
  872. // Seniority = oldUser.Seniority,
  873. // Birthday = birthday,
  874. // IDCard = idCradNumber,
  875. // StartWorkDate = startWorkDate,
  876. // GraduateInstitutions = oldUser.GraduateInstitutions,
  877. // Professional = oldUser.Professional,
  878. // Education = education,
  879. // TheOrAdultEducation = theOrAdultEducation,
  880. // MaritalStatus = oldUser.MaritalStatus,
  881. // HomeAddress = oldUser.HomeAddress,
  882. // UsePeriod = oldUser.UsePeriod,
  883. // WorkExperience = oldUser.WorkExperience,
  884. // Certificate = oldUser.Certificate,
  885. // HrAudit = 1,
  886. // CreateUserId = 208,
  887. // CreateTime = DateTime.Now,
  888. // DeleteUserId = null,
  889. // DeleteTime = string.Empty,
  890. // Remark = oldUser.Remark,
  891. // IsDel = oldUser.IsDel,
  892. // };
  893. // newOaUserDatas.Add(user);
  894. // }
  895. // if (newOaUserDatas.Count > 0)
  896. // {
  897. // //执行删除
  898. // bool resetStatus = _sqlSuar.DbMaintenance.TruncateTable<Sys_Users>();
  899. // //执行批量添加
  900. // int addTotal = await _sqlSuar.Insertable(newOaUserDatas).IgnoreColumns(it => it.Id).ExecuteCommandAsync();
  901. // }
  902. // view = new
  903. // {
  904. // Code = 200,
  905. // Msg = "操作成功!",
  906. // Data = newOaUserDatas
  907. // };
  908. // }
  909. // catch (Exception ex)
  910. // {
  911. // view = new
  912. // {
  913. // Code = 400,
  914. // Msg = ex.Message
  915. // };
  916. // }
  917. // return Ok(JsonView(view));
  918. //}
  919. /// <summary>
  920. /// 测试
  921. /// 创建员工号
  922. /// </summary>
  923. /// <param name="depId">部门Id</param>
  924. /// <returns></returns>
  925. [HttpPost("TestCreateUserNumber")]
  926. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  927. public async Task<IActionResult> TestCreateUserNumber(int depId)
  928. {
  929. try
  930. {
  931. var number = await _loginRep.CreateNumber(depId);
  932. return Ok(JsonView(true, "操作成功!", number));
  933. }
  934. catch (Exception ex)
  935. {
  936. return Ok(JsonView(false, "操作失败!", ex.Message));
  937. }
  938. }
  939. /// <summary>
  940. /// ClientTest
  941. /// </summary>
  942. /// <returns></returns>
  943. [HttpPost("ClientTest")]
  944. [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
  945. public async Task<IActionResult> ClientTest()
  946. {
  947. var _sqlsugar = _loginRep._sqlSugar;
  948. var groups = await _sqlsugar.Queryable<Grp_DelegationInfo>()
  949. .Where(x => x.IsDel == 0 && x.VisitDate >= Convert.ToDateTime("2024-01-01") && x.VisitDate <= Convert.ToDateTime("2024-12-31"))
  950. .Select(x => new { x.Id, x.TeamName, x.ClientUnit, x.ClientName, x.VisitDate })
  951. .ToListAsync();
  952. var newClients = await _sqlsugar.Queryable<Crm_NewClientData>()
  953. .Where(x => x.IsDel == 0 && !string.IsNullOrEmpty(x.Contact))
  954. .Select(x => new Crm_NewClientData() { Contact = x.Contact, Telephone = x.Telephone, Phone = x.Phone })
  955. .ToListAsync();
  956. foreach (var item in newClients) EncryptionProcessor.DecryptProperties(item);
  957. var datas = new List<NewClientInfo>();
  958. foreach (var group in groups)
  959. {
  960. var clientName = group.ClientName;
  961. var clientInfo = newClients.Find(x => !string.IsNullOrEmpty(clientName) && !string.IsNullOrEmpty(x.Contact) && clientName.Contains(x.Contact));
  962. if (clientInfo != null)
  963. {
  964. datas.Add(new NewClientInfo()
  965. {
  966. TeamName = group.TeamName,
  967. ClientUnit = group.ClientUnit,
  968. ClientName = group.ClientName,
  969. VisitDate = group.VisitDate,
  970. NewClientContact = clientInfo?.Contact ?? "",
  971. Telephone = clientInfo?.Telephone ?? "",
  972. Phone = clientInfo?.Phone ?? "",
  973. });
  974. }
  975. }
  976. datas = datas.OrderBy(x => x.VisitDate).ToList();
  977. return Ok(JsonView(datas));
  978. }
  979. public class NewClientInfo
  980. {
  981. public string TeamName { get; set; }
  982. public string ClientUnit { get; set; }
  983. public string ClientName { get; set; }
  984. public DateTime VisitDate { get; set; }
  985. public string NewClientContact { get; set; }
  986. public string Telephone { get; set; }
  987. public string Phone { get; set; }
  988. }
  989. }
  990. }