Impl sendText

This commit is contained in:
Changhua 2023-03-20 00:28:44 +08:00
parent 8736b82040
commit 7ed08d6e26
2 changed files with 25 additions and 0 deletions

View File

@ -115,6 +115,27 @@ public class Client {
return tables;
}
/**
* @Description 发送文本消息
* @param msg: 消息内容如果是 @ 消息则需要有跟 @ 的人数量相同的 @
* @param receiver: 消息接收人私聊为 wxidwxid_xxxxxxxxxxxxxx群聊为 roomidxxxxxxxxxx@chatroom
* @param aters: 群聊时要 @ 的人私聊时为空字符串多个用逗号分隔@所有人 notify@all必须是群主或者管理员才有权限
* @return int
* @author Changhua
* @example sendText("Hello @某人1 @某人2", "xxxxxxxx@chatroom", "wxid_xxxxxxxxxxxxx1,wxid_xxxxxxxxxxxxx2");
**/
public int sendText(String msg, String receiver, String aters) {
Wcf.TextMsg textMsg = Wcf.TextMsg.newBuilder().setMsg(msg).setReceiver(receiver).setAters(aters).build();
Request req = new Request.Builder().setFuncValue(Functions.FUNC_SEND_TXT_VALUE).setTxt(textMsg).build();
logger.debug(bytesToHex(req.toByteArray()));
Response rsp = sendCmd(req);
int ret = -1;
if (rsp != null) {
ret = rsp.getStatus();
}
return ret;
}
public void waitMs(int ms) {
try {

View File

@ -28,5 +28,9 @@ public class Main {
// 获取数据库下的表
String db = "MicroMsg.db";
logger.info("tables in {}: {}", db, client.getDbTables(db));
// 发送文本消息aters 是要 @ wxid多个用逗号分隔消息里@的数量要与aters里的数量对应
client.sendText("Hello", "filehelper", "");
// client.sendText("Hello @某人1 @某人2", "xxxxxxxx@chatroom", "wxid_xxxxxxxxxxxxx1,wxid_xxxxxxxxxxxxx2");
}
}