店铺账号cookie保存功能

This commit is contained in:
wule committed 2025-06-30 10:21:16 +08:00
1 parent 4aaf264e89
commit 311971ca21
4 files changed
+122 -83

No files matched your search

+3 -1
View File
@@ -3,4 +3,6 @@
Bin
NotUse
obj
.psd
.psd
packages
.user
+2 -2
View File
@@ -89,7 +89,7 @@ namespace AllBase
public static string OriginUrl = "http://mobile.yangkeduo.com";
public static string NewUrl = "https://yangkeduo.com";
public static string ServerUrl = "http://localhost:8000";
public static string ServerUrl = "http://localhost:9000";
/// <summary>
/// 订单监控延迟
/// </summary>
@@ -142,7 +142,7 @@ namespace AllBase
/// 图片API
/// </summary>
//public static string LoginApiUrl = "http://new.qixiaoke.com/";
public static string LoginApiUrl = "http://localhost:8000";
public static string LoginApiUrl = "http://localhost:9000";
public static string BigDataApiUrl = "http://bigdata.qixiaoke.com/";
public static string GateApi = "";
public static string QqGroupNum = "";
+56 -42
View File
@@ -218,12 +218,14 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
/// <param name="shopName">店铺名称</param>
/// <param name="shopCookies">cookies</param>
/// <param name="fromTool">工具名称(可不填写)</param>
public static void AddServerDouShopCookies(string shopName, string shopCookies, string fromTool = null)
public static void AddServerShopCookies(DouShopLoginInfo shop, string shopCookies, string fromTool = null)
{
var fTool = string.IsNullOrEmpty(fromTool) ? "" : "&from_tool=" + fromTool;
var url = BaseClass.BuildObjString("shop&act=add_shop_cookie");
var url = BaseClass.BuildObjString("shop/mdy_shop");
var data = UserLogin.GetSignaturex()
+ "&shop_name=" + shopName
+ "&login_name=" + shop.LoginName
+ "&shop_id=" + shop.ShopAccountId
+ "&shop_account=" + shop.ShopAccount
+ "&cookie=" + shopCookies.Replace("&", "&").Replace("%", "%").Replace("+", "+")
+ fTool;
var result = GetHtml.PostUtf8(url, data);
@@ -517,18 +519,18 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
if (shop != null)
{
retryLogin:
var loginResult = GetShopStatus(shop);
var loginResult = "\"code\":0";//GetShopStatus(shop);
if (loginResult.Contains("\"code\":0"))
{
shop.LoginStatus = "登录成功";
var shopId = BaseRegex.GetStringJson(ref loginResult, "id");
var shopToken = BaseRegex.GetStringJson(ref loginResult, "token");
var shopName = BaseRegex.GetStringJson(ref loginResult, "shop_name");
var mobile = BaseRegex.GetStringJson(ref loginResult, "mobile");
if (!string.IsNullOrEmpty(shopId)) shop.ShopAccountId = shopId;
if (!string.IsNullOrEmpty(shopToken)) shop.ShopToken = shopToken;
if (!string.IsNullOrEmpty(shopName)) shop.ShopAccount = shopName;
if (!string.IsNullOrEmpty(mobile)) shop.Mobile = mobile;
//var shopId = BaseRegex.GetStringJson(ref loginResult, "id");
//var shopToken = BaseRegex.GetStringJson(ref loginResult, "token");
//var shopName = BaseRegex.GetStringJson(ref loginResult, "shop_name");
//var mobile = BaseRegex.GetStringJson(ref loginResult, "mobile");
//if (!string.IsNullOrEmpty(shopId)) shop.ShopAccountId = shopId;
//if (!string.IsNullOrEmpty(shopToken)) shop.ShopToken = shopToken;
//if (!string.IsNullOrEmpty(shopName)) shop.ShopAccount = shopName;
//if (!string.IsNullOrEmpty(mobile)) shop.Mobile = mobile;
}
else if (loginResult.Contains("未登录"))
{
@@ -720,7 +722,15 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
switch (headerText)
{
case "检测":
CheckShopLoginAsync(new string[] { loginName });
//CheckShopLoginAsync(new string[] { loginName });
IsOperate = true;
{
ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
shopLoginForm.openType = EnumOpenType.manage;
shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
shopLoginForm.ShowDialog();
IsOperate = false;
}
break;
case "删除":
if (BaseMsgForm.ShowConfirm("确定删除店铺吗?删除后不可恢复!").DialogResult == DialogResult.Cancel)
@@ -736,37 +746,40 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
break;
case "登录":
IsOperate = true;
ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
shopLoginForm.ShowDialog();
IsOperate = false;
break;
case "多重登录":
IsOperate = true;
ShopLoginForm shopMultiLoginForm = new ShopLoginForm(shop);
shopMultiLoginForm.isMultiLogin = true;
shopMultiLoginForm.SaveComplete += shopLoginForm_SaveComplete;
shopMultiLoginForm.ShowDialog();
IsOperate = false;
break;
case "接口授权":
case "上货授权":
IsOperate = true;
//GetHtml.OpenUrl("https://fuwu.jinritemai.com/authorize?service_id=815");
ShopAuthForm shopAuthForm = new ShopAuthForm(shop);
shopAuthForm.SaveComplete += shopLoginForm_SaveComplete;
shopAuthForm.ShowDialog();
IsOperate = false;
break;
case "拍单授权":
IsOperate = true;
//GetHtml.OpenUrl("https://fuwu.jinritemai.com/detail?from=fuwu_market_orderDetail&service_id=20896");
ShopAuthForm shopAuthForm1 = new ShopAuthForm(shop);
shopAuthForm1.shopAuthUrl = "https://fuwu.jinritemai.com/authorize?service_id=20896";
shopAuthForm1.SaveComplete += shopLoginForm_SaveComplete;
shopAuthForm1.ShowDialog();
{
ShopLoginForm shopLoginForm = new ShopLoginForm(shop);
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
shopLoginForm.ShowDialog();
}
IsOperate = false;
break;
//case "多重登录":
// IsOperate = true;
// ShopLoginForm shopMultiLoginForm = new ShopLoginForm(shop);
// shopMultiLoginForm.isMultiLogin = true;
// shopMultiLoginForm.SaveComplete += shopLoginForm_SaveComplete;
// shopMultiLoginForm.ShowDialog();
// IsOperate = false;
// break;
//case "接口授权":
//case "上货授权":
// IsOperate = true;
// //GetHtml.OpenUrl("https://fuwu.jinritemai.com/authorize?service_id=815");
// ShopAuthForm shopAuthForm = new ShopAuthForm(shop);
// shopAuthForm.SaveComplete += shopLoginForm_SaveComplete;
// shopAuthForm.ShowDialog();
// IsOperate = false;
// break;
//case "拍单授权":
// IsOperate = true;
// //GetHtml.OpenUrl("https://fuwu.jinritemai.com/detail?from=fuwu_market_orderDetail&service_id=20896");
// ShopAuthForm shopAuthForm1 = new ShopAuthForm(shop);
// shopAuthForm1.shopAuthUrl = "https://fuwu.jinritemai.com/authorize?service_id=20896";
// shopAuthForm1.SaveComplete += shopLoginForm_SaveComplete;
// shopAuthForm1.ShowDialog();
// IsOperate = false;
// break;
default:
dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value = !(bool)dgvShop.Rows[e.RowIndex].Cells["colSelect"].Value;
break;
@@ -830,6 +843,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
if (shopInfo != null && !string.IsNullOrEmpty(shopInfo.LoginName) && !string.IsNullOrEmpty(shopInfo.Password))
{
ShopLoginForm shopLoginForm = new ShopLoginForm(shopInfo);
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
shopLoginForm.ShowDialog();
}
+61 -38
View File
@@ -26,9 +26,15 @@ using Work.BLL.Tools;
namespace LittleRabbit.LittleRabbitForms.ShopForms
{
public enum EnumOpenType
{
login,
manage,
}
public partial class ShopLoginForm : LRBaseForm
{
public int CloseAfterSecond { get; set; }
public EnumOpenType openType = EnumOpenType.manage;
public bool isMultiLogin = false;
public string MultiLoginCookieName = "";
private string shopCookieHead = "kuajingmaihuo.com";
@@ -51,6 +57,12 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
{
//this.splitContainer1.SplitterDistance = 674;
if (openType == EnumOpenType.login)
{
this.shop.ShopAccountId = "";
this.shop.ShopAccount = "";
}
if (isMultiLogin && shop != null)
{
this.pnlMultiLogin.Visible = true;
@@ -87,25 +99,27 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
while (this.Created)
{
Thread.Sleep(3000);
if (this.shop != null && currentUrl == shopMainUrl)
//continue;
if (this.shop != null && currentUrl.TrimEnd('/') == shopMainUrl)
{
if (!cefWebBrowser.GetBrowser().MainFrame.IsValid)
continue;
continue;
if (openType!= EnumOpenType.login)
continue;
var jsStr = "function getShopName() { return document.getElementsByClassName('headerShopName')[0].innerHTML; } getShopName();";
var response = cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
response.Wait(5000);
var res = response.Result.Result?.ToString();
if (res != null && res.Contains("</span>"))
if (string.IsNullOrEmpty(shop.ShopAccountId) || string.IsNullOrEmpty(shop.ShopAccount))
continue;
//var jsStr = "function getShopName() { return document.getElementsByClassName('headerShopName')[0].innerHTML; } getShopName();";
//var response = cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
//response.Wait(5000);
//var res = response.Result.Result?.ToString();
//if (res != null && res.Contains("</span>"))
{
shop.ShopAccount = res.Substring(res.IndexOf("</span>") + 7);
shop.ShopAccount = BaseRegex.FliterHtmlTag(shop.ShopAccount);
//if (shop.ShopName.Contains("<span class="))
// shop.ShopName = shop.ShopName.Substring(shop.ShopName.IndexOf(">") + 1);
//if (shop.ShopName.Contains("</span>"))
// shop.ShopName = shop.ShopName.Substring(0, shop.ShopName.IndexOf("</span>"));
//shop.ShopAccount = res.Substring(res.IndexOf("</span>") + 7);
//shop.ShopAccount = BaseRegex.FliterHtmlTag(shop.ShopAccount);
string cookies = "";
List<Cookie> cookieList = CEFBrowser.GetCookieList(shopCookieHead, cefWebBrowser.RequestContext.GetCookieManager(null));
if (cookieList != null && cookieList.Count > 0)
@@ -120,16 +134,17 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
cookies = cookies.Trim().TrimEnd(';');
}
shop.Cookies = cookies;
if (isMultiLogin)
{
shop.DictMultiCookies[MultiLoginCookieName] = cookies;
}
//if (isMultiLogin)
//{
// shop.DictMultiCookies[MultiLoginCookieName] = cookies;
//}
if (!string.IsNullOrEmpty(shop.Cookies)
&& !string.IsNullOrEmpty(shop.ShopAccount)
&& !string.IsNullOrEmpty(shop.ShopAccountId)
//&& !string.IsNullOrEmpty(shop.Mobile)
&& !string.IsNullOrEmpty(shop.ShopToken))
//&& !string.IsNullOrEmpty(shop.ShopToken)
)
{
shop.LoginStatus = "登录成功";
@@ -137,16 +152,18 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
var shopInfo = GlobalConfig.DouShopLoginList.FirstOrDefault(v => v.ShopAccountId == shop.ShopAccountId);
if (shopInfo != null)
{
shopInfo.ShopToken = shop.ShopToken;
shopInfo.Mobile = shop.Mobile;
//shopInfo.ShopToken = shop.ShopToken;
//shopInfo.Mobile = shop.Mobile;
shopInfo.Cookies = shop.Cookies;
shopInfo.Password = shop.Password;
shopInfo.ShopAccountId = shop.ShopAccountId;
shopInfo.ShopAccount = shop.ShopAccount;
}
else
GlobalConfig.DouShopLoginList.Add(shop);
StartUp.SaveDouShopLoginInfo();
//ShopListForm.AddServerDouShop(shop); // 店铺写入到服务端
ShopListForm.AddServerDouShopCookies(shop.ShopAccount, shop.Cookies); // cookie写入到服务端
ShopListForm.AddServerShopCookies(shop, shop.Cookies); // cookie写入到服务端
OnSaveComplete(shop);
if (this.Created && this.chkCloseAfterLogin.Checked)
{
@@ -232,7 +249,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
if (cefWebBrowser == null)
{
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(shopMainUrl, false);
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser("about:blank", false);
CustomResourceRequestHandlerLocal resourceRequestHandler = new CustomResourceRequestHandlerLocal();
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadComplete;
cefWebBrowser.RequestHandler = new CustomRequestHandler(resourceRequestHandler);
@@ -252,32 +269,38 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
cookie = shop.DictMultiCookies.Keys.Contains(MultiLoginCookieName) ? shop.DictMultiCookies[MultiLoginCookieName] : "";
var t = CEFBrowser.SetCookieAsync(shopCookieHead, cookie, cefWebBrowser.RequestContext.GetCookieManager(null));
splitContainer1.Panel1.Controls.Add(cefWebBrowser);
Task.Run(() =>
{
Thread.Sleep(20);
cefWebBrowser.Load(shopMainUrl);
if (openType != EnumOpenType.login)
return;
for (int i = 0; i < 50; i++)
{
Thread.Sleep(100);
}
if (GlobalConfig.dicLocalStorage != null)
{
Thread.Sleep(500);
string jsCode = "function setStorage() {";
foreach (var item in GlobalConfig.dicLocalStorage)
{
if (item.Key == "$TCC_CONFIG" || item.Key == "$TCC_CONFIG_operate_config" || item.Key == "menuStyleStr")
continue;
//设置 local storage
//if (GlobalConfig.dicLocalStorage != null)
//{
// Thread.Sleep(500);
// string jsCode = "function setStorage() {";
// foreach (var item in GlobalConfig.dicLocalStorage)
// {
// if (item.Key == "$TCC_CONFIG" || item.Key == "$TCC_CONFIG_operate_config" || item.Key == "menuStyleStr")
// continue;
jsCode += "window.localStorage.setItem('" + item.Key + "', '" + item.Value + "');\r\n";
}
jsCode += "}";
jsCode += "setStorage();";
if (cefWebBrowser.GetBrowser().MainFrame.IsValid)
cefWebBrowser.GetBrowser().MainFrame.ExecuteJavaScriptAsync(jsCode);
}
// jsCode += "window.localStorage.setItem('" + item.Key + "', '" + item.Value + "');\r\n";
// }
// jsCode += "}";
// jsCode += "setStorage();";
// if (cefWebBrowser.GetBrowser().MainFrame.IsValid)
// cefWebBrowser.GetBrowser().MainFrame.ExecuteJavaScriptAsync(jsCode);
//}
if (!this.Created)
return;