tijiao
This commit is contained in:
1 parent
860b4408ef
commit
b27c473c99
8 files changed
+327
-219
No files matched your search
@@ -46,9 +46,10 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
private string currentUrl = "";
|
||||
|
||||
private string shopCookieHead = "store.weixin.qq.com";
|
||||
private ShopLoginInfo shop = null;
|
||||
private ShopLoginInfo mainShop = null;
|
||||
private ConcurrentList<ShopCompany> lstShopCompany = new ConcurrentList<ShopCompany>();
|
||||
private ConcurrentList<ShopLoginInfo> lstSwitchShop = new ConcurrentList<ShopLoginInfo>();
|
||||
private ConcurrentList<ShopSwitchInfo> lstSwitchInfo = new ConcurrentList<ShopSwitchInfo>();
|
||||
|
||||
|
||||
public WXShopMultiLoginForm(ShopLoginInfo shopInfo)
|
||||
@@ -56,12 +57,57 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
InitializeComponent();
|
||||
|
||||
shopMultiLoginFormInstance = this;
|
||||
this.shop = shopInfo;
|
||||
this.mainShop = shopInfo;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
var shopSwitchRst = WXShopSwitch.getShopSwitchList(mainShop);
|
||||
if (!shopSwitchRst.Contains("\"code\":0"))
|
||||
{
|
||||
BaseMsgForm.ShowError("获取切换列表失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
string shopSwitchStr = JsonHelper.SerializeObject(JsonHelper.JObjectParse(shopSwitchRst)["list"]);
|
||||
lstSwitchInfo.Clear();
|
||||
lstSwitchShop.Clear();
|
||||
lstSwitchInfo.AddRange(JsonHelper.DeserializeJsonToList<ShopSwitchInfo>(shopSwitchStr));
|
||||
lstSwitchShop.AddRange(GlobalConfig.ShopLoginList.Where(s => lstSwitchInfo.Any(sw => sw.appid == s.ShopId)));
|
||||
foreach(var shop in lstSwitchShop)
|
||||
{
|
||||
bool canUse = shop.LoginStatus == "登录成功";
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
this.dgvShop.Rows.Add
|
||||
(
|
||||
true,
|
||||
shop.LoginName,
|
||||
shop.ShopId,
|
||||
shop.ShopAccount,
|
||||
shop.Notes,
|
||||
canUse ? "在线" : "掉线",
|
||||
canUse,
|
||||
"-"
|
||||
);
|
||||
}));
|
||||
displayAuthStatus(shop);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
BaseMsgForm.ShowError("切换列表解析失败!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void ShopLoginForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
this.splitContainer1.SplitterDistance = this.splitContainer1.Height - 62;
|
||||
this.Size = new Size(1680, 900);
|
||||
this.CenterToScreen();
|
||||
|
||||
this.splitContainer3.SplitterDistance = this.splitContainer3.Height - 62;
|
||||
if (string.IsNullOrWhiteSpace(InitUrl))
|
||||
InitUrl = DefaultUrl;
|
||||
|
||||
@@ -92,7 +138,7 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
/// </summary>
|
||||
private void initCefAndMainShop()
|
||||
{
|
||||
if (openType != EnumOpenType.login && shop == null)
|
||||
if (openType != EnumOpenType.login && mainShop == null)
|
||||
return;
|
||||
|
||||
if (cefWebBrowser == null)
|
||||
@@ -124,9 +170,9 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
List<Cookie> cookieLst = new List<Cookie>();
|
||||
try
|
||||
{
|
||||
if (shop != null)
|
||||
if (mainShop != null)
|
||||
{
|
||||
cookieLst = JsonHelper.DeserializeJsonToList<CefSharp.Cookie>(shop.Cookies.ParseToString());
|
||||
cookieLst = JsonHelper.DeserializeJsonToList<CefSharp.Cookie>(mainShop.Cookies.ParseToString());
|
||||
if (cookieLst == null)
|
||||
cookieLst = new List<Cookie>();
|
||||
}
|
||||
@@ -221,12 +267,12 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
var shopId = BaseRegex.GetStringJson(ref data, "appid");
|
||||
var nickName = BaseRegex.GetStringJson(ref data, "nickName");
|
||||
var openId = BaseRegex.GetStringJson(ref data, "openid"); // oGu7k7HxmUyOmc1X6VM7GQwS-9cI
|
||||
if (shop != null && shop.ShopId != shopId)
|
||||
if (mainShop != null && mainShop.ShopId != shopId)
|
||||
{
|
||||
BaseMsgForm.ShowError("cookie与店铺不匹配,请核对店铺!");
|
||||
return;
|
||||
}
|
||||
if (shop == null && GlobalConfig.ShopLoginList.Any(s=>s.ShopId == shopId))
|
||||
if (mainShop == null && GlobalConfig.ShopLoginList.Any(s=>s.ShopId == shopId))
|
||||
{
|
||||
BaseMsgForm.ShowError("录入的新店铺已存在,请核对店铺!");
|
||||
return;
|
||||
@@ -279,6 +325,69 @@ namespace TemuKJD.WXForms.ShopForms
|
||||
{
|
||||
cefWebBrowser.Forward();
|
||||
}
|
||||
|
||||
private void btnRefreshNum_Click(object sender, EventArgs e)
|
||||
{
|
||||
foreach (var shop in lstSwitchShop)
|
||||
{
|
||||
var switchInfo = lstSwitchInfo.FirstOrDefault(s => s.appid == shop.ShopId);
|
||||
var row = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(r => r.Cells["colShopId"].Value.ParseToString() == shop.ShopId);
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
row.Cells["colMessage"].Value = "-";
|
||||
}));
|
||||
|
||||
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
|
||||
if (shop.LoginStatus == "登录成功")
|
||||
{
|
||||
Thread.Sleep(100);
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
row.Cells["colMessage"].Value = "登录成功";
|
||||
}));
|
||||
continue;
|
||||
}
|
||||
|
||||
string jsStr1 = @"document.getElementsByClassName('shop-info-popover')[0].style ='';
|
||||
var divLst = document.getElementsByClassName('shop-info-popover')[0].getElementsByTagName('div');
|
||||
for (i=0; i<divLst.length; i++){
|
||||
if(divLst[i].innerHTML.indexOf('切换店铺') >= 0){
|
||||
divLst[i].click();
|
||||
//return 'success'
|
||||
}
|
||||
}";
|
||||
var t1 = cefWebBrowser.GetMainFrame().EvaluateScriptAsync(jsStr1);
|
||||
t1.Wait(5000);
|
||||
|
||||
Thread.Sleep(Randomx.GetId(500, 1000));
|
||||
jsStr1 = @"for (i=0; i<divLst.length; i++){
|
||||
if(divLst[i].innerHTML.indexOf('" + switchInfo.nickname + @"') >= 0){
|
||||
divLst[i].click();
|
||||
}
|
||||
}";
|
||||
t1 = cefWebBrowser.GetMainFrame().EvaluateScriptAsync(jsStr1);
|
||||
t1.Wait(5000);
|
||||
|
||||
Thread.Sleep(Randomx.GetId(2000, 3000));
|
||||
|
||||
|
||||
List<Cookie> cookieList = CEFBrowser.GetCookieList(shopCookieHead, cefWebBrowser.GetCookieManager(null));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void displayAuthStatus(ShopLoginInfo shop)
|
||||
{
|
||||
var rows = this.dgvShop.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colShopId"].Value.ParseToString() == shop?.ShopId);
|
||||
foreach (var row in rows)
|
||||
{
|
||||
bool canUse = row.Cells["colLoginStatus"].Value.ParseToString() == "在线";
|
||||
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).Style.ForeColor = canUse ? Color.Blue : Color.Red;
|
||||
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).LinkColor = canUse ? Color.Blue : Color.Red;
|
||||
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).ActiveLinkColor = canUse ? Color.LightBlue : Color.OrangeRed;
|
||||
(row.Cells["colLoginStatus"] as DataGridViewLinkCell).VisitedLinkColor = canUse ? Color.DarkBlue : Color.DarkRed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class WXShopSwitch
|
||||
|
||||
Reference in new issue
Block a user