| | |
| | | using Newtonsoft.Json; |
| | | using DTO; |
| | | using static CommonToolsCore.SendMailHelper; |
| | | using Microsoft.Extensions.Configuration; |
| | | using System.Net.Http; |
| | | using Newtonsoft.Json.Linq; |
| | | using System.Net.Http.Headers; |
| | | |
| | | namespace zhengcaioa.Controllers |
| | | { |
| | |
| | | { |
| | | private readonly ILogger<HomeController> _logger; |
| | | private readonly IUserService _userService; |
| | | private readonly IConfiguration _configuration; |
| | | private readonly IHttpClientFactory _clientFactory; |
| | | |
| | | |
| | | public HomeController(ILogger<HomeController> logger, IUserService userService) |
| | | public HomeController(ILogger<HomeController> logger, IUserService userService |
| | | , IConfiguration configuration |
| | | , IHttpClientFactory clientFactory) |
| | | { |
| | | _logger = logger; |
| | | _userService = userService; |
| | | _configuration = configuration; |
| | | _clientFactory = clientFactory; |
| | | } |
| | | |
| | | public IActionResult Index() |
| | |
| | | return View(); |
| | | } |
| | | |
| | | |
| | | public async Task<IActionResult> HomeIndexAsync() |
| | | { |
| | | var session = HttpContext.Session.GetString(("User")); |
| | | if (session == null || session == "") |
| | | { |
| | | return View("Login"); |
| | | } |
| | | var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User")); |
| | | ViewData["curentuser"] = curentuser; |
| | | if (string.IsNullOrEmpty(curentuser.Yaoqingma)) |
| | | { |
| | | try |
| | | { |
| | | var pltUserDTO = _userService.GetPltUserEntity(curentuser.Id); |
| | | string huiyuanurl = _configuration.GetSection("huiyuanurl").Value; |
| | | string GetYGPromoteCode = _configuration.GetSection("GetYGPromoteCode").Value; |
| | | Uri postUrl2 = new Uri(huiyuanurl + GetYGPromoteCode); |
| | | |
| | | JObject questions2 = new JObject(); |
| | | questions2.Add("UserID", pltUserDTO.Id); |
| | | questions2.Add("UserName", pltUserDTO.UserName); |
| | | |
| | | string requestJson2 = questions2.ToString(); |
| | | string result2 = string.Empty; |
| | | |
| | | using (HttpContent httpContent = new StringContent(requestJson2)) |
| | | { |
| | | httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); |
| | | |
| | | var httpClient2 = _clientFactory.CreateClient(); |
| | | httpClient2.Timeout = new TimeSpan(0, 0, 10); |
| | | var Result2 = await httpClient2.PostAsync(postUrl2, httpContent); |
| | | result2 = Result2.Content.ReadAsStringAsync().Result; |
| | | } |
| | | |
| | | _logger.LogInformation("result2:" + result2); |
| | | JObject jobjectresult = (JObject)JsonConvert.DeserializeObject(result2); |
| | | |
| | | if (jobjectresult["code"] != null && jobjectresult["code"].ToString() == "1") |
| | | { |
| | | curentuser.Yaoqingma = jobjectresult["data"].ToString(); |
| | | pltUserDTO.Yaoqingma = curentuser.Yaoqingma; |
| | | ResultEntity resultEntity = _userService.savePltUser(pltUserDTO); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | } |
| | | |
| | | } |
| | | string yaoqingma = _configuration.GetSection("yaoqingma").Value; |
| | | ViewBag.yaoqingma = yaoqingma + curentuser.Yaoqingma; |
| | | return View(); |
| | | } |
| | | |
| | | public IActionResult Privacy() |
| | | { |
| | | return View(); |