230 lines
8.6 KiB
C#
230 lines
8.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 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.Build29WxObjString("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;
|
|
}
|
|
}
|
|
}
|