| | |
| | | using CefSharp.WinForms; |
| | | using WindowsFormsApp1.utils.tb; |
| | | using static System.Collections.Specialized.NameObjectCollectionBase; |
| | | using WindowsFormsApp1.entity.tb; |
| | | using WindowsFormsApp1.utils; |
| | | |
| | | namespace WindowsFormsApp1 |
| | | { |
| | | |
| | | public delegate void TBLoginSuccessDelegate(); |
| | | public partial class TBLogin : Form |
| | | { |
| | | public ChromiumWebBrowser browser; |
| | | private int position; |
| | | |
| | | private bool hasShown=false;//是否已经展示过 |
| | | |
| | | public bool HasShown { |
| | | get { return this.hasShown; } |
| | | } |
| | | |
| | | private void init() |
| | | { |
| | | InitializeComponent(); |
| | | initBrowser(); |
| | | InitBrowser(); |
| | | this.timer1.Start(); |
| | | } |
| | | |
| | | public TBLogin() |
| | |
| | | //this.Visible = show; |
| | | if (!show) |
| | | { |
| | | this.Visible = false; |
| | | //准备要刷新的链接 |
| | | if (this.Visible) { |
| | | browser.Load("https://m.tb.cn/h.VN61jro?sm=9ed9c4"); |
| | | this.Visible = false; |
| | | hasShown = true; |
| | | if (this.loginSuccess != null) |
| | | this.loginSuccess(); |
| | | } |
| | | |
| | | |
| | | } |
| | | 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) |
| | | public TBLogin(int position ) |
| | | { |
| | | this.position = position; |
| | | init(); |
| | | Thread th = new Thread(changeShow); |
| | | th.Start(); |
| | | |
| | | this.Visible = false; |
| | | |
| | | } |
| | | |
| | | private void initBrowser() |
| | | private TBLoginSuccessDelegate loginSuccess; |
| | | public void SetTBLoginSuccess(TBLoginSuccessDelegate loginSuccess) { |
| | | this.loginSuccess = loginSuccess; |
| | | } |
| | | |
| | | 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), |
| | |
| | | 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)); |
| | | TBCookieDelegate tbCookieDelegate = setCookies; |
| | | |
| | | |
| | | browser.RequestHandler = new TBLoginRequestHandler("https://h5api.m.tmall.com/h5/mtop.tmall.kangaroo.core.service.route.aldlampservicefixedres/1.0/?", tbCookieDelegate); |
| | | |
| | | this.Controls.Clear(); |
| | | 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<String, String> cookiesMap, String cookies) |
| | | { |
| | | public void ReLogin() { |
| | | this.Visible = true; |
| | | InitBrowser(); |
| | | } |
| | | |
| | | //this.form.Visible = false; |
| | | //this.form.Close(); |
| | | |
| | | |
| | | //刷新Cookie |
| | | public void RefeshCookie() {//登录是否有效 |
| | | if (TBCookieUtil.IsLoginValid(position)) |
| | | { |
| | | Console.WriteLine(position + ":刷新Cookie"); |
| | | String url = "https://m.tb.cn/h.VN61jro?sm=9ed9c4"; |
| | | CefSharp.WebBrowserExtensions.Reload(browser, true); |
| | | } |
| | | } |
| | | |
| | | |
| | | private void setCookies(Dictionary<String, String> cookiesMap, String cookies,String url) { |
| | | |
| | | if (!Constant.sdljBaseUrl.ContainsKey(position) || Constant.sdljBaseUrl[position] == null) { |
| | | Constant.sdljBaseUrl.Add(position, url); |
| | | } |
| | | if (TBCookieUtil.updateCookie(position, cookies)) { |
| | | if (this.Visible == true && !this.IsDisposed) |
| | | { |
| | | this.BeginInvoke(new ChangeShow(setShow), false); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void TBLogin_FormClosed(object sender, FormClosedEventArgs e) |
| | | { |
| | | if(Login.loginContainer.ContainsKey(position)){ |
| | | Login.loginContainer.Remove(position); |
| | | } |
| | | } |
| | | |
| | | private void timer1_Tick(object sender, EventArgs e) |
| | | { |
| | | if (this.Visible == false) |
| | | { |
| | | Console.WriteLine(position + ":刷新Cookie"); |
| | | String url = "https://m.tb.cn/h.VN61jro?sm=9ed9c4"; |
| | | browser.Load(url); |
| | | } |
| | | } |
| | | } |