Exemple #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox_users.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
            comboBox_users.AutoCompleteSource = AutoCompleteSource.ListItems;

            wc = new WechatClient();
            wc.OnGetQRCodeImage = (image) => {
                RunInMainthread(() => {
                    pictureBox_qr.Image = image;
                });
            };

            wc.OnUserScanQRCode = (image) => {
                RunInMainthread(() => {
                    pictureBox_qr.Image = image;
                    label_status.Text   = "扫描成功\n请在手机上确认登陆";
                });
            };

            wc.OnLoginSucess = () => {
                RunInMainthread(() => {
                    label_status.Text = "已确认,正在登陆....";
                });
            };

            wc.OnInitComplate = () => {
                RunInMainthread(() => {
                    label_status.Text = wc.CurrentUser.NickName + "(" + wc.CurrentUser.Alias + ")";
                });
            };

            wc.OnRecvMsg = (msg) => {
                if (msg.ToUserName == wc.CurrentUser.UserName && !msg.FromUserName.StartsWith("@@"))
                {
                    System.Diagnostics.Debug.WriteLine("RecvMsg:" + msg.Content + " from " + msg.FromUserName);
                    string rep = "";
                    if (msg.Content == "1")
                    {
                        rep = "你";
                    }
                    if (msg.Content == "2")
                    {
                        rep = "你好";
                    }
                    if (msg.Content == "3")
                    {
                        rep = "你好吗";
                    }
                    //var rep = Simsimi.say(msg.Content);
                    wc.SendMsg(msg.FromUserName, rep);
                    System.Diagnostics.Debug.WriteLine("SendMsg:" + rep + " to " + msg.FromUserName);
                }
            };

            wc.OnAddUser = (user) => {
                RunInMainthread(() => {
                    string nickName = ClearHtml(user.NickName);
                    comboBox_users.Items.Add(nickName + "|" + user.UserName);
                });
            };


            RunAsync(() => {
                wc.Run();
            });
        }
Exemple #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            comboBox_users.AutoCompleteMode   = AutoCompleteMode.SuggestAppend;
            comboBox_users.AutoCompleteSource = AutoCompleteSource.ListItems;

            wc = new WechatClient();
            wc.OnGetQRCodeImage = (image) => {
                RunInMainthread(() => {
                    pictureBox_qr.Image = image;
                });
            };

            wc.OnUserScanQRCode = (image) => {
                RunInMainthread(() => {
                    pictureBox_qr.Image = image;
                    label_status.Text   = "扫描成功\n请在手机上确认登陆";
                });
            };

            wc.OnLoginSucess = () => {
                RunInMainthread(() => {
                    label_status.Text = "登录成功,开始聊天吧。。。";
                });
            };

            wc.OnInitComplate = () => {
                RunInMainthread(() => {
                    label_status.Text = wc.CurrentUser.NickName + "(" + wc.CurrentUser.Alias + ")";
                });
            };

            wc.OnRecvMsg = (msg) => {
                if (msg.ToUserName == wc.CurrentUser.UserName && !msg.FromUserName.StartsWith("@@"))
                {
                    System.Diagnostics.Debug.WriteLine("RecvMsg:" + msg.Content + " from " + msg.FromUserName);
                    //string rep = "";
                    //if ("hello".Equals(msg.Content,StringComparison.OrdinalIgnoreCase)) {
                    //    rep = "你好,请说中文!";
                    //}else if (msg.Content == "哈哈") {
                    //    rep = "哈哈,你是逗逼吗?笑啥?";
                    //}else{
                    //    rep = "还能好好聊天吗?我都不知道你在说啥?";
                    //}
                    var rep = TuLingRobot.Answer(msg.Content);
                    wc.SendMsg(msg.FromUserName, rep);
                    System.Diagnostics.Debug.WriteLine("SendMsg:" + rep + " to " + msg.FromUserName);
                }
            };

            wc.OnAddUser = (user) => {
                RunInMainthread(() => {
                    string nickName = ClearHtml(user.NickName);
                    comboBox_users.Items.Add(nickName + "|" + user.UserName);
                });
            };


            RunAsync(() => {
                wc.Run();
            });
        }