Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Commit

Permalink
调整注释优化使用描述
Browse files Browse the repository at this point in the history
  • Loading branch information
acexy committed Jun 7, 2018
1 parent a212322 commit 1e456b5
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 40 deletions.
12 changes: 8 additions & 4 deletions src/main/java/com/thankjava/wqq/entity/msg/Content.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 "";
}
Expand Down
39 changes: 20 additions & 19 deletions src/main/java/com/thankjava/wqq/entity/msg/PollMsg.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
}

}
11 changes: 9 additions & 2 deletions src/main/java/com/thankjava/wqq/entity/msg/SendMsg.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
32 changes: 17 additions & 15 deletions src/test/java/com/thankjava/wqq/test/qq/MessageListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
// }

Expand Down

0 comments on commit 1e456b5

Please sign in to comment.