Files
KJD/TEMUKJD/KJDForms/ShopForms/ShopUpdateCookieForm.cs
T
2025-07-22 16:57:02 +08:00

265 lines
12 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AllBase.Helper;
using AllBase.Model.Result;
using TemuKJD.KJDForms.BaseForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AllBase;
using NaiBa.Util.Extension;
using Newtonsoft.Json.Linq;
using Work;
using TemuKJD.KJDForms.AdminForms;
namespace TemuKJD.KJDForms.ShopForms
{
public enum SetCookieFromEnum
{
normal_user,
sa,
}
public partial class ShopUpdateCookieForm : LRBaseForm
{
ShopLoginInfo shopLoginInfo = null;
SetCookieFromEnum updateFrom;
public ShopUpdateCookieForm(ShopLoginInfo shop = null, SetCookieFromEnum from = SetCookieFromEnum.normal_user)
{
InitializeComponent();
shopLoginInfo = shop;
updateFrom = from;
}
private void ShopUpdateCookieForm_Load(object sender, EventArgs e)
{
if (shopLoginInfo != null)
txtLoginName.Text = shopLoginInfo.LoginName + " " + shopLoginInfo.ShopAccount + " " + shopLoginInfo.Notes;
}
/*
localStorage.clear();
sessionStorage.clear();
var cookieDate = new Date(2037, 01, 01);
var cookieDateEnd = new Date(2000, 01, 01);
document.cookie = "SUB_PASS_ID=; path='/'; expires=" + cookieDateEnd.toUTCString();
document.cookie = "_nano_fp=; path='/'; expires=" + cookieDateEnd.toUTCString();
document.cookie = "api_uid=; path='/'; domain=.kuajingmaihuo.com; expires=" + cookieDateEnd.toUTCString();
document.cookie = "_bee=; path='/'; domain=.kuajingmaihuo.com; expires=" + cookieDateEnd.toUTCString();
document.cookie = "ru2k=; path='/'; domain=.kuajingmaihuo.com; expires=" + cookieDateEnd.toUTCString();
document.cookie = "_f77=; path='/'; domain=.kuajingmaihuo.com; expires=" + cookieDateEnd.toUTCString();
document.cookie = "_a42=; path='/'; domain=.kuajingmaihuo.com; expires=" + cookieDateEnd.toUTCString();
document.cookie = "rckk=; path='/'; domain=.kuajingmaihuo.com; expires=" + cookieDateEnd.toUTCString();
document.cookie = "ru1k=; path='/'; domain=.kuajingmaihuo.com; expires=" + cookieDateEnd.toUTCString();
document.cookie = "api_uid=CmP1wGhwa64RUwBSBILCAg==; path='/'; expires=" + cookieDate.toUTCString();
document.cookie = "_nano_fp=XpmyX5gbl09jlpdoXo_mijphq7nL0UmRaA77jyt3; domain=.kuajingmaihuo.com; path='/'; expires=" + cookieDate.toUTCString();
document.cookie = "_bee=NkjhfozSFfDuGSJ2zBlOqjOh3KVvJam3; path='/'; expires=" + cookieDate.toUTCString();
document.cookie = "_f77=2f854ce8-8d0f-4a78-84a1-04e19842a1cb; path='/'; expires=" + cookieDate.toUTCString();
document.cookie = "_a42=1e97ae4a-c357-4c22-a53f-db43655371e3; path='/'; expires=" + cookieDate.toUTCString();
document.cookie = "rckk=NkjhfozSFfDuGSJ2zBlOqjOh3KVvJam3; path='/'; expires=" + cookieDate.toUTCString();
document.cookie = "ru1k=2f854ce8-8d0f-4a78-84a1-04e19842a1cb; path='/'; expires=" + cookieDate.toUTCString();
document.cookie = "ru2k=1e97ae4a-c357-4c22-a53f-db43655371e3; path='/'; expires=" + cookieDate.toUTCString();
document.cookie = "SUB_PASS_ID=eyJ0IjoiRDZZY1F2N2JjMnZNK1E0eEZjTm1GVmxsN20yN3N3Ymg2dnVjdmxiclZPQW5uRkJlendUOUtKTHRoWHJyZWlNUCIsInYiOjEsInMiOjEwMDAwLCJ1IjoyMzAxMjcwOTkwNDI5OH0=; domain=.kuajingmaihuo.com; path='/'; expires=" + cookieDate.toUTCString();
location.reload();
window.location.href = 'https://seller.kuajingmaihuo.com/goods/product/list';
*/
private void btnOk_Click(object sender, EventArgs e)
{
if (shopLoginInfo == null)
{
BaseMsgForm.ShowError("店铺为空!");
return;
}
string txt = this.txtCookieJs.Text;
txt = txt.Replace("SUB_PASS_ID=;", "").Replace("_nano_fp=;", "").Replace("api_uid=;", "")
.Replace("_bee=;", "").Replace("ru2k=;", "").Replace("_f77=;", "")
.Replace("_a42=;", "").Replace("rckk=;", "").Replace("ru1k=;", "");
string api_uid = BaseRegex.GetStringCookie(ref txt, "api_uid").ParseToString().Trim('\'');
string _nano_fp = BaseRegex.GetStringCookie(ref txt, "_nano_fp").ParseToString().Trim('\'');
string _bee = BaseRegex.GetStringCookie(ref txt, "_bee").ParseToString().Trim('\'');
string _f77 = BaseRegex.GetStringCookie(ref txt, "_f77").ParseToString().Trim('\'');
string _a42 = BaseRegex.GetStringCookie(ref txt, "_a42").ParseToString().Trim('\'');
string rckk = BaseRegex.GetStringCookie(ref txt, "rckk").ParseToString().Trim('\'');
string ru1k = BaseRegex.GetStringCookie(ref txt, "ru1k").ParseToString().Trim('\'');
string ru2k = BaseRegex.GetStringCookie(ref txt, "ru2k").ParseToString().Trim('\'');
string SUB_PASS_ID = BaseRegex.GetStringCookie(ref txt, "SUB_PASS_ID").ParseToString().Trim('\'');
string cookie = "api_uid=" + api_uid + ";" +
"_nano_fp=" + _nano_fp + ";" +
"_bee=" + _bee + ";" +
"_f77=" + _f77 + ";" +
"_a42=" + _a42 + ";" +
"rckk=" + rckk + ";" +
"ru1k=" + ru1k + ";" +
"ru2k=" + ru2k + ";" +
"SUB_PASS_ID=" + SUB_PASS_ID + ";";
if (string.IsNullOrEmpty(SUB_PASS_ID))
{
BaseMsgForm.ShowError("Cookie缺少关键字段,请检查!");
return;
}
var cookieShop = new ShopLoginInfo();
cookieShop.Cookies = cookie;
var data = ShopListForm.GetShopStatus(cookieShop);
if (!data.Contains("\"success\":true"))
{
BaseMsgForm.ShowError("cookie已失效!");
return;
}
var maskMobile = BaseRegex.GetStringJson(ref data, "maskOwnerMobile");
if (!shopLoginInfo.LoginName.EndsWith(maskMobile))
{
BaseMsgForm.ShowError("cookie与店铺不匹配,请核对店铺!");
return;
}
List<ShopLoginInfo> serverShopLst = new List<ShopLoginInfo>();
var rst = AdminGetServerShopListForSetCookie(shopLoginInfo, serverShopLst);
if (rst != "success")
{
BaseMsgForm.ShowError(rst);
return;
}
//如果店铺没有cookie登录过,处理店铺第一次登录(分裂cookie下的所有店铺)
GetShopFirstLogin(data, serverShopLst);
if (updateFrom == SetCookieFromEnum.normal_user) // 普通用户更新本地店铺
{
var localShop = GlobalConfig.ShopLoginList.Where(v => v.LoginName == shopLoginInfo.LoginName).ToList();
foreach (var sc in localShop)
{
sc.Cookies = cookie;
sc.LoginStatus = "登录成功";
}
}
shopLoginInfo.Cookies = cookie;
shopLoginInfo.LoginStatus = "登录成功";
ShopListForm.UpdateServerShopCookies(shopLoginInfo, shopLoginInfo.Cookies); // 店铺cookie写入服务端,多店共用一个登录账号一组cookie
this.OnSaveComplete(shopLoginInfo);
this.Close();
}
/// <summary>
/// 如果店铺没有cookie登录过,处理店铺第一次登录(分裂cookie下的所有店铺)
/// </summary>
/// <param name="loginData"></param>
void GetShopFirstLogin(string loginData, List<ShopLoginInfo> lstServerShop)
{
if (this.shopLoginInfo == null)
return;
if (lstServerShop == null)
lstServerShop = new List<ShopLoginInfo>();
List<ShopCompany> lstShopCompany = new List<ShopCompany>();
var jObj = JObject.Parse(loginData);
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 = shopLoginInfo.LoginName,
UserName = BaseClass.UserName,
LoginStatus = "登录成功",
};
lstShopCompany.Add(sc);
}
var lstShopCompanyCopy = lstShopCompany.ToList();
foreach (ShopCompany sc in lstShopCompanyCopy)
{
ShopLoginInfo newShop = new ShopLoginInfo()
{
UserName = shopLoginInfo.UserName,
LoginName = shopLoginInfo.LoginName,
Password = shopLoginInfo.Password,
GroupName = shopLoginInfo.GroupName,
ShopAccount = sc.AccountName,
ShopId = sc.AccountId,
SubUserName = shopLoginInfo.SubUserName,
Notes = shopLoginInfo.Notes,
};
var oldServerShop = lstServerShop.FirstOrDefault(s =>
s.LoginName == newShop.LoginName && s.ShopId == newShop.ShopId);
if (oldServerShop == null)
{
if (updateFrom != SetCookieFromEnum.normal_user)
AdminShopForm.AdminAddServerShop(newShop); // 店铺写入到服务端
else
ShopListForm.AddServerDouShop(newShop); // 店铺写入到服务端
}
}
}
public static string AdminGetServerShopListForSetCookie(ShopLoginInfo loginShop, List<ShopLoginInfo> lstRst)
{
if (lstRst == null)
lstRst = new List<ShopLoginInfo>();
var url = BaseClass.BuildObjString("shop/admin_get_shop_list");
var data = UserLogin.GetSignaturex() +
"&search_user_name=" + loginShop.UserName +
"&search_login_name=" + loginShop.LoginName;
var html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html)
|| !html.Contains("shop_id") || !html.Contains("shop_account") || !html.Contains("login_pass"))
{
return "获取失败:" + BaseRegex.GetStringJson(ref html, "msg");
}
var jArr = JObject.Parse(html)["data"];
if (jArr.Count() == 0)
return "获取失败:未获取到data数据";
foreach (JObject jObj in jArr)
{
string shopStr = jObj.ToString();
ShopLoginInfo shop = new ShopLoginInfo();
shop.DbId = BaseRegex.GetStringJson(ref shopStr, "id");
if (shop.DbId == null)
continue;
shop.LoginName = BaseRegex.GetStringJson(ref shopStr, "login_name");
shop.Password = BaseRegex.GetStringJson(ref shopStr, "login_pass");
shop.ShopId = BaseRegex.GetStringJson(ref shopStr, "shop_id");
shop.ShopAccount = BaseRegex.GetStringJson(ref shopStr, "shop_account");
shop.UserName = BaseRegex.GetStringJson(ref shopStr, "user_name");
shop.SubUserName = BaseRegex.GetStringJson(ref shopStr, "sub_user_name");
shop.GroupName = BaseRegex.GetStringJson(ref shopStr, "shop_group");
shop.Cookies = BaseRegex.GetStringJson(ref shopStr, "cookie");
shop.Cookies = shop.Cookies.Replace("&", "&").Replace("%", "%").Replace("+", "+");
shop.CompanyName = BaseRegex.GetStringJson(ref shopStr, "company_name");
shop.Notes = BaseRegex.GetStringJson(ref shopStr, "notes");
shop.LoginStatus = BaseRegex.GetStringJson(ref shopStr, "login_status");
shop.OperateSubSaName = BaseRegex.GetStringJson(ref shopStr, "operate_sub_sa_name");
lstRst.Add(shop);
}
return "success";
}
}
}