add application token

This commit is contained in:
heavyrian2012
2022-05-02 22:07:54 +08:00
parent 9d23f9c996
commit 537221b0b4
16 changed files with 272 additions and 103 deletions
@@ -9,28 +9,28 @@ import java.util.List;
//仅专业版支持,社区版不支持
public class ChannelServiceApi {
private final ChannelHttpUtils httpUtils;
private final ChannelHttpUtils channelHttpUtils;
public ChannelServiceApi(String imurl, String channelId, String secret) {
httpUtils = new ChannelHttpUtils(imurl, channelId, secret);
channelHttpUtils = new ChannelHttpUtils(imurl, channelId, secret);
}
public IMResult<InputOutputUserInfo> getUserInfo(String userId) throws Exception {
String path = APIPath.Channel_User_Info;
InputGetUserInfo getUserInfo = new InputGetUserInfo(userId, null, null);
return httpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
return channelHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
}
public IMResult<InputOutputUserInfo> getUserInfoByName(String userName) throws Exception {
String path = APIPath.Channel_User_Info;
InputGetUserInfo getUserInfo = new InputGetUserInfo(null, userName, null);
return httpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
return channelHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
}
public IMResult<InputOutputUserInfo> getUserInfoByMobile(String mobile) throws Exception {
String path = APIPath.Channel_User_Info;
InputGetUserInfo getUserInfo = new InputGetUserInfo(null, null, mobile);
return httpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
return channelHttpUtils.httpJsonPost(path, getUserInfo, InputOutputUserInfo.class);
}
public IMResult<Void> modifyChannelInfo(/*ProtoConstants.ModifyChannelInfoType*/int type, String value) throws Exception {
@@ -38,12 +38,12 @@ public class ChannelServiceApi {
InputModifyChannelInfo modifyChannelInfo = new InputModifyChannelInfo();
modifyChannelInfo.setType(type);
modifyChannelInfo.setValue(value);
return httpUtils.httpJsonPost(path, modifyChannelInfo, Void.class);
return channelHttpUtils.httpJsonPost(path, modifyChannelInfo, Void.class);
}
public IMResult<OutputGetChannelInfo> getChannelInfo() throws Exception {
String path = APIPath.Channel_Get_Profile;
return httpUtils.httpJsonPost(path, null, OutputGetChannelInfo.class);
return channelHttpUtils.httpJsonPost(path, null, OutputGetChannelInfo.class);
}
public IMResult<SendMessageResult> sendMessage(int line, List<String> targets, MessagePayload payload) throws Exception {
@@ -52,7 +52,7 @@ public class ChannelServiceApi {
messageData.setLine(0);
messageData.setTargets(targets);
messageData.setPayload(payload);
return httpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
return channelHttpUtils.httpJsonPost(path, messageData, SendMessageResult.class);
}
public IMResult<Void> subscribe(String userId) throws Exception {
@@ -60,7 +60,7 @@ public class ChannelServiceApi {
InputChannelSubscribe input = new InputChannelSubscribe();
input.setTarget(userId);
input.setSubscribe(1);
return httpUtils.httpJsonPost(path, input, Void.class);
return channelHttpUtils.httpJsonPost(path, input, Void.class);
}
public IMResult<Void> unsubscribe(String userId) throws Exception {
@@ -68,12 +68,20 @@ public class ChannelServiceApi {
InputChannelSubscribe input = new InputChannelSubscribe();
input.setTarget(userId);
input.setSubscribe(0);
return httpUtils.httpJsonPost(path, input, Void.class);
return channelHttpUtils.httpJsonPost(path, input, Void.class);
}
public IMResult<OutputStringList> getSubscriberList() throws Exception {
String path = APIPath.Channel_Subscriber_List;
return httpUtils.httpJsonPost(path, null, OutputStringList.class);
return channelHttpUtils.httpJsonPost(path, null, OutputStringList.class);
}
public IMResult<OutputVerifyApplicationUserInfo> verifyApplicationUserInfo(String token) throws Exception {
String path = APIPath.Channel_Verify_Application_UserInfo;
InputVerifyApplicationUserInfo input = new InputVerifyApplicationUserInfo();
input.setToken(token);
return channelHttpUtils.httpJsonPost(path, input, OutputVerifyApplicationUserInfo.class);
}
}
+59 -65
View File
@@ -1328,58 +1328,54 @@ public class Main {
ChannelServiceApi channelServiceApi = new ChannelServiceApi(IMUrl, resultCreateChannel.getResult().getTargetId(), secret);
if (commercialServer) {
//3. 测试channel api功能
IMResult<Void> resultVoid = channelServiceApi.subscribe("userId2");
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("subscribe success");
} else {
System.out.println("subscribe failure");
System.exit(-1);
}
resultVoid = channelServiceApi.subscribe("userId3");
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("subscribe done");
} else {
System.out.println("subscribe failure");
System.exit(-1);
}
IMResult<OutputStringList> resultStringList = channelServiceApi.getSubscriberList();
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId2") && resultStringList.getResult().getList().contains("userId3")) {
System.out.println("get subscriber done");
} else {
System.out.println("get subscriber failure");
System.exit(-1);
}
resultVoid = channelServiceApi.unsubscribe("userId2");
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("unsubscriber done");
} else {
System.out.println("unsubscriber failure");
System.exit(-1);
}
resultStringList = channelServiceApi.getSubscriberList();
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId3") && !resultStringList.getResult().getList().contains("userId2")) {
System.out.println("get subscriber done");
} else {
System.out.println("get subscriber failure");
System.exit(-1);
}
IMResult<InputOutputUserInfo> resultGetUserInfo1 = channelServiceApi.getUserInfo("userId3");
if (resultGetUserInfo1 != null && resultGetUserInfo1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("get user info success");
} else {
System.out.println("get user info failure");
System.exit(-1);
}
//3. 测试channel api功能
IMResult<Void> resultVoid = channelServiceApi.subscribe("userId2");
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("subscribe success");
} else {
System.out.println("subscribe failure");
System.exit(-1);
}
resultVoid = channelServiceApi.subscribe("userId3");
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("subscribe done");
} else {
System.out.println("subscribe failure");
System.exit(-1);
}
IMResult<OutputStringList> resultStringList = channelServiceApi.getSubscriberList();
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId2") && resultStringList.getResult().getList().contains("userId3")) {
System.out.println("get subscriber done");
} else {
System.out.println("get subscriber failure");
System.exit(-1);
}
resultVoid = channelServiceApi.unsubscribe("userId2");
if (resultVoid != null && resultVoid.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("unsubscriber done");
} else {
System.out.println("unsubscriber failure");
System.exit(-1);
}
resultStringList = channelServiceApi.getSubscriberList();
if (resultStringList != null && resultStringList.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS && resultStringList.getResult().getList().contains("userId3") && !resultStringList.getResult().getList().contains("userId2")) {
System.out.println("get subscriber done");
} else {
System.out.println("get subscriber failure");
System.exit(-1);
}
IMResult<InputOutputUserInfo> resultGetUserInfo1 = channelServiceApi.getUserInfo("userId3");
if (resultGetUserInfo1 != null && resultGetUserInfo1.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("get user info success");
} else {
System.out.println("get user info failure");
System.exit(-1);
}
MessagePayload payload = new MessagePayload();
payload.setType(1);
@@ -1403,22 +1399,20 @@ public class Main {
System.exit(-1);
}
if (commercialServer) {
IMResult<Void> voidIMResult = channelServiceApi.modifyChannelInfo(ProtoConstants.ModifyChannelInfoType.Modify_Channel_Desc, "this is a test channel, update at:" + new Date().toString());
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("modify channel profile success");
} else {
System.out.println("modify channel profile failure");
System.exit(-1);
}
IMResult<Void> voidIMResult = channelServiceApi.modifyChannelInfo(ProtoConstants.ModifyChannelInfoType.Modify_Channel_Desc, "this is a test channel, update at:" + new Date().toString());
if (voidIMResult != null && voidIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("modify channel profile success");
} else {
System.out.println("modify channel profile failure");
System.exit(-1);
}
IMResult<OutputGetChannelInfo> outputGetChannelInfoIMResult = channelServiceApi.getChannelInfo();
if (outputGetChannelInfoIMResult != null && outputGetChannelInfoIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("get channel info success");
} else {
System.out.println("get channel info failure");
System.exit(-1);
}
IMResult<OutputGetChannelInfo> outputGetChannelInfoIMResult = channelServiceApi.getChannelInfo();
if (outputGetChannelInfoIMResult != null && outputGetChannelInfoIMResult.getErrorCode() == ErrorCode.ERROR_CODE_SUCCESS) {
System.out.println("get channel info success");
} else {
System.out.println("get channel info failure");
System.exit(-1);
}
}
static void testSensitiveApi() throws Exception {
@@ -4,7 +4,6 @@ import cn.wildfirechat.common.APIPath;
import cn.wildfirechat.pojos.*;
import cn.wildfirechat.sdk.model.IMResult;
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
import cn.wildfirechat.sdk.utilities.RobotHttpUtils;
import java.util.List;
@@ -214,4 +213,13 @@ public class RobotService {
input.setNotify_message(notify_message);
return robotHttpUtils.httpJsonPost(path, input, Void.class);
}
public IMResult<OutputVerifyApplicationUserInfo> verifyApplicationUserInfo(String token) throws Exception {
String path = APIPath.Robot_Verify_Application_UserInfo;
InputVerifyApplicationUserInfo input = new InputVerifyApplicationUserInfo();
input.setToken(token);
return robotHttpUtils.httpJsonPost(path, input, OutputVerifyApplicationUserInfo.class);
}
}