Exemplo n.º 1
0
        /**
         * <p>
         * processDiscuzMsg.
         * </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 processDiscuzMsg(JSONObject pollData)
        {
            QQStore store = getContext().getStore();

            QQMsg msg     = new QQMsg();
            long  fromUin = pollData.getLong("send_uin");
            long  did     = pollData.getLong("did");

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

            if (msg.getDiscuz() != null)
            {
                msg.setFrom(msg.getDiscuz().getMemberByUin(fromUin));
            }

            if (msg.getFrom() == null)
            {
                QQDiscuzMember member = new QQDiscuzMember();
                member.setUin(fromUin);
                msg.setFrom(member);
                if (msg.getDiscuz() != null)
                {
                    msg.getDiscuz().getMembers().Add(member);
                }
            }
            return(new QQNotifyEvent(QQNotifyEvent.Type.CHAT_MSG, msg));
        }
Exemplo n.º 2
0
        /**
         * <p>
         * processBuddyMsg.
         * </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 processBuddyMsg(JSONObject pollData)
        {
            QQStore store = getContext().getStore();

            long  fromUin = pollData.getLong("from_uin");
            QQMsg msg     = new QQMsg();

            msg.setId(pollData.getLong("msg_id"));
            msg.setId2(pollData.getLong("msg_id2"));
            msg.parseContentList(pollData.getJSONArray("content").ToString());
            msg.setType(QQMsg.Type.BUDDY_MSG);
            msg.setTo(getContext().getAccount());
            msg.setFrom(store.getBuddyByUin(fromUin));
            msg.setDate(new DateTime(pollData.getLong("time") * 1000));
            if (msg.getFrom() == null)
            {
                QQUser member = store.getStrangerByUin(fromUin);         // 搜索陌生人列表
                if (member == null)
                {
                    member = new QQHalfStranger();
                    member.setUin(fromUin);
                    store.addStranger((QQStranger)member);
                }
                msg.setFrom(member);
            }
            return(new QQNotifyEvent(QQNotifyEvent.Type.CHAT_MSG, msg));
        }
Exemplo n.º 3
0
 /**
  * <p>Constructor for GetGroupPicAction.</p>
  *
  * @param context a {@link iqq.im.core.QQContext} object.
  * @param listener a {@link iqq.im.QQActionListener} object.
  * @param cface a {@link iqq.im.bean.content.CFaceItem} object.
  * @param msg a {@link iqq.im.bean.QQMsg} object.
  * @param picOut a {@link java.io.OutputStream} object.
  */
 public GetGroupPicAction(QQContext context, QQActionListener.OnActionEvent listener,
                          CFaceItem cface, QQMsg msg, byte[] picOut) : base(context, listener)
 {
     this.cface  = cface;
     this.msg    = msg;
     this.picOut = picOut;
 }
Exemplo n.º 4
0
        /// <summary>
        /// 获取离线图片
        /// </summary>
        /// <param name="offpic"></param>
        /// <param name="msg"></param>
        /// <param name="picout"></param>
        /// <param name="listener"></param>
        /// <returns></returns>
        public QQActionFuture GetOffPic(OffPicItem offpic, QQMsg msg, Stream picout,
                                        QQActionEventHandler listener)
        {
            var mod = GetModule <ChatModule>(QQModuleType.CHAT);

            return(mod.GetOffPic(offpic, msg, picout, listener));
        }
Exemplo n.º 5
0
 /**
  * <p>sendMsg.</p>
  *
  * @param msg a {@link iqq.im.bean.QQMsg} object.
  * @param listener a {@link iqq.im.QQActionListener.OnActionEvent} object.
  * @return a {@link iqq.im.evt.AbstractActionFuture} object.
  */
 private void  doSendMsg(QQMsg msg, AbstractActionFuture future)
 {
     doSendMsg(msg, delegate(QQActionEvent evt)
     {
         future.notifyActionEvent(evt.getType(), evt.getTarget());
     });
 }
Exemplo n.º 6
0
        /// <summary>
        /// 获取群聊天图片
        /// </summary>
        /// <param name="cface"></param>
        /// <param name="msg"></param>
        /// <param name="picout"></param>
        /// <param name="listener"></param>
        /// <returns></returns>
        public QQActionFuture GetGroupPic(CFaceItem cface, QQMsg msg,
                                          Stream picout, QQActionEventHandler listener)
        {
            var mod = GetModule <ChatModule>(QQModuleType.CHAT);

            return(mod.GetGroupPic(cface, msg, picout, listener));
        }
Exemplo n.º 7
0
        /**
         * 程序入口
         *
         */
//    public void loginWb(){
//      client.preloginWb(new QQActionListener() {
//
//			@Override
//			public void onActionEvent(QQActionEvent evt) {
//				// TODO Auto-generated method stub
//				if (evt.getType() == Type.EVT_OK) {
//					//到这里就算是登录成功了
//					ArrayList<String> list = (ArrayList<String>) evt.getTarget();
//					foreach (String string : list) {
//						Console.WriteLine(string);
//					}
//					Console.WriteLine("就算是登录成功微博了");
//
//					new Thread(new Runnable() {
//
//						@Override
//						public void run() {
//							// TODO Auto-generated method stub
//							while(true){
//								try {
//									String sendMsg = new BufferedReader(new InputStreamReader(System.in)).readLine();
//									if(sendMsg.contains("#")){
//										client.pollWbMsg("5175429989", new QQActionListener() {
//
//											@Override
//											public void onActionEvent(QQActionEvent evt) {
//												// TODO Auto-generated method stub
//												if (evt.getType() == Type.EVT_OK) {
//													Console.WriteLine("pllmsg:   "+evt.getTarget());
//												}
//											}
//										});
//									}else{
//										client.sendWbMsg(sendMsg, "5175429989", new QQActionListener() {
//
//											@Override
//											public void onActionEvent(QQActionEvent evt) {
//												// TODO Auto-generated method stub
//												if (evt.getType() == Type.EVT_OK) {
//													Console.WriteLine("发送成功");
//												}
//											}
//										});
//									}
//
//								} catch (IOException e) {
//									// TODO Auto-generated catch block
//									e.printStackTrace();
//								}
//							}
//
//						}
//					}).start();
//
//				}else{
//					Console.WriteLine(evt.getTarget());
//				}
//			}
//		});
//    }

        /**
         * 聊天消息通知,使用这个注解可以收到QQ消息
         *
         * 接收到消息然后组装消息发送回去
         *
         * @throws QQException
         */
        public void processBuddyMsg(QQNotifyEvent evt)
        {
            QQMsg msg = (QQMsg)evt.getTarget();

            List <ContentItem> items = msg.getContentList();

            foreach (ContentItem item in items)
            {
                if (item.getType() == ContentItem.Type.FACE)
                {
                }
                else if (item.getType() == ContentItem.Type.OFFPIC)
                {
                }
                else if (item.getType() == ContentItem.Type.TEXT)
                {
                    Console.WriteLine(" Text:" + ((TextItem)item).getContent());
                }
            }

            // 组装QQ消息发送回去
            QQMsg sendMsg = new QQMsg();

            sendMsg.setTo(msg.getFrom());                   // QQ好友UIN
            sendMsg.setType(QQMsg.Type.BUDDY_MSG);          // 发送类型为好友
            // QQ内容
            sendMsg.addContentItem(new TextItem("hello"));  // 添加文本内容
            sendMsg.addContentItem(new FaceItem(0));        // QQ id为0的表情
            sendMsg.addContentItem(new FontItem());         // 使用默认字体
            client.sendMsg(sendMsg, null);                  // 调用接口发送消息
        }
Exemplo n.º 8
0
 public GetOffPicAction(QQContext context, QQActionEventHandler listener,
                        OffPicItem offpic, QQMsg msg, Stream picOut)
     : base(context, listener)
 {
     this.offpic = offpic;
     this.msg    = msg;
     this.picOut = picOut;
 }
Exemplo n.º 9
0
 public GetUserPicAction(IQQContext context, QQActionListener listener,
                         CFaceItem cface, QQMsg msg, Stream picOut)
     : base(context, listener)
 {
     this.cface  = cface;
     this.msg    = msg;
     this.picOut = picOut;
 }
Exemplo n.º 10
0
 public GetOffPicAction(IQQContext context, QQActionListener listener,
                        OffPicItem offpic, QQMsg msg, Stream picOut)
     : base(context, listener)
 {
     _offpic = offpic;
     _msg    = msg;
     _picOut = picOut;
 }
Exemplo n.º 11
0
 /**
  * <p>Constructor for GetGroupPicAction.</p>
  *
  * @param context a {@link iqq.im.core.QQContext} object.
  * @param listener a {@link iqq.im.IQQActionListener} object.
  * @param cface a {@link iqq.im.bean.content.CFaceItem} object.
  * @param msg a {@link iqq.im.bean.QQMsg} object.
  * @param picOut a {@link java.io.OutputStream} object.
  */
 public GetGroupPicAction(QQContext context, QQActionEventHandler listener,
                          CFaceItem cface, QQMsg msg, Stream picOut)
     : base(context, listener)
 {
     this.cface  = cface;
     this.msg    = msg;
     this.picOut = picOut;
 }
Exemplo n.º 12
0
 /**
  * <p>Constructor for GetGroupPicAction.</p>
  *
  * @param context a {@link iqq.im.core.IQQContext} object.
  * @param listener a {@link iqq.im.IQQActionListener} object.
  * @param cface a {@link iqq.im.bean.content.CFaceItem} object.
  * @param msg a {@link iqq.im.bean.QQMsg} object.
  * @param picOut a {@link java.io.OutputStream} object.
  */
 public GetGroupPicAction(IQQContext context, QQActionListener listener,
                          CFaceItem cface, QQMsg msg, Stream picOut)
     : base(context, listener)
 {
     _cface  = cface;
     _msg    = msg;
     _picOut = picOut;
 }
Exemplo n.º 13
0
 /// <summary>
 /// 处理好友信息
 /// </summary>
 /// <param name="pollData"></param>
 /// <returns></returns>
 private QQNotifyEvent ProcessBuddyMsg(JObject pollData)
 {
     /*
      *  {
      *      "content": [
      *          [
      *              "font",
      *              {
      *                  "color": "000000",
      *                  "name": "微软雅黑",
      *                  "size": 10,
      *                  "style": [0, 0, 0]
      *              }
      *          ],
      *          "你好!"
      *      ],
      *      "from_uin": 1000693217,
      *      "msg_id": 25426,
      *      "msg_type": 0,
      *      "time": 1472754511,
      *      "to_uin": 89009143
      *  }
      */
     try
     {
         var store   = Context.Store;
         var fromUin = pollData["from_uin"].ToObject <long>();
         var ticks   = pollData["time"].ToObject <long>() * 1000;
         var msg     = new QQMsg
         {
             Id   = pollData["msg_id"].ToObject <long>(),
             Type = QQMsgType.BUDDY_MSG,
             To   = Context.Account,
             From = store.GetBuddyByUin(fromUin),
             Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks),
             // Id2 = pollData["msg_id2"]?.ToObject<long>() ?? 0
         };
         msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"]));
         if (msg.From == null)
         {
             var member = new QQBuddy()
             {
                 Uin = fromUin
             };
             store.AddBuddy(member);
             // 获取用户信息
             var userModule = Context.GetModule <UserModule>(QQModuleType.USER);
             userModule.GetUserInfo(member);
             msg.From = member;
         }
         return(new QQNotifyEvent(QQNotifyEventType.ChatMsg, msg));
     }
     catch (Exception ex)
     {
         return(new QQNotifyEvent(QQNotifyEventType.NetError, ex));
     }
 }
Exemplo n.º 14
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.º 15
0
        public static void SendMsg(QQUser user)
        {
            Console.WriteLine("sendMsg " + user);

            // 组装QQ消息发送回去
            var sendMsg = new QQMsg
            {
                To   = user,
                Type = QQMsgType.BUDDY_MSG
            };

            sendMsg.AddContentItem(new TextItem("hello from iqq")); // 添加文本内容
            sendMsg.AddContentItem(new FaceItem(0));                // QQ id为0的表情
            sendMsg.AddContentItem(new FontItem());                 // 使用默认字体
            mClient.SendMsg(sendMsg, null);                         // 调用接口发送消息
        }
Exemplo n.º 16
0
        /// <summary>
        /// 处理讨论组信息
        /// </summary>
        /// <param name="pollData"></param>
        /// <returns></returns>
        private QQNotifyEvent ProcessDiscuzMsg(JObject pollData)
        {
            try
            {
                var store = Context.Store;

                var msg     = new QQMsg();
                var fromUin = pollData["send_uin"].ToObject <long>();
                var did     = pollData["did"].ToObject <long>();

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

                if (msg.Discuz == null)
                {
                    var discuz = new QQDiscuz();
                    discuz.Did = did;
                    store.AddDiscuz(discuz);
                    msg.Discuz = store.GetDiscuzByDid(did);

                    var discuzModule = Context.GetModule <DiscuzModule>(QQModuleType.DISCUZ);
                    discuzModule.GetDiscuzInfo(discuz, null);
                }
                msg.From = msg.Discuz.GetMemberByUin(fromUin);

                if (msg.From == null)
                {
                    var member = new QQDiscuzMember {
                        Uin = fromUin
                    };
                    msg.From = member;
                    msg.Discuz.Members.Add(member);
                    // 获取用户信息
                    var userModule = Context.GetModule <UserModule>(QQModuleType.USER);
                    userModule.GetUserInfo(member, null);
                }
                return(new QQNotifyEvent(QQNotifyEventType.GroupMsg, msg));
            }
            catch (Exception ex)
            {
                return(new QQNotifyEvent(QQNotifyEventType.NetError, ex));
            }
        }
Exemplo n.º 17
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.º 18
0
        public IQQActionFuture SendMsg(QQMsg msg, QQActionListener listener)
        {
            var future = new ProcActionFuture(listener, true);

            if (msg.Type == QQMsgType.SESSION_MSG)
            {
                var stranger = (QQStranger)msg.To;
                if (string.IsNullOrEmpty(stranger.GroupSig))
                {
                    GetSessionMsgSig(stranger, (sender, Event) =>
                    {
                        if (Event.Type == QQActionEventType.EvtOK)
                        {
                            DoSendMsg(msg, future.Listener);
                        }
                        else if (Event.Type == QQActionEventType.EvtError)
                        {
                            future.NotifyActionEvent(Event.Type, Event.Target);
                        }
                    });
                }
                return(future);
            }
            else if (msg.Type == QQMsgType.GROUP_MSG || msg.Type == QQMsgType.DISCUZ_MSG)
            {
                if (msg.Type == QQMsgType.GROUP_MSG)
                {
                    if (msg.Group.Gin == 0)
                    {
                        msg.Group = Context.Store.GetGroupByCode(msg.Group.Code);
                        return(future);
                    }
                }
            }
            return(DoSendMsg(msg, listener));
        }
Exemplo n.º 19
0
 /// <summary>
 /// 处理好友信息
 /// </summary>
 /// <param name="pollData"></param>
 /// <returns></returns>
 public QQNotifyEvent ProcessBuddyMsg(JObject pollData)
 {
     try
     {
         var store   = Context.Store;
         var fromUin = pollData["from_uin"].ToObject <long>();
         var msg     = new QQMsg
         {
             Id  = pollData["msg_id"].ToObject <long>(),
             Id2 = pollData["msg_id2"].ToObject <long>()
         };
         msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"]));
         msg.Type = QQMsgType.BUDDY_MSG;
         msg.To   = Context.Account;
         msg.From = store.GetBuddyByUin(fromUin);
         var ticks = pollData["time"].ToObject <long>() * 1000;
         msg.Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks);
         if (msg.From == null)
         {
             var member = new QQBuddy()
             {
                 Uin = fromUin
             };
             store.AddBuddy(member);
             // 获取用户信息
             var userModule = Context.GetModule <UserModule>(QQModuleType.USER);
             userModule.GetUserInfo(member, null);
             msg.From = member;
         }
         return(new QQNotifyEvent(QQNotifyEventType.CHAT_MSG, msg));
     }
     catch (Exception ex)
     {
         return(new QQNotifyEvent(QQNotifyEventType.NET_ERROR, ex));
     }
 }
Exemplo n.º 20
0
        /**
         * {@inheritDoc}
         *
         * 发送QQ消息
         */

        public AbstractActionFuture sendMsg(QQMsg msg, QQActionListener.OnActionEvent qqActionListener)
        {
            ChatModule mod = (ChatModule)getModule(AbstractModule.Type.CHAT);

            return(mod.sendMsg(msg, qqActionListener));
        }
Exemplo n.º 21
0
        public IQQActionFuture GetUserPic(CFaceItem cface, QQMsg msg, Stream picout, QQActionListener listener)
        {
            var mod = GetModule <ChatModule>(QQModuleType.CHAT);

            return(mod.GetUserPic(cface, msg, picout, listener));
        }
Exemplo n.º 22
0
        public IQQActionFuture GetRobotReply(QQMsg input, RobotType robotType, QQActionListener listener)
        {
            var mod = GetModule <ChatModule>(QQModuleType.CHAT);

            return(mod.GetRobotReply(input, robotType, listener));
        }
Exemplo n.º 23
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="listener"></param>
        /// <returns></returns>
        public IQQActionFuture SendMsg(QQMsg msg, QQActionListener listener)
        {
            var mod = GetModule <ChatModule>(QQModuleType.CHAT);

            return(mod.SendMsg(msg, listener));
        }
Exemplo n.º 24
0
 public SendMsgAction(IQQContext context, QQActionListener listener, QQMsg msg)
     : base(context, listener)
 {
     _msg = msg;
 }
Exemplo n.º 25
0
 public QQActionFuture GetRobotReply(QQMsg input, RobotType robotType, QQActionEventHandler listener)
 {
     return(PushHttpAction(new GetRobotReplyAction(Context, listener, input, robotType)));
 }
Exemplo n.º 26
0
 private QQActionFuture DoSendMsg(QQMsg msg, QQActionEventHandler listener)
 {
     return(PushHttpAction(new SendMsgAction(Context, listener, msg)));
 }
Exemplo n.º 27
0
 public QQActionFuture GetGroupPic(CFaceItem cface, QQMsg msg, Stream picout, QQActionEventHandler listener)
 {
     return(PushHttpAction(new GetGroupPicAction(this.Context, listener, cface, msg, picout)));
 }
Exemplo n.º 28
0
 public QQActionFuture GetOffPic(OffPicItem offpic, QQMsg msg, Stream picout, QQActionEventHandler listener)
 {
     return(PushHttpAction(new GetOffPicAction(this.Context, listener, offpic, msg, picout)));
 }
Exemplo n.º 29
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));
        }
Exemplo n.º 30
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));
        }