Exemplo n.º 1
0
        public override QQHttpRequest OnBuildRequest()
        {
            // r:{"to":2982077931,"face":0,"content":"[\"123\",[\"face\",1],\"456\",[\"face\",0],\"\",\"\\n【提示:此用户正在使用Q+ Web:http://web.qq.com/】\",[\"font\",{\"name\":\"微软雅黑\",\"size\":\"11\",\"style\":[0,0,0],\"color\":\"ffcc99\"}]]","msg_id":91310001,"clientid":"74131454","psessionid":"8368046764001e636f6e6e7365727665725f77656271714031302e3133332e34312e3230320000230700001f01026e04002aafd23f6d0000000a40484a526f4866467a476d00000028d954c71693cd99ae8c0c64b651519e88f55ce5075140346da7d957f3abefb51d0becc25c425d7cf5"}
            // r:{"group_uin":3408869879,"content":"[\"群消息发送测试\",[\"face\",13],\"\",\"\\n【提示:此用户正在使用Q+ Web:http://web.qq.com/】\",[\"font\",{\"name\":\"微软雅黑\",\"size\":\"11\",\"style\":[0,0,0],\"color\":\"ffcc99\"}]]","msg_id":91310002,"clientid":"74131454","psessionid":"8368046764001e636f6e6e7365727665725f77656271714031302e3133332e34312e3230320000230700001f01026e04002aafd23f6d0000000a40484a526f4866467a476d00000028d954c71693cd99ae8c0c64b651519e88f55ce5075140346da7d957f3abefb51d0becc25c425d7cf5"}
            // clientid、psessionid

            QQSession     session = Context.Session;
            JObject       json    = new JObject();
            QQHttpRequest req     = null;

            if (msg.Type == QQMsgType.BUDDY_MSG)
            {
                req = CreateHttpRequest("POST", QQConstants.URL_SEND_BUDDY_MSG);
                json.Add("to", msg.To.Uin);
                json.Add("face", 0); // 这个是干嘛的??
            }
            else if (msg.Type == QQMsgType.GROUP_MSG)
            {
                req = CreateHttpRequest("POST", QQConstants.URL_SEND_GROUP_MSG);
                json.Add("group_uin", msg.Group.Gin);
                json.Add("key", session.CfaceKey);
                json.Add("sig", session.CfaceSig);
            }
            else if (msg.Type == QQMsgType.DISCUZ_MSG)
            {
                req = CreateHttpRequest("POST", QQConstants.URL_SEND_DISCUZ_MSG);
                json.Add("did", msg.Discuz.Did);
                json.Add("key", session.CfaceKey);
                json.Add("sig", session.CfaceSig);
            }
            else if (msg.Type == QQMsgType.SESSION_MSG)
            {   // 临时会话消息
                req = CreateHttpRequest("POST", QQConstants.URL_SEND_SESSION_MSG);
                QQStranger member = (QQStranger)msg.To;
                json.Add("to", member.Uin);
                json.Add("face", 0); // 这个是干嘛的??
                json.Add("group_sig", member.GroupSig);
                json.Add("service_type", member.ServiceType + "");
            }
            else
            {
                MyLogger.Default.Warn("unknown MsgType: " + msg.Type);
            }

            json.Add("content", msg.PackContentList());
            json.Add("msg_id", ++_msgId);
            json.Add("clientid", session.ClientId);
            json.Add("psessionid", session.SessionId);

            req.AddPostValue("r", JsonConvert.SerializeObject(json));
            req.AddPostValue("clientid", session.ClientId + "");
            req.AddPostValue("psessionid", session.SessionId);
            req.AddHeader("Referer", QQConstants.REFFER);

            // System.out.println("sendMsg: " + JsonConvert.SerializeObject(json));
            return(req);
        }
Exemplo n.º 2
0
        /** {@inheritDoc} */
        public override QQHttpRequest onBuildRequest()
        {
            // r:{"to":2982077931,"face":0,"content":"[\"123\",[\"face\",1],\"456\",[\"face\",0],\"\",\"\\n【提示:此用户正在使用Q+ Web:http://web.qq.com/】\",[\"font\",{\"name\":\"微软雅黑\",\"size\":\"11\",\"style\":[0,0,0],\"color\":\"ffcc99\"}]]","msg_id":91310001,"clientid":"74131454","psessionid":"8368046764001e636f6e6e7365727665725f77656271714031302e3133332e34312e3230320000230700001f01026e04002aafd23f6d0000000a40484a526f4866467a476d00000028d954c71693cd99ae8c0c64b651519e88f55ce5075140346da7d957f3abefb51d0becc25c425d7cf5"}
            // r:{"group_uin":3408869879,"content":"[\"群消息发送测试\",[\"face\",13],\"\",\"\\n【提示:此用户正在使用Q+ Web:http://web.qq.com/】\",[\"font\",{\"name\":\"微软雅黑\",\"size\":\"11\",\"style\":[0,0,0],\"color\":\"ffcc99\"}]]","msg_id":91310002,"clientid":"74131454","psessionid":"8368046764001e636f6e6e7365727665725f77656271714031302e3133332e34312e3230320000230700001f01026e04002aafd23f6d0000000a40484a526f4866467a476d00000028d954c71693cd99ae8c0c64b651519e88f55ce5075140346da7d957f3abefb51d0becc25c425d7cf5"}
            // clientid、psessionid

            QQSession     session = getContext().getSession();
            JSONObject    json    = new JSONObject();
            QQHttpRequest req     = null;

            if (msg.getType() == QQMsg.Type.BUDDY_MSG)
            {
                req = createHttpRequest("POST", QQConstants.URL_SEND_BUDDY_MSG);
                json.put("to", msg.getTo().getUin());
                json.put("face", 0);         // 这个是干嘛的??
            }
            else if (msg.getType() == QQMsg.Type.GROUP_MSG)
            {
                req = createHttpRequest("POST", QQConstants.URL_SEND_GROUP_MSG);
                json.put("group_uin", msg.getGroup().getGin());
//			json.put("key", session.getCfaceKey());
//			json.put("sig", session.getCfaceSig());
            }
            else if (msg.getType() == QQMsg.Type.DISCUZ_MSG)
            {
                req = createHttpRequest("POST", QQConstants.URL_SEND_DISCUZ_MSG);
                json.put("did", msg.getDiscuz().getDid());
                json.put("key", session.getCfaceKey());
                json.put("sig", session.getCfaceSig());
            }
            else if (msg.getType() == QQMsg.Type.SESSION_MSG)           // 临时会话消息
            {
                req = createHttpRequest("POST", QQConstants.URL_SEND_SESSION_MSG);
                QQStranger member = (QQStranger)msg.getTo();
                json.put("to", member.getUin());
                json.put("face", 0);         // 这个是干嘛的??
                json.put("group_sig", member.getGroupSig());
                json.put("service_type", member.getServiceType() + "");
            }
            else
            {
            }

            json.put("content", msg.packContentList());
            json.put("msg_id", 91310001 + "");
            json.put("clientid", session.getClientId());
            json.put("psessionid", session.getSessionId());

            req.addPostValue("r", json.ToString());
            req.addPostValue("clientid", session.getClientId() + "");
            req.addPostValue("psessionid", session.getSessionId());
            req.addHeader("Referer", QQConstants.REFFER);

            return(req);
        }
Exemplo n.º 3
0
 public QQActionFuture SendMsg(QQMsg msg, QQActionEventHandler listener)
 {
     if (msg.Type == QQMsgType.SESSION_MSG)
     {
         ProcActionFuture future   = new ProcActionFuture(listener, true);
         QQStranger       stranger = (QQStranger)msg.To;
         if (string.IsNullOrEmpty(stranger.GroupSig))
         {
             GetSessionMsgSig(stranger, new QQActionEventHandler((sender, Event) =>
             {
                 if (Event.Type == QQActionEventType.EVT_OK)
                 {
                     if (!future.IsCanceled)
                     {
                         DoSendMsg(msg, future.Listener);
                     }
                 }
                 else if (Event.Type == QQActionEventType.EVT_ERROR)
                 {
                     future.NotifyActionEvent(Event.Type, Event.Target);
                 }
             }));
         }
         return(future);
     }
     else if (msg.Type == QQMsgType.GROUP_MSG || msg.Type == QQMsgType.DISCUZ_MSG)
     {
         if (string.IsNullOrEmpty(this.Context.Session.CfaceKey))
         {
             ProcActionFuture future = new ProcActionFuture(listener, true);
             GetCFaceSig(new QQActionEventHandler((sender, Event) =>
             {
                 if (Event.Type == QQActionEventType.EVT_OK)
                 {
                     if (!future.IsCanceled)
                     {
                         DoSendMsg(msg, future.Listener);
                     }
                 }
                 else if (Event.Type == QQActionEventType.EVT_ERROR)
                 {
                     future.NotifyActionEvent(Event.Type, Event.Target);
                 }
             }));
             return(future);
         }
     }
     return(DoSendMsg(msg, listener));
 }
Exemplo n.º 4
0
 public AbstractActionFuture sendMsg(QQMsg msg, QQActionListener.OnActionEvent listener)
 {
     if (msg.getType() == QQMsg.Type.SESSION_MSG)
     {
         AbstractActionFuture future   = new AbstractActionFuture(listener);
         QQStranger           stranger = (QQStranger)msg.getTo();
         if (stranger.getGroupSig() == null || stranger.getGroupSig().Equals(""))
         {
             getSessionMsgSig(stranger, delegate(QQActionEvent evt) {
                 if (evt.getType() == QQActionEvent.Type.EVT_OK)
                 {
                     doSendMsg(msg, future);
                 }
                 else if (evt.getType() == QQActionEvent.Type.EVT_ERROR)
                 {
                     future.notifyActionEvent(evt.getType(), evt.getTarget());
                 }
             });
         }
         return(future);
     }
     else if (msg.getType() == QQMsg.Type.GROUP_MSG || msg.getType() == QQMsg.Type.DISCUZ_MSG)
     {
         if (getContext().getSession().getCfaceKey() == null || getContext().getSession().getCfaceKey().Equals(""))
         {
             AbstractActionFuture future = new AbstractActionFuture(listener);
             getCFaceSig(delegate(QQActionEvent evt) {
                 if (evt.getType() == QQActionEvent.Type.EVT_OK)
                 {
                     doSendMsg(msg, future);
                 }
                 else if (evt.getType() == QQActionEvent.Type.EVT_ERROR)
                 {
                     future.notifyActionEvent(evt.getType(), evt.getTarget());
                 }
             });
             return(future);
         }
     }
     return(doSendMsg(msg, listener));
 }
Exemplo n.º 5
0
        /// <summary>
        /// 临时消息信道,用于发送群U2U会话消息
        /// </summary>
        /// <param name="user"></param>
        /// <param name="listener"></param>
        /// <returns></returns>
        public IQQActionFuture GetSessionMsgSig(QQStranger user, QQActionListener listener)
        {
            var mod = GetModule <ChatModule>(QQModuleType.CHAT);

            return(mod.GetSessionMsgSig(user, listener));
        }
Exemplo n.º 6
0
 public void DeleteStranger(QQStranger stranger)
 {
     _strangerMap.Remove(stranger.Uin);
 }
Exemplo n.º 7
0
 public void AddStranger(QQStranger stranger)
 {
     _strangerMap.Add(stranger.Uin, stranger, AddChoice.Update);
 }
Exemplo n.º 8
0
 public QQActionFuture GetSessionMsgSig(QQStranger user, QQActionEventHandler listener)
 {
     return(PushHttpAction(new GetSessionMsgSigAction(this.Context, listener, user)));
 }
Exemplo n.º 9
0
 public GetSessionMsgSigAction(IQQContext context, QQActionListener listener,
                               QQStranger user)
     : base(context, listener)
 {
     this._user = user;
 }
Exemplo n.º 10
0
 /**
  * <p>getSessionMsgSig.</p>
  *
  * @param user a {@link iqq.im.bean.QQStranger} object.
  * @param listener a {@link iqq.im.QQActionListener.OnActionEvent} object.
  * @return a {@link iqq.im.evt.AbstractActionFuture} object.
  */
 public AbstractActionFuture getSessionMsgSig(QQStranger user, QQActionListener.OnActionEvent listener)
 {
     return(pushHttpAction(new GetSessionMsgSigAction(getContext(), listener, user)));
 }
Exemplo n.º 11
0
        /// <summary>
        /// 处理临时会话消息
        /// </summary>
        /// <param name="pollData"></param>
        /// <returns></returns>
        private QQNotifyEvent ProcessSessionMsg(JObject pollData)
        {
            // {"retcode":0,"result":[{"poll_type":"sess_message",
            // "value":{"msg_id":25144,"from_uin":167017143,"to_uin":1070772010,"msg_id2":139233,"msg_type":140,"reply_ip":176752037,"time":1365931836,"id":2581801127,"ruin":444674479,"service_type":1,
            // "flags":{"text":1,"pic":1,"file":1,"audio":1,"video":1},"content":[["font",{"size":9,"color":"000000","style":[0,0,0],"name":"Tahoma"}],"2\u8F7D3 ",["face",1]," "]}}]}
            try
            {
                var store       = Context.Store;
                var msg         = new QQMsg();
                var fromUin     = pollData["from_uin"].ToObject <long>();
                var fromQQ      = pollData["ruin"].ToObject <long>();        // 真实QQ
                var serviceType = pollData["service_type"].ToObject <int>(); // Group:0,Discuss:1
                var typeId      = pollData["id"].ToObject <long>();          // Group ID or Discuss ID

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

                QQUser user = store.GetBuddyByUin(fromUin); // 首先看看是不是自己的好友
                if (user != null)
                {
                    msg.Type = QQMsgType.BUDDY_MSG; // 是自己的好友
                }
                else
                {
                    if (serviceType == 0)
                    { // 是群成员
                        var group = store.GetGroupByCode(typeId);
                        if (group == null)
                        {
                            group      = new QQGroup();
                            group.Code = typeId;
                            // 获取群信息
                            var groupModule = Context.GetModule <GroupModule>(QQModuleType.GROUP);
                            groupModule.GetGroupInfo(group, null);
                        }
                        foreach (var u in group.Members)
                        {
                            if (u.Uin == fromUin)
                            {
                                user = u;
                                break;
                            }
                        }
                    }
                    else if (serviceType == 1)
                    { // 是讨论组成员
                        var discuz = store.GetDiscuzByDid(typeId);
                        if (discuz == null)
                        {
                            discuz = new QQDiscuz {
                                Did = typeId
                            };

                            // 获取讨论组信息
                            var discuzModule = Context.GetModule <DiscuzModule>(QQModuleType.DISCUZ);
                            discuzModule.GetDiscuzInfo(discuz, null);
                        }

                        foreach (var u in discuz.Members)
                        {
                            if (u.Uin == fromUin)
                            {
                                user = u;
                                break;
                            }
                        }
                    }
                    else
                    {
                        user = store.GetStrangerByUin(fromUin); // 看看陌生人列表中有木有
                    }
                    if (user == null)
                    { // 还没有就新建一个陌生人,原理来说不应该这样。后面我就不知道怎么回复这消息了,但是消息是不能丢失的
                        user = new QQStranger
                        {
                            QQ       = pollData["ruin"].ToObject <long>(),
                            Uin      = fromUin,
                            Nickname = pollData["ruin"].ToString()
                        };
                        store.AddStranger((QQStranger)user);

                        // 获取用户信息
                        var userModule = Context.GetModule <UserModule>(QQModuleType.USER);
                        userModule.GetStrangerInfo(user, null);
                    }
                }
                user.QQ  = fromQQ; // 带上QQ号码
                msg.From = user;
                return(new QQNotifyEvent(QQNotifyEventType.ChatMsg, msg));
            }
            catch (Exception ex)
            {
                return(new QQNotifyEvent(QQNotifyEventType.NetError, ex));
            }
        }
Exemplo n.º 12
0
 public GetSessionMsgSigAction(QQContext context, QQActionEventHandler listener,
                               QQStranger user)
     : base(context, listener)
 {
     this.user = user;
 }
Exemplo n.º 13
0
 public IQQActionFuture GetSessionMsgSig(QQStranger user, QQActionListener listener)
 {
     return(PushHttpAction(new GetSessionMsgSigAction(Context, listener, user)));
 }
Exemplo n.º 14
0
 /**
  * <p>addStranger.</p>
  *
  * @param stranger a {@link iqq.im.bean.QQStranger} object.
  */
 public void addStranger(QQStranger stranger)
 {
     strangerDictionary.Add(stranger.getUin(), stranger);
 }
Exemplo n.º 15
0
 /**
  * <p>deleteStranger.</p>
  *
  * @param stranger a {@link iqq.im.bean.QQStranger} object.
  */
 public void deleteStranger(QQStranger stranger)
 {
     strangerDictionary.Remove(stranger.getUin());
 }
Exemplo n.º 16
0
 public void AddStranger(QQStranger stranger)
 {
     _strangerMap[stranger.Uin] = stranger;
 }
Exemplo n.º 17
0
 public void DeleteStranger(QQStranger stranger)
 {
     _strangerMap.TryRemove(stranger.Uin, out stranger);
 }
Exemplo n.º 18
0
        /**
         * <p>
         * processSessionMsg.
         * </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 processSessionMsg(JSONObject pollData)
        {
            // {"retcode"in0,"result"in[{"poll_type"in"sess_message",
            // "value"in{"msg_id"in25144,"from_uin"in167017143,"to_uin"in1070772010,"msg_id2"in139233,"msg_type"in140,"reply_ip"in176752037,"time"in1365931836,"id"in2581801127,"ruin"in444674479,"service_type"in1,
            // "flags"in{"text"in1,"pic"in1,"file"in1,"audio"in1,"video"in1},"content"in[["font",{"size"in9,"color"in"000000","style"in[0,0,0],"name"in"Tahoma"}],"2\u8F7D3 ",["face",1]," "]}}]}
            QQStore store = getContext().getStore();

            QQMsg msg         = new QQMsg();
            long  fromUin     = pollData.getLong("from_uin");
            long  fromQQ      = pollData.getLong("ruin");        // 真实QQ
            int   serviceType = pollData.getInt("service_type"); // Groupin0,Discussin1
            long  typeId      = pollData.getLong("id");          // Group ID or Discuss ID

            msg.parseContentList(pollData.getJSONArray("content").ToString());
            msg.setType(QQMsg.Type.SESSION_MSG);
            msg.setTo(getContext().getAccount());
            msg.setDate(new DateTime(pollData.getLong("time") * 1000));

            QQUser user = store.getBuddyByUin(fromUin);     // 首先看看是不是自己的好友

            if (user != null)
            {
                msg.setType(QQMsg.Type.BUDDY_MSG);         // 是自己的好友
            }
            else
            {
                if (serviceType == 0)           // 是群成员
                {
                    QQGroup group = store.getGroupByCode(typeId);
                    foreach (QQUser u in group.getMembers())
                    {
                        if (u.getUin() == fromUin)
                        {
                            user = u;
                            break;
                        }
                    }
                }
                else if (serviceType == 1)             // 是讨论组成员
                {
                    QQDiscuz discuz = store.getDiscuzByDid(typeId);
                    foreach (QQUser u in discuz.getMembers())
                    {
                        if (u.getUin() == fromUin)
                        {
                            user = u;
                            break;
                        }
                    }
                }
                else
                {
                    user = store.getStrangerByUin(fromUin); // 看看陌生人列表中有木有
                }
                if (user == null)                           // 还没有就新建一个陌生人,原理来说不应该这样。后面我就不知道怎么回复这消息了,但是消息是不能丢失的
                {
                    user = new QQStranger();
                    user.setQQ(pollData.getLong("ruin"));
                    user.setUin(fromUin);
                    user.setNickname(pollData.getLong("ruin") + "");
                    store.addStranger((QQStranger)user);
                }
            }
            user.setQQ(fromQQ);     // 带上QQ号码
            msg.setFrom(user);
            return(new QQNotifyEvent(QQNotifyEvent.Type.CHAT_MSG, msg));
        }