public override QQHttpRequest OnBuildRequest()
        {
            QQSession     session = Context.Session;
            QQHttpRequest req     = CreateHttpRequest("GET",
                                                      QQConstants.URL_GET_SESSION_MSG_SIG);

            if (user is QQGroupMember)
            {
                QQGroupMember mb = user as QQGroupMember;
                mb.ServiceType = 0;
                req.AddGetValue("id", mb.Group.Gin + "");
                req.AddGetValue("service_type", "0"); // 0为群,1为讨论组
            }
            else if (user is QQDiscuzMember)
            {
                QQDiscuzMember mb = (QQDiscuzMember)user;
                mb.ServiceType = 1;
                req.AddGetValue("id", mb.Discuz.Did + "");
                req.AddGetValue("service_type", "1"); // 0为群,1为讨论组
            }
            else
            {
                // LOG.info("GetSessionMsgSigAction unknow type :" + user);
            }
            req.AddGetValue("to_uin", user.Uin + "");
            req.AddGetValue("clientid", session.ClientId + "");
            req.AddGetValue("psessionid", session.SessionId);
            req.AddGetValue("t", DateUtils.NowTimestamp() / 1000 + "");
            return(req);
        }
        /** {@inheritDoc} */
        public override QQHttpRequest onBuildRequest()
        {
            QQSession     session = getContext().getSession();
            QQHttpRequest req     = createHttpRequest("GET",
                                                      QQConstants.URL_GET_SESSION_MSG_SIG);

            if (user is QQGroupMember)
            {
                QQGroupMember mb = (QQGroupMember)user;
                mb.setServiceType(0);
                req.addGetValue("id", mb.getGroup().getGin() + "");
                req.addGetValue("service_type", "0");         // 0为群,1为讨论组
            }
            else if (user is QQDiscuzMember)
            {
                QQDiscuzMember mb = (QQDiscuzMember)user;
                mb.setServiceType(1);
                req.addGetValue("id", mb.getDiscuz().getDid() + "");
                req.addGetValue("service_type", "1");         // 0为群,1为讨论组
            }
            else
            {
            }
            req.addGetValue("to_uin", user.getUin() + "");
            req.addGetValue("clientid", session.getClientId() + "");
            req.addGetValue("psessionid", session.getSessionId());
            req.addGetValue("t", DateTime.Now.Ticks / 1000 + "");
            return(req);
        }
Exemple #3
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            JObject json = JObject.Parse(response.GetResponseString());

            if (json["retcode"].ToString() == "0")
            {
                json = json["result"].ToObject <JObject>();

                // 消除所有成员状态,如果不在线的,webqq是不会返回的。
                foreach (QQGroupMember member in group.Members)
                {
                    member.Status     = QQStatus.OFFLINE;
                    member.ClientType = QQClientType.Unknown;
                }

                //result/stats
                JArray stats = json["stats"].ToObject <JArray>();
                for (int i = 0; i < stats.Count; i++)
                {
                    // 下面重新设置最新状态
                    JObject       stat   = stats[i].ToObject <JObject>();
                    QQGroupMember member = group.GetMemberByUin(stat["uin"].ToObject <long>());
                    if (member != null)
                    {
                        member.ClientType = QQClientType.ValueOfRaw(stat["client_type"].ToObject <int>());
                        member.Status     = QQStatus.ValueOfRaw(stat["stat"].ToObject <int>());
                    }
                }

                NotifyActionEvent(QQActionEventType.EVT_OK, group);
            }
            else
            {
                NotifyActionEvent(QQActionEventType.EVT_ERROR, QQErrorCode.UNEXPECTED_RESPONSE);
            }
        }
        /** {@inheritDoc} */
        public override void onHttpStatusOK(QQHttpResponse response)
        {
            JSONObject json = new JSONObject(response.getResponseString());

            if (json.getInt("retcode") == 0)
            {
                json = json.getJSONObject("result");

                // 消除所有成员状态,如果不在线的,webqq是不会返回的。
                foreach (QQGroupMember member in  group.getMembers())
                {
                    member.setStatus(QQStatus.OFFLINE);
                    //member.setClientType(QQClientType.UNKNOWN);
                }

                //result/stats
                JSONArray stats = json.getJSONArray("stats");
                for (int i = 0; i < stats.length(); i++)
                {
                    // 下面重新设置最新状态
                    JSONObject    stat   = stats.getJSONObject(i);
                    QQGroupMember member = group.getMemberByUin(stat.getLong("uin"));
                    if (member != null)
                    {
                        //member.setClientType(QQClientType.valueOfRaw(stat.getInt("client_type")));
                        //member.setStatus(QQStatus.valueOfRaw(stat.getInt("stat")));
                    }
                }

                notifyActionEvent(QQActionEvent.Type.EVT_OK, group);
            }
            else
            {
                notifyActionEvent(QQActionEvent.Type.EVT_ERROR, QQWpfApplication1.action.QQException.QQErrorCode.UNEXPECTED_RESPONSE);
            }
        }
Exemple #5
0
        public override void onHttpStatusOK(QQHttpResponse response)
        {
            JSONObject json = new JSONObject(response.getResponseString());

            if (json.getInt("retcode") == 0)
            {
                json = json.getJSONObject("result");
                JSONObject ginfo = json.getJSONObject("ginfo");
                group.setMemo(ginfo.getString("memo"));
                group.setLevel(ginfo.getInt("level"));
                group.setCreateTime(DateTime.FromBinary(ginfo.getInt("createtime")));

                JSONArray members = ginfo.getJSONArray("members");
                for (int i = 0; i < members.length(); i++)
                {
                    JSONObject    memjson = members.getJSONObject(i);
                    QQGroupMember member  = group.getMemberByUin(memjson.getLong("muin"));
                    if (member == null)
                    {
                        member = new QQGroupMember();
                        group.getMembers().Add(member);
                    }
                    member.setUin(memjson.getLong("muin"));
                    member.setGroup(group);
                    //memjson.getLong("mflag"); //TODO ...
                }

                //result/minfo
                JSONArray minfos = json.getJSONArray("minfo");
                for (int i = 0; i < minfos.length(); i++)
                {
                    JSONObject    minfo  = minfos.getJSONObject(i);
                    QQGroupMember member = group.getMemberByUin(minfo.getLong("uin"));
                    member.setNickname(minfo.getString("nick"));
                    member.setProvince(minfo.getString("province"));
                    member.setCountry(minfo.getString("country"));
                    member.setCity(minfo.getString("city"));
                    member.setGender(minfo.getString("gender"));
                }

                //result/stats
                JSONArray stats = json.getJSONArray("stats");
                for (int i = 0; i < stats.length(); i++)
                {
                    // 下面重新设置最新状态
                    JSONObject    stat   = stats.getJSONObject(i);
                    QQGroupMember member = group.getMemberByUin(stat.getLong("uin"));
                    //member.setClientType(QQClientType.valueOfRaw(stat.getInt("client_type")));
                    //member.setStatus(QQStatus.valueOfRaw(stat.getInt("stat")));
                }

                //results/cards
                if (json.has("cards"))
                {
                    JSONArray cards = json.getJSONArray("cards");
                    for (int i = 0; i < cards.length(); i++)
                    {
                        JSONObject    card   = cards.getJSONObject(i);
                        QQGroupMember member = group.getMemberByUin(card.getLong("muin"));
                        if (card != null && card.has("card") && member != null)
                        {
                            member.setCard(card.getString("card"));
                        }
                    }
                }

                //results/vipinfo
                JSONArray vipinfos = json.getJSONArray("vipinfo");
                for (int i = 0; i < vipinfos.length(); i++)
                {
                    JSONObject    vipinfo = vipinfos.getJSONObject(i);
                    QQGroupMember member  = group.getMemberByUin(vipinfo.getLong("u"));
                    member.setVipLevel(vipinfo.getInt("vip_level"));
                    member.setVip(vipinfo.getInt("is_vip") == 1);
                }

                notifyActionEvent(QQActionEvent.Type.EVT_OK, group);
            }
            else
            {
                notifyActionEvent(QQActionEvent.Type.EVT_ERROR, QQWpfApplication1.action.QQException.QQErrorCode.UNEXPECTED_RESPONSE);
            }
        }
Exemple #6
0
        /**
         * <p>
         * processGroupMsg.
         * </p>
         *
         * @param pollData
         *            a {@link org.json.JSONObject} object.
         * @throws org.json.JSONException
         *             if any.
         * @throws iqq.im.QQException
         *             if any.
         * @return a {@link iqq.im.event.QQNotifyEvent} object.
         */
        public QQNotifyEvent processGroupMsg(JSONObject pollData)
        {
            // {"retcode"in0,"result"in[{"poll_type"in"group_message",
            // "value"in{"msg_id"in6175,"from_uin"in3924684389,"to_uin"in1070772010,"msg_id2"in992858,"msg_type"in43,"reply_ip"in176621921,
            // "group_code"in3439321257,"send_uin"in1843694270,"seq"in875,"time"in1365934781,"info_seq"in170125666,"content"in[["font",{"size"in10,"color"in"3b3b3b","style"in[0,0,0],"name"in"\u5FAE\u8F6F\u96C5\u9ED1"}],"eeeeeeeee "]}}]}
            QQStore store = getContext().getStore();
            QQMsg   msg   = new QQMsg();

            msg.setId(pollData.getLong("msg_id"));
            msg.setId2(pollData.getLong("msg_id2"));
            int     msgType   = pollData.getInt("msg_type");
            long    gin       = pollData.getLong("from_uin");
            long    fromUin   = pollData.getLong("send_uin");
            long    groupCode = pollData.getLong("group_code");
            QQGroup group     = store.getGroupByCode(groupCode);
            long    groupID   = -1;

            if (group == null)
            {
                group = new QQGroup();
                group.setGin(gin);
                group.setCode(groupCode);
                // put to store
                store.addGroup(group);
            }
            switch (msgType)
            {
            case 32: {
                // 魔法、超级、涂鸦表情
                groupID = pollData.getLong("t_gcode");         // 真实群号码
                break;
            }

            case 43:
                // 一般消息
                groupID = pollData.getLong("info_seq");         // 真实群号码


                msg.parseContentList(pollData.getJSONArray("content").ToString());
                msg.setType(QQMsg.Type.GROUP_MSG);
                msg.setDate(new DateTime(pollData.getLong("time") * 1000));
                break;

            default:
                break;
            }
            if (group.getGid() <= 0)
            {
                group.setGid(groupID);
            }
            msg.setGroup(group);
            if (group != null)
            {
                msg.setFrom(group.getMemberByUin(fromUin));
            }
            msg.setTo(getContext().getAccount());
            if (msg.getFrom() == null)
            {
                QQGroupMember member = new QQGroupMember();
                member.setUin(fromUin);
                msg.setFrom(member);
                if (group != null)
                {
                    group.getMembers().Add(member);
                }
            }

            return(new QQNotifyEvent(QQNotifyEvent.Type.CHAT_MSG, msg));
        }
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            JObject json = JObject.Parse(response.GetResponseString());

            if (json["retcode"].ToString() == "0")
            {
                json = json["result"].ToObject <JObject>();
                JObject ginfo = json["ginfo"].ToObject <JObject>();
                group.Memo       = ginfo["memo"].ToString();
                group.Level      = ginfo["level"].ToObject <int>();
                group.CreateTime = new DateTime(ginfo["createtime"].ToObject <int>());

                JArray members = ginfo["members"].ToObject <JArray>();
                for (int i = 0; i < members.Count; i++)
                {
                    JObject       memjson = members[i].ToObject <JObject>();
                    QQGroupMember member  = group.GetMemberByUin(memjson["muin"].ToObject <long>());
                    if (member == null)
                    {
                        member = new QQGroupMember();
                        group.Members.Add(member);
                    }
                    member.Uin   = memjson["muin"].ToObject <long>();
                    member.Group = group;
                    //memjson["mflag"]; //TODO ...
                }

                //result/minfo
                JArray minfos = json["minfo"].ToObject <JArray>();
                for (int i = 0; i < minfos.Count; i++)
                {
                    JObject       minfo  = minfos[i].ToObject <JObject>();
                    QQGroupMember member = group.GetMemberByUin(minfo["uin"].ToObject <int>());
                    member.Nickname = minfo["nick"].ToString();
                    member.Province = minfo["province"].ToString();
                    member.Country  = minfo["country"].ToString();
                    member.City     = minfo["city"].ToString();
                    member.Gender   = minfo["gender"].ToString();
                }

                //result/stats
                JArray stats = json["stats"].ToObject <JArray>();
                for (int i = 0; i < stats.Count; i++)
                {
                    // 下面重新设置最新状态
                    JObject       stat   = stats[i].ToObject <JObject>();
                    QQGroupMember member = group.GetMemberByUin(stat["uin"].ToObject <long>());
                    member.ClientType = QQClientType.ValueOfRaw(stat["client_type"].ToObject <int>());
                    member.Status     = QQStatus.ValueOfRaw(stat["stat"].ToObject <int>());
                }

                //results/cards
                if (json["cards"] != null)
                {
                    JArray cards = json["cards"].ToObject <JArray>();
                    for (int i = 0; i < cards.Count; i++)
                    {
                        JObject       card   = cards[i].ToObject <JObject>();
                        QQGroupMember member = group.GetMemberByUin(card["muin"].ToObject <long>());
                        if (card["card"] != null && member != null)
                        {
                            member.Card = card["card"].ToString();
                        }
                    }
                }

                //results/vipinfo
                JArray vipinfos = json["vipinfo"].ToObject <JArray>();
                for (int i = 0; i < vipinfos.Count; i++)
                {
                    JObject       vipinfo = vipinfos[i].ToObject <JObject>();
                    QQGroupMember member  = group.GetMemberByUin(vipinfo["u"].ToObject <long>());
                    member.VipLevel = vipinfo["vip_level"].ToObject <int>();
                    member.IsVip    = (vipinfo["is_vip"].ToString() != "0");
                }

                NotifyActionEvent(QQActionEventType.EVT_OK, group);
            }
            else
            {
                NotifyActionEvent(QQActionEventType.EVT_ERROR, QQErrorCode.UNEXPECTED_RESPONSE);
            }
        }
Exemple #8
0
        /// <summary>
        /// 处理群消息
        /// </summary>
        /// <param name="pollData"></param>
        /// <returns></returns>
        private QQNotifyEvent ProcessGroupMsg(JObject pollData)
        {
            /*
             *  {
             *      "content": [
             *          [
             *              "font",
             *              {
             *                  "color": "000000",
             *                  "name": "微软雅黑",
             *                  "size": 10,
             *                  "style": [
             *                      0,
             *                      0,
             *                      0
             *                  ]
             *              }
             *          ],
             *          "d"
             *      ],
             *      "from_uin": 3471070329,
             *      "group_code": 3471070329,
             *      "msg_id": 29208,
             *      "msg_type": 0,
             *      "send_uin": 1000693217,
             *      "time": 1472803177,
             *      "to_uin": 89009143
             *  }
             */
            try
            {
                var store       = Context.Store;
                var groupMudule = Context.GetModule <GroupModule>(QQModuleType.GROUP);

                var ticks = pollData["time"].ToObject <long>() * 1000;
                var msg   = new QQMsg
                {
                    Id   = pollData["msg_id"].ToObject <long>(),
                    Type = QQMsgType.GROUP_MSG,
                    To   = Context.Account,
                    Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks),
                };
                var fromUin = pollData["send_uin"].ToObject <long>();
                var code    = pollData["group_code"].ToObject <long>(); // 实际上是gid不是gcode
                var group   = store.GetGroupById(code);
                if (group == null)
                {
                    groupMudule.GetGroupList();
                    group = new QQGroup {
                        Gid = code
                    };
                }
                groupMudule.GetGroupInfo(group);

                msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"]));
                msg.Date  = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks);
                msg.Group = group;
                msg.From  = group.GetMemberByUin(fromUin);

                if (msg.From == null)
                {
                    var member = new QQGroupMember {
                        Uin = fromUin
                    };
                    msg.From = member;
                    group.Members.Add(member);
                    // 获取用户信息
                    var userModule = Context.GetModule <UserModule>(QQModuleType.USER);
                    userModule.GetUserInfo(member);
                }

                return(new QQNotifyEvent(QQNotifyEventType.GroupMsg, msg));
            }
            catch (Exception ex)
            {
                return(new QQNotifyEvent(QQNotifyEventType.NetError, ex));
            }
        }
Exemple #9
0
        public override void OnHttpStatusOK(QQHttpResponse response)
        {
            var str  = response.GetResponseString();
            var json = JObject.Parse(str);

            if (json["retcode"].ToString() == "0")
            {
                var result = json["result"].ToObject <JObject>();
                var ginfo  = result["ginfo"].ToObject <JObject>();
                _group.Memo  = ginfo["memo"].ToString();
                _group.Level = ginfo["level"].ToObject <int>();
                var ticks = ginfo["createtime"].ToObject <long>() * 1000;
                _group.CreateTime = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks);

                var members = ginfo["members"].ToObject <JArray>();
                for (var i = 0; i < members.Count; i++)
                {
                    var memjson = members[i].ToObject <JObject>();
                    var member  = _group.GetMemberByUin(memjson["muin"].ToObject <long>());
                    if (member == null)
                    {
                        member = new QQGroupMember();
                        _group.Members.Add(member);
                    }
                    member.Uin   = memjson["muin"].ToObject <long>();
                    member.Group = _group;
                    //memjson["mflag"]; //TODO ...
                }

                //result/minfo
                var minfos = result["minfo"].ToObject <JArray>();
                foreach (var token in minfos)
                {
                    var minfo  = token.ToObject <JObject>();
                    var member = _group.GetMemberByUin(minfo["uin"].ToObject <long>());
                    member.Nickname = minfo["nick"].ToString();
                    member.Province = minfo["province"].ToString();
                    member.Country  = minfo["country"].ToString();
                    member.City     = minfo["city"].ToString();
                    member.Gender   = minfo["gender"].ToString();
                }

                //result/stats
                var stats = result["stats"].ToObject <JArray>();
                for (var i = 0; i < stats.Count; i++)
                {
                    // 下面重新设置最新状态
                    var stat   = stats[i].ToObject <JObject>();
                    var member = _group.GetMemberByUin(stat["uin"].ToObject <long>());
                    member.ClientType = QQClientTypeInfo.ValueOfRaw(stat["client_type"].ToObject <int>());
                    member.Status     = QQStatus.ValueOfRaw(stat["stat"].ToObject <int>());
                }

                //results/cards
                if (result["cards"] != null)
                {
                    var cards = result["cards"].ToObject <JArray>();
                    for (var i = 0; i < cards.Count; i++)
                    {
                        var card   = cards[i].ToObject <JObject>();
                        var member = _group.GetMemberByUin(card["muin"].ToObject <long>());
                        if (card["card"] != null && member != null)
                        {
                            member.Card = card["card"].ToString();
                        }
                    }
                }

                //results/vipinfo
                var vipinfos = result["vipinfo"].ToObject <JArray>();
                for (var i = 0; i < vipinfos.Count; i++)
                {
                    var vipinfo = vipinfos[i].ToObject <JObject>();
                    var member  = _group.GetMemberByUin(vipinfo["u"].ToObject <long>());
                    member.VipLevel = vipinfo["vip_level"].ToObject <int>();
                    member.IsVip    = (vipinfo["is_vip"].ToString() != "0");
                }

                NotifyActionEvent(QQActionEventType.EvtOK, _group);
            }
            else
            {
                // NotifyActionEvent(QQActionEventType.EVT_ERROR, QQErrorCode.UNEXPECTED_RESPONSE);
                throw new QQException(QQErrorCode.UnexpectedResponse, str);
            }
        }
Exemple #10
0
        /// <summary>
        /// 处理群消息
        /// </summary>
        /// <param name="pollData"></param>
        /// <returns></returns>
        public QQNotifyEvent ProcessGroupMsg(JObject pollData)
        {
            // {"retcode":0,"result":[{"poll_type":"group_message",
            // "value":{"msg_id":6175,"from_uin":3924684389,"to_uin":1070772010,"msg_id2":992858,"msg_type":43,"reply_ip":176621921,
            // "group_code":3439321257,"send_uin":1843694270,"seq":875,"time":1365934781,"info_seq":170125666,"content":[["font",{"size":10,"color":"3b3b3b","style":[0,0,0],"name":"\u5FAE\u8F6F\u96C5\u9ED1"}],"eeeeeeeee "]}}]}

            try
            {
                var store = Context.Store;
                var msg   = new QQMsg
                {
                    Id  = pollData["msg_id"].ToObject <long>(),
                    Id2 = pollData["msg_id2"].ToObject <long>()
                };
                var fromUin   = pollData["send_uin"].ToObject <long>();
                var groupCode = pollData["group_code"].ToObject <long>();
                var groupId   = pollData["info_seq"].ToObject <long>(); // 真实群号码
                var group     = store.GetGroupByCode(groupCode);
                if (group == null)
                {
                    var groupModule = Context.GetModule <GroupModule>(QQModuleType.GROUP);
                    group = new QQGroup
                    {
                        Code = groupCode,
                        Gid  = groupId
                    };
                    // put to store
                    store.AddGroup(group);
                    groupModule.GetGroupInfo(group, null);
                }
                if (group.Gid <= 0)
                {
                    group.Gid = groupId;
                }

                msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"]));
                msg.Type = QQMsgType.GROUP_MSG;
                msg.To   = Context.Account;
                var ticks = pollData["time"].ToObject <long>() * 1000;
                msg.Date  = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks);
                msg.Group = group;
                msg.From  = group.GetMemberByUin(fromUin);

                if (msg.From == null)
                {
                    var member = new QQGroupMember {
                        Uin = fromUin
                    };
                    msg.From = member;
                    group.Members.Add(member);
                    // 获取用户信息
                    var userModule = Context.GetModule <UserModule>(QQModuleType.USER);
                    userModule.GetUserInfo(member, null);
                }
                return(new QQNotifyEvent(QQNotifyEventType.CHAT_MSG, msg));
            }
            catch (Exception ex)
            {
                return(new QQNotifyEvent(QQNotifyEventType.NET_ERROR, ex));
            }
        }