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; }
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(); }