Search in sources :

Example 46 with ErrorCode2

use of com.akaxin.common.constant.ErrorCode2 in project openzaly by akaxincom.

the class ApiGroupService method list.

/**
 * 获取用户群列表 <br>
 * 无权限限制
 *
 * @param command
 * @return
 */
public CommandResponse list(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupListProto.ApiGroupListRequest request = ApiGroupListProto.ApiGroupListRequest.parseFrom(command.getParams());
        String siteUserId = command.getSiteUserId();
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(siteUserId) && siteUserId.equals(siteUserId)) {
            List<SimpleGroupBean> groupBeanList = UserGroupDao.getInstance().getUserGroups(siteUserId);
            ApiGroupListProto.ApiGroupListResponse.Builder responseBuilder = ApiGroupListProto.ApiGroupListResponse.newBuilder();
            for (SimpleGroupBean groupBean : groupBeanList) {
                GroupProto.SimpleGroupProfile groupProfile = GroupProto.SimpleGroupProfile.newBuilder().setGroupId(String.valueOf(groupBean.getGroupId())).setGroupName(String.valueOf(groupBean.getGroupName())).setGroupIcon(String.valueOf(groupBean.getGroupPhoto())).build();
                responseBuilder.addList(groupProfile);
            }
            ApiGroupListProto.ApiGroupListResponse response = responseBuilder.build();
            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);
}
Also used : ApiGroupListProto(com.akaxin.proto.site.ApiGroupListProto) GroupProto(com.akaxin.proto.core.GroupProto) SimpleGroupBean(com.akaxin.site.storage.bean.SimpleGroupBean) CommandResponse(com.akaxin.common.command.CommandResponse) ErrorCode2(com.akaxin.common.constant.ErrorCode2)

Example 47 with ErrorCode2

use of com.akaxin.common.constant.ErrorCode2 in project openzaly by akaxincom.

the class ApiGroupService method members.

/**
 * 获取群成员 <br>
 * 无权限控制
 *
 * @param command
 * @return
 */
public CommandResponse members(Command command) {
    CommandResponse commandResponse = new CommandResponse().setAction(CommandConst.ACTION_RES);
    ErrorCode2 errCode = ErrorCode2.ERROR;
    try {
        ApiGroupMembersProto.ApiGroupMembersRequest request = ApiGroupMembersProto.ApiGroupMembersRequest.parseFrom(command.getParams());
        String groupId = request.getGroupId();
        int pageNum = 1;
        int pageSize = GroupConfig.GROUP_MAX_MEMBER_COUNT;
        LogUtils.requestDebugLog(logger, command, request.toString());
        if (StringUtils.isNotBlank(groupId)) {
            List<GroupMemberBean> memberList = UserGroupDao.getInstance().getGroupMemberList(groupId, pageNum, pageSize);
            ApiGroupMembersProto.ApiGroupMembersResponse.Builder responseBuilder = ApiGroupMembersProto.ApiGroupMembersResponse.newBuilder();
            for (GroupMemberBean member : memberList) {
                GroupProto.GroupMemberRole memberRole = GroupProto.GroupMemberRole.forNumber(member.getUserRole());
                UserProto.UserProfile memberProfile = UserProto.UserProfile.newBuilder().setSiteUserId(member.getUserId()).setUserName(String.valueOf(member.getUserName())).setUserPhoto(String.valueOf(member.getUserPhoto())).build();
                GroupProto.GroupMemberProfile groupMember = GroupProto.GroupMemberProfile.newBuilder().setRole(memberRole).setProfile(memberProfile).build();
                responseBuilder.addList(groupMember);
            }
            commandResponse.setParams(responseBuilder.build().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);
}
Also used : ApiGroupMembersProto(com.akaxin.proto.site.ApiGroupMembersProto) GroupProto(com.akaxin.proto.core.GroupProto) UserProto(com.akaxin.proto.core.UserProto) CommandResponse(com.akaxin.common.command.CommandResponse) GroupMemberBean(com.akaxin.site.storage.bean.GroupMemberBean) ErrorCode2(com.akaxin.common.constant.ErrorCode2)

Example 48 with ErrorCode2

use of com.akaxin.common.constant.ErrorCode2 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);
}
Also used : CommandResponse(com.akaxin.common.command.CommandResponse) ByteString(com.google.protobuf.ByteString) ErrorCode2(com.akaxin.common.constant.ErrorCode2) ApiPluginProxyProto(com.akaxin.proto.site.ApiPluginProxyProto) PluginBean(com.akaxin.site.storage.bean.PluginBean)

Example 49 with ErrorCode2

use of com.akaxin.common.constant.ErrorCode2 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);
}
Also used : ApiSecretChatApplyU2Proto(com.akaxin.proto.site.ApiSecretChatApplyU2Proto) ErrorCode2(com.akaxin.common.constant.ErrorCode2) ConfigProto(com.akaxin.proto.core.ConfigProto) UserDeviceBean(com.akaxin.site.storage.bean.UserDeviceBean) CommandResponse(com.akaxin.common.command.CommandResponse) DeviceProto(com.akaxin.proto.core.DeviceProto)

Example 50 with ErrorCode2

use of com.akaxin.common.constant.ErrorCode2 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);
}
Also used : ErrorCode2(com.akaxin.common.constant.ErrorCode2) ApiSiteConfigProto(com.akaxin.proto.site.ApiSiteConfigProto) ConfigProto(com.akaxin.proto.core.ConfigProto) ApiSiteRegisterProto(com.akaxin.proto.site.ApiSiteRegisterProto) CommandResponse(com.akaxin.common.command.CommandResponse) UserProfileBean(com.akaxin.site.storage.bean.UserProfileBean)

Aggregations

CommandResponse (com.akaxin.common.command.CommandResponse)68 ErrorCode2 (com.akaxin.common.constant.ErrorCode2)68 UserProto (com.akaxin.proto.core.UserProto)12 PluginBean (com.akaxin.site.storage.bean.PluginBean)7 GroupProto (com.akaxin.proto.core.GroupProto)6 GroupProfileBean (com.akaxin.site.storage.bean.GroupProfileBean)6 SimpleUserBean (com.akaxin.site.storage.bean.SimpleUserBean)6 UserProfileBean (com.akaxin.site.storage.bean.UserProfileBean)6 UserDeviceBean (com.akaxin.site.storage.bean.UserDeviceBean)5 ByteString (com.google.protobuf.ByteString)5 DeviceProto (com.akaxin.proto.core.DeviceProto)4 ProtocolStringList (com.google.protobuf.ProtocolStringList)4 ConfigProto (com.akaxin.proto.core.ConfigProto)3 GroupMemberBean (com.akaxin.site.storage.bean.GroupMemberBean)3 UserGroupBean (com.akaxin.site.storage.bean.UserGroupBean)3 FileProto (com.akaxin.proto.core.FileProto)2 HaiSiteUpdateConfigProto (com.akaxin.proto.plugin.HaiSiteUpdateConfigProto)2 ApiFriendSettingProto (com.akaxin.proto.site.ApiFriendSettingProto)2 ApiGroupUpdateSettingProto (com.akaxin.proto.site.ApiGroupUpdateSettingProto)2 User2Notice (com.akaxin.site.business.impl.notice.User2Notice)2