From 7b52260c2a83d23adb5447a9e9848d90b4dc018c Mon Sep 17 00:00:00 2001
From: username@email.com <yzy2002yzy@163.com>
Date: 星期五, 20 六月 2025 08:49:09 +0800
Subject: [PATCH] 爬虫 处理处罚
---
zhengcaioa/zhengcaioa/Controllers/HomeController.cs | 73 +++++++++++++++++++++++++++++++++++-
1 files changed, 70 insertions(+), 3 deletions(-)
diff --git a/zhengcaioa/zhengcaioa/Controllers/HomeController.cs b/zhengcaioa/zhengcaioa/Controllers/HomeController.cs
index 13ab955..f0ffd47 100644
--- a/zhengcaioa/zhengcaioa/Controllers/HomeController.cs
+++ b/zhengcaioa/zhengcaioa/Controllers/HomeController.cs
@@ -12,6 +12,10 @@
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
{
@@ -19,12 +23,18 @@
{
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()
@@ -52,10 +62,67 @@
return View("Login");
}
var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
- ViewData["curentuser"] = curentuser;
+ ViewData["curentuser"] = curentuser;
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();
--
Gitblit v1.9.1