/** * 程序入口 * */ // 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); // 调用接口发送消息 }
/** * <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)); }
/** * <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)); }
/* (non-Javadoc) * @see iqq.im.action.AbstractHttpAction#onBuildRequest() */ /** {@inheritDoc} */ public override QQHttpRequest onBuildRequest() { QQHttpRequest req = createHttpRequest("GET", QQConstants.URL_GET_GROUP_PIC); // fid 3648788200 // gid 2890126166 // pic {F2B04C26-9087-437D-4FD9-6A0ED84155FD}.jpg // rip 123.138.154.167 // rport 8000 // t 1365343106 // type 0 // uin 3559750777 // vfwebqq 70b5f77bfb1db1367a2ec483ece317ea9ef119b9b59e542b2e8586f7ede6030ff56f7ba8798ba34b // "cface", // { // "name": "{F2B04C26-9087-437D-4FD9-6A0ED84155FD}.jpg", // "file_id": 3648788200, // "key": "pcm4N6IKmQ852Pus", // "server": "123.138.154.167:8000" // } QQSession session = getContext().getSession(); req.addGetValue("fid", cface.getFileId() + ""); req.addGetValue("gid", (msg.getGroup() != null ? msg.getGroup().getCode(): msg.getDiscuz().getDid()) + ""); req.addGetValue("pic", cface.getFileName()); String[] parts = cface.getServer().Split(':'); req.addGetValue("rip", parts[0]); req.addGetValue("rport", parts[1]); req.addGetValue("t", DateTime.Now.Ticks / 1000 + ""); req.addGetValue("type", msg.getGroup() != null ? "0" : "1"); req.addGetValue("uin", msg.getFrom().getUin() + ""); req.addGetValue("vfwebqq", session.getVfwebqq()); //req.setOutputStream(picOut); return(req); }
/** * <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)); }