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