private void OnWechatAppEvent(Wechat.WeChatClient sender, Wechat.WeChatClientEvent e) { RunInMainthread(() => { if (e is Wechat.GetQRCodeImageEvent) { pictureBox_wechat.Image = (e as Wechat.GetQRCodeImageEvent).QRImage; } if (e is Wechat.UserScanQRCodeEvent) { pictureBox_wechat.Image = (e as Wechat.UserScanQRCodeEvent).UserAvatarImage; } if (e is Wechat.LoginSucessEvent) { Console.WriteLine("登陆成功!"); } if (e is Wechat.AddMessageEvent) { var message = (e as Wechat.AddMessageEvent).Msg; Console.WriteLine("AddMsg:" + message.GetType()); } if (e is Wechat.StatusChangedEvent) { var changedEvent = (e as Wechat.StatusChangedEvent); Console.WriteLine(string.Format("StatusChanged {0} -> {1}", changedEvent.FromStatus, changedEvent.ToStatus)); } if (e is Wechat.InitedEvent) { ShowGroups(); } }); }
private void Form1_Load(object sender, EventArgs e) { ComboBox_users.AutoCompleteMode = AutoCompleteMode.SuggestAppend; ComboBox_users.AutoCompleteSource = AutoCompleteSource.ListItems; wc = new Wechat.WeChatClient { OnGetQRCodeImage = (xxx, xx) => { RunInMainthread(() => { PictureBox_qr.Image = xx.QRImage; }); }, OnUserScanQRCode = (xxx, xx) => { RunInMainthread(() => { PictureBox_qr.Image = xx.UserAvatarImage; Label_status.Text = "扫描成功\n请在手机上确认登陆"; }); }, OnLoginSucess = (xxx, xx) => { RunInMainthread(() => { Label_status.Text = "已确认,正在登陆...."; }); }, OnInitComplate = (xxx, xx) => { RunInMainthread(() => { Label_status.Text = wc.CurrentUser.NickName; }); }, OnRecvMsg = (xxx, xx) => { if (xx.Msg.ToUserName == wc.CurrentUser.UserName && !xx.Msg.FromUserName.StartsWith("@@")) { System.Diagnostics.Debug.WriteLine("RecvMsg:" + xx.Msg.Content + " from " + xx.Msg.FromUserName); } }, OnAddUser = (xxx, xx) => { RunInMainthread(() => { string nickName = ClearHtml(xx.User.NickName); ComboBox_users.Items.Add(xx.User.RemarkName + "(" + xx.User.NickName + ")" + xx.User.UserName); }); } }; RunAsync(() => { wc.Run(); }); //var wxRobot = new WXRobot(wc); //wc.OnAddUser += wxRobot.Init; //wc.OnRecvMsg += wxRobot.MessageRecived; //var WxSendAll = new WXSendMessageWithName() { WxServices = wc }; //wc.OnRecvMsg += WxSendAll.MsgRecived; }