diff --git a/src/main/java/com/thankjava/wqq/entity/msg/Content.java b/src/main/java/com/thankjava/wqq/entity/msg/Content.java index 9597af7..cb0efd7 100644 --- a/src/main/java/com/thankjava/wqq/entity/msg/Content.java +++ b/src/main/java/com/thankjava/wqq/entity/msg/Content.java @@ -55,7 +55,7 @@ public String toSendMsg(){ for (Object m : msg) { if(String.class == m.getClass()){ array.add(m); - }else if (Integer.class == m.getClass()){ + }else if (Integer.class == m.getClass() || int.class == m.getClass()){ JSONArray faceArray = new JSONArray(); faceArray.add("face"); faceArray.add((Integer)m); @@ -66,9 +66,13 @@ public String toSendMsg(){ array.add(font.toFontArray()); return array.toJSONString(); } - - - public String toGetMsgText(){ + + + /** + * 获取消息问题 + * @return + */ + public String getMsgContext(){ if(msg == null || msg.length == 0){ return ""; } diff --git a/src/main/java/com/thankjava/wqq/entity/msg/PollMsg.java b/src/main/java/com/thankjava/wqq/entity/msg/PollMsg.java index 3a19559..5ab11d4 100644 --- a/src/main/java/com/thankjava/wqq/entity/msg/PollMsg.java +++ b/src/main/java/com/thankjava/wqq/entity/msg/PollMsg.java @@ -8,25 +8,19 @@ public class PollMsg { @JSONField(name = "poll_type") private MsgType msgType; - - private Value value; - + private Value value; public Value getValue() { return value; } public MsgType getMsgType() { return msgType; } - public void setMsgType(String msgType) { - this.msgType = MsgType.valueOf(msgType); - } - public void setValue(Value value) { - this.value = value; - } - - // 提供给发送信息时快速获取发送方信息 - public long getFrom(){ - + + /** + * 根据消息类型获取消息回复的目标id + * @return + */ + public long getTargetFromId(){ switch (msgType) { case message: // 好友信息 return value.getFromUin(); @@ -35,22 +29,29 @@ public long getFrom(){ case group_message: // 群信息 return value.getGroupCode(); } - return 0; } - - public long getFromUin(){ + + /** + * 获取消息所属发送用户的uin + * @return + */ + public long getMsgUin(){ return value.getFromUin(); } - - public String toGetMsgText() { + + /** + * 获取对方发送的消息文本 + * @return + */ + public String getMsgContext() { if(value == null){ return ""; } if(value.getContent() == null){ return ""; } - return value.getContent().toGetMsgText(); + return value.getContent().getMsgContext(); } } diff --git a/src/main/java/com/thankjava/wqq/entity/msg/SendMsg.java b/src/main/java/com/thankjava/wqq/entity/msg/SendMsg.java index e557da1..7deee5b 100644 --- a/src/main/java/com/thankjava/wqq/entity/msg/SendMsg.java +++ b/src/main/java/com/thankjava/wqq/entity/msg/SendMsg.java @@ -14,6 +14,13 @@ public class SendMsg { private Long did; private Content content; + /** + * 发送消息构造 + * @param to 根据 msgType 指定回复对象 + * @param msgType + * @param content 回复内容 Content + * @see Content + */ public SendMsg(long to, MsgType msgType, Content content) { switch (msgType) { @@ -56,7 +63,7 @@ public SendMsg(long to, MsgType msgType, String msg) { public SendMsg(PollMsg pollMsg, Content content) { msgType = pollMsg.getMsgType(); - long to = pollMsg.getFrom(); + long to = pollMsg.getTargetFromId(); switch (msgType) { case message: // 好友信息 this.to = to; @@ -73,7 +80,7 @@ public SendMsg(PollMsg pollMsg, Content content) { public SendMsg(PollMsg pollMsg, String msg) { msgType = pollMsg.getMsgType(); - long to = pollMsg.getFrom(); + long to = pollMsg.getTargetFromId(); switch (msgType) { case message: // 好友信息 this.to = to; diff --git a/src/test/java/com/thankjava/wqq/test/qq/MessageListener.java b/src/test/java/com/thankjava/wqq/test/qq/MessageListener.java index cb4bcaf..7645b53 100644 --- a/src/test/java/com/thankjava/wqq/test/qq/MessageListener.java +++ b/src/test/java/com/thankjava/wqq/test/qq/MessageListener.java @@ -7,24 +7,26 @@ public class MessageListener implements NotifyListener { - @Override - public void handler(SmartQQClient smartQQClient, PollMsg pollMsg) { - switch (pollMsg.getMsgType()) { - case message: - smartQQClient.sendMsg(new SendMsg(pollMsg, "I Have Got Your Msg: `Friend`")); - break; - case group_message: - smartQQClient.sendMsg(new SendMsg(pollMsg, "I Have Got Your Msg: `Group`")); - break; - case discu_message: - smartQQClient.sendMsg(new SendMsg(pollMsg, "I Have Got Your Msg: `Discu`")); - break; - } - } + @Override + public void handler(SmartQQClient smartQQClient, PollMsg pollMsg) { + System.out.println("received msg : " + pollMsg.getMsgContext()); + switch (pollMsg.getMsgType()) { + case message: + smartQQClient.sendMsg(new SendMsg(pollMsg, "I Have Got Your Msg: `Friend`")); + break; + case group_message: + smartQQClient.sendMsg(new SendMsg(pollMsg, "I Have Got Your Msg: `Group`")); + break; + case discu_message: + smartQQClient.sendMsg(new SendMsg(pollMsg, "I Have Got Your Msg: `Discu`")); + break; + } + } - // sendMsg 接口能通过pollMsg得到msg的类型,然后自动回复该类型的msg + // sendMsg 接口能通过pollMsg得到msg的类型,然后自动回复该类型的msg // @Override // public void handler(SmartQQClient smartQQClient, PollMsg pollMsg) { +// System.out.println("received msg : " + pollMsg.getMsgContext()); // smartQQClient.sendMsg(new SendMsg(pollMsg, "I Have Got Your Msg")); // }