Package iqq.im.bean

Examples of iqq.im.bean.QQMsg


   *
   * @throws QQException
   */
  @QQNotifyHandler(QQNotifyEvent.Type.CHAT_MSG)
  public void processBuddyMsg(QQNotifyEvent event) throws QQException{
    QQMsg msg = (QQMsg) event.getTarget();
   
    System.out.println("[消息] " + msg.getFrom().getNickname() + "说:" + msg.packContentList());
    System.out.print("消息内容: ");
    List<ContentItem> items = msg.getContentList();
    for(ContentItem item : items) {
      if(item.getType() == ContentItem.Type.FACE) {
        System.out.print(" Face:" + ((FaceItem)item).getId());
      }else if(item.getType() == ContentItem.Type.OFFPIC) {
        System.out.print(" Picture:" + ((OffPicItem)item).getFilePath());
      }else if(item.getType() == ContentItem.Type.TEXT) {
        System.out.print(" Text:" + ((TextItem)item).getContent());
      }
    }
    System.out.println();

        // 组装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);                      // 调用接口发送消息
  }
View Full Code Here


  public static void main(String[] args) throws QQException, IOException {
    client = new WebQQClient("1070772010","xu1234", new QQNotifyListener() {
      public void onNotifyEvent(QQNotifyEvent event) {
        System.out.println("QQNotifyEvent: " + event.getType() +", " + event.getTarget());
        if(event.getType() ==  QQNotifyEvent.Type.CHAT_MSG){
          QQMsg msg = (QQMsg) event.getTarget();
          try {
            System.out.println("好友消息: " + msg.packContentList());
          } catch (QQException e) {
            e.printStackTrace();
          }
        }else if(event.getType() ==  QQNotifyEvent.Type.KICK_OFFLINE){
          System.out.println("被踢下线: " + (String)event.getTarget());
View Full Code Here

  public QQNotifyEvent processBuddyMsg(JSONObject pollData)
      throws JSONException, QQException {
    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 Date(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);
  }
View Full Code Here

    // {"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 "]}}]}

    QQStore store = getContext().getStore();
    QQMsg msg = new QQMsg();
    msg.setId(pollData.getLong("msg_id"));
    msg.setId2(pollData.getLong("msg_id2"));
    long fromUin = pollData.getLong("send_uin");
    long groupCode = pollData.getLong("group_code");
    long groupID = pollData.getLong("info_seq"); // 真实群号码
    QQGroup group = store.getGroupByCode(groupCode);
    if (group.getGid() <= 0) {
      group.setGid(groupID);
    }
    msg.parseContentList(pollData.getJSONArray("content").toString());
    msg.setType(QQMsg.Type.GROUP_MSG);
    msg.setGroup(group);
    msg.setTo(getContext().getAccount());
    msg.setDate(new Date(pollData.getLong("time") * 1000));

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

    if (msg.getFrom() == null) {
      QQGroupMember member = new QQGroupMember();
      member.setUin(fromUin);
      msg.setFrom(member);
      if (group != null) {
        group.getMembers().add(member);
      }
    }

View Full Code Here

   */
  public QQNotifyEvent processDiscuzMsg(JSONObject pollData)
      throws JSONException, QQException {
    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 Date(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);
  }
View Full Code Here

    // {"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]," "]}}]}
    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"); // Group:0,Discuss:1
    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 Date(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);
        for (QQUser u : group.getMembers()) {
          if (u.getUin() == fromUin) {
            user = u;
            break;
          }
        }
      } else if (serviceType == 1) { // 是讨论组成员
        QQDiscuz discuz = store.getDiscuzByDid(typeId);
        for (QQUser u : 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);
  }
View Full Code Here

TOP

Related Classes of iqq.im.bean.QQMsg

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.