コード例 #1
0
ファイル: WXService.cs プロジェクト: zupu8/WeChat.NET
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="type"></param>
        public void SendMsg(string msg, string from, string to, int type)
        {
            string msg_json = "{{" +
                              "\"BaseRequest\":{{" +
                              "\"DeviceID\" : \"e441551176\"," +
                              "\"Sid\" : \"{0}\"," +
                              "\"Skey\" : \"{6}\"," +
                              "\"Uin\" : \"{1}\"" +
                              "}}," +
                              "\"Msg\" : {{" +
                              "\"ClientMsgId\" : {8}," +
                              "\"Content\" : \"{2}\"," +
                              "\"FromUserName\" : \"{3}\"," +
                              "\"LocalID\" : {9}," +
                              "\"ToUserName\" : \"{4}\"," +
                              "\"Type\" : {5}" +
                              "}}," +
                              "\"rr\" : {7}" +
                              "}}";

            Cookie sid = BaseService.GetCookie("wxsid");
            Cookie uin = BaseService.GetCookie("wxuin");

            if (sid != null && uin != null)
            {
                msg_json = string.Format(msg_json, sid.Value, uin.Value, msg, from, to, type, LoginService.SKey, DateTime.Now.Millisecond, DateTime.Now.Millisecond, DateTime.Now.Millisecond);

                byte[] bytes = BaseService.SendPostRequest(_sendmsg_url + sid.Value + "&lang=zh_CN&pass_ticket=" + LoginService.Pass_Ticket, msg_json);

                string send_result = Encoding.UTF8.GetString(bytes);
            }
        }
コード例 #2
0
ファイル: WXService.cs プロジェクト: zupu8/WeChat.NET
        /// <summary>
        /// 微信初始化
        /// </summary>
        /// <returns></returns>
        public JObject WxInit()
        {
            string init_json = "{{\"BaseRequest\":{{\"Uin\":\"{0}\",\"Sid\":\"{1}\",\"Skey\":\"\",\"DeviceID\":\"e1615250492\"}}}}";
            Cookie sid       = BaseService.GetCookie("wxsid");
            Cookie uin       = BaseService.GetCookie("wxuin");

            if (sid != null && uin != null)
            {
                init_json = string.Format(init_json, uin.Value, sid.Value);
                byte[] bytes    = BaseService.SendPostRequest(_init_url + "&pass_ticket=" + LoginService.Pass_Ticket, init_json);
                string init_str = Encoding.UTF8.GetString(bytes);

                JObject init_result = JsonConvert.DeserializeObject(init_str) as JObject;

                foreach (JObject synckey in init_result["SyncKey"]["List"])  //同步键值
                {
                    _syncKey.Add(synckey["Key"].ToString(), synckey["Val"].ToString());
                }
                return(init_result);
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
ファイル: WXService.cs プロジェクト: miuzel/WeChat.NET
        /// <summary>
        /// 微信初始化
        /// </summary>
        /// <returns></returns>
        public JObject WxInit()
        {
            //string init_json = "{{\"BaseRequest\":{{\"Uin\":\"{0}\",\"Sid\":\"{1}\",\"Skey\":\"\",\"DeviceID\":\"e1615250492\"}}}}";
            string init_json = "{{\"BaseRequest\":{{\"Uin\":\"{0}\",\"Sid\":\"{1}\",\"Skey\":\"\",\"DeviceID\":\"e2324132323\"}}}}";
            string init_url  = "";
            Cookie sid       = BaseService.GetCookie("wxsid");
            Cookie uin       = BaseService.GetCookie("wxuin");

            if (sid != null && uin != null)
            {
                init_json = string.Format(init_json, uin.Value, sid.Value);
                init_url  = string.Format(_init_url, (long)(DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1)).TotalMilliseconds);
                byte[] bytes    = BaseService.SendPostRequest(_init_url + "&pass_ticket=" + LoginService.Pass_Ticket, init_json);
                string init_str = Encoding.UTF8.GetString(bytes);

                log.Debug("Login Response: \n" + init_str);
                JObject init_result = JsonConvert.DeserializeObject(init_str) as JObject;

                if (init_result["SyncKey"]["Count"].ToString() != "0")
                {
                    _syncKey.Clear();
                    foreach (JObject synckey in init_result["SyncKey"]["List"])  //同步键值
                    {
                        _syncKey.Add(synckey["Key"].ToString(), synckey["Val"].ToString());
                    }
                }
                return(init_result);
            }
            else
            {
                return(null);
            }
        }
コード例 #4
0
ファイル: WXService.cs プロジェクト: abc52406/WebWechat
        /// <summary>
        /// 移除群聊成员
        /// </summary>
        /// <param name="roomName">房间名</param>
        /// <param name="userNames">成员</param>
        /// <returns></returns>
        public JObject DeleteMember(string roomName, List <string> userNames)
        {
            Cookie sid = BaseService.GetCookie("wxsid");
            Cookie uin = BaseService.GetCookie("wxuin");

            byte[] bytes = BaseService.SendPostRequest(string.Format(_delmember_url, LoginService.Pass_Ticket)
                                                       , string.Format(_delmem_msg_json, uin.Value, sid.Value, LoginService.SKey, roomName
                                                                       , string.Join(",", userNames)));
            string delmem_str = Encoding.UTF8.GetString(bytes);

            return(JsonConvert.DeserializeObject(delmem_str) as JObject);
        }
コード例 #5
0
ファイル: WXService.cs プロジェクト: daya76688/WeChat
        /// <summary>
        /// 发送pic图片
        /// </summary>
        /// <param name="ToUserName"></param>
        /// <param name="MediaId"></param>
        public void Wx_SendPicByMediaId(string ToUserName, string MediaId)
        {
            Cookie sid         = BaseService.GetCookie("wxsid");
            Cookie uin         = BaseService.GetCookie("wxuin");
            string MsgType     = "3";
            string Content     = "";
            string ClientMsgId = DateTime.Now.Millisecond.ToString();
            string url         = "https://" + LoginService.Url + ".qq.com/cgi-bin/mmwebwx-bin/webwxsendmsgimg?fun=async&f=json&lang=zh_CN&pass_ticket=" + LoginService.Pass_Ticket;
            string data        = "{\"BaseRequest\":{\"Uin\":" + uin.Value + ",\"Sid\":\"" + sid.Value + "\",\"Skey\":\"" + LoginService.SKey + "\",\"DeviceID\":\"" + "e831645047756137" + "\"},\"Msg\":{\"Type\":" + MsgType + ",\"MediaId\":\"" + MediaId + "\",\"Content\":\"" + Content + "\",\"FromUserName\":\"" + frmMain.usernameid + "\",\"ToUserName\":\"" + ToUserName + "\",\"LocalID\":\"" + ClientMsgId + "\",\"ClientMsgId\":\"" + ClientMsgId + "\"},\"Scene\":0}";

            byte [] bytes       = BaseService.SendPostRequest(url, data);
            string  send_result = Encoding.UTF8.GetString(bytes);
        }
コード例 #6
0
ファイル: WXService.cs プロジェクト: abc52406/WebWechat
        /// <summary>
        /// 创建群聊
        /// </summary>
        /// <param name="userNames">群成员</param>
        /// <returns></returns>
        public JObject CreateRoom(List <string> userNames)
        {
            Cookie sid = BaseService.GetCookie("wxsid");
            Cookie uin = BaseService.GetCookie("wxuin");

            byte[] bytes = BaseService.SendPostRequest(string.Format(_addroom_url, LoginService.Pass_Ticket
                                                                     , (long)(DateTime.Now.ToUniversalTime() - new System.DateTime(1970, 1, 1)).TotalMilliseconds)
                                                       , string.Format(_addroom_msg_json, uin.Value, sid.Value, LoginService.SKey, userNames.Count()
                                                                       , JsonConvert.SerializeObject(userNames.Select(c => new { UserName = c }).ToList(), Formatting.None)));
            string room_str = Encoding.UTF8.GetString(bytes);

            return(JsonConvert.DeserializeObject(room_str) as JObject);
        }
コード例 #7
0
ファイル: WXService.cs プロジェクト: daya76688/WeChat
        /// <summary>
        /// 发送动态图
        /// </summary>
        /// <param name="ToUserName"></param>
        /// <param name="MediaId"></param>
        public void Wx_SendGifByMediaId(string ToUserName, string MediaId)
        {
            Random ran         = new Random();
            int    RandKey     = ran.Next(1000, 9999);
            Cookie sid         = BaseService.GetCookie("wxsid");
            Cookie uin         = BaseService.GetCookie("wxuin");
            string MsgType     = "47";
            string EmojiFlag   = "2";
            string ClientMsgId = ((long)((DateTime.Now.ToUniversalTime() - new System.DateTime(1970, 1, 1)).TotalMilliseconds)).ToString() + RandKey.ToString();
            string url         = "https://" + LoginService.Url + ".qq.com/cgi-bin/mmwebwx-bin/webwxsendemoticon?fun=sys&lang=zh_CN&pass_ticket=" + LoginService.Pass_Ticket;
            string data        = "{\"BaseRequest\":{\"Uin\":" + uin.Value + ",\"Sid\":\"" + sid.Value + "\",\"Skey\":\"" + LoginService.SKey + "\",\"DeviceID\":\"" + "e831645047756137" + "\"},\"Msg\":{\"Type\":" + MsgType + ",\"EmojiFlag\":" + EmojiFlag + ",\"MediaId\":\"" + MediaId + "\",\"FromUserName\":\"" + frmMain.usernameid + "\",\"ToUserName\":\"" + ToUserName + "\",\"LocalID\":\"" + ClientMsgId + "\",\"ClientMsgId\":\"" + ClientMsgId + "\"},\"Scene\":0}";

            byte[] bytes       = BaseService.SendPostRequest(url, data);
            string send_result = Encoding.UTF8.GetString(bytes);
        }
コード例 #8
0
ファイル: WXService.cs プロジェクト: daya76688/WeChat
        /// <summary>
        /// 获取群聊成员列表
        /// </summary>
        /// <returns></returns>
        public JObject GetGroupItem(string groupid)
        {
            Cookie sid = BaseService.GetCookie("wxsid");
            Cookie uin = BaseService.GetCookie("wxuin");

            if (sid != null && uin != null)
            {
                string data        = "{\"List\":[{\"UserName\":\"" + groupid + "\",\"EncryChatRoomId\":\"\"}],\"Count\":1,\"BaseRequest\":{\"Uin\":" + uin.Value + ",\"Sid\":\"" + sid.Value + "\",\"Skey\":\"" + LoginService.SKey + "\",\"DeviceID\":\"" + "e831645047756137" + "\"}}";
                string urll        = _group_url + "&r=" + (long)(DateTime.Now.ToUniversalTime() - new System.DateTime(1970, 1, 1)).TotalMilliseconds + "&pass_ticket=" + LoginService.Pass_Ticket;
                byte[] bytes1      = BaseService.SendPostRequest(urll, data);
                string contact_str = Encoding.UTF8.GetString(bytes1);
                return(JsonConvert.DeserializeObject(contact_str) as JObject);
            }
            else
            {
                return(null);
            }
        }
コード例 #9
0
ファイル: WXService.cs プロジェクト: miuzel/WeChat.NET
        /// <summary>
        /// 微信同步
        /// </summary>
        /// <returns></returns>
        public JObject WxSync()
        {
            string sync_json = "{{\"BaseRequest\" : {{\"DeviceID\":\"e1615250492\",\"Sid\":\"{1}\", \"Skey\":\"{5}\", \"Uin\":\"{0}\"}},\"SyncKey\" : {{\"Count\":{2},\"List\":[{3}]}},\"rr\" :{4}}}";
            Cookie sid       = BaseService.GetCookie("wxsid");
            Cookie uin       = BaseService.GetCookie("wxuin");

            string sync_keys = "";

            foreach (KeyValuePair <string, string> p in _syncKey)
            {
                sync_keys += "{\"Key\":" + p.Key + ",\"Val\":" + p.Value + "},";
            }
            sync_keys = sync_keys.TrimEnd(',');
            sync_json = string.Format(sync_json, uin.Value, sid.Value, _syncKey.Count, sync_keys, (long)(DateTime.Now.ToUniversalTime() - new System.DateTime(1970, 1, 1)).TotalMilliseconds, LoginService.SKey);

            if (sid != null && uin != null)
            {
                byte[] bytes    = BaseService.SendPostRequest(_sync_url + sid.Value + "&lang=zh_CN&skey=" + LoginService.SKey + "&pass_ticket=" + LoginService.Pass_Ticket, sync_json);
                string sync_str = Encoding.UTF8.GetString(bytes);
                log.Debug("SynResString:" + sync_str + "\n");
                JObject sync_resul = JsonConvert.DeserializeObject(sync_str) as JObject;

                if (sync_resul["BaseResponse"]["Ret"].ToString() != "0")
                {
                    log.Debug("Sync Failed With code " + sync_resul["BaseResponse"]["Ret"].ToString() + " \n");
                    return(null);
                }

                if (sync_resul["SyncKey"]["Count"].ToString() != "0")
                {
                    _syncKey.Clear();
                    foreach (JObject key in sync_resul["SyncKey"]["List"])
                    {
                        log.Debug("SynRes:" + key["Key"].ToString() + ":" + key["Val"].ToString() + "\n");
                        _syncKey.Add(key["Key"].ToString(), key["Val"].ToString());
                    }
                }
                return(sync_resul);
            }
            else
            {
                return(null);
            }
        }