店铺账号cookie保存功能
This commit is contained in:
1 parent
4aaf264e89
commit
311971ca21
4 files changed
+122
-83
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user