店铺登录逻辑处理
This commit is contained in:
1 parent
311971ca21
commit
89eb9ce9d4
8 files changed
+139
-75
No files matched your search
@@ -193,4 +193,14 @@ namespace AllBase.Model.Result
|
||||
public string brand_reg_num { get; set; }
|
||||
public long id { get; set; }
|
||||
}
|
||||
|
||||
// temu 一个登录账号下可以有多个店铺
|
||||
public class ShopCompany
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
public string LoginName { get; set; }
|
||||
public string AccountId { get; set; }
|
||||
public string AccountName { get; set; }
|
||||
public string LoginStatus { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
{
|
||||
//shop.ApiAuthStatus = "授权成功";
|
||||
ShopListForm.UpdateShopTokens(GlobalConfig.DouShopLoginList.Where(s => s.ShopAccount == shop.ShopAccount).ToList());
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
OnSaveComplete(shop);
|
||||
if (this.Created && this.chkCloseAfterLogin.Checked)
|
||||
{
|
||||
@@ -134,7 +134,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
if (this.Created && this.chkCloseAfterLogin.Checked)
|
||||
{
|
||||
ShopListForm.UpdateShopTokens(GlobalConfig.DouShopLoginList.Where(s => s.ShopAccount == shop.ShopAccount).ToList());
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
OnSaveComplete(shop);
|
||||
Thread.Sleep(2000);
|
||||
Invoke(new Action(() => { this.Close(); }));
|
||||
|
||||
@@ -37,6 +37,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
+ "&login_pass=" + GetHtml.UrlEncodeUtf8(_shop.Password)
|
||||
+ "&shop_id=" + _shop.ShopAccountId
|
||||
+ "&shop_account=" + _shop.ShopAccount
|
||||
+ "&cookie=" + _shop.Cookies
|
||||
+ "&shop_group=" + GetHtml.UrlEncodeUtf8(_shop.Group);
|
||||
|
||||
var result = GetHtml.PostUtf8(url, data);
|
||||
@@ -218,14 +219,12 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
/// <param name="shopName">店铺名称</param>
|
||||
/// <param name="shopCookies">cookies</param>
|
||||
/// <param name="fromTool">工具名称(可不填写)</param>
|
||||
public static void AddServerShopCookies(DouShopLoginInfo shop, string shopCookies, string fromTool = null)
|
||||
public static void UpdateServerShopCookies(DouShopLoginInfo shop, string shopCookies, string fromTool = null)
|
||||
{
|
||||
var fTool = string.IsNullOrEmpty(fromTool) ? "" : "&from_tool=" + fromTool;
|
||||
var url = BaseClass.BuildObjString("shop/mdy_shop");
|
||||
var data = UserLogin.GetSignaturex()
|
||||
+ "&login_name=" + shop.LoginName
|
||||
+ "&shop_id=" + shop.ShopAccountId
|
||||
+ "&shop_account=" + shop.ShopAccount
|
||||
+ "&cookie=" + shopCookies.Replace("&", "&").Replace("%", "%").Replace("+", "+")
|
||||
+ fTool;
|
||||
var result = GetHtml.PostUtf8(url, data);
|
||||
@@ -236,17 +235,17 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
BaseMsgForm.ShowError("服务端登录状态保存失败!请检查网络连接。");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取店铺Cookies
|
||||
/// </summary>
|
||||
/// <param name="shopNames">店铺名称,逗号隔开</param>
|
||||
public static string GetServerShopCookies(string shopNames)
|
||||
{
|
||||
var url = BaseClass.BuildObjString("shop&act=get_shop_cookie");
|
||||
var data = UserLogin.GetSignaturex() + "&shop_name=" + shopNames.Trim(',');
|
||||
var result = GetHtml.PostUtf8(url, data);
|
||||
return result;
|
||||
}
|
||||
///// <summary>
|
||||
///// 获取店铺Cookies
|
||||
///// </summary>
|
||||
///// <param name="shopNames">店铺名称,逗号隔开</param>
|
||||
//public static string GetServerShopCookies(string shopNames)
|
||||
//{
|
||||
// var url = BaseClass.BuildObjString("shop&act=get_shop_cookie");
|
||||
// var data = UserLogin.GetSignaturex() + "&shop_name=" + shopNames.Trim(',');
|
||||
// var result = GetHtml.PostUtf8(url, data);
|
||||
// return result;
|
||||
//}
|
||||
#endregion
|
||||
|
||||
public static string GetServerShopTokens(string shopLoginNames)
|
||||
@@ -280,13 +279,21 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
{
|
||||
if ((isAdd as bool?) == true)
|
||||
{
|
||||
ShopLoginForm shopLoginForm = new ShopLoginForm(shopInfo);
|
||||
shopLoginForm.SaveComplete += shopLoginForm_SaveComplete;
|
||||
shopLoginForm.Show();
|
||||
var shop = GlobalConfig.DouShopLoginList.FirstOrDefault(v => v.LoginName == shopInfo.LoginName);
|
||||
if (shop != null)
|
||||
{
|
||||
BaseMsgForm.ShowError("店铺" + shopInfo.LoginName + "已存在!");
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalConfig.DouShopLoginList.Add(shopInfo);
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
ShopListForm.AddServerDouShop(shopInfo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
ShopListForm.AddServerDouShop(shopInfo);
|
||||
shopLoginForm_SaveComplete(shopInfo);
|
||||
}
|
||||
@@ -356,7 +363,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
}
|
||||
else
|
||||
GlobalConfig.DouShopLoginList.Add(shop);
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
ShopListForm.AddServerDouShop(shop);
|
||||
}
|
||||
}
|
||||
@@ -423,7 +430,9 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
return;
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
DataGridViewRow dgvr = dgvShop.Rows.Cast<DataGridViewRow>().Where(p => p.Cells.GetCellValueFromColumnName("colLoginName").ParseToString() == param.LoginName).FirstOrDefault();
|
||||
DataGridViewRow dgvr = dgvShop.Rows.Cast<DataGridViewRow>().Where(p =>
|
||||
p.Cells.GetCellValueFromColumnName("colLoginName").ParseToString() == param.LoginName &&
|
||||
p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == param.ShopAccountId).FirstOrDefault();
|
||||
if (dgvr != null)
|
||||
{
|
||||
UpdateDataGridViewRowToken(dgvr, param);
|
||||
@@ -603,7 +612,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
if (!string.IsNullOrEmpty(loginResult))
|
||||
shop.LastRefreshDate = DateTime.Now.ToString("yyyyMMdd");
|
||||
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
AddDataGridViewRow(shop);
|
||||
}
|
||||
if (this.Created && isShowProgress)
|
||||
@@ -737,7 +746,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
return;
|
||||
DeleteShop(e.RowIndex);
|
||||
DelServerDouShop(shop.LoginName);
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
break;
|
||||
case "编辑":
|
||||
ShopAddEditForm editForm = new ShopAddEditForm(shop);
|
||||
@@ -788,8 +797,12 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
private void DeleteShop(int rowIndex)
|
||||
{
|
||||
string shopLoginName = this.dgvShop.Rows[rowIndex].Cells["colLoginName"].Value.ParseToString();
|
||||
dgvShop.Rows.RemoveAt(rowIndex);
|
||||
GlobalConfig.DouShopLoginList.RemoveAll(v => v.ShopAccount == shopLoginName);
|
||||
List<DataGridViewRow> dgvRows = dgvShop.Rows.Cast<DataGridViewRow>().Where(p =>
|
||||
p.Cells.GetCellValueFromColumnName("colLoginName").ParseToString() == shopLoginName).ToList();
|
||||
|
||||
foreach(var row in dgvRows)
|
||||
dgvShop.Rows.Remove(row);
|
||||
GlobalConfig.DouShopLoginList.RemoveAll(v => v.LoginName == shopLoginName);
|
||||
}
|
||||
|
||||
private void btnCheck_Click(object sender, EventArgs e)
|
||||
|
||||
@@ -10,6 +10,7 @@ using Microsoft.Win32;
|
||||
using NaiBa.CefHelper;
|
||||
using NaiBa.CefHelper.Handler;
|
||||
using NaiBa.Util.Extension;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@@ -42,6 +43,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
private string shopMainUrl = "https://seller.kuajingmaihuo.com";
|
||||
private ChromiumWebBrowser cefWebBrowser = null;
|
||||
private DouShopLoginInfo shop = null;
|
||||
private List<ShopCompany> lstShopCompany = new List<ShopCompany>();
|
||||
private string currentUrl = "";
|
||||
|
||||
public ShopLoginForm(DouShopLoginInfo shopInfo)
|
||||
@@ -109,17 +111,10 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
if (openType!= EnumOpenType.login)
|
||||
continue;
|
||||
|
||||
if (string.IsNullOrEmpty(shop.ShopAccountId) || string.IsNullOrEmpty(shop.ShopAccount))
|
||||
if (!lstShopCompany.Any(c => c.LoginName == shop.LoginName))
|
||||
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);
|
||||
string cookies = "";
|
||||
List<Cookie> cookieList = CEFBrowser.GetCookieList(shopCookieHead, cefWebBrowser.RequestContext.GetCookieManager(null));
|
||||
if (cookieList != null && cookieList.Count > 0)
|
||||
@@ -133,37 +128,69 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
}
|
||||
cookies = cookies.Trim().TrimEnd(';');
|
||||
}
|
||||
shop.Cookies = 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)
|
||||
)
|
||||
if (!string.IsNullOrEmpty(cookies)
|
||||
&& lstShopCompany.Any(c => c.LoginName == shop.LoginName))
|
||||
{
|
||||
shop.LoginStatus = "登录成功";
|
||||
var lstShopCompanyCopy = lstShopCompany.ToList();
|
||||
//var shopCompany = lstShopCompany.FirstOrDefault(c=>c.LoginName==shop.LoginName);
|
||||
//if (shopCompany == null)
|
||||
// shopCompany = new ShopCompany();
|
||||
|
||||
shop.LastRefreshDate = DateTime.Now.ToString("yyyyMMdd");
|
||||
var shopInfo = GlobalConfig.DouShopLoginList.FirstOrDefault(v => v.ShopAccountId == shop.ShopAccountId);
|
||||
if (shopInfo != null)
|
||||
//shop.LoginStatus = "登录成功";
|
||||
//shop.ShopAccountId = shopCompany.AccountId;
|
||||
//shop.ShopAccount = shopCompany.AccountName;
|
||||
//shop.Cookies = cookies;
|
||||
|
||||
//shop.LastRefreshDate = DateTime.Now.ToString("yyyyMMdd");
|
||||
//var shopInfo = GlobalConfig.DouShopLoginList.FirstOrDefault(v => v.ShopAccountId == shop.ShopAccountId);
|
||||
//if (shopInfo != null)
|
||||
//{
|
||||
// shopInfo.Cookies = shop.Cookies;
|
||||
// shopInfo.Password = shop.Password;
|
||||
// shopInfo.ShopAccountId = shop.ShopAccountId;
|
||||
// shopInfo.ShopAccount = shop.ShopAccount;
|
||||
//}
|
||||
//else
|
||||
// GlobalConfig.DouShopLoginList.Add(shop);
|
||||
//StartUp.SaveLocalShopLoginInfo();
|
||||
////ShopListForm.AddServerDouShop(shop); // 店铺写入到服务端
|
||||
//ShopListForm.UpdateServerShopCookies(shop, shop.Cookies); // cookie写入到服务端
|
||||
|
||||
foreach (ShopCompany sc in lstShopCompanyCopy)
|
||||
{
|
||||
//shopInfo.ShopToken = shop.ShopToken;
|
||||
//shopInfo.Mobile = shop.Mobile;
|
||||
shopInfo.Cookies = shop.Cookies;
|
||||
shopInfo.Password = shop.Password;
|
||||
shopInfo.ShopAccountId = shop.ShopAccountId;
|
||||
shopInfo.ShopAccount = shop.ShopAccount;
|
||||
DouShopLoginInfo newShop = new DouShopLoginInfo()
|
||||
{
|
||||
LoginName = shop.LoginName,
|
||||
Password = shop.Password,
|
||||
Group = shop.Group,
|
||||
LoginStatus = "登录成功",
|
||||
ShopAccount = sc.AccountName,
|
||||
ShopAccountId = sc.AccountId,
|
||||
Cookies = cookies,
|
||||
};
|
||||
|
||||
var oldShop = GlobalConfig.DouShopLoginList.FirstOrDefault(l =>
|
||||
l.LoginName == newShop.LoginName && l.ShopAccountId == newShop.ShopAccountId);
|
||||
if (oldShop == null)
|
||||
{
|
||||
GlobalConfig.DouShopLoginList.Add(newShop);
|
||||
ShopListForm.AddServerDouShop(newShop); // 店铺写入到服务端
|
||||
}
|
||||
else
|
||||
{
|
||||
oldShop.LoginName = shop.LoginName;
|
||||
oldShop.Password = shop.Password;
|
||||
oldShop.Group = shop.Group;
|
||||
oldShop.LoginStatus = "登录成功";
|
||||
oldShop.ShopAccount = sc.AccountName;
|
||||
oldShop.ShopAccountId = sc.AccountId;
|
||||
oldShop.Cookies = cookies;
|
||||
}
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
ShopListForm.UpdateServerShopCookies(newShop, newShop.Cookies);
|
||||
}
|
||||
else
|
||||
GlobalConfig.DouShopLoginList.Add(shop);
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
//ShopListForm.AddServerDouShop(shop); // 店铺写入到服务端
|
||||
ShopListForm.AddServerShopCookies(shop, shop.Cookies); // cookie写入到服务端
|
||||
|
||||
OnSaveComplete(shop);
|
||||
if (this.Created && this.chkCloseAfterLogin.Checked)
|
||||
{
|
||||
@@ -359,10 +386,24 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms
|
||||
var maskMobile = BaseRegex.GetStringJson(ref data, "maskOwnerMobile");
|
||||
if (shop.LoginName.EndsWith(maskMobile))
|
||||
{
|
||||
shop.ShopAccountId = BaseRegex.GetStringJson(ref data, "mallId");
|
||||
shop.ShopAccount = BaseRegex.GetStringJson(ref data, "mallName");
|
||||
//shop.ShopToken = BaseRegex.GetStringJson(ref data, "token");
|
||||
//shop.Mobile = BaseRegex.GetStringJson(ref data, "mobile");
|
||||
lstShopCompany.Clear();
|
||||
var jObj = JObject.Parse(data);
|
||||
var jArr = jObj["result"]?["companyList"]?[0]?["malInfoList"] as JArray;
|
||||
if (jArr == null)
|
||||
jArr = new JArray();
|
||||
foreach (var productObj in jArr)
|
||||
{
|
||||
var prod = JsonHelper.SerializeObject(productObj);
|
||||
ShopCompany sc = new ShopCompany()
|
||||
{
|
||||
AccountId = BaseRegex.GetStringJson(ref prod, "mallId"),
|
||||
AccountName = BaseRegex.GetStringJson(ref prod, "mallName"),
|
||||
LoginName = shop.LoginName,
|
||||
UserName = BaseClass.UserName,
|
||||
LoginStatus = "登录成功",
|
||||
};
|
||||
this.lstShopCompany.Add(sc);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -716,7 +757,7 @@ function fireKeyEvent(el, evtType, keyCode) {
|
||||
if (shop != null)
|
||||
{
|
||||
shop.DictMultiCookies.Remove(cmbMultiCookieName.Text);
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
|
||||
InitMultiLoginCookies();
|
||||
}
|
||||
|
||||
@@ -689,7 +689,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms
|
||||
break;
|
||||
if (dyShop.LoginStatus == "未登录")
|
||||
{
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
dyShop = GlobalConfig.DouShopLoginList.FirstOrDefault(s => s.LoginStatus == "登录成功");
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
@@ -2075,7 +2075,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms
|
||||
if (result.Contains("已过期"))
|
||||
{
|
||||
shop.ApiAuthStatus = "未授权";
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2130,7 +2130,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms
|
||||
BaseMsgForm.ShowInfo("获取类目失败!");
|
||||
}
|
||||
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("cat_dy", list);
|
||||
return list;
|
||||
}
|
||||
@@ -2576,7 +2576,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms
|
||||
while (propResult.Contains("已过期"))
|
||||
{
|
||||
dyShop.ApiAuthStatus = "未授权";
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
dyShop = GlobalConfig.DouShopLoginList.FirstOrDefault(s => s.ApiAuthStatus == "授权成功");
|
||||
if (dyShop == null)
|
||||
{
|
||||
|
||||
@@ -304,7 +304,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms
|
||||
if (result.Contains("已过期"))
|
||||
{
|
||||
shop.ApiAuthStatus = "未授权";
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
GoodsCategoryModel cat = new GoodsCategoryModel()
|
||||
{
|
||||
enable = true,
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms
|
||||
Thread.Sleep(Randomx.GetId(50, 150));
|
||||
}
|
||||
if (shopList.Count() > 0)
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
if (isShowProgress)
|
||||
@@ -1594,7 +1594,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms
|
||||
if (shop.PayStatus != 1)
|
||||
{
|
||||
shop.TrialOperateCount++;
|
||||
StartUp.SaveDouShopLoginInfo();
|
||||
StartUp.SaveLocalShopLoginInfo();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -85,10 +85,10 @@ namespace LittleRabbit
|
||||
localDouShopList.AddRange(serverDouShopList);
|
||||
foreach (var localShop in localDouShopList)
|
||||
{
|
||||
if (GlobalConfig.DouShopLoginList.Any(s => s.LoginName == localShop.LoginName))
|
||||
if (GlobalConfig.DouShopLoginList.Any(s => s.LoginName == localShop.LoginName && s.ShopAccountId == localShop.ShopAccountId))
|
||||
continue;
|
||||
|
||||
var serverShop = serverDouShopList.FirstOrDefault(s => s.LoginName == localShop.LoginName);
|
||||
var serverShop = serverDouShopList.FirstOrDefault(s => s.LoginName == localShop.LoginName && s.ShopAccountId == localShop.ShopAccountId);
|
||||
if (serverShop != null)
|
||||
{
|
||||
localShop.ShopAccount = serverShop.ShopAccount;
|
||||
@@ -450,7 +450,7 @@ namespace LittleRabbit
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("fission_setting_param", GlobalConfig.FissionSettingParam);
|
||||
}
|
||||
|
||||
public static void SaveDouShopLoginInfo()
|
||||
public static void SaveLocalShopLoginInfo()
|
||||
{
|
||||
ConcurrentList<DouShopLoginInfo> shopLoginListCopy =
|
||||
JsonHelper.DeserializeJsonToObject<ConcurrentList<DouShopLoginInfo>>(JsonHelper.SerializeObject(GlobalConfig.DouShopLoginList));
|
||||
|
||||
Reference in new issue
Block a user