コード例 #1
0
ファイル: Form1.cs プロジェクト: Airszero0/WechatFc_k
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                while (true)
                {
                    WechatHttpClient <LoginLoopResponse, LoginLoopRequest> wechatHttpClient = new WechatHttpClient <LoginLoopResponse, LoginLoopRequest>(new LoginLoopRequest(loginCode));
                    LoginLoopResponse loginLoopResponse = wechatHttpClient.DoGet();
                    //登陆跳转授权地址
                    if (loginLoopResponse != null && !string.IsNullOrWhiteSpace(loginLoopResponse.RedirectUri))
                    {
                        authUrl = loginLoopResponse.RedirectUri;
                    }
                    if (!string.IsNullOrEmpty(authUrl))
                    {
                        break;
                    }

                    System.Threading.Thread.Sleep(1000);
                }
            }
            catch (Exception xe)
            {
                MessageBox.Show("先扫二维码");
            }

            WechatHttpClient <WechatInitResponse, WechatInitRequest> wechatHttp = new WechatHttpClient <WechatInitResponse, WechatInitRequest>(new WechatInitRequest(authUrl));

            WechatInitResponse response = wechatHttp.DoGet();

            skey        = response.skey;
            label6.Text = skey;
            wxsid       = response.wxsid;
            label7.Text = wxsid;
            wxuin       = response.wxuin;
            label8.Text = wxuin;
            pass_ticket = response.pass_ticket;
            label9.Text = pass_ticket;

            BaseRequest baseRequest = new BaseRequest();

            baseRequest.Sid  = wxsid;
            baseRequest.Uin  = wxuin;
            baseRequest.Skey = skey;


            WechatHttpClient <InitResponse, InitPostModel> initWechatHttp = new WechatHttpClient <InitResponse, InitPostModel>(new InitPostModel(pass_ticket, baseRequest));
            InitResponse resp = initWechatHttp.DoPost();

            user_name = resp.User.UserName;

            List <ListSource> source = new List <ListSource>();

            foreach (var item in resp.ContactList)
            {
                source.Add(new ListSource(item.UserName, item.NickName));
            }
            dataGridView1.DataSource = source;
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Airszero0/WechatFc_k
        private void Button3_Click(object sender, EventArgs e)
        {
            string      toUser      = textBox3.Text;
            string      toMsg       = textBox2.Text;
            MsgData     data        = new MsgData();
            BaseRequest baseRequest = new BaseRequest();

            baseRequest.Sid  = wxsid;
            baseRequest.Uin  = wxuin;
            baseRequest.Skey = skey;
            data.BaseRequest = baseRequest;

            string at = textBox5.Text;

            Msg _msg = new Msg();

            _msg.Type         = 1;
            _msg.Content      = (string.IsNullOrEmpty(at)?"":at + " ") + toMsg;
            _msg.FromUserName = user_name;
            _msg.ToUserName   = toUser;
            data.Msg          = _msg;



            int times = int.Parse(textBox4.Text);

            Task task = Task.Run(() =>
            {
                int i = 0;
                while (i < times)
                {
                    i++;

                    if (checkBox1.Checked)
                    {
                        int _d           = DateTime.Now.Millisecond;
                        Random r         = new Random(_d);
                        data.Msg.Content = (string.IsNullOrEmpty(at) ? "" : at + " ") + keyValuePairs[r.Next(1, keyValuePairs.Count)];
                    }

                    if (checkBox2.Checked)
                    {
                        i = 0;
                    }
                    WechatHttpClient <MsgResponse, MsgRequest> wechatHttpClient = new WechatHttpClient <MsgResponse, MsgRequest>(new MsgRequest(pass_ticket, data));
                    MsgResponse response = wechatHttpClient.DoPost();

                    BeginInvoke(new update_textbox(update_text), JsonConvert.SerializeObject(response));
                    BeginInvoke(new update_textbox(lable_text), i.ToString());
                    Thread.Sleep(500);
                }
            });
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: Airszero0/WechatFc_k
        private void RefushCode()
        {
            WechatHttpClient <JsLoginResponse, JsLoginRequest> wechatHttpClient = new WechatHttpClient <JsLoginResponse, JsLoginRequest>(new JsLoginRequest());

            loginCode   = wechatHttpClient.DoGet().Code;
            label1.Text = loginCode;

            if (String.IsNullOrEmpty(loginCode))
            {
                throw new Exception("获取二维码code失败");
            }

            WechatHttpClient <CodeGenerateResponse, CodeGenerateRequest> CodeWechatHttpClient = new WechatHttpClient <CodeGenerateResponse, CodeGenerateRequest>(new CodeGenerateRequest(loginCode));
            Stream ImageStream = new MemoryStream(CodeWechatHttpClient.DoImageGet());
            Image  _image      = Image.FromStream(ImageStream);

            pictureBox1.Image = _image;
            ImageStream.Close();
        }