using AllBase.Helper; using AllBase.Model.Result; using TemuKJD.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; using TemuKJD.BLL; namespace TemuKJD.WXForms.ShopForms { public enum SetCookieFromEnum { normal_user, sa, } public partial class WXShopUpdateCookieForm : BaseGeneralForm { ShopLoginInfo shopLoginInfo = null; SetCookieFromEnum updateFrom; string cookieVersion = ""; public WXShopUpdateCookieForm(ShopLoginInfo shop = null, SetCookieFromEnum from = SetCookieFromEnum.normal_user, string _cookieVersion="国内版") { InitializeComponent(); shopLoginInfo = shop; updateFrom = from; cookieVersion = _cookieVersion; this.TitleText = "更新Cookie"; } private void ShopUpdateCookieForm_Load(object sender, EventArgs e) { if (shopLoginInfo != null) txtLoginName.Text = shopLoginInfo.LoginName + " " + shopLoginInfo.ShopAccount + " " + shopLoginInfo.Notes; } /* document.cookie='_qimei_uuid42=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; document.cookie='_qpsvr_localtk=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; document.cookie='biz_magic=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; document.cookie='biz_rand=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; document.cookie='biz_ticket=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; document.cookie='biz_token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; document.cookie='ptcz=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; document.cookie='RK=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; document.cookie='yyb_muid=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'; document.cookie='_qimei_uuid42=19b0b09361e100c47695a05aaf3375f6d5eb35bb32; domain=.qq.com; expires=2026-11-11T01:54:30.000Z; path=/'; document.cookie='_qpsvr_localtk=5432784879518021; domain=.qq.com;expires=Fri, 06 Feb 2026 01:31:39 UTC; path=/'; document.cookie='biz_magic=4a425a343f033dd057463cfafc3e04b1531e36a25b0e99be21efce245c9129e8; domain=store.weixin.qq.com;expires=Fri, 06 Feb 2026 01:31:39 UTC; path=/'; document.cookie='biz_rand=CAESIMo2sjiyv4vip6jSSg+6B6Uh7gdgW4GBae7AEySSXswt; domain=store.weixin.qq.com;expires=Fri, 06 Feb 2026 01:31:39 UTC; path=/'; document.cookie='biz_ticket=; domain=store.weixin.qq.com;expires=Fri, 06 Feb 2026 01:31:39 UTC; path=/'; document.cookie='biz_token=b_0000019b_8e3d689c_f4835bf4_23267fa7_c4ff2be1; domain=store.weixin.qq.com;expires=Fri, 06 Feb 2026 01:31:39 UTC; path=/'; document.cookie='ptcz=584e5aff2216045382bfed928d03d10924787f910ea5a5e09e0df73b6c5e6c9d; domain=.qq.com;expires=2027-02-09T06:15:17.542Z; path=/'; document.cookie='RK=WCfEwM0OZQ; domain=.qq.com;expires=2026-07-30T07:12:51.627Z; path=/'; document.cookie='yyb_muid=3B8E28E6B8EA60762CCA3EF0B9EF61AB; domain=.qq.com; expires=2026-08-01T04:50:29.209Z; path=/'; window.location.href='https://store.weixin.qq.com/shop/goods/list'; */ private void btnOk_Click(object sender, EventArgs e) { if (shopLoginInfo == null) { BaseMsgForm.ShowError("店铺为空!"); return; } bool ok1 = false; bool ok2 = false; if (!string.IsNullOrWhiteSpace(txtSubPassId.Text) || !string.IsNullOrWhiteSpace(txtCookieJs1.Text)) { ok1 = GetCookie1(); } if (ok1 || ok2) { this.OnSaveComplete(shopLoginInfo); this.Close(); } } bool GetCookie1() { string txt = this.txtCookieJs1.Text; txt = txt.Replace("_qimei_uuid42=;", "").Replace("_qpsvr_localtk=;", "").Replace("biz_magic=;", "") .Replace("biz_rand=;", "").Replace("biz_ticket=;", "").Replace("biz_token=;", "") .Replace("ptcz=;", "").Replace("RK=;", "").Replace("yyb_muid=;", ""); List cookieLst = new List(); string _qimei_uuid42 = BaseRegex.GetStringCookie(ref txt, "_qimei_uuid42").ParseToString().Trim('\''); string _qpsvr_localtk = BaseRegex.GetStringCookie(ref txt, "_qpsvr_localtk").ParseToString().Trim('\''); string biz_magic = BaseRegex.GetStringCookie(ref txt, "biz_magic").ParseToString().Trim('\''); string biz_rand = BaseRegex.GetStringCookie(ref txt, "biz_rand").ParseToString().Trim('\''); string biz_ticket = BaseRegex.GetStringCookie(ref txt, "biz_ticket").ParseToString().Trim('\''); string biz_token = BaseRegex.GetStringCookie(ref txt, "biz_token").ParseToString().Trim('\''); string ptcz = BaseRegex.GetStringCookie(ref txt, "ptcz").ParseToString().Trim('\''); string RK = BaseRegex.GetStringCookie(ref txt, "RK").ParseToString().Trim('\''); string yyb_muid = BaseRegex.GetStringCookie(ref txt, "yyb_muid").ParseToString().Trim('\''); //cookieLst.Add(new CefSharp.Cookie() { Name = "_qimei_uuid42", Value = _qimei_uuid42, Domain = ".qq.com", Expires = DateTime.Now.AddMonths(1) }); //cookieLst.Add(new CefSharp.Cookie() { Name = "_qpsvr_localtk", Value = _qpsvr_localtk, Domain = ".qq.com", Expires = DateTime.Now.AddMonths(1) }); cookieLst.Add(new CefSharp.Cookie() { Name = "biz_magic", Value = biz_magic, Domain = "store.weixin.qq.com", Expires = DateTime.Now.AddMonths(1) }); cookieLst.Add(new CefSharp.Cookie() { Name = "biz_rand", Value = biz_rand, Domain = "store.weixin.qq.com", Expires = DateTime.Now.AddMonths(1) }); cookieLst.Add(new CefSharp.Cookie() { Name = "biz_ticket", Value = biz_ticket, Domain = "store.weixin.qq.com", Expires = DateTime.Now.AddMonths(1) }); cookieLst.Add(new CefSharp.Cookie() { Name = "biz_token", Value = biz_token, Domain = "store.weixin.qq.com", Expires = DateTime.Now.AddMonths(1) }); //cookieLst.Add(new CefSharp.Cookie() { Name = "ptcz", Value = ptcz, Domain = ".qq.com", Expires = DateTime.Now.AddMonths(1) }); //cookieLst.Add(new CefSharp.Cookie() { Name = "RK", Value = RK, Domain = ".qq.com", Expires = DateTime.Now.AddMonths(1) }); //cookieLst.Add(new CefSharp.Cookie() { Name = "yyb_muid", Value = yyb_muid, Domain = ".qq.com", Expires = DateTime.Now.AddMonths(1) }); if (string.IsNullOrEmpty(biz_magic)) { BaseMsgForm.ShowError("Cookie缺少关键字段,请检查!"); return false; } string chkRst = CheckCookieUpdate(shopLoginInfo, cookieLst); if (!string.IsNullOrEmpty(chkRst)) { BaseMsgForm.ShowError(chkRst); return false; } return true; } public static string CheckCookieUpdate(ShopLoginInfo shopLoginInfo, List cookieLst) { // 建立一个临时店铺并用这个店铺去登录 var cookieShop = new ShopLoginInfo(); cookieShop.Cookies = JsonHelper.SerializeObject(cookieLst); var data = ""; data = WXShopListForm.GetShopInfo(cookieShop); var index = data.IndexOf("window.__INITIAL_PINIA_DATA__=") + "window.__INITIAL_PINIA_DATA__=".Length; var indexEnd = data.IndexOf(";window.__USE_VITE__="); if (index < 1000) { return "cookie已失效!"; } var dataStr = data.Substring(index, indexEnd - index); dataStr = GetHtml.Unicode2String(dataStr); var shopId = BaseRegex.GetStringJson(ref data, "appid"); var nickName = BaseRegex.GetStringJson(ref data, "nickName"); if (shopLoginInfo.ShopId != shopId) { return "cookie与店铺不匹配,请核对店铺!"; } shopLoginInfo.Cookies = JsonHelper.SerializeObject(cookieLst); shopLoginInfo.ShopAccount = nickName; shopLoginInfo.LoginStatus = "登录成功"; WXShopListForm.UpdateServerShopCookies(shopLoginInfo); // 店铺cookie写入服务端,多店共用一个登录账号一组cookie return ""; } /// /// 如果店铺没有cookie登录过,处理店铺第一次登录(分裂cookie下的所有店铺) /// /// void GetShopFirstLogin(string loginData, List lstServerShop) { if (this.shopLoginInfo == null) return; if (lstServerShop == null) lstServerShop = new List(); List lstShopCompany = new List(); 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) ShopBLL.AdminAddServerShop(newShop); // 店铺写入到服务端 else ShopBLL.AddServerShop(newShop); // 店铺写入到服务端 } } } private void btnGetCookie_Click(object sender, EventArgs e) { //复制cookie var cookJs = @" document.body.innerHTML = '' + document.body.innerHTML; function geCookie() { var cookieText = document.cookie; navigator.clipboard.writeText(cookieText).then(function() { alert('复制cookie成功!'); }, function(err) { alert('复制cookie失败: ', err); }); }"; Clipboard.SetDataObject(cookJs); BaseMsgForm.ShowInfo("js复制成功"); } } }