admin
2020-06-10 a610f2ab6e543d2cb78c1ef212ac6a74ddc067d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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<String, String> cookiesMap, String cookies)
            {
 
                //this.form.Visible = false;
                //this.form.Close();
            }
        }
    }
}