예제 #1
0
        public void SendMessageInit()
        {
            //ServiceRecordSvc svc = new ServiceRecordSvc();
            //var Authdata = svc.IsAuth();
            //if (Authdata.Code == ResultCodeEnums.AuthExpire)
            //{
            //    MetroMessageBox.Show(this, Authdata.Msg, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    GetLoginQRCode();
            //    return;
            //}
            this.BeginInvoke((Action)(delegate()
            {
                if (from == null)
                {
                    from = new SendLogFrom(this);
                }
                from.Left = this.Left + this.Width;
                from.Top = this.Top;
                from.Show();
            }));
            Thread.Sleep(500);
            ExecEven("正初化发送信息设置!", null);
            List <WXUser> list = FilterOjb();

            ExecEven(string.Format("一共获取了{0}个好友,此次将发送给{1}个好友", contact_all.Count(), list.Count()), null);
            GetSendMessage();
            ExecEvenColse("", null);
            WXServices services = new WXServices();

            services.Wxlogout();
            GetLoginQRCode();
        }
예제 #2
0
        private void UploadViedo(List <MessageType> message, List <WXMesssage> wxMsgList)
        {
            WXMesssage msg       = new WXMesssage();
            var        sendVideo = message.Where(a => a.SendType == "视频").FirstOrDefault();

            if (null != sendVideo)
            {
                if (!File.Exists(sendVideo.TxtContent))
                {
                    MetroMessageBox.Show(this, "文件不存在,请选择好文件!!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                MessageTypeServices svc = new MessageTypeServices();
                var result = svc.SetMessgeSendCount(sendVideo.Id);
                if (result.Code != ResultCodeEnums.success)
                {
                    MetroMessageBox.Show(this, result.Msg, "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                WXServices wxServices = new WXServices();
                ExecEven("正在上传文件到微信服务器.........", null);
                var resultJson = wxServices.UploadVideo(sendVideo.TxtContent, _me.UserName, contact_all[0].UserName);
                if (!string.IsNullOrEmpty(resultJson))
                {
                    JObject obj = JsonConvert.DeserializeObject(resultJson) as JObject;
                    msg.MediaId = obj["MediaId"].ToString();
                    msg.Type    = 43;
                    msg.Readed  = false;
                    msg.Time    = DateTime.Now;
                    msg.From    = _me.UserName;
                    wxMsgList.Add(msg);
                }
            }
        }
예제 #3
0
        public void SendImage(WXMesssage msg)
        {
            WXServices wxs = new WXServices();

            wxs.SendImage(msg.MediaId, msg.From, msg.To, msg.Type);
        }
예제 #4
0
        public void SendFile(WXMesssage msg, long totallen, string title, string fileext)
        {
            WXServices wxs = new WXServices();

            wxs.SendFile(msg.MediaId, totallen, title, fileext, msg.From, msg.To);
        }
예제 #5
0
        /// <summary>
        /// 向该用户发送消息
        /// </summary>
        /// <param name="msg"></param>
        public void SendMsg(WXMesssage msg)
        {
            WXServices wxs = new WXServices();

            wxs.SendMessage(msg.Msg, msg.From, msg.To, msg.Type);
        }
예제 #6
0
        /// <summary>
        ///
        /// </summary>
        private void GetLoginQRCode()
        {
            contact_all.Clear();
            _contact_all.Clear();
            picQRCode.Image    = null;
            picQRCode.SizeMode = PictureBoxSizeMode.Zoom;
            ((Action)(delegate()
            {
                //异步加载二维码
                LoginService ls = new LoginService();
                Image qrcode = ls.GetQRCode();
                if (qrcode != null)
                {
                    this.BeginInvoke((Action) delegate()
                    {
                        picQRCode.Image = qrcode;
                    });
                    object login_result = null;
                    while (true)  //循环判断手机扫面二维码结果
                    {
                        login_result = ls.LoginCheck();
                        if (login_result is Image) //已扫描 未登录
                        {
                            this.BeginInvoke((Action) delegate()
                            {
                                picQRCode.SizeMode = PictureBoxSizeMode.CenterImage;  //显示头像
                                picQRCode.Image = login_result as Image;
                            });
                        }
                        if (login_result is string)  //已完成登录
                        {
                            //访问登录跳转URL
                            ls.GetSidUid(login_result as string);
                            //初始化API
                            HttpApi api = new HttpApi();
                            api.InitApi(login_result.ToString());
                            //获取好友和并绑定
                            UserServices userServices = new UserServices();
                            WXServices wxServices = new WXServices();
                            JObject initResult = wxServices.WxInit();
                            if (initResult != null)
                            {
                                _me = new WXUser();
                                _me.UserName = initResult["User"]["UserName"].ToString();
                                _me.City = "";
                                _me.HeadImgUrl = initResult["User"]["HeadImgUrl"].ToString();
                                _me.NickName = initResult["User"]["NickName"].ToString();
                                _me.Province = "";
                                _me.PYQuanPin = initResult["User"]["PYQuanPin"].ToString();
                                _me.RemarkName = initResult["User"]["RemarkName"].ToString();
                                _me.RemarkPYQuanPin = initResult["User"]["RemarkPYQuanPin"].ToString();
                                _me.Sex = initResult["User"]["Sex"].ToString();
                                _me.Signature = initResult["User"]["Signature"].ToString();
                            }

                            JObject contact_result = userServices.GetContact(); //通讯录
                            if (contact_result != null)
                            {
                                foreach (JObject contact in contact_result["MemberList"])  //完整好友名单
                                {
                                    WXUser user = new WXUser();
                                    user.UserName = contact["UserName"].ToString();
                                    user.City = contact["City"].ToString();
                                    user.HeadImgUrl = contact["HeadImgUrl"].ToString();
                                    user.NickName = contact["NickName"].ToString();
                                    user.Province = contact["Province"].ToString();
                                    user.PYQuanPin = contact["PYQuanPin"].ToString();
                                    user.RemarkName = contact["RemarkName"].ToString();
                                    user.RemarkPYQuanPin = contact["RemarkPYQuanPin"].ToString();
                                    user.Sex = contact["Sex"].ToString();
                                    user.Signature = contact["Signature"].ToString();
                                    user.ContactFlag = contact["ContactFlag"].ToString();
                                    user.VerifyFlag = contact["VerifyFlag"].ToString();
                                    contact_all.Add(user);
                                }
                            }
                            IOrderedEnumerable <WXUser> list_all = contact_all.OrderBy(e => (e as WXUser).ShowPinYin);
                            WXUser wx;
                            string start_char;
                            foreach (object o in list_all)
                            {
                                wx = o as WXUser;
                                start_char = wx.ShowPinYin == "" ? "" : wx.ShowPinYin.Substring(0, 1);
                                if (!_contact_all.Contains(start_char.ToUpper()))
                                {
                                    _contact_all.Add(start_char.ToUpper());
                                }
                                _contact_all.Add(o);
                            }
                            SendMessageInit();
                            return;
                        }
                    }
                }
            })).BeginInvoke(null, null);
        }
예제 #7
0
        public void SendVideo(WXMesssage msg)
        {
            WXServices wxs = new WXServices();

            wxs.SendVideo(msg.MediaId, msg.From, msg.To);
        }
예제 #8
0
        private void skinButton1_Click(object sender, EventArgs e)
        {
            this.skinButton1.Enabled = false;
            List <MessageType> message = new List <MessageType>();
            int count = DataGridMessage.Rows.Count;

            for (int i = 0; i < count; i++)
            {
                DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)DataGridMessage.Rows[i].Cells[0];
                Boolean flag = Convert.ToBoolean(checkCell.Value);
                if (flag == true)
                {
                    MessageType msgType = new MessageType()
                    {
                        SendType   = this.DataGridMessage.Rows[i].Cells[1].Value.ToString(),
                        TxtContent = this.DataGridMessage.Rows[i].Cells[2].Value.ToString()
                    };
                    message.Add(msgType);
                }
            }
            if (message.Count <= 0)
            {
                MessageBox.Show("请选择好你要发送的消息!");
                return;
            }
            WXMesssage msg = new WXMesssage();
            //发消息
            var sendMsg = message.Where(a => a.SendType == "文本").FirstOrDefault();

            if (null != sendMsg)
            {
                foreach (var item in contact_all)
                {
                    msg.From   = _me.UserName;
                    msg.Readed = false;
                    msg.To     = item.UserName;
                    msg.Time   = DateTime.Now;
                    msg.Type   = 1;
                    msg.Msg    = sendMsg.TxtContent;
                    _me.SendMsg(msg);
                    outPost(item.NickName, sendMsg.SendType);
                }
            }
            //发图片
            var sendImage = message.Where(a => a.SendType == "图片").FirstOrDefault();

            if (null != sendImage)
            {
                if (!File.Exists(sendImage.TxtContent))
                {
                    MessageBox.Show("文件不存在,请选择好文件!");
                    return;
                }
                //先上传
                WXServices wxServices = new WXServices();
                var        resultJson = wxServices.UploadImage(sendImage.TxtContent);
                if (!string.IsNullOrEmpty(resultJson))
                {
                    JObject obj     = JsonConvert.DeserializeObject(resultJson) as JObject;
                    string  mediaId = obj["MediaId"].ToString();
                    if (!string.IsNullOrEmpty(mediaId))
                    {
                        foreach (var item in contact_all)
                        {
                            msg.From    = _me.UserName;
                            msg.Readed  = false;
                            msg.To      = item.UserName;
                            msg.Time    = DateTime.Now;
                            msg.MediaId = mediaId;
                            _me.SendImage(msg);
                            outPost(item.NickName, sendImage.SendType);
                        }
                    }
                }
            }
            //发视频
            var sendVideo = message.Where(a => a.SendType == "视频").FirstOrDefault();

            if (null != sendVideo)
            {
                if (!File.Exists(sendVideo.TxtContent))
                {
                    MessageBox.Show("文件不存在,请选择好文件!");
                    return;
                }
                WXServices wxServices = new WXServices();
                var        resultJson = wxServices.UploadVideo(sendVideo.TxtContent, _me.UserName, contact_all[0].UserName);
                if (!string.IsNullOrEmpty(resultJson))
                {
                    JObject obj     = JsonConvert.DeserializeObject(resultJson) as JObject;
                    string  mediaId = obj["MediaId"].ToString();
                    if (!string.IsNullOrEmpty(mediaId))
                    {
                        foreach (var item in contact_all)
                        {
                            msg.From    = _me.UserName;
                            msg.Readed  = false;
                            msg.To      = item.UserName;
                            msg.Time    = DateTime.Now;
                            msg.MediaId = mediaId;
                            _me.SendVideo(msg);
                            outPost(item.NickName, sendVideo.SendType);
                        }
                    }
                }
            }
            this.skinButton1.Enabled = true;
        }