use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class ApiPluginService method proxy.
/**
* <pre>
* 代理前台客户端中扩展的请求
* 1.界面请求后台一般使用http请求
* 2.使用tcp代理,代替http请求
* </pre>
*
* @param command
* @return
*/
public CommandResponse proxy(Command command) {
CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
ErrorCode2 errCode = ErrorCode2.ERROR;
try {
ApiPluginProxyProto.ApiPluginProxyRequest request = ApiPluginProxyProto.ApiPluginProxyRequest.parseFrom(command.getParams());
String siteUserId = command.getSiteUserId();
String pluginId = request.getPluginId();
String requestApi = request.getApi();
String requestParams = request.getParams();
LogUtils.requestDebugLog(logger, command, request.toString());
Map<Integer, String> header = command.getHeader();
String siteSessionId = header.get(CoreProto.HeaderKey.CLIENT_SOCKET_SITE_SESSION_ID_VALUE);
String pluginRefere = header.get(CoreProto.HeaderKey.PLUGIN_CLIENT_REFERER_VALUE);
if (!StringUtils.isAnyBlank(siteUserId, pluginId, requestApi)) {
PluginBean bean = SitePluginDao.getInstance().getPluginProfile(Integer.valueOf(pluginId));
if (bean != null && bean.getApiUrl() != null) {
String pluginUrl = this.buildUrl(bean.getApiUrl(), requestApi, null);
logger.debug("action={} pluginId={} api={} url={} params={}", command.getAction(), pluginId, requestApi, pluginUrl, requestParams);
PluginProto.ProxyPluginPackage.Builder packageBuilder = PluginProto.ProxyPluginPackage.newBuilder();
packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_USER_ID_VALUE, siteUserId);
packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.CLIENT_SITE_SESSION_ID_VALUE, siteSessionId);
packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_ID_VALUE, pluginId);
packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_TIMESTAMP_VALUE, String.valueOf(System.currentTimeMillis()));
if (StringUtils.isNotEmpty(pluginRefere)) {
packageBuilder.putPluginHeader(PluginProto.PluginHeaderKey.PLUGIN_REFERER_VALUE, pluginRefere);
}
if (StringUtils.isNotEmpty(requestParams)) {
packageBuilder.setData(requestParams);
}
byte[] httpContent = packageBuilder.build().toByteArray();
String authKey = bean.getAuthKey();
if (StringUtils.isNotEmpty(authKey)) {
// AES 加密整个proto,通过http传输给plugin
// byte[] tsk = AESCrypto.generateTSKey(bean.getAuthKey());
byte[] tsk = bean.getAuthKey().getBytes(CharsetCoding.ISO_8859_1);
byte[] enPostContent = AESCrypto.encrypt(tsk, httpContent);
httpContent = enPostContent;
}
byte[] httpResponse = ZalyHttpClient.getInstance().postBytes(pluginUrl, httpContent);
ApiPluginProxyProto.ApiPluginProxyResponse response = ApiPluginProxyProto.ApiPluginProxyResponse.newBuilder().setData(ByteString.copyFrom(httpResponse)).build();
// httpResposne,callback方法的回调方法参数
commandResponse.setParams(response.toByteArray());
errCode = ErrorCode2.SUCCESS;
}
} else {
errCode = ErrorCode2.ERROR_PARAMETER;
}
} catch (Exception e) {
errCode = ErrorCode2.ERROR_SYSTEMERROR;
LogUtils.requestErrorLog(logger, command, e);
}
return commandResponse.setErrCode2(errCode);
}
use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class ApiSecretChatService method applyU2.
/**
* 申请二人密聊
*
* @param command
* @return
*/
public CommandResponse applyU2(Command command) {
CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
ErrorCode2 errCode = ErrorCode2.ERROR;
try {
ApiSecretChatApplyU2Proto.ApiSecretChatApplyU2Request request = ApiSecretChatApplyU2Proto.ApiSecretChatApplyU2Request.parseFrom(command.getParams());
String siteUserId = command.getSiteUserId();
String siteFriendId = request.getSiteFriendId();
LogUtils.requestDebugLog(logger, command, request.toString());
if (StringUtils.isNoneBlank(siteUserId, siteFriendId) && !siteUserId.equals(siteFriendId)) {
ConfigProto.U2EncryptionStatus status = SiteConfig.getU2EncryStatus();
logger.debug("siteUserId={} apply encryption chat to siteFriendId={} status={}", siteUserId, siteFriendId, status);
if (ConfigProto.U2EncryptionStatus.U2_OPEN == status) {
UserDeviceBean deviceBean = userDeviceDao.getLatestDevice(siteFriendId);
logger.debug("get siteUserId:{} deviceInfo:{}", siteFriendId, deviceBean.toString());
DeviceProto.SimpleDeviceProfile deviceProfile = DeviceProto.SimpleDeviceProfile.newBuilder().setDeviceId(deviceBean.getDeviceId()).setDeviceName(String.valueOf(deviceBean.getDeviceName())).setUserDevicePubk(deviceBean.getUserDevicePubk()).setLastLoginTime(deviceBean.getActiveTime()).build();
ApiSecretChatApplyU2Proto.ApiSecretChatApplyU2Response response = ApiSecretChatApplyU2Proto.ApiSecretChatApplyU2Response.newBuilder().setDeviceProfile(deviceProfile).build();
commandResponse.setParams(response.toByteArray());
errCode = ErrorCode2.SUCCESS;
} else {
errCode = ErrorCode2.ERROR2_SECRETCHAT_CLOSE;
}
} else {
errCode = ErrorCode2.ERROR_PARAMETER;
}
} catch (Exception e) {
errCode = ErrorCode2.ERROR_SYSTEMERROR;
LogUtils.requestErrorLog(logger, command, e);
}
return commandResponse.setErrCode2(errCode);
}
use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class ApiSiteService method register.
public CommandResponse register(Command command) {
CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
ErrorCode2 errorCode = ErrorCode2.ERROR;
try {
ApiSiteRegisterProto.ApiSiteRegisterRequest registerRequest = ApiSiteRegisterProto.ApiSiteRegisterRequest.parseFrom(command.getParams());
// 这里需要验证邀请码,如果有需要
String userIdPubk = registerRequest.getUserIdPubk();
// siteUserId保证各站不同
String siteUserId = UUID.randomUUID().toString();
String userName = registerRequest.getUserName();
String userPhoto = registerRequest.getUserPhoto();
String userUic = registerRequest.getUserUic();
String applyInfo = registerRequest.getApplyInfo();
String phoneToken = registerRequest.getPhoneToken();
// 通过phoneCod
String phoneId = null;
LogUtils.requestDebugLog(logger, command, registerRequest.toString());
if (StringUtils.isAnyEmpty(userIdPubk, userName)) {
errorCode = ErrorCode2.ERROR_PARAMETER;
return commandResponse.setErrCode2(errorCode);
}
// 判断站点的注册方式
ConfigProto.RegisterWay regWay = SiteConfig.getRegisterWay();
logger.debug("api.site.register register way={}", regWay);
switch(regWay) {
case USERUIC:
logger.debug("注册方式:邀请码注册");
if (!UserUic.getInstance().checkUic(userUic, siteUserId)) {
errorCode = ErrorCode2.ERROR_REGISTER_UIC;
return commandResponse.setErrCode2(errorCode);
}
break;
case REALNAME:
logger.debug("注册方式:实名注册");
if (StringUtils.isNotBlank(phoneToken)) {
phoneId = UserPhone.getInstance().getPhoneIdFromPlatform(phoneToken);
logger.debug("实名注册,站点获取手机号:{}", phoneId);
if (!StringUtils.isNotBlank(phoneId)) {
errorCode = ErrorCode2.ERROR_REGISTER_PHONEID;
return commandResponse.setErrCode2(errorCode);
}
}
break;
case ANONYMOUS:
logger.debug("注册方式:匿名注册");
break;
case UNRECOGNIZED:
break;
}
UserProfileBean regBean = new UserProfileBean();
regBean.setSiteUserId(siteUserId);
regBean.setUserIdPubk(userIdPubk);
regBean.setUserName(userName);
regBean.setApplyInfo(applyInfo);
regBean.setUserPhoto(userPhoto);
regBean.setPhoneId(phoneId);
regBean.setUserStatus(UserProto.UserStatus.NORMAL_VALUE);
regBean.setRegisterTime(System.currentTimeMillis());
if (SiteLoginDao.getInstance().registerUser(regBean)) {
ApiSiteRegisterProto.ApiSiteRegisterResponse response = ApiSiteRegisterProto.ApiSiteRegisterResponse.newBuilder().setSiteUserId(siteUserId).build();
commandResponse.setParams(response.toByteArray());
errorCode = ErrorCode2.SUCCESS;
} else {
errorCode = ErrorCode2.ERROR_REGISTER_SAVEPROFILE;
}
logger.info("client={} siteUserId={} action={} register on site", command.getClientIp(), siteUserId, command.getAction());
if (ErrorCode2.SUCCESS == errorCode) {
// 注册成功,需要做一个管理员身份验证
justForAdminUser(siteUserId, command.getHeader());
}
} catch (Exception e) {
errorCode = ErrorCode2.ERROR_SYSTEMERROR;
LogUtils.requestErrorLog(logger, command, e);
}
return commandResponse.setErrCode2(errorCode);
}
use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class ApiUserService method mute.
public CommandResponse mute(Command command) {
CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
ErrorCode2 errCode = ErrorCode2.ERROR;
try {
String siteUserId = command.getSiteUserId();
boolean mute = UserProfileDao.getInstance().getUserMute(siteUserId);
LogUtils.requestDebugLog(logger, command, "");
ApiUserMuteProto.ApiUserMuteResponse response = ApiUserMuteProto.ApiUserMuteResponse.newBuilder().setMute(mute).build();
commandResponse.setParams(response.toByteArray());
errCode = ErrorCode2.SUCCESS;
} catch (Exception e) {
errCode = ErrorCode2.ERROR_SYSTEMERROR;
LogUtils.requestErrorLog(logger, command, e);
}
return commandResponse.setErrCode2(errCode);
}
use of com.akaxin.common.command.CommandResponse in project openzaly by akaxincom.
the class ApiUserService method updateMute.
public CommandResponse updateMute(Command command) {
CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
ErrorCode2 errCode = ErrorCode2.ERROR;
try {
ApiUserUpdateMuteProto.ApiUserUpdateMuteRequest request = ApiUserUpdateMuteProto.ApiUserUpdateMuteRequest.parseFrom(command.getParams());
String siteUserId = command.getSiteUserId();
boolean mute = request.getMute();
LogUtils.requestDebugLog(logger, command, request.toString());
if (UserProfileDao.getInstance().updateUserMute(siteUserId, mute)) {
errCode = ErrorCode2.SUCCESS;
} else {
errCode = ErrorCode2.ERROR_DATABASE_EXECUTE;
}
} catch (Exception e) {
errCode = ErrorCode2.ERROR_SYSTEMERROR;
LogUtils.requestErrorLog(logger, command, e);
}
return commandResponse.setErrCode2(errCode);
}
Aggregations