Example #1
0
        /// <summary>
        /// 对手机端信息进行同步
        /// </summary>
        /// <param name="FromUserName"></param>
        /// <param name="ToUserName"></param>
        public static void WebwxStatusNotify(string FromUserName, string ToUserName)
        {
            NotifyPhoneEntity Npe = new NotifyPhoneEntity();
            BaseRequestEntity br  = new BaseRequestEntity();

            br.DeviceID     = MethodsHelper.GetDeviceId();
            br.Sid          = CommonDefine.LoginResult.wxsid;
            br.Skey         = CommonDefine.LoginResult.skey;
            br.Uin          = CommonDefine.LoginResult.wxuin;
            Npe.BaseRequest = br;
            Random ran = new Random();

            Npe.ClientMsgId  = MethodsHelper.GetClientMsgId();// "1497590764" + ((int)ran.Next(0, 9)).ToString() + ((int)ran.Next(0, 9)).ToString() + ((int)ran.Next(0, 9)).ToString();
            Npe.Code         = "1";
            Npe.FromUserName = FromUserName;
            Npe.ToUserName   = ToUserName;
            string PostData = JsonConvert.SerializeObject(Npe);
            string list     = HttpMethods.PostData(UrlDefine.WexNotifyUrl + CommonDefine.LoginResult.pass_ticket, PostData, CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString();

            if (list != null)
            {
                SendMsgResultEntity Sre = JsonConvert.DeserializeObject <SendMsgResultEntity>(list);
                if (Sre.BaseResponse.Ret == 0)
                {
                }
                //if (list.Count >= 1)
                //{
                //    Console.WriteLine(list[0].ToString());
                //}
            }
        }
Example #2
0
        /// <summary>
        /// 获取群成员信息
        /// </summary>
        /// <param name="GroupList"></param>
        public static void GetGroupContactsMethod(List <MemberListItemEntity> GroupList)
        {
            GroupContacts GC = new GroupContacts();

            GC.BaseRequest = new BaseRequestEntity()
            {
                DeviceID = MethodsHelper.GetDeviceId(), Sid = CommonDefine.LoginResult.wxsid, Skey = CommonDefine.LoginResult.skey, Uin = CommonDefine.LoginResult.wxuin
            };
            List <GroupListItem> GroupNumberList = new List <GroupListItem>();

            for (int index = 0; index < GroupList.Count; index++)
            {
                if (GroupList[index].UserName.Contains("@@"))
                {
                    GroupListItem Groupitem = new GroupListItem();
                    Groupitem.UserName = GroupList[index].UserName;
                    GroupNumberList.Add(Groupitem);
                }
            }
            GC.List  = GroupNumberList;
            GC.Count = GroupNumberList.Count;
            string PostData = JsonConvert.SerializeObject(GC);
            string Result   = HttpMethods.PostData(string.Format(UrlDefine.GetQunContactUrl, CommonDefine.LoginResult.pass_ticket), PostData, CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString();

            if (!string.IsNullOrWhiteSpace(Result))
            {
                GroupMemberListEntity GroupMumberInfo = JsonConvert.DeserializeObject <GroupMemberListEntity>(Result);
                CommonDefine.GroupMemberList = GroupMumberInfo;
            }
            else
            {
                LogWriter.Write("获取群成员失败,返回结果为空!", LogPathDefine.WeChatGrouplogPath);
            }
            //GGC.List=new List<Entity.ListItem>(
        }
Example #3
0
        /// <summary>
        /// 获取心跳key
        /// </summary>
        /// <returns></returns>
        public static string GetSyncKey()
        {
            BaseRequestEntity Bre = new BaseRequestEntity()
            {
                Uin = CommonDefine.LoginResult.wxuin, Sid = CommonDefine.LoginResult.wxsid, Skey = CommonDefine.LoginResult.skey, DeviceID = MethodsHelper.GetDeviceId()
            };
            BaseRequestSubmitEntity le = new BaseRequestSubmitEntity()
            {
                BaseRequest = Bre
            };
            string            SyncKeyData = JsonConvert.SerializeObject(le);
            string            SyncKeyUrl  = UrlDefine.GetSyncKey + CommonDefine.LoginResult.pass_ticket;
            string            SyncKeyList = HttpMethods.PostData(SyncKeyUrl, SyncKeyData, CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString();
            BaseContactEntity bce         = JsonConvert.DeserializeObject <BaseContactEntity>(SyncKeyList);

            CommonDefine.SyncKey = bce.SyncKey;
            string SyncKey = string.Empty;

            for (int index = 0; index < bce.SyncKey.List.Count; index++)
            {
                if (!string.IsNullOrWhiteSpace(SyncKey))
                {
                    SyncKey = SyncKey + "|";
                }
                SyncKey = SyncKey + bce.SyncKey.List[index].Key + "_" + bce.SyncKey.List[index].Val;
            }
            Thread.Sleep(5000);
            return(SyncKey);
        }
Example #4
0
        /// <summary>
        /// 获取聊天信息
        /// </summary>
        /// <param name="SyncKeyList"></param>
        /// <returns></returns>
        public static string GetMsg(SyncKeyEntity SyncKey)
        {
            string           ReturnKey = string.Empty;
            ReceiveMsgEntity Rme       = new ReceiveMsgEntity();
            GetMsgEntiy      Gme       = new GetMsgEntiy()
            {
                BaseRequest = new BaseRequestEntity()
                {
                    Uin = CommonDefine.LoginResult.wxuin, Sid = CommonDefine.LoginResult.wxsid, Skey = CommonDefine.LoginResult.skey, DeviceID = MethodsHelper.GetDeviceId()
                }, SyncKey = SyncKey, rr = -113317163
            };
            string PostData = JsonConvert.SerializeObject(Gme);
            string posturl  = UrlDefine.GetChatUrl
                              + "sid=" + CommonDefine.LoginResult.wxsid
                              + "&skey=" + CommonDefine.LoginResult.skey
                              + "&pass_ticket=" + CommonDefine.LoginResult.pass_ticket;
            string Msglist = HttpMethods.PostData(posturl, PostData, CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString();

            try
            {
                Rme = JsonConvert.DeserializeObject <ReceiveMsgEntity>(Msglist);
                CommonDefine.SyncKey = Rme.SyncKey;
            }
            catch (Exception ex)
            {
                Console.WriteLine("GetMsg" + ex.Message);
            }
            try
            {
                if (Rme.AddMsgCount != 0)
                {
                    //说明有消息
                    AnalyseMsg(Rme.AddMsgList);
                }
                else
                {
                    //到这 说明没有消息
                }
            }
            catch (Exception ex)
            {
                // KeepHeart(FristKey);
                Console.WriteLine("GetMsg is out Exception" + ex.Message);
            }
            return(ReturnKey);
        }
Example #5
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="Msg">消息体</param>
        /// <param name="IsAddChatList">是否添加到聊天列表</param>
        /// <param name="ToName">向谁发送</param>
        public static bool SendToOtherMsg(string Msg = "", string ToName = "")
        {
            string SendMsg    = string.Empty;
            string LocalMsgId = MethodsHelper.GetClientMsgId();

            if (!string.IsNullOrWhiteSpace(Msg))
            {
                SendMsg = Msg;
            }
            string            chaturl = UrlDefine.ChatUrl + CommonDefine.LoginResult.pass_ticket;
            SendMsgBodyEntity Smbe    = new SendMsgBodyEntity()
            {
                BaseRequest = new BaseRequestEntity()
                {
                    DeviceID = MethodsHelper.GetDeviceId(), Uin = CommonDefine.LoginResult.wxuin, Sid = CommonDefine.LoginResult.wxsid, Skey = CommonDefine.LoginResult.skey
                }, Msg = new SendMsgEntity()
                {
                    Type = MsgTypeEnum.Text, FromUserName = CommonDefine.BaseContact.User.UserName, ToUserName = ToName, Content = Msg, LocalID = LocalMsgId, ClientMsgId = LocalMsgId
                }
            };
            string PostData         = JsonConvert.SerializeObject(Smbe);
            string Result           = HttpMethods.PostData(chaturl, PostData, CommonDefine.Cookies, Encoding.UTF8, "AcceptEncoding", "gzip, deflate").ContentData.ToString();
            SendMsgResultEntity Sre = JsonConvert.DeserializeObject <SendMsgResultEntity>(Result);

            if (Sre.BaseResponse.Ret == 0)
            {
                //消息发送成功
                CommonMethodCallBackHandlers.OnSendMsgCompleted(true);
                return(true);
            }
            else
            {
                Console.WriteLine("发送失败:" + Result);
                CommonMethodCallBackHandlers.OnSendMsgCompleted(false);
                return(false);
            }
        }
Example #6
0
        /// <summary>
        /// 登录
        /// </summary>
        public static void Login()
        {
            string str = string.Empty;

            HttpMethods.ContentType = "application/json;charset=utf-8";
            while (true)
            {
                if (!str.Contains("200"))
                {
                    HttpResponseResult ResponseResult = HttpMethods.Get(UrlDefine.WaitingUrl(UrlDefine.Tickets), CommonDefine.Cookies, Encoding.UTF8);
                    str = ResponseResult.ContentData.ToString();
                    Console.WriteLine("当前返回值是:" + str);
                    if (str.Contains("201"))
                    {
                        //扫码登录中
                        string[] base64 = str.Split(',');
                        CommonDefine.Base64 = base64[1];
                        byte[] arr = Convert.FromBase64String(CommonDefine.Base64.Replace("'", "").Replace(";", "").Trim());
                        File.WriteAllBytes(Environment.CurrentDirectory + "\\User.jpg", arr);
                        MemoryStream ms = new MemoryStream(arr);
                        BitmapImage  bi = new BitmapImage();
                        bi.BeginInit();
                        bi.StreamSource = ms;// new FileStream();
                        bi.EndInit();
                        CommonDefine.UserImage = bi;
                        CommonMethodCallBackHandlers.OnLoginScranQRCodeCompleted(Environment.CurrentDirectory + "\\User.jpg");
                    }
                }
                if (str.Contains("200"))
                {
                    //扫码登录完成
                    LogWriter.Write("扫码登录成功...", LogPathDefine.WeChatLogPath);
                    string[] strs = str.Split(';');
                    UrlDefine.LoginUrls = strs[1].Substring(strs[1].IndexOf("=\"") + 2, strs[1].Length - strs[1].IndexOf("=\"") - 3);
                    string XmlList = HttpMethods.Get(UrlDefine.LoginUrls, CommonDefine.Cookies, Encoding.UTF8, true).ContentData.ToString();
                    CommonDefine.GetCookieDictionary = HttpMethods.SetCookieDictionary;
                    CommonDefine.LoginResult         = XMLHelper.DESerializer <LoginResultEntity>(XmlList);
                    //此处可用于二次点击登录
                    LogWriter.Write(CommonDefine.LoginResult.wxuin, Environment.CurrentDirectory + "\\Data\\data.dat");
                    Random            r   = new Random();
                    BaseRequestEntity Bre = new BaseRequestEntity()
                    {
                        Uin = CommonDefine.LoginResult.wxuin, Sid = CommonDefine.LoginResult.wxsid, Skey = CommonDefine.LoginResult.skey, DeviceID = MethodsHelper.GetDeviceId()
                    };
                    BaseRequestSubmitEntity le = new BaseRequestSubmitEntity()
                    {
                        BaseRequest = Bre
                    };
                    string postdata   = JsonConvert.SerializeObject(le);
                    string MySelfList = HttpMethods.PostData(UrlDefine.GetLoginId + CommonDefine.LoginResult.pass_ticket, postdata, CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString();
                    LogWriter.Write(string.Format("获取个人信息{0}...", MySelfList), LogPathDefine.WeChatLogPath);
                    CommonDefine.BaseContact = JsonConvert.DeserializeObject <BaseContactEntity>(MySelfList);
                    string ContentList = HttpMethods.Get(UrlDefine.GetContactUrl(CommonDefine.LoginResult.pass_ticket, CommonDefine.LoginResult.skey), CommonDefine.Cookies, Encoding.UTF8).ContentData.ToString();
                    CommonDefine.ContactsList = JsonConvert.DeserializeObject <ContactsListEntity>(ContentList);
                    LogWriter.Write(string.Format("获取联系人信息{0}...", ContentList), LogPathDefine.WeChatLogPath);
                    new Task(() => { GetGroupContactsMethod(CommonDefine.ContactsList.MemberList); }).Start();
                    new Task(() =>
                    {
                        CommonDefine.ContactsList.MemberList.ForEach((p) =>
                        {
                            p.DownloadImage();
                        });
                    }).Start();
                    CommonMethodCallBackHandlers.OnLoginCompleted(true);
                    break;
                }
                Thread.Sleep(5000);
            }
        }