Ejemplo n.º 1
0
        public void UploadVideo()
        {
            var _path      = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var _uploadApp = Path.Combine(_path, "Video.Test.exe");

            Process p = new Process();

            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName         = _uploadApp;
            p.StartInfo.CreateNoWindow   = true;
            p.StartInfo.WorkingDirectory = _path;
            p.StartInfo.Arguments        = string.Format(" {0}", this.VideoUrl);
            p.Start();
            p.WaitForExit();

            var _sendTextRequest = new Entity.WxSendMsgRequest
            {
                BaseRequest = new Entity.WxBaseRequest(new Entity.WxRequest(this.LoginResponse)),
                PassTicket  = this.PassTicket,
                Message     = new Entity.WxMsg
                {
                    FromUserName = this.MyUserName,
                    ToUserName   = this.ToUserName,
                    Content      = "您分享的视频。\n\n标题:\n" + this.VideoTitle + "\n\nUrl:\n" + this.VideoUrl + "\n\n已经成功上传到共享账号。"
                }
            };

            this.Client.Execute(_sendTextRequest);
        }
Ejemplo n.º 2
0
        private async void timer1_Tick(object sender, EventArgs e)
        {
            var now = DateTime.Now;

            if (now.Hour >= 18 && now.Hour <= 24 && now.DayOfWeek != DayOfWeek.Saturday && now.DayOfWeek != DayOfWeek.Sunday)
            {
                if (!_userMsgMapping.Keys.Contains(_toUser) || _userMsgMapping[_toUser] != "朕知道了")
                {
                    var _sendTextRequest = new Entity.WxSendMsgRequest
                    {
                        BaseRequest = new Entity.WxBaseRequest(new Entity.WxRequest(_loginWxResponse)),
                        PassTicket  = _passTicket,
                        Message     = new Entity.WxMsg
                        {
                            FromUserName = _myUserName,
                            ToUserName   = "******",
                            Content      = "记着打卡!记着打卡!记着打卡!"
                        }
                    };

                    await client.ExecuteAsync(_sendTextRequest);
                }
            }
        }
Ejemplo n.º 3
0
        private async void button2_Click(object sender, EventArgs e)
        {
            this.button2.Enabled = false;

            DoTask();

            while (true)
            {
                var syncRequest  = new Entity.SyncCheckRequest(new Entity.WxRequest(_loginWxResponse), _syncCheckKey.List);
                var syncResponse = await client.ExecuteAsync(syncRequest);

                if (syncResponse.RetCode == 0 && syncResponse.Selector > 0)
                {
                    var syncMsgRequest  = new Entity.WxSyncRequest(new Entity.WxRequest(_loginWxResponse), _passTicket, _syncKey, _loginWxResponse.WxSid, _loginWxResponse.SKey);
                    var syncMsgResponse = await client.ExecuteAsync(syncMsgRequest);

                    WriteLog(System.Web.HttpUtility.HtmlDecode(Helper.SerializationHelper.SerializeObjectToJson(syncMsgResponse)));

                    if (syncMsgResponse.BaseResponse.Ret == 0)
                    {
                        _syncKey      = syncMsgResponse.SyncKey;
                        _syncCheckKey = syncMsgResponse.SyncCheckKey;

                        foreach (var msg in syncMsgResponse.AddMsgList)
                        {
                            if (msg.MsgType == 1)
                            {
                                #region text msg
                                SetText("收到来自{0}的消息:{1}", msg.FromUserName, msg.Content);

                                if (_userMsgMapping.Keys.Contains(msg.FromUserName))
                                {
                                    _userMsgMapping[msg.FromUserName] = msg.Content;
                                }
                                else
                                {
                                    _userMsgMapping.Add(msg.FromUserName, msg.Content);
                                }
                                #endregion
                            }
                            else if (msg.MsgType == 3)
                            {
                                #region img msg
                                SetText("收到来自{0}的图片:{1}", msg.FromUserName, Helper.SerializationHelper.SerializeObjectToJson(Helper.SerializationHelper.DeserializeXML <Entity.WxImgMsgContent>(msg.Content, true, "<br/>")));

                                SetText("给对方发送确认信息...");
                                var _sendTextRequest = new Entity.WxSendMsgRequest
                                {
                                    BaseRequest = new Entity.WxBaseRequest(new Entity.WxRequest(_loginWxResponse)),
                                    PassTicket  = _passTicket,
                                    Message     = new Entity.WxMsg
                                    {
                                        FromUserName = _myUserName,
                                        ToUserName   = msg.FromUserName,
                                        Content      = "您的图片已经收到,本地保存后会回复给您。"
                                    }
                                };

                                var _sendTextResponse = await client.ExecuteAsync(_sendTextRequest);

                                if (_sendTextResponse.BaseResponse.Ret == 0)
                                {
                                    SetText("成功发送确认信息!");
                                }

                                SetText("下载图片...");
                                var _downloadPicRequest  = new Entity.GetMsgImgRequest(msg.MsgId, _loginWxResponse.SKey, "_");
                                var _downloadPicResponse = await client.ExecuteAsync(_downloadPicRequest);

                                var _img = _downloadPicResponse.HeadImage;
                                var _ext = ".png";
                                if (_img.RawFormat == System.Drawing.Imaging.ImageFormat.Bmp)
                                {
                                    _ext = ".bmp";
                                }
                                else if (_img.RawFormat == System.Drawing.Imaging.ImageFormat.Png)
                                {
                                    _ext = ".png";
                                }
                                else if (_img.RawFormat == System.Drawing.Imaging.ImageFormat.Jpeg)
                                {
                                    _ext = ".jpg";
                                }
                                else if (_img.RawFormat == System.Drawing.Imaging.ImageFormat.Gif)
                                {
                                    _ext = ".gif";
                                }

                                SetText("保存图片...");
                                var _file = System.IO.Path.Combine(Application.StartupPath, "images", Guid.NewGuid().ToString() + _ext);
                                //_downloadPicResponse.HeadImage.Save(_file);
                                var _finfo = new System.IO.FileInfo(_file);
                                if (!_finfo.Directory.Exists)
                                {
                                    _finfo.Directory.Create();
                                }

                                System.IO.File.WriteAllBytes(_file, Convert.FromBase64String(_downloadPicResponse.ResponseBase64String));

                                SetText("返回图片给对方...");
                                SetText("上传图片...");
                                var _uploadImgRequest = new Entity.UploadMediaRequest(
                                    new System.IO.FileInfo(_file),
                                    new Entity.WxRequest(_loginWxResponse),
                                    _myUserName, msg.FromUserName, client.GetWxDataTicket(), _passTicket);
                                var _uploadImgResponse = await client.ExecuteAsync(_uploadImgRequest);

                                if (_uploadImgResponse.BaseResponse.Ret == 0)
                                {
                                    SetText("上传成功!");
                                }

                                SetText("发送图片...");
                                var _sendImgRequest = new Entity.WxSendImgMsgRequest
                                {
                                    BaseRequest = new Entity.WxBaseRequest(new Entity.WxRequest(_loginWxResponse)),
                                    PassTicket  = _passTicket,
                                    Message     = new Entity.WxImgMsg
                                    {
                                        FromUserName = _myUserName,
                                        ToUserName   = msg.FromUserName,
                                        MediaId      = _uploadImgResponse.MediaId
                                    }
                                };
                                var _sendImgResponse = await client.ExecuteAsync(_sendImgRequest);

                                SetText("成功...{0}", _sendImgResponse.MsgID);
                                #endregion
                            }
                            else if (msg.MsgType == 37)
                            {
                                #region add friend
                                SetText("收到好友添加信息...");
                                if (syncMsgResponse.AddMsgList[0].RecommendInfo.Content == "12345678")
                                {
                                    var _verifyUserRequest  = new Entity.VerifyUserRequest(new Entity.WxRequest(_loginWxResponse), syncMsgResponse.AddMsgList[0].RecommendInfo, _passTicket);
                                    var _verifyUserResponse = await client.ExecuteAsync(_verifyUserRequest);

                                    if (_verifyUserResponse.BaseResponse.Ret == 0)
                                    {
                                        SetText("已经自动通过!");
                                        SetText("发送打招呼内容");
                                        var _sayHello = await client.ExecuteAsync(new Entity.WxSendMsgRequest(new Entity.WxMsg()
                                        {
                                            Content = "Hi, I'm Jarvis", FromUserName = _myUserName, ToUserName = syncMsgResponse.AddMsgList[0].RecommendInfo.UserName
                                        }, _passTicket));

                                        if (_sayHello.BaseResponse.Ret == 0)
                                        {
                                            SetText("打招呼成功");
                                        }
                                    }
                                }
                                #endregion
                            }
                            else if (msg.MsgType == 49)
                            {
                                #region app msg

                                try
                                {
                                    var _appMsg = Helper.SerializationHelper.DeserializeXML <Entity.WxAppMsgContent>(msg.Content, true, "<br/>");
                                    if (_appMsg != null && _appMsg.AppInformation.AppName == "优酷视频")
                                    {
                                        SetText("收到一条分享的优酷视频:\r\n\t标题:{0}\r\n\tUrl:{1}",
                                                _appMsg.AppMsg.Title, _appMsg.AppMsg.Url);

                                        SetText("给对方发送确认信息...");
                                        var _sendTextRequest = new Entity.WxSendMsgRequest
                                        {
                                            BaseRequest = new Entity.WxBaseRequest(new Entity.WxRequest(_loginWxResponse)),
                                            PassTicket  = _passTicket,
                                            Message     = new Entity.WxMsg
                                            {
                                                FromUserName = _myUserName,
                                                ToUserName   = msg.FromUserName,
                                                Content      = "收到您分享的视频。\n\n标题:\n" + _appMsg.AppMsg.Title + "\n\nUrl:\n" + _appMsg.AppMsg.Url + "\n\n后台会自动转存到共享账号,转存成功后会微信通知您。"
                                            }
                                        };
                                        await client.ExecuteAsync(_sendTextRequest);

                                        var s = new VideoTask
                                        {
                                            LoginResponse = _loginWxResponse,
                                            MyUserName    = _myUserName,
                                            ToUserName    = msg.FromUserName,
                                            Client        = client,
                                            PassTicket    = _passTicket,
                                            VideoTitle    = _appMsg.AppMsg.Title,
                                            VideoUrl      = _appMsg.AppMsg.Url
                                        };

                                        _queue.Enqueue(s);
                                    }
                                }
                                catch
                                {
                                }

                                #endregion
                            }
                        }
                    }
                }
                else if (syncResponse.RetCode != 0)
                {
                    SetText("已经退出.");
                    break;
                }
            }

            client.SetCookie(null);
            this.button1.Enabled = true;
            this.button2.Enabled = true;
        }