自动批量登录
This commit is contained in:
1 parent
82adb510be
commit
6754342366
4 files changed
+1346
-1072
No files matched your search
@@ -496,7 +496,92 @@ namespace TemuKJD.BLL
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string kdniaoPostResponse(string _url, string _data, string referer, Dictionary<string, object> reqDic, string kdnAuth = null, string kdnAuthKey = "Auth")
|
||||
public static async Task<string> WeiXinGetResponseAsync(ShopLoginInfo shop, string _url, string referer = "", bool isGetDocument = false)
|
||||
{
|
||||
string biz_magic = "";
|
||||
string cookies = "";
|
||||
try
|
||||
{
|
||||
var cookieLst = JsonHelper.DeserializeJsonToList<CefSharp.Cookie>(shop?.Cookies.ParseToString());
|
||||
if (cookieLst == null)
|
||||
cookieLst = new List<CefSharp.Cookie>();
|
||||
foreach (var cook in cookieLst)
|
||||
{
|
||||
if (cook.Name.StartsWith("biz"))
|
||||
cookies += cook.Name + "=" + cook.Value + ";";
|
||||
}
|
||||
var bizMagicCookie = cookieLst.FirstOrDefault(c => c.Name == "biz_magic");
|
||||
if (bizMagicCookie != null)
|
||||
biz_magic = bizMagicCookie.Value;
|
||||
}
|
||||
catch { }
|
||||
|
||||
HttpWebResponse response = null;
|
||||
string result;
|
||||
try
|
||||
{
|
||||
string url = _url;
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
request.KeepAlive = true;
|
||||
if (isGetDocument)
|
||||
{
|
||||
request.Headers.Add("sec-ch-ua", @"""Not)A;Brand"";v=""8"", ""Chromium"";v=""138""");
|
||||
request.Headers.Add("sec-ch-ua-mobile", @"?0");
|
||||
request.Headers.Add("sec-ch-ua-platform", @"""Windows""");
|
||||
request.Headers.Add("Upgrade-Insecure-Requests", @"1");
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
|
||||
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7";
|
||||
request.Headers.Set(HttpRequestHeader.Cookie, cookies);
|
||||
request.Headers.Add("Sec-Fetch-Site", @"none");
|
||||
request.Headers.Add("Sec-Fetch-Mode", @"navigate");
|
||||
request.Headers.Add("Sec-Fetch-User", @"?1");
|
||||
request.Headers.Add("Sec-Fetch-Dest", @"document");
|
||||
}
|
||||
else
|
||||
{
|
||||
request.Headers.Add("wecom_magic", @"");
|
||||
request.Headers.Add("sec-ch-ua-platform", @"""Windows""");
|
||||
request.Headers.Add("supplier_magic", @"");
|
||||
request.Headers.Add("sec-ch-ua", @"""Not)A;Brand"";v=""8"", ""Chromium"";v=""138""");
|
||||
request.Headers.Add("sec-ch-ua-mobile", @"?0");
|
||||
request.Headers.Add("potter-scene", @"weixinShop");
|
||||
request.Headers.Add("biz_magic", biz_magic);
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
|
||||
request.Accept = "application/json, text/plain, */*";
|
||||
request.Headers.Add("talent_magic", @"");
|
||||
request.Headers.Add("mcn_magic", @"");
|
||||
request.Headers.Set(HttpRequestHeader.Cookie, cookies);
|
||||
request.Headers.Add("Sec-Fetch-Site", @"same-origin");
|
||||
request.Headers.Add("Sec-Fetch-Mode", @"cors");
|
||||
request.Headers.Add("Sec-Fetch-Dest", @"empty");
|
||||
request.Referer = referer;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br, zstd");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||||
}
|
||||
|
||||
response = (HttpWebResponse)await request.GetResponseAsync();
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
if (ex.Status == WebExceptionStatus.ProtocolError)
|
||||
{
|
||||
response = (HttpWebResponse)ex.Response;
|
||||
result = GetProxyHtml.ReadResponse(response);
|
||||
return result;
|
||||
}
|
||||
else return ex.Message;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (response != null) response.Close();
|
||||
return e.Message;
|
||||
}
|
||||
result = GetProxyHtml.ReadResponse(response);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string kdniaoPostResponse(string _url, string _data, string referer, Dictionary<string, object> reqDic, string kdnAuth = null, string kdnAuthKey = "Auth")
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
string result;
|
||||
|
||||
+1127
-1068
File diff suppressed because it is too large.
Load diff
@@ -33,7 +33,10 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
private static WXShopListForm _instance = null;
|
||||
public static WXShopListForm Instance { get { if (_instance == null) { _instance = new WXShopListForm(); } return _instance; } set { _instance = value; } }
|
||||
public static bool IsOperate { get; set; } = false;
|
||||
|
||||
public List<List<ShopSwitchInfo>> shopSwitchInfoListList { get; set; } = new List<List<ShopSwitchInfo>>();
|
||||
private bool isLoading { get; set; } = false;
|
||||
private bool isCancel = false;
|
||||
|
||||
#region 服务端店铺管理
|
||||
public static void UpdateShop()
|
||||
@@ -1315,6 +1318,98 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
numAddTopUp.Value = 1;
|
||||
pnlTopUp.Visible = true;
|
||||
}
|
||||
|
||||
private async void btnAutoBatchLogin_Click(object sender, EventArgs e)
|
||||
{
|
||||
isCancel = false;
|
||||
shopSwitchInfoListList = new List<List<ShopSwitchInfo>>();
|
||||
int i = 1;
|
||||
foreach (var shop in GlobalConfig.ShopLoginList)
|
||||
{
|
||||
if (isCancel)
|
||||
break;
|
||||
|
||||
this.statusBar.pgbTaskProgress.Maximum = GlobalConfig.ShopLoginList.Count;
|
||||
this.statusBar.pgbTaskProgress.Value = i;
|
||||
this.statusBar.pgbTaskProgress.Text = i + "/" + GlobalConfig.ShopLoginList.Count;
|
||||
this.statusBar.lblTaskStatus.Text = "第1步(共2步):正在获取批量登录信息 " + i + "/" + GlobalConfig.ShopLoginList.Count;
|
||||
i++;
|
||||
|
||||
if (shop.LoginStatus != "登录成功")
|
||||
continue;
|
||||
if (shopSwitchInfoListList.Any(ll => ll.Any(l => l.appid == shop.ShopId)))
|
||||
continue;
|
||||
|
||||
var shopSwitchRst = await WXShopSwitch.getShopSwitchListAsync(shop);
|
||||
if (!shopSwitchRst.Contains("\"code\":0"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string shopSwitchStr = JsonHelper.SerializeObject(JsonHelper.JObjectParse(shopSwitchRst)["list"]);
|
||||
shopSwitchInfoListList.Add(JsonHelper.DeserializeJsonToList<ShopSwitchInfo>(shopSwitchStr));
|
||||
|
||||
await Task.Delay(100);
|
||||
}
|
||||
|
||||
i = 1;
|
||||
var waitLoginShopList = GlobalConfig.ShopLoginList.Where(s => s.LoginStatus != "登录成功").ToList();
|
||||
foreach (var shop in waitLoginShopList)
|
||||
{
|
||||
if (isCancel)
|
||||
break;
|
||||
|
||||
this.statusBar.pgbTaskProgress.Maximum = waitLoginShopList.Count;
|
||||
this.statusBar.pgbTaskProgress.Value = i;
|
||||
this.statusBar.pgbTaskProgress.Text = i + "/" + waitLoginShopList.Count;
|
||||
this.statusBar.lblTaskStatus.Text = "第2步(共2步):正在自动批量登录 " + i + "/" + waitLoginShopList.Count;
|
||||
i++;
|
||||
|
||||
// 直接比较相等,但是带入if以后就不相等 ?
|
||||
if (shop.LoginStatus.Equals("登录成功"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var switchInfoListList = shopSwitchInfoListList.Where(ll => ll.Any(l => l.appid == shop.ShopId)).ToList();
|
||||
if (switchInfoListList.Count == 0)
|
||||
continue;
|
||||
|
||||
ShopLoginInfo loginShop = null;
|
||||
foreach (var switchInfoList in switchInfoListList)
|
||||
{
|
||||
for (int a = 0; a < 100 && loginShop?.LoginStatus != "登录成功"; a++)
|
||||
{
|
||||
loginShop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.LoginStatus == "登录成功" && switchInfoList.Any(l => l.appid == s.ShopId));
|
||||
if (loginShop == null)
|
||||
break;
|
||||
else
|
||||
{
|
||||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { loginShop }, false);
|
||||
await Task.Delay(100);
|
||||
}
|
||||
}
|
||||
if (loginShop != null)
|
||||
break;
|
||||
}
|
||||
// 店铺不存在或者全部掉线了,继续
|
||||
if (loginShop?.LoginStatus != "登录成功")
|
||||
continue;
|
||||
|
||||
WXShopMultiLoginForm shopMultiLoginForm = new WXShopMultiLoginForm(loginShop);
|
||||
shopMultiLoginForm.openType = EnumOpenType.multi_login;
|
||||
shopMultiLoginForm.isAutoLogin = true;
|
||||
shopMultiLoginForm.ShowDialog();
|
||||
RefreshDataGridView(true, shopMultiLoginForm.lstSwitchShop.ToList());
|
||||
|
||||
await Task.Delay(500);
|
||||
}
|
||||
this.statusBar.lblTaskStatus.Text += isCancel ? " 自动批量登录取消" : " 自动批量登录结束";
|
||||
}
|
||||
|
||||
private void btnCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
isCancel = true;
|
||||
}
|
||||
}
|
||||
public class ShopRenewResponse
|
||||
{
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
{
|
||||
public static WXShopMultiLoginForm shopMultiLoginFormInstance { get; set; } = null;
|
||||
|
||||
public bool isAutoLogin = false;
|
||||
|
||||
public int CloseAfterSecond { get; set; }
|
||||
public EnumOpenType openType = EnumOpenType.manage;
|
||||
public bool isMultiLogin = false;
|
||||
@@ -100,6 +102,26 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
{
|
||||
BaseMsgForm.ShowError("切换列表解析失败!");
|
||||
}
|
||||
|
||||
if (isAutoLogin)
|
||||
{
|
||||
Thread.Sleep(Randomx.GetId(2500, 3500));
|
||||
while(this.cefWebBrowser == null || this.cefWebBrowser.IsLoading)
|
||||
{
|
||||
if (!this.Created)
|
||||
return;
|
||||
|
||||
Thread.Sleep(100);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!this.Created)
|
||||
return;
|
||||
Invoke(() =>
|
||||
{
|
||||
btnRefreshNum_Click(null, null);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -416,12 +438,18 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
Thread.Sleep(Randomx.GetId(2500, 5000));
|
||||
}
|
||||
|
||||
if (!this.Created)
|
||||
return;
|
||||
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
btnRefreshNum.Enabled = true;
|
||||
pbLoading.Visible = false;
|
||||
BaseMsgForm.ShowInfo("操作完成!");
|
||||
|
||||
if (this.isAutoLogin)
|
||||
this.Close();
|
||||
else
|
||||
BaseMsgForm.ShowInfo("操作完成!");
|
||||
}));
|
||||
});
|
||||
}
|
||||
@@ -448,8 +476,15 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
string refere = "https://store.weixin.qq.com/shop/home";
|
||||
var result = WXHttpResponseBLL.WeiXinGetResponse(shop, url, refere);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static async Task<string> getShopSwitchListAsync(ShopLoginInfo shop)
|
||||
{
|
||||
string url = "https://store.weixin.qq.com/shop-faas/mmecnodelogin/session/getShopSwitchList?token=&lang=zh_CN";
|
||||
string refere = "https://store.weixin.qq.com/shop/home";
|
||||
var result = await WXHttpResponseBLL.WeiXinGetResponseAsync(shop, url, refere);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class ShopSwitchInfo
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user