update
This commit is contained in:
@@ -28,7 +28,7 @@ public class UnknownErrorAction extends Action{
|
||||
|
||||
@Override
|
||||
public boolean action(Request request, Response response) {
|
||||
response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
|
||||
response.setStatus(HttpResponseStatus.NOT_FOUND);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class GetUserAction extends RobotAction {
|
||||
if (request.getNettyRequest() instanceof FullHttpRequest) {
|
||||
InputGetUserInfo inputUserId = getRequestBody(request.getNettyRequest(), InputGetUserInfo.class);
|
||||
if (inputUserId != null
|
||||
&& (!StringUtil.isNullOrEmpty(inputUserId.getUserId()) || !StringUtil.isNullOrEmpty(inputUserId.getName()))) {
|
||||
&& (!StringUtil.isNullOrEmpty(inputUserId.getUserId()) || !StringUtil.isNullOrEmpty(inputUserId.getName()) || !StringUtil.isNullOrEmpty(inputUserId.getMobile()))) {
|
||||
|
||||
WFCMessage.User user = null;
|
||||
if(!StringUtil.isNullOrEmpty(inputUserId.getUserId())) {
|
||||
|
||||
@@ -11,6 +11,7 @@ public interface APIPath {
|
||||
String Sensitive_Query = "/admin/sensitive/query";
|
||||
|
||||
String Create_User = "/admin/user/create";
|
||||
String Create_Robot = "/admin/robot/create";
|
||||
String User_Get_Token = "/admin/user/get_token";
|
||||
String User_Update_Block_Status = "/admin/user/update_block_status";
|
||||
String User_Get_Info = "/admin/user/get_info";
|
||||
@@ -33,7 +34,6 @@ public interface APIPath {
|
||||
String Group_Member_Add = "/admin/group/member/add";
|
||||
String Group_Member_Kickoff = "/admin/group/member/del";
|
||||
|
||||
String Create_Robot = "/admin/robot/create";
|
||||
|
||||
String Channel_Message_Send = "/channel/message/send";
|
||||
|
||||
|
||||
@@ -97,6 +97,12 @@
|
||||
<destName>sdk-${project.version}.jar</destName>
|
||||
</file>
|
||||
|
||||
<file>
|
||||
<source>../sdk/sdk_readme.txt</source>
|
||||
<outputDirectory>server_sdk/</outputDirectory>
|
||||
<destName>sdk_readme.txt</destName>
|
||||
</file>
|
||||
|
||||
<file>
|
||||
<source>../common/target/common-${project.version}.jar</source>
|
||||
<outputDirectory>server_sdk/</outputDirectory>
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
SDK使用说明:
|
||||
1. 把common.jar和sdk.jar 放到lib目录下(如没有需要手动建)。
|
||||
2. 添加下属依赖,注意本地jar包的路径。
|
||||
3. 修改build plugin,把common和sdk打包进去。
|
||||
4. 使用方法请查看sdk.jar/cn.wildfirechat.sdk/Main.class(没有混淆,可以看到源码)
|
||||
|
||||
<!--# 需要添加如下依赖-->
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-httpclient</groupId>
|
||||
<artifactId>commons-httpclient</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.11</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<version>2.5.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<artifactId>sdk</artifactId>
|
||||
<version>0.20</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/src/lib/sdk-0.20.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.wildfirechat</groupId>
|
||||
<artifactId>common</artifactId>
|
||||
<version>0.20</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/src/lib/common-0.20.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<!--# 由于添加了本地jar包,需要打包时把sdk和common打进去,下面是springboot项目添加includeSystemScope部分,其它类型项目请百度。 -->
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<includeSystemScope>true</includeSystemScope>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
@@ -2,20 +2,23 @@ package cn.wildfirechat.sdk;
|
||||
|
||||
import cn.wildfirechat.common.ErrorCode;
|
||||
import cn.wildfirechat.pojos.*;
|
||||
import cn.wildfirechat.proto.ProtoConstants;
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
//初始化服务API
|
||||
AdminHttpUtils.init("http://localhost:18080", "123456");
|
||||
|
||||
|
||||
//***********************************************
|
||||
//**** 用户相关的API
|
||||
//***********************************************
|
||||
//***********************************************
|
||||
//**** 用户相关的API
|
||||
//***********************************************
|
||||
InputOutputUserInfo userInfo = new InputOutputUserInfo();
|
||||
userInfo.setUserId("userId1");
|
||||
userInfo.setName("user1");
|
||||
@@ -30,6 +33,20 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
InputCreateRobot createRobot = new InputCreateRobot();
|
||||
createRobot.setUserId("robot1");
|
||||
createRobot.setName("robot1");
|
||||
createRobot.setDisplayName("机器人");
|
||||
createRobot.setSecret("123456");
|
||||
createRobot.setCallback("http://127.0.0.1:8883/robot/recvmsg");
|
||||
IMResult<OutputCreateRobot> resultCreateRobot = UserAdmin.createRobot(createRobot);
|
||||
if (resultCreateRobot != null && resultCreateRobot.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("Create robot " + resultCreateRobot.getResult().getUserId() + " success");
|
||||
} else {
|
||||
System.out.println("Create robot failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<InputOutputUserInfo> resultGetUserInfo1 = UserAdmin.getUserByName(userInfo.getName());
|
||||
if (resultGetUserInfo1 != null && resultGetUserInfo1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
if (userInfo.getUserId().equals(resultGetUserInfo1.getResult().getUserId())
|
||||
@@ -127,9 +144,9 @@ public class Main {
|
||||
}
|
||||
|
||||
|
||||
//***********************************************
|
||||
//**** 群组相关API
|
||||
//***********************************************
|
||||
//***********************************************
|
||||
//**** 群组相关功能
|
||||
//***********************************************
|
||||
IMResult<Void> voidIMResult1 = GroupAdmin.dismissGroup("user1", "groupId1", null, null);
|
||||
|
||||
PojoGroupInfo groupInfo = new PojoGroupInfo();
|
||||
@@ -203,5 +220,77 @@ public class Main {
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
voidIMResult = GroupAdmin.addGroupMembers("user1", groupInfo.getTarget_id(), Arrays.asList("use4", "user5"), null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("add group member success");
|
||||
} else {
|
||||
System.out.println("add group member failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
voidIMResult = GroupAdmin.kickoffGroupMembers("user1", groupInfo.getTarget_id(), Arrays.asList("use2", "user3"), null, null);
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("kickoff group member success");
|
||||
} else {
|
||||
System.out.println("kickoff group member failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
//***********************************************
|
||||
//**** 消息相关功能
|
||||
//***********************************************
|
||||
Conversation conversation = new Conversation();
|
||||
conversation.setTarget("user2");
|
||||
conversation.setType(ProtoConstants.ConversationType.ConversationType_Private);
|
||||
MessagePayload payload = new MessagePayload();
|
||||
payload.setType(1);
|
||||
payload.setSearchableContent("hello world");
|
||||
|
||||
IMResult<SendMessageResult> resultSendMessage = MessageAdmin.sendMessage("user1", conversation, payload);
|
||||
if (resultSendMessage != null && resultSendMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("send message success");
|
||||
} else {
|
||||
System.out.println("send message failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
|
||||
voidIMResult = MessageAdmin.recallMessage("user1", resultSendMessage.getResult().getMessageUid());
|
||||
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("recall message success");
|
||||
} else {
|
||||
System.out.println("recall message failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//初始化机器人API
|
||||
RobotHttpUtils.init("http://localhost:18080", "robot1", "123456");
|
||||
//***********************************************
|
||||
//**** 机器人API
|
||||
//***********************************************
|
||||
conversation = new Conversation();
|
||||
conversation.setTarget("user2");
|
||||
conversation.setType(ProtoConstants.ConversationType.ConversationType_Private);
|
||||
payload = new MessagePayload();
|
||||
payload.setType(1);
|
||||
payload.setSearchableContent("hello world");
|
||||
|
||||
IMResult<SendMessageResult> resultRobotSendMessage = RobotService.sendMessage("robot1", conversation, payload);
|
||||
if (resultRobotSendMessage != null && resultRobotSendMessage.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("robot send message success");
|
||||
} else {
|
||||
System.out.println("robot send message failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
IMResult<InputOutputUserInfo> resultRobotGetUserInfo = RobotService.getUserInfo("user1");
|
||||
if (resultRobotGetUserInfo != null && resultRobotGetUserInfo.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
|
||||
System.out.println("robot get user info success");
|
||||
} else {
|
||||
System.out.println("robot get user info by userId failure");
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package cn.wildfirechat.sdk;
|
||||
|
||||
import cn.wildfirechat.common.APIPath;
|
||||
import cn.wildfirechat.pojos.*;
|
||||
import cn.wildfirechat.sdk.model.IMResult;
|
||||
import cn.wildfirechat.sdk.utilities.AdminHttpUtils;
|
||||
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
|
||||
|
||||
public class RobotService {
|
||||
public static IMResult<SendMessageResult> sendMessage(String sender, Conversation conversation, MessagePayload payload) throws Exception {
|
||||
String path = APIPath.Robot_Message_Send;
|
||||
SendMessageData messageData = new SendMessageData();
|
||||
messageData.setSender(sender);
|
||||
messageData.setConv(conversation);
|
||||
messageData.setPayload(payload);
|
||||
return RobotHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
|
||||
}
|
||||
|
||||
public static IMResult<InputOutputUserInfo> getUserInfo(String userId) throws Exception {
|
||||
String path = APIPath.Robot_User_Info;
|
||||
InputGetUserInfo getUserInfo = new InputGetUserInfo(userId, null, null);
|
||||
return RobotHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,11 @@ public class UserAdmin {
|
||||
return AdminHttpUtils.httpJsonPost(path, user, OutputCreateUser.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputCreateRobot> createRobot(InputCreateRobot robot) throws Exception {
|
||||
String path = APIPath.Create_Robot;
|
||||
return AdminHttpUtils.httpJsonPost(path, robot, OutputCreateRobot.class);
|
||||
}
|
||||
|
||||
public static IMResult<OutputGetIMTokenData> getUserToken(String userId, String clientId) throws Exception {
|
||||
String path = APIPath.User_Get_Token;
|
||||
InputGetToken getToken = new InputGetToken(userId, clientId);
|
||||
|
||||
@@ -54,6 +54,7 @@ public class RobotHttpUtils {
|
||||
post.setHeader("Connection", "Keep-Alive");
|
||||
post.setHeader("nonce", nonce + "");
|
||||
post.setHeader("timestamp", "" + timestamp);
|
||||
post.setHeader("rid", robotId);
|
||||
post.setHeader("sign", sign);
|
||||
|
||||
String jsonStr = null;
|
||||
|
||||
Reference in New Issue
Block a user