DefaultHttpContextAccessor.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Microsoft.AspNetCore.Http;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Security.Claims;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using XF.Domain.Authentications;
  9. namespace Hotline.Application.Tests;
  10. public class DefaultHttpContextAccessor : IHttpContextAccessor, ISessionContext
  11. {
  12. private HttpContext _content = new DefaultHttpContext();
  13. private HttpContext GetContext()
  14. {
  15. var context = new DefaultHttpContext();
  16. //var openId = new Claim(AppClaimTypes.OpenId, "测试生成的OpenId");
  17. var id = new ClaimsIdentity("身份");
  18. //id.AddClaim(openId);
  19. context.User = new ClaimsPrincipal(id);
  20. //OpenId = context.User.FindFirstValue(AppClaimTypes.OpenId);
  21. return context;
  22. }
  23. public HttpContext? HttpContext { get => GetContext(); set => _content = value; }
  24. public string? UserId => throw new NotImplementedException();
  25. public string RequiredUserId => throw new NotImplementedException();
  26. public string? UserName => throw new NotImplementedException();
  27. public string? Phone => throw new NotImplementedException();
  28. public string[] Roles => throw new NotImplementedException();
  29. public string? OrgId { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  30. public string RequiredOrgId => throw new NotImplementedException();
  31. public string? OrgName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  32. public int OrgLevel { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  33. public string? OrgAreaCode { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  34. public bool OrgIsCenter { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  35. public string? OrgAreaName { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
  36. public string? AreaId => throw new NotImplementedException();
  37. public string? ClientId => throw new NotImplementedException();
  38. public string? StaffNo => throw new NotImplementedException();
  39. public string? OpenId { get; set; }
  40. }