using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using CefSharp; using CefSharp.WinForms; using WindowsFormsApp1.utils.tb; using static System.Collections.Specialized.NameObjectCollectionBase; namespace WindowsFormsApp1 { public partial class TBLogin : Form { public ChromiumWebBrowser browser; private int position; private void init() { InitializeComponent(); initBrowser(); } public TBLogin() { init(); } delegate void ChangeShow(bool show); void setShow(bool show) { //this.Visible = show; if (!show) { this.Visible = false; } else { browser.Reload(); } } public void changeShow() { int i = 0; while (true) { Thread.Sleep(10000); i++; if (i == 1) { this.BeginInvoke(new ChangeShow(setShow), false); } else { this.BeginInvoke(new ChangeShow(setShow), true); } } } public TBLogin(int position) { this.position = position; init(); Thread th = new Thread(changeShow); th.Start(); this.Visible = false; } private void initBrowser() { string url = "http://login.taobao.com/member/login.jhtml?style=mini&newMini2=true&redirectURL=https%3a%2f%2fm.tb.cn%2fh.VOj5T1G%3fsm%3d7d686c&full_redirect=true&disableQuickLogin=true"; url = "https://m.tb.cn/h.VN61jro?sm=9ed9c4"; var setting = new RequestContextSettings() { CachePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "BKZ\\Cache_tb_" + position), PersistSessionCookies = true, PersistUserPreferences = true }; var context = new RequestContext(setting); var cookieManager = context.GetCookieManager(null); browser = new ChromiumWebBrowser(url, context); browser.RequestHandler = new TBLoginRequestHandler("https://h5api.m.tmall.com/h5/mtop.tmall.kangaroo.core.service.route.pagerecommendservice/1.0/?", new TBLoginCallBack(this)); this.Controls.Add(browser); browser.Dock = DockStyle.Fill; } class TBLoginCallBack : IGetTBCookieListener { private Form form; public TBLoginCallBack(Form form) { this.form = form; } public void onSuccess(Dictionary cookiesMap, String cookies) { //this.form.Visible = false; //this.form.Close(); } } } }