341 lines
11 KiB
C#
341 lines
11 KiB
C#
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.Build29WxObjString("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;
|
|
}
|
|
}
|
|
}
|