add authcode and config api for open platform

This commit is contained in:
heavyrian2012
2022-05-15 10:19:07 +08:00
parent 92fa40f1fd
commit 391f7345c0
22 changed files with 2113 additions and 75 deletions
-3
View File
@@ -108,9 +108,6 @@ message.global_mute_exception_types 401,402,403,404,405,407,408,410,411
## 当为true时,不转发server api发送的消息;当为false时,转发server api发送的消息。
message.no_forward_admin_message false
## 应用密钥
application.secret_key 123456
##禁止搜索用户
friend.disable_search false
@@ -10,8 +10,9 @@ package com.xiaoleilu.loServer.action.channel;
import cn.wildfirechat.common.APIPath;
import cn.wildfirechat.common.ErrorCode;
import cn.wildfirechat.pojos.InputVerifyApplicationUserInfo;
import cn.wildfirechat.pojos.OutputVerifyApplicationUserInfo;
import cn.wildfirechat.pojos.InputApplicationGetUserInfo;
import cn.wildfirechat.pojos.OutputApplicationUserInfo;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
import com.google.gson.Gson;
import com.xiaoleilu.loServer.RestResult;
@@ -23,21 +24,21 @@ import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.internal.StringUtil;
@Route(APIPath.Channel_Verify_Application_UserInfo)
@Route(APIPath.Channel_Application_Get_UserInfo)
@HttpMethod("POST")
public class VerifyApplicationUserInfoAction extends ChannelAction {
public class ApplicationGetUserInfoAction extends ChannelAction {
@Override
public boolean action(Request request, Response response) {
if (request.getNettyRequest() instanceof FullHttpRequest) {
InputVerifyApplicationUserInfo inputUserToken = getRequestBody(request.getNettyRequest(), InputVerifyApplicationUserInfo.class);
InputApplicationGetUserInfo inputUserToken = getRequestBody(request.getNettyRequest(), InputApplicationGetUserInfo.class);
RestResult result;
if (inputUserToken == null || StringUtil.isNullOrEmpty(inputUserToken.getToken())) {
if (inputUserToken == null || StringUtil.isNullOrEmpty(inputUserToken.getAuthCode())) {
result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
} else {
String userId = messagesStore.verifyApplicationToken(inputUserToken.getToken(), channelInfo.getTargetId());
String userId = messagesStore.verifyApplicationAuthCode(inputUserToken.getAuthCode(), channelInfo.getTargetId(), ProtoConstants.ApplicationType.ApplicationType_Channel);
if(userId != null) {
OutputVerifyApplicationUserInfo outputVerifyApplicationUser = new OutputVerifyApplicationUserInfo();
OutputApplicationUserInfo outputVerifyApplicationUser = new OutputApplicationUserInfo();
outputVerifyApplicationUser.setUserId(userId);
WFCMessage.User user = messagesStore.getUserInfo(userId);
if(user != null) {
@@ -0,0 +1,59 @@
/*
* This file is part of the Wildfire Chat package.
* (c) Heavyrain2012 <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
package com.xiaoleilu.loServer.action.robot;
import cn.wildfirechat.common.APIPath;
import cn.wildfirechat.common.ErrorCode;
import cn.wildfirechat.pojos.InputApplicationGetUserInfo;
import cn.wildfirechat.pojos.OutputApplicationUserInfo;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
import com.google.gson.Gson;
import com.xiaoleilu.loServer.RestResult;
import com.xiaoleilu.loServer.annotation.HttpMethod;
import com.xiaoleilu.loServer.annotation.Route;
import com.xiaoleilu.loServer.handler.Request;
import com.xiaoleilu.loServer.handler.Response;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.internal.StringUtil;
@Route(APIPath.Robot_Application_Get_UserInfo)
@HttpMethod("POST")
public class ApplicationGetUserInfoAction extends RobotAction {
@Override
public boolean action(Request request, Response response) {
if (request.getNettyRequest() instanceof FullHttpRequest) {
InputApplicationGetUserInfo inputUserToken = getRequestBody(request.getNettyRequest(), InputApplicationGetUserInfo.class);
RestResult result;
if (inputUserToken == null || StringUtil.isNullOrEmpty(inputUserToken.getAuthCode())) {
result = RestResult.resultOf(ErrorCode.INVALID_PARAMETER);
} else {
String userId = messagesStore.verifyApplicationAuthCode(inputUserToken.getAuthCode(), robot.getUid(), ProtoConstants.ApplicationType.ApplicationType_Robot);
if(userId != null) {
OutputApplicationUserInfo outputVerifyApplicationUser = new OutputApplicationUserInfo();
outputVerifyApplicationUser.setUserId(userId);
WFCMessage.User user = messagesStore.getUserInfo(userId);
if(user != null) {
outputVerifyApplicationUser.setDisplayName(user.getDisplayName());
outputVerifyApplicationUser.setPortraitUrl(user.getPortrait());
}
result = RestResult.ok(outputVerifyApplicationUser);
} else {
result = RestResult.resultOf(ErrorCode.ERROR_CODE_APPLICATION_TOKEN_ERROR_OR_TIMEOUT);
}
}
response.setStatus(HttpResponseStatus.OK);
response.setContent(new Gson().toJson(result));
}
return true;
}
}
@@ -176,8 +176,6 @@ public final class BrokerConstants {
public static final String MESSAGES_RECALL_TIME_LIMIT = "message.recall_time_limit";
public static final String MESSAGES_DISABLE_GROUP_MANAGER_RECALL = "message.disable_group_manager_recall";
public static final String APPLICATION_SECRET_KEY = "application.secret_key";
public static final String HTTP_ADMIN_RATE_LIMIT = "http.admin.rate_limit";
public static final String HTTP_ROBOT_RATE_LIMIT = "http.robot.rate_limit";
public static final String HTTP_CHANNEL_RATE_LIMIT = "http.channel.rate_limit";
@@ -0,0 +1,28 @@
/*
* This file is part of the Wildfire Chat package.
* (c) Heavyrain2012 <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
package io.moquette.imhandler;
import cn.wildfirechat.common.ErrorCode;
import cn.wildfirechat.proto.ProtoConstants;
import cn.wildfirechat.proto.WFCMessage;
import io.moquette.spi.impl.Qos1PublishHandler;
import io.netty.buffer.ByteBuf;
import win.liyufan.im.IMTopic;
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
@Handler(IMTopic.ApplicationConfigRequestTopic)
public class ConfigApplicationHandler extends IMHandler<WFCMessage.ApplicationConfigRequest> {
@Override
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, ProtoConstants.RequestSourceType requestSourceType, WFCMessage.ApplicationConfigRequest request, Qos1PublishHandler.IMCallback callback) {
ErrorCode errorCode = m_messagesStore.configApplication(request.getAppId(), request.getAppType(), request.getTimestamp(), request.getNonce(), request.getSignature());
return errorCode;
}
}
@@ -18,12 +18,16 @@ import win.liyufan.im.IMTopic;
import static cn.wildfirechat.common.ErrorCode.ERROR_CODE_SUCCESS;
@Handler(IMTopic.GetApplicationTokenRequestTopic)
public class GetApplicationTokenHandler extends IMHandler<WFCMessage.IDBuf> {
public class GetApplicationTokenHandler extends IMHandler<WFCMessage.AuthCodeRequest> {
@Override
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, ProtoConstants.RequestSourceType requestSourceType, WFCMessage.IDBuf request, Qos1PublishHandler.IMCallback callback) {
String token = m_messagesStore.getApplicationToken(fromUser, request.getId());
byte[] data = WFCMessage.IDBuf.newBuilder().setId(token).build().toByteArray();
ackPayload.ensureWritable(data.length).writeBytes(data);
return ERROR_CODE_SUCCESS;
public ErrorCode action(ByteBuf ackPayload, String clientID, String fromUser, ProtoConstants.RequestSourceType requestSourceType, WFCMessage.AuthCodeRequest request, Qos1PublishHandler.IMCallback callback) {
String authCode = m_messagesStore.getApplicationAuthCode(fromUser, request.getTargetId(), request.getType(), request.getHost());
if(authCode != null) {
byte[] data = WFCMessage.IDBuf.newBuilder().setId(authCode).build().toByteArray();
ackPayload.ensureWritable(data.length).writeBytes(data);
return ERROR_CODE_SUCCESS;
}
return ErrorCode.INVALID_PARAMETER;
}
}
@@ -35,11 +35,14 @@ import io.moquette.spi.impl.security.AES;
import io.moquette.spi.security.Tokenor;
import io.moquette.spi.impl.subscriptions.Topic;
import io.netty.handler.codec.mqtt.MqttVersion;
import org.apache.commons.codec.digest.DigestUtils;
import org.json.simple.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import win.liyufan.im.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
@@ -62,7 +65,6 @@ import static cn.wildfirechat.proto.ProtoConstants.PersistFlag.Transparent;
import static cn.wildfirechat.proto.ProtoConstants.Platform.*;
import static cn.wildfirechat.proto.ProtoConstants.UpdateUserInfoMask.*;
import static io.moquette.BrokerConstants.*;
import static io.moquette.BrokerConstants.APPLICATION_SECRET_KEY;
import static io.moquette.server.Constants.MAX_CHATROOM_MESSAGE_QUEUE;
import static io.moquette.server.Constants.MAX_MESSAGE_QUEUE;
import static cn.wildfirechat.pojos.MyInfoType.*;
@@ -166,8 +168,6 @@ public class MemoryMessagesStore implements IMessagesStore {
private Set<Integer> mUserHideProperties = new HashSet<>();
private String mApplicationSecretKey;
MemoryMessagesStore(Server server, DatabaseStore databaseStore) {
m_Server = server;
this.databaseStore = databaseStore;
@@ -445,17 +445,6 @@ public class MemoryMessagesStore implements IMessagesStore {
} catch (NumberFormatException e) {
e.printStackTrace();
}
try {
mApplicationSecretKey = server.getConfig().getProperty(APPLICATION_SECRET_KEY, "wfcapp1290secretkey");
} catch (Exception e) {
e.printStackTrace();
}
while (StringUtil.isNullOrEmpty(mApplicationSecretKey) || mApplicationSecretKey.length() < 16) {
mApplicationSecretKey += "w";
mApplicationSecretKey += mApplicationSecretKey;
}
}
private void printMissConfigLog(String config, String defaultValue) {
@@ -3315,23 +3304,103 @@ public class MemoryMessagesStore implements IMessagesStore {
return true;
}
private String ensureSecretLength(String secret) {
while ( secret.length() < 16) {
secret += "w";
secret += secret;
}
return secret;
}
@Override
public String getApplicationToken(String fromUser, String applicationId) {
byte[] token = AES.AESEncrypt(fromUser + "?|?" + System.currentTimeMillis() + "?|?" + applicationId, mApplicationSecretKey);
return new String(Base64.getEncoder().encode(token));
public String getApplicationAuthCode(String fromUser, String applicationId, int type, String host) {
String secret = null;
if(type == 0) {
WFCMessage.Robot robotData = getRobot(applicationId);
if(robotData != null && !StringUtil.isNullOrEmpty(robotData.getCallback()) && !StringUtil.isNullOrEmpty(robotData.getSecret())) {
try {
URL url = new URL(robotData.getCallback());
if(url.getHost().equals(host)) {
secret = robotData.getSecret();
} else {
LOG.warn("get application auth code error, request host is not the same host with callback host");
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
} else {
String errorReason;
if(robotData == null) {
errorReason = "Robot not exist.";
} else if(StringUtil.isNullOrEmpty(robotData.getCallback())) {
errorReason = "Robot no callback address";
} else {
errorReason = "Robot no secret";
}
LOG.warn("get application auth code error, reason {}", errorReason);
}
} else if(type == 1) {
WFCMessage.ChannelInfo channelData = getChannelInfo(applicationId);
if(channelData != null && !StringUtil.isNullOrEmpty(channelData.getCallback()) && !StringUtil.isNullOrEmpty(channelData.getSecret())) {
try {
URL url = new URL(channelData.getCallback());
if(url.getHost().equals(host)) {
secret = channelData.getSecret();
} else {
LOG.warn("get application auth code error, request host is not the same host with callback host");
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
} else {
String errorReason;
if(channelData == null) {
errorReason = "Channel not exist.";
} else if(StringUtil.isNullOrEmpty(channelData.getCallback())) {
errorReason = "Channel no callback address";
} else {
errorReason = "Channel no secret";
}
LOG.warn("get application auth code error, reason {}", errorReason);
}
}
if(!StringUtil.isNullOrEmpty(secret)) {
secret = ensureSecretLength(secret);
byte[] token = AES.AESEncrypt(fromUser + "?|?" + System.currentTimeMillis() + "?|?" + applicationId + "?|?" + type, secret);
return new String(Base64.getEncoder().encode(token));
}
return null;
}
@Override
public String verifyApplicationToken(String token, String applicationId) {
byte[] data = Base64.getDecoder().decode(token);
data = AES.AESDecrypt(data, mApplicationSecretKey, true);
public String verifyApplicationAuthCode(String authCode, String applicationId, int type) {
String secret = null;
if(type == 0) {
WFCMessage.Robot robotData = getRobot(applicationId);
if(robotData != null && !StringUtil.isNullOrEmpty(robotData.getCallback()) && !StringUtil.isNullOrEmpty(robotData.getSecret())) {
secret = robotData.getSecret();
}
} else if(type == 1) {
WFCMessage.ChannelInfo channelData = getChannelInfo(applicationId);
if(channelData != null && !StringUtil.isNullOrEmpty(channelData.getCallback()) && !StringUtil.isNullOrEmpty(channelData.getSecret())) {
secret = channelData.getSecret();
}
}
secret = ensureSecretLength(secret);
byte[] data = Base64.getDecoder().decode(authCode);
data = AES.AESDecrypt(data, secret, true);
if (data == null || data.length == 0) {
return null;
} else {
String str = new String(data);
String[] strArr = str.split("\\?\\|\\?");
if (strArr.length == 3) {
if (strArr.length == 4) {
if (applicationId.equals(strArr[2])) {
long timestamp= Long.parseLong(strArr[1]);
if(System.currentTimeMillis() - timestamp > 60*1000) {
@@ -3344,6 +3413,40 @@ public class MemoryMessagesStore implements IMessagesStore {
return null;
}
@Override
public ErrorCode configApplication(String appId, int appType, long timestamp, String nonce, String signature) {
String secret;
if(System.currentTimeMillis()/1000 - timestamp > 300) {
return ErrorCode.ERROR_CODE_SIGN_EXPIRED;
}
if(appType == ProtoConstants.ApplicationType.ApplicationType_Robot) {
WFCMessage.Robot robotData = getRobot(appId);
if(robotData != null) {
secret = robotData.getSecret();
} else {
return ErrorCode.ERROR_CODE_NOT_EXIST;
}
} else if(appType == ProtoConstants.ApplicationType.ApplicationType_Channel) {
WFCMessage.ChannelInfo channelData = getChannelInfo(appId);
if(channelData != null) {
secret = channelData.getSecret();
} else {
return ErrorCode.ERROR_CODE_NOT_EXIST;
}
} else {
LOG.error("Config application type only support 0 or 1");
return ErrorCode.INVALID_PARAMETER;
}
String str = nonce + "|" + appId + "|" + timestamp + "|" + secret;
String sign = DigestUtils.sha1Hex(str);
if(sign.equals(signature)) {
return ErrorCode.ERROR_CODE_SUCCESS;
}
return ErrorCode.ERROR_CODE_AUTH_FAILURE;
}
@Override
public boolean isNewFriendWelcomeMessage() {
@@ -194,8 +194,9 @@ public interface IMessagesStore {
boolean checkChatroomParticipantIdelTime(MemorySessionStore.Session session);
String getApplicationToken(String fromUser, String applicationId);
String verifyApplicationToken(String token, String applicationId);
String getApplicationAuthCode(String fromUser, String applicationId, int appType, String host);
String verifyApplicationAuthCode(String token, String applicationId, int type);
ErrorCode configApplication(String appId, int appType, long timestamp, String nonce, String signature);
ErrorCode getUserSettings(String userId, long version, WFCMessage.GetUserSettingResult.Builder builder);
WFCMessage.UserSettingEntry getUserSetting(String userId, int scope, String key);
@@ -85,4 +85,5 @@ public interface IMTopic {
String ClearSessionTopic = "CST";
String GetApplicationTokenRequestTopic = "ATR";
String ApplicationConfigRequestTopic = "ACR";
}
@@ -92,7 +92,7 @@ public interface APIPath {
String Channel_Message_Send = "/channel/message/send";
String Channel_Subscribe = "/channel/subscribe";
String Channel_Subscriber_List = "/channel/subscriber_list";
String Channel_Verify_Application_UserInfo = "/channel/user/verify";
String Channel_Application_Get_UserInfo = "/channel/application/get_user_info";
String Robot_User_Info = "/robot/user_info";
String Robot_Get_Profile = "/robot/profile";
@@ -101,7 +101,7 @@ public interface APIPath {
String Robot_Get_Callback = "/robot/get_callback";
String Robot_Delete_Callback = "/robot/delete_callback";
String Robot_Update_Profile = "/robot/update_profile";
String Robot_Verify_Application_UserInfo = "/robot/user/verify";
String Robot_Application_Get_UserInfo = "/robot/application/get_user_info";
String Robot_Group_Member_Add = "/robot/group/member/add";
String Robot_Group_Allow_Member = "/robot/group/manager/allow";
String Robot_Create_Group = "/robot/group/create";
@@ -8,14 +8,14 @@
package cn.wildfirechat.pojos;
public class InputVerifyApplicationUserInfo {
private String token;
public class InputApplicationGetUserInfo {
private String authCode;
public String getToken() {
return token;
public String getAuthCode() {
return authCode;
}
public void setToken(String token) {
this.token = token;
public void setAuthCode(String authCode) {
this.authCode = authCode;
}
}
@@ -0,0 +1,57 @@
/*
* This file is part of the Wildfire Chat package.
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
package cn.wildfirechat.pojos;
public class OutputApplicationConfigData {
private String appId;
private int appType;
private long timestamp;
private String nonceStr;
private String signature;
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
public int getAppType() {
return appType;
}
public void setAppType(int appType) {
this.appType = appType;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public String getNonceStr() {
return nonceStr;
}
public void setNonceStr(String nonceStr) {
this.nonceStr = nonceStr;
}
public String getSignature() {
return signature;
}
public void setSignature(String signature) {
this.signature = signature;
}
}
@@ -8,7 +8,7 @@
package cn.wildfirechat.pojos;
public class OutputVerifyApplicationUserInfo {
public class OutputApplicationUserInfo {
private String userId;
private String displayName;
private String portraitUrl;
-8
View File
@@ -1,11 +1,3 @@
/*
* This file is part of the Wildfire Chat package.
* (c) Heavyrain2012 <heavyrain.lee@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
package cn.wildfirechat.pojos;
@@ -230,6 +230,11 @@ public class ProtoConstants {
Request_From_Channel;
}
public interface ApplicationType {
int ApplicationType_Robot = 0;
int ApplicationType_Channel = 1;
}
public static final int MESSAGE_CONTENT_TYPE_CREATE_GROUP = 104;
public static final int MESSAGE_CONTENT_TYPE_ADD_GROUP_MEMBER = 105;
public static final int MESSAGE_CONTENT_TYPE_KICKOF_GROUP_MEMBER = 106;
File diff suppressed because it is too large Load Diff
@@ -103,9 +103,6 @@ message.global_mute_exception_types 401,402,403,404,405,407,408,410,411
## 当为true时,不转发server api发送的消息;当为false时,转发server api发送的消息。
message.no_forward_admin_message false
## 应用密钥
application.secret_key 123456
##禁止搜索用户
friend.disable_search false
@@ -4,9 +4,13 @@ import cn.wildfirechat.common.APIPath;
import cn.wildfirechat.pojos.*;
import cn.wildfirechat.sdk.model.IMResult;
import cn.wildfirechat.sdk.utilities.ChannelHttpUtils;
import org.apache.commons.codec.digest.DigestUtils;
import java.util.List;
import static cn.wildfirechat.proto.ProtoConstants.ApplicationType.ApplicationType_Channel;
import static cn.wildfirechat.proto.ProtoConstants.ApplicationType.ApplicationType_Robot;
//仅专业版支持,社区版不支持
public class ChannelServiceApi {
private final ChannelHttpUtils channelHttpUtils;
@@ -76,12 +80,25 @@ public class ChannelServiceApi {
return channelHttpUtils.httpJsonPost(path, null, OutputStringList.class);
}
public IMResult<OutputApplicationUserInfo> applicationGetUserInfo(String authCode) throws Exception {
String path = APIPath.Channel_Application_Get_UserInfo;
InputApplicationGetUserInfo input = new InputApplicationGetUserInfo();
input.setAuthCode(authCode);
return channelHttpUtils.httpJsonPost(path, input, OutputApplicationUserInfo.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);
public OutputApplicationConfigData getApplicationSignature() {
int nonce = (int)(Math.random() * 100000 + 3);
long timestamp = System.currentTimeMillis()/1000;
String str = nonce + "|" + channelHttpUtils.getChannelId() + "|" + timestamp + "|" + channelHttpUtils.getChannelSecret();
String sign = DigestUtils.sha1Hex(str);
OutputApplicationConfigData configData = new OutputApplicationConfigData();
configData.setAppId(channelHttpUtils.getChannelId());
configData.setAppType(ApplicationType_Channel);
configData.setTimestamp(timestamp);
configData.setNonceStr(nonce+"");
configData.setSignature(sign);
return configData;
}
}
@@ -1196,6 +1196,9 @@ public class Main {
System.out.println("cancel group manager failure");
System.exit(-1);
}
OutputApplicationConfigData config = robotService.getApplicationSignature();
System.out.println(config);
}
@@ -1422,6 +1425,8 @@ public class Main {
System.out.println("get channel info failure");
System.exit(-1);
}
OutputApplicationConfigData config = channelServiceApi.getApplicationSignature();
System.out.println(config);
}
static void testSensitiveApi() throws Exception {
List<String> words = Arrays.asList("a","b","c");
@@ -3,11 +3,13 @@ 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;
import org.apache.commons.codec.digest.DigestUtils;
import java.util.List;
import static cn.wildfirechat.proto.ProtoConstants.ApplicationType.ApplicationType_Robot;
public class RobotService {
private final RobotHttpUtils robotHttpUtils;
@@ -216,11 +218,25 @@ public class RobotService {
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);
public IMResult<OutputApplicationUserInfo> applicationGetUserInfo(String authCode) throws Exception {
String path = APIPath.Robot_Application_Get_UserInfo;
InputApplicationGetUserInfo input = new InputApplicationGetUserInfo();
input.setAuthCode(authCode);
return robotHttpUtils.httpJsonPost(path, input, OutputApplicationUserInfo.class);
}
public OutputApplicationConfigData getApplicationSignature() {
int nonce = (int)(Math.random() * 100000 + 3);
long timestamp = System.currentTimeMillis()/1000;
String str = nonce + "|" + robotHttpUtils.getRobotId() + "|" + timestamp + "|" + robotHttpUtils.getRobotSecret();
String sign = DigestUtils.sha1Hex(str);
OutputApplicationConfigData configData = new OutputApplicationConfigData();
configData.setAppId(robotHttpUtils.getRobotId());
configData.setAppType(ApplicationType_Robot);
configData.setTimestamp(timestamp);
configData.setNonceStr(nonce+"");
configData.setSignature(sign);
return configData;
}
@@ -115,4 +115,11 @@ public class ChannelHttpUtils {
return str == null || str.isEmpty();
}
public String getChannelId() {
return channelId;
}
public String getChannelSecret() {
return channelSecret;
}
}
@@ -118,4 +118,11 @@ public class RobotHttpUtils {
return str == null || str.isEmpty();
}
public String getRobotId() {
return robotId;
}
public String getRobotSecret() {
return robotSecret;
}
}