29Wx状态初始化
This commit is contained in:
1 parent
9fd5579fcd
commit
40c702883c
322 files changed
+155553
No files matched your search
@@ -0,0 +1,181 @@
|
||||
using AllBase;
|
||||
using CefSharp;
|
||||
using NaiBa.CefHelper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.BuyUsers
|
||||
{
|
||||
public class ALBuyUser
|
||||
{
|
||||
public static Dictionary<BuyNumber, UserCookies> buyUserCookies = new Dictionary<BuyNumber, UserCookies>();//拍单买手号
|
||||
|
||||
private List<Cookie> cookies;
|
||||
public void DeleteAL()
|
||||
{
|
||||
var cookieManager = Cef.GetGlobalCookieManager();
|
||||
CEFBrowser.DeleteCookie(cookieManager, "1688.com");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存cookie
|
||||
/// </summary>
|
||||
public string SaveCookies(List<CefSharp.Cookie> cookie)
|
||||
{
|
||||
string cookies = "";
|
||||
|
||||
foreach (CefSharp.Cookie item in cookie)
|
||||
{
|
||||
cookies += item.Name + "=" + item.Value + ";";
|
||||
string mainDomain = GetHtml.GetMainDomain(item.Domain);
|
||||
if (BaseClass.CookiesAll.ContainsKey(mainDomain))
|
||||
{
|
||||
if (BaseClass.CookiesAll[mainDomain].ContainsKey(item.Name))
|
||||
BaseClass.CookiesAll[mainDomain][item.Name] = item.Value;
|
||||
else
|
||||
BaseClass.CookiesAll[mainDomain].Add(item.Name, item.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass.CookiesAll.Add(mainDomain, new Dictionary<string, string>());
|
||||
BaseClass.CookiesAll[mainDomain].Add(item.Name, item.Value);
|
||||
}
|
||||
}
|
||||
BaseClass.ChromeCookies = cookies;
|
||||
foreach (KeyValuePair<string, Dictionary<string, string>> co in BaseClass.CookiesAll) // 同步到系统
|
||||
{
|
||||
string cook = "";
|
||||
for (int i = 0; i < co.Value.Count; i++)
|
||||
{
|
||||
KeyValuePair<string, string> c = co.Value.ToArray()[i];
|
||||
if (c.Key == "x5sec")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(c.Value))
|
||||
{
|
||||
cook += c.Key + "=" + c.Value + "; ";
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(BaseClass.x5Sec))
|
||||
{
|
||||
cook += c.Key + "=" + BaseClass.x5Sec + "; ";
|
||||
}
|
||||
else
|
||||
{
|
||||
cook += c.Key + "=" + c.Value + "; ";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cook += c.Key + "=" + c.Value + "; ";
|
||||
}
|
||||
}
|
||||
if (BaseClass.CookiesAllString.ContainsKey(co.Key))
|
||||
BaseClass.CookiesAllString[co.Key] = cook;
|
||||
else
|
||||
BaseClass.CookiesAllString.Add(co.Key, cook);
|
||||
}
|
||||
string mainDomainx = "1688.com";
|
||||
string uid = BaseClass.CookiesAll[mainDomainx]["unb"];
|
||||
string name = BaseClass.CookiesAll[mainDomainx]["_nk_"];
|
||||
name = GetHtml.Decode(name.Replace("%5Cu", "\\u"));
|
||||
name = HttpUtility.UrlDecode(name);
|
||||
|
||||
|
||||
//string cookies = BaseClass.CookiesAllString["yangkeduo.com"];
|
||||
string url = BaseClass.DouYinBuildObjString("user_login_cookies&act=insert");
|
||||
StringBuilder data = new StringBuilder();
|
||||
data.Append("&user_name=" + name);
|
||||
data.Append("&site_id=3");
|
||||
data.Append("&user_id=" + uid);
|
||||
data.Append("&cookies=" + GetHtml.UrlEncodeUtf8(cookies));
|
||||
string html = GetHtml.PostUtf8(url, UserLogin.GetSignaturex() + data);
|
||||
BuyNumber buynumber = new BuyNumber(3, uid, name);
|
||||
List<Cookie> listcookie = new List<Cookie>();
|
||||
foreach (var item in cookie)
|
||||
{
|
||||
Cookie c = new Cookie();
|
||||
c.Domain = "1688.com";
|
||||
c.Expires = DateTime.Now.AddDays(10);
|
||||
c.Name = item.Name;
|
||||
c.Value = item.Value;
|
||||
c.Path = "/";
|
||||
listcookie.Add(c);
|
||||
}
|
||||
UserCookies uc = new UserCookies();
|
||||
uc.Cookies = listcookie;
|
||||
uc.UserName = name;
|
||||
uc.uid = uid;
|
||||
uc.SiteId = 3;
|
||||
uc.Times = 0;
|
||||
if (!buyUserCookies.ContainsKey(buynumber))
|
||||
buyUserCookies.Add(buynumber, uc);
|
||||
else
|
||||
buyUserCookies[buynumber] = uc;
|
||||
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void DelCookies(BuyNumber buynumber)
|
||||
{
|
||||
buyUserCookies.Remove(buynumber);
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加cookies到集合
|
||||
/// </summary>
|
||||
public void AddBuyUserCookies(string uid, string name, string cookies)
|
||||
{
|
||||
BuyNumber buynumber = new BuyNumber(3, uid, name);
|
||||
string[] l = cookies.Split(';');
|
||||
List<Cookie> cookie = new List<Cookie>();
|
||||
for (int j = 0; j < l.Length; j++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(l[j]) || !l[j].Contains("="))
|
||||
continue;
|
||||
string[] ll = l[j].Split('=');
|
||||
Cookie c = new Cookie();
|
||||
c.Domain = "1688.com";
|
||||
c.Expires = DateTime.Now.AddDays(10);
|
||||
c.Name = ll[0].Trim();
|
||||
c.Value = ll[1];
|
||||
c.Path = "/";
|
||||
cookie.Add(c);
|
||||
}
|
||||
UserCookies uc = new UserCookies();
|
||||
uc.Cookies = cookie;
|
||||
uc.UserName = name;
|
||||
uc.uid = uid;
|
||||
uc.SiteId = 3;
|
||||
uc.Times = 0;
|
||||
if (!buyUserCookies.ContainsKey(buynumber))
|
||||
buyUserCookies.Add(buynumber, uc);
|
||||
else
|
||||
buyUserCookies[buynumber] = uc;
|
||||
}
|
||||
|
||||
public bool SetAL(string uid, int siteid = -1)
|
||||
{
|
||||
var usercookie = buyUserCookies.ToList().Find(x => x.Value.uid == uid);
|
||||
if (siteid >= 0)
|
||||
{
|
||||
usercookie = buyUserCookies.ToList().Find(x => x.Value.uid == uid && x.Value.SiteId == siteid);
|
||||
}
|
||||
if (usercookie.Key == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
DeleteAL();
|
||||
cookies = usercookie.Value.Cookies;
|
||||
var cookieManager = Cef.GetGlobalCookieManager();
|
||||
//cookieManager.SetStoragePath(Environment.CurrentDirectory, true);
|
||||
|
||||
string domain = "1688.com";
|
||||
CEFBrowser.SetCookieAsync(Work.Helper.CEFHelper.CefCookieToCookieStr(cookies), cookieManager);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.BuyUsers
|
||||
{
|
||||
public class CookieVisitor : CefSharp.ICookieVisitor
|
||||
{
|
||||
public event Action<CefSharp.Cookie> SendCookie;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public bool Visit(CefSharp.Cookie cookie, int count, int total, ref bool deleteCookie)
|
||||
{
|
||||
deleteCookie = false;
|
||||
if (SendCookie != null)
|
||||
{
|
||||
SendCookie(cookie);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,340 @@
|
||||
using AllBase;
|
||||
using CefSharp;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.BuyUsers
|
||||
{
|
||||
public class PddBuyUser
|
||||
{
|
||||
public static Dictionary<BuyNumber, UserCookies> buyUserCookies = new Dictionary<BuyNumber, UserCookies>();//拍单买手号
|
||||
|
||||
private BuyNumber buynumber;
|
||||
private List<Cookie> Cookies;
|
||||
public void Set(string uid, string cookiesStr = "", int site = -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
KeyValuePair<BuyNumber, UserCookies> usercookie;
|
||||
if (site >= 0)
|
||||
{
|
||||
usercookie = buyUserCookies.First(x => x.Value.uid == uid && x.Value.SiteId == site);
|
||||
}
|
||||
else
|
||||
{
|
||||
usercookie = buyUserCookies.First(x => x.Value.uid == uid);
|
||||
}
|
||||
Cookies = usercookie.Value.Cookies;//UserCookies[mobile];
|
||||
Delete();
|
||||
var cookieManager = Cef.GetGlobalCookieManager();
|
||||
//cookieManager.SetStoragePath(Environment.CurrentDirectory, true);
|
||||
string domain = BaseClass.PddMobileUrlx;
|
||||
string cookiestr = "";
|
||||
foreach (Cookie c in Cookies)
|
||||
{
|
||||
cookiestr += c.Name + "=" + c.Value + ";";
|
||||
var cookie = new CefSharp.Cookie
|
||||
{
|
||||
Domain = c.Domain,
|
||||
Name = c.Name,
|
||||
Value = c.Value,
|
||||
Expires = DateTime.Now.AddDays(10),
|
||||
Path = "/"
|
||||
};
|
||||
try
|
||||
{
|
||||
Task<bool> task = cookieManager.SetCookieAsync(domain, cookie);
|
||||
while (!task.IsCompleted)
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
new Thread(Set).Start();
|
||||
|
||||
if (!BaseClass.CookiesAllString.ContainsKey("yangkeduo.com"))
|
||||
{
|
||||
BaseClass.CookiesAllString.Add("yangkeduo.com", cookiestr);
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass.CookiesAllString["pinduoduo.com"] = cookiestr;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 重试一次设置cookies
|
||||
/// </summary>
|
||||
public void Set()
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
try
|
||||
{
|
||||
var cookieManager = Cef.GetGlobalCookieManager();
|
||||
//cookieManager.SetStoragePath(Environment.CurrentDirectory, true);
|
||||
string domain = BaseClass.PddMobileUrlx;
|
||||
foreach (Cookie c in Cookies)
|
||||
{
|
||||
var cookie = new CefSharp.Cookie
|
||||
{
|
||||
Domain = c.Domain,
|
||||
Name = c.Name,
|
||||
Value = c.Value,
|
||||
Expires = DateTime.Now.AddDays(10),
|
||||
Path = "/"
|
||||
};
|
||||
Task<bool> task = cookieManager.SetCookieAsync(domain, cookie);
|
||||
while (!task.IsCompleted)
|
||||
{
|
||||
Thread.Sleep(1);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public void Delete()
|
||||
{
|
||||
var cookieManager = Cef.GetGlobalCookieManager();
|
||||
if (BaseClass.CookiesAllString.ContainsKey("yangkeduo.com"))
|
||||
{
|
||||
var cookies = BaseClass.CookiesAllString["yangkeduo.com"];
|
||||
string[] l = cookies.Split(';');
|
||||
for (int i = 0; i < l.Length; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(l[i]) || !l[i].Contains("="))
|
||||
continue;
|
||||
string name = l[i].Split('=')[0].Trim();
|
||||
try
|
||||
{
|
||||
cookieManager.DeleteCookies(BaseClass.PddMobileUrlx, name);
|
||||
//cookieManager.DeleteCookies(BaseClass.PddMobileUrlx, name);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void DelCookies(BuyNumber buynumber)
|
||||
{
|
||||
buyUserCookies.Remove(buynumber);
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存cookie
|
||||
/// </summary>
|
||||
public void SaveCookies(string uid, string name, List<CefSharp.Cookie> cookie)
|
||||
{
|
||||
string cookies = "";
|
||||
|
||||
foreach (CefSharp.Cookie item in cookie)
|
||||
{
|
||||
cookies += item.Name + "=" + item.Value + ";";
|
||||
string mainDomain = GetHtml.GetMainDomain(item.Domain);
|
||||
if (BaseClass.CookiesAll.ContainsKey(mainDomain))
|
||||
{
|
||||
if (BaseClass.CookiesAll[mainDomain].ContainsKey(item.Name))
|
||||
BaseClass.CookiesAll[mainDomain][item.Name] = item.Value;
|
||||
else
|
||||
BaseClass.CookiesAll[mainDomain].Add(item.Name, item.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass.CookiesAll.Add(mainDomain, new Dictionary<string, string>());
|
||||
BaseClass.CookiesAll[mainDomain].Add(item.Name, item.Value);
|
||||
}
|
||||
}
|
||||
BaseClass.ChromeCookies = cookies;
|
||||
foreach (KeyValuePair<string, Dictionary<string, string>> co in BaseClass.CookiesAll)//同步到系统
|
||||
{
|
||||
string cook = "";
|
||||
foreach (KeyValuePair<string, string> c in co.Value)
|
||||
{
|
||||
if (c.Key == "x5sec")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(c.Value))
|
||||
{
|
||||
cook += c.Key + "=" + c.Value + "; ";
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(BaseClass.x5Sec))
|
||||
{
|
||||
cook += c.Key + "=" + BaseClass.x5Sec + "; ";
|
||||
}
|
||||
else
|
||||
{
|
||||
cook += c.Key + "=" + c.Value + "; ";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cook += c.Key + "=" + c.Value + "; ";
|
||||
}
|
||||
}
|
||||
if (BaseClass.CookiesAllString.ContainsKey(co.Key))
|
||||
BaseClass.CookiesAllString[co.Key] = cook;
|
||||
else
|
||||
BaseClass.CookiesAllString.Add(co.Key, cook);
|
||||
}
|
||||
string mainDomainx = "yangkeduo.com";
|
||||
if (BaseClass.CookiesAll.ContainsKey("yangkeduo.com") && BaseClass.CookiesAll[mainDomainx].ContainsKey("pdd_user_id"))
|
||||
{
|
||||
BaseClass.PddUid = BaseClass.CookiesAll[mainDomainx]["pdd_user_id"];
|
||||
}
|
||||
|
||||
//string cookies = BaseClass.CookiesAllString["yangkeduo.com"];
|
||||
string url = BaseClass.DouYinBuildObjString("user_login_cookies&act=insert");
|
||||
StringBuilder data = new StringBuilder();
|
||||
data.Append("&user_name=" + name);
|
||||
data.Append("&site_id=0");
|
||||
data.Append("&user_id=" + uid);
|
||||
data.Append("&cookies=" + GetHtml.UrlEncodeUtf8(cookies));
|
||||
string html = GetHtml.PostUtf8(url, UserLogin.GetSignaturex() + data);
|
||||
BuyNumber buynumber = new BuyNumber(0, uid, name);
|
||||
List<Cookie> listcookie = new List<Cookie>();
|
||||
foreach (var item in cookie)
|
||||
{
|
||||
Cookie c = new Cookie();
|
||||
c.Domain = "yangkeduo.com";
|
||||
c.Expires = DateTime.Now.AddDays(10);
|
||||
c.Name = item.Name;
|
||||
c.Value = item.Value;
|
||||
c.Path = "/";
|
||||
listcookie.Add(c);
|
||||
}
|
||||
UserCookies uc = new UserCookies();
|
||||
uc.Cookies = listcookie;
|
||||
uc.UserName = name;
|
||||
uc.uid = uid;
|
||||
uc.SiteId = 0;
|
||||
uc.Times = 0;
|
||||
if (!buyUserCookies.ContainsKey(buynumber))
|
||||
buyUserCookies.Add(buynumber, uc);
|
||||
else
|
||||
buyUserCookies[buynumber] = uc;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加cookies到集合
|
||||
/// </summary>
|
||||
public void AddBuyUserCookies(string uid, string name, string cookies)
|
||||
{
|
||||
BuyNumber buynumber = new BuyNumber(0, uid, name);
|
||||
string[] l = cookies.Split(';');
|
||||
List<Cookie> cookie = new List<Cookie>();
|
||||
for (int j = 0; j < l.Length; j++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(l[j]) || !l[j].Contains("="))
|
||||
continue;
|
||||
string[] ll = l[j].Split('=');
|
||||
Cookie c = new Cookie();
|
||||
c.Domain = "yangkeduo.com";
|
||||
c.Expires = DateTime.Now.AddDays(10);
|
||||
c.Name = ll[0].Trim();
|
||||
c.Value = ll[1];
|
||||
c.Path = "/";
|
||||
cookie.Add(c);
|
||||
}
|
||||
UserCookies uc = new UserCookies();
|
||||
uc.Cookies = cookie;
|
||||
uc.UserName = name;
|
||||
uc.uid = uid;
|
||||
uc.SiteId = 0;
|
||||
uc.Times = 0;
|
||||
if (!buyUserCookies.ContainsKey(buynumber))
|
||||
buyUserCookies.Add(buynumber, uc);
|
||||
else
|
||||
buyUserCookies[buynumber] = uc;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public class BuyNumber
|
||||
{
|
||||
/// <summary>
|
||||
/// 1淘宝 2拼多多 3阿里巴巴 4京喜 6微店 7抖音 8拼多多批发
|
||||
/// </summary>
|
||||
public int site_id { get; set; }
|
||||
public string name { get; set; }
|
||||
public string uid { get; set; }
|
||||
public BuyNumber(int site_id, string uid, string name)
|
||||
{
|
||||
this.site_id = site_id;
|
||||
this.uid = uid;
|
||||
this.name = name;
|
||||
}
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var buynumber_class = (BuyNumber)obj;
|
||||
return buynumber_class.site_id == this.site_id && buynumber_class.name == this.name;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
try
|
||||
{
|
||||
int site_id_hashcode = site_id.GetHashCode();
|
||||
int name_hashcode = name.GetHashCode();
|
||||
return site_id_hashcode + name_hashcode;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class UserCookies
|
||||
{
|
||||
public string UserName = "";
|
||||
public string uid = "";
|
||||
public List<Cookie> Cookies = new List<Cookie>();
|
||||
public string CookiesStr
|
||||
{
|
||||
get
|
||||
{
|
||||
string cook = "";
|
||||
if (Cookies != null)
|
||||
foreach (var c in Cookies)
|
||||
cook += c.Name + "=" + c.Value + ";";
|
||||
return cook;
|
||||
}
|
||||
}
|
||||
public int SiteId = 0;
|
||||
public int Times = 0;
|
||||
}
|
||||
|
||||
public class ComboboxItem
|
||||
{
|
||||
public string Text { get; set; }
|
||||
public object Value { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Text;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,229 @@
|
||||
using AllBase;
|
||||
using CefSharp;
|
||||
using NaiBa.CefHelper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.BuyUsers
|
||||
{
|
||||
public class TaoBaoBuyUser
|
||||
{
|
||||
public static Dictionary<BuyNumber, UserCookies> buyUserCookies = new Dictionary<BuyNumber, UserCookies>();//拍单买手号
|
||||
public void DeleteTaoBao()
|
||||
{
|
||||
var cookieManager = Cef.GetGlobalCookieManager();
|
||||
if (BaseClass.CookiesAllString.ContainsKey("taobao.com"))
|
||||
{
|
||||
var cookies = BaseClass.CookiesAllString["taobao.com"];
|
||||
string[] l = cookies.Split(';');
|
||||
for (int i = 0; i < l.Length; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(l[i]) || !l[i].Contains("="))
|
||||
continue;
|
||||
string name = l[i].Split('=')[0].Trim();
|
||||
try
|
||||
{
|
||||
cookieManager.DeleteCookies("https://i.taobao.com/my_taobao.htm", name);
|
||||
cookieManager.DeleteCookies("https://login.taobao.com/member/login.jhtml", name);
|
||||
//cookieManager.Dispose();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
if (BaseClass.CookiesAllString.ContainsKey("tmall.com"))
|
||||
{
|
||||
var cookies = BaseClass.CookiesAllString["tmall.com"];
|
||||
string[] l = cookies.Split(';');
|
||||
for (int i = 0; i < l.Length; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(l[i]) || !l[i].Contains("="))
|
||||
continue;
|
||||
string name = l[i].Split('=')[0].Trim();
|
||||
try
|
||||
{
|
||||
cookieManager.DeleteCookies("https://i.taobao.com/my_taobao.htm", name);
|
||||
cookieManager.DeleteCookies("https://login.taobao.com/member/login.jhtml", name);
|
||||
//cookieManager.Dispose();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 保存cookie
|
||||
/// </summary>
|
||||
public void SaveCookies(List<CefSharp.Cookie> cookie)
|
||||
{
|
||||
string cookies = "";
|
||||
|
||||
foreach (CefSharp.Cookie item in cookie)
|
||||
{
|
||||
cookies += item.Name + "=" + item.Value + ";";
|
||||
string mainDomain = GetHtml.GetMainDomain(item.Domain);
|
||||
if (BaseClass.CookiesAll.ContainsKey(mainDomain))
|
||||
{
|
||||
if (BaseClass.CookiesAll[mainDomain].ContainsKey(item.Name))
|
||||
BaseClass.CookiesAll[mainDomain][item.Name] = item.Value;
|
||||
else
|
||||
BaseClass.CookiesAll[mainDomain].Add(item.Name, item.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
BaseClass.CookiesAll.Add(mainDomain, new Dictionary<string, string>());
|
||||
BaseClass.CookiesAll[mainDomain].Add(item.Name, item.Value);
|
||||
}
|
||||
}
|
||||
BaseClass.ChromeCookies = cookies;
|
||||
foreach (KeyValuePair<string, Dictionary<string, string>> co in BaseClass.CookiesAll)//同步到系统
|
||||
{
|
||||
string cook = "";
|
||||
for (int i = 0; i < co.Value.Count; i++)
|
||||
{
|
||||
KeyValuePair<string, string> c = co.Value.ToArray()[i];
|
||||
if (c.Key == "x5sec")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(c.Value))
|
||||
{
|
||||
cook += c.Key + "=" + c.Value + "; ";
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(BaseClass.x5Sec))
|
||||
{
|
||||
cook += c.Key + "=" + BaseClass.x5Sec + "; ";
|
||||
}
|
||||
else
|
||||
{
|
||||
cook += c.Key + "=" + c.Value + "; ";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cook += c.Key + "=" + c.Value + "; ";
|
||||
}
|
||||
}
|
||||
if (BaseClass.CookiesAllString.ContainsKey(co.Key))
|
||||
BaseClass.CookiesAllString[co.Key] = cook;
|
||||
else
|
||||
BaseClass.CookiesAllString.Add(co.Key, cook);
|
||||
}
|
||||
string mainDomainx = "taobao.com";
|
||||
string uid = BaseClass.CookiesAll[mainDomainx]["unb"];
|
||||
string name = BaseClass.CookiesAll[mainDomainx]["_nk_"];
|
||||
name = GetHtml.Decode(name.Replace("%5Cu", "\\u"));
|
||||
name = HttpUtility.UrlDecode(name);
|
||||
|
||||
|
||||
//string cookies = BaseClass.CookiesAllString["yangkeduo.com"];
|
||||
string url = BaseClass.DouYinBuildObjString("user_login_cookies&act=insert");
|
||||
StringBuilder data = new StringBuilder();
|
||||
data.Append("&user_name=" + name);
|
||||
data.Append("&site_id=1");
|
||||
data.Append("&user_id=" + uid);
|
||||
data.Append("&cookies=" + GetHtml.UrlEncodeUtf8(cookies));
|
||||
string html = GetHtml.PostUtf8(url, UserLogin.GetSignaturex() + data);
|
||||
BuyNumber buynumber = new BuyNumber(1, uid, name);
|
||||
List<Cookie> listcookie = new List<Cookie>();
|
||||
foreach (var item in cookie)
|
||||
{
|
||||
Cookie c = new Cookie();
|
||||
c.Domain = "taobao.com";
|
||||
c.Expires = DateTime.Now.AddDays(10);
|
||||
c.Name = item.Name;
|
||||
c.Value = item.Value;
|
||||
c.Path = "/";
|
||||
listcookie.Add(c);
|
||||
}
|
||||
UserCookies uc = new UserCookies();
|
||||
uc.Cookies = listcookie;
|
||||
uc.UserName = name;
|
||||
uc.uid = uid;
|
||||
uc.SiteId = 1;
|
||||
uc.Times = 0;
|
||||
if (!buyUserCookies.ContainsKey(buynumber))
|
||||
buyUserCookies.Add(buynumber, uc);
|
||||
else
|
||||
buyUserCookies[buynumber] = uc;
|
||||
}
|
||||
|
||||
public void DelCookies(BuyNumber buynumber)
|
||||
{
|
||||
buyUserCookies.Remove(buynumber);
|
||||
}
|
||||
/// <summary>
|
||||
/// 添加cookies到集合
|
||||
/// </summary>
|
||||
public void AddBuyUserCookies(string uid, string name, string cookies)
|
||||
{
|
||||
BuyNumber buynumber = new BuyNumber(1, uid, name);
|
||||
string[] l = cookies.Split(';');
|
||||
List<Cookie> cookie = new List<Cookie>();
|
||||
for (int j = 0; j < l.Length; j++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(l[j]) || !l[j].Contains("="))
|
||||
continue;
|
||||
string[] ll = l[j].Split('=');
|
||||
Cookie c = new Cookie();
|
||||
c.Domain = "taobao.com";
|
||||
c.Expires = DateTime.Now.AddDays(10);
|
||||
c.Name = ll[0].Trim();
|
||||
c.Value = ll[1];
|
||||
c.Path = "/";
|
||||
cookie.Add(c);
|
||||
}
|
||||
UserCookies uc = new UserCookies();
|
||||
uc.Cookies = cookie;
|
||||
uc.UserName = name;
|
||||
uc.uid = uid;
|
||||
uc.SiteId = 1;
|
||||
uc.Times = 0;
|
||||
if (!buyUserCookies.ContainsKey(buynumber))
|
||||
buyUserCookies.Add(buynumber, uc);
|
||||
else
|
||||
buyUserCookies[buynumber] = uc;
|
||||
}
|
||||
|
||||
public bool SetTaoBao(string userName, int siteid = 0)
|
||||
{
|
||||
var usercookie = buyUserCookies.ToList().Find(x => x.Value.uid == userName);
|
||||
if (siteid != 0)
|
||||
{
|
||||
usercookie = buyUserCookies.ToList().Find(x => x.Value.uid == userName && x.Key.site_id == siteid);
|
||||
}
|
||||
|
||||
if (usercookie.Key == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
DeleteTaoBao();
|
||||
var cookieManager = Cef.GetGlobalCookieManager();
|
||||
List<Cookie> cookies = usercookie.Value.Cookies.Where(c => !c.Domain.Contains("tmall")).ToList(); // UserCookies[userName].Cookies;
|
||||
//cookieManager.SetStoragePath(Environment.CurrentDirectory, true);
|
||||
|
||||
//string domain = "taobao.com";
|
||||
|
||||
//CEFBrowser.SetCookie(cookieManager, cookies); // 67版
|
||||
foreach (var cookie in cookies)
|
||||
CEFBrowser.SetCookieAsync(cookie.Domain, cookie.Name + "=" + cookie.Value + ";", cookieManager);
|
||||
|
||||
//PayMobileTb = userName;
|
||||
//if (!refundFlag)
|
||||
//{
|
||||
// MessageBox.Show("切换到账户:" + userName + " 成功", "提示");
|
||||
//}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user