Search in sources :

Example 1 with TencentCloudSDKException

use of com.tencentcloudapi.common.exception.TencentCloudSDKException in project Ant-Live by PinTeh.

the class TencentLiveServiceImpl method ban.

@Override
public boolean ban(Integer rid, String resumeTime, String reason) {
    List<BanRecord> banRecords = banRecordMapper.selectList(new QueryWrapper<BanRecord>().eq("room_id", rid).eq("status", 0));
    if (banRecords.size() > 0) {
        return false;
    }
    LiveInfo liveInfo = liveInfoMapper.selectOne(new QueryWrapper<LiveInfo>().eq("room_id", rid).orderByDesc("id").last("limit 0,1"));
    if (liveInfo.getEndTime() == null) {
        // 不能直接更新liveInfo
        LiveInfo updateInfo = new LiveInfo();
        updateInfo.setId(liveInfo.getId());
        updateInfo.setEndTime(LocalDateTime.now());
        // 0-living 1-finished
        updateInfo.setStatus(Constants.LiveInfoStatus.YES.getCode());
        liveInfoMapper.updateById(updateInfo);
    }
    try {
        roomMapper.updateById(Room.builder().id(rid).status(Constants.LiveStatus.BANNING.getCode()).build());
    } catch (Exception e) {
        log.error("更新房间状态异常:{}", e.getMessage());
    }
    log.info("调用腾讯云封禁接口: rid = " + rid);
    ForbidLiveStreamRequest forbidLiveStreamRequest = new ForbidLiveStreamRequest();
    forbidLiveStreamRequest.setAppName("live");
    forbidLiveStreamRequest.setDomainName("live.imhtb.cn");
    forbidLiveStreamRequest.setStreamName(String.valueOf(rid));
    forbidLiveStreamRequest.setReason("reason");
    /*
         * 	恢复流的时间。UTC 格式,例如:2018-11-29T19:00:00Z。
         * 注意:
         * 1. 默认禁播7天,且最长支持禁播90天。
         */
    LocalDateTime resumeLocalDateTime = LocalDateTime.now().plusDays(7);
    DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    if (!StringUtils.isEmpty(resumeTime)) {
        forbidLiveStreamRequest.setResumeTime(resumeTime);
        // TODO 手动添加8小时
        resumeLocalDateTime = LocalDateTime.parse(resumeTime, df).plusHours(8L);
    }
    ForbidLiveStreamResponse resp = null;
    try {
        resp = client.ForbidLiveStream(forbidLiveStreamRequest);
    } catch (TencentCloudSDKException e) {
        e.printStackTrace();
        return false;
    }
    LocalDateTime now = LocalDateTime.now();
    BanRecord record = new BanRecord();
    record.setRoomId(rid);
    record.setReason(reason);
    record.setCreateTime(now);
    record.setStartTime(now);
    record.setResumeTime(resumeLocalDateTime);
    record.setStatus(0);
    banRecordMapper.insert(record);
    roomMapper.updateById(Room.builder().id(rid).status(Constants.LiveStatus.BANNING.getCode()).build());
    log.info(ForbidLiveStreamRequest.toJsonString(resp));
    log.info("调用腾讯云封禁接口:执行成功");
    return true;
}
Also used : LocalDateTime(java.time.LocalDateTime) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) DateTimeFormatter(java.time.format.DateTimeFormatter) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BanRecord(cn.imhtb.antlive.entity.database.BanRecord) LiveInfo(cn.imhtb.antlive.entity.LiveInfo)

Example 2 with TencentCloudSDKException

use of com.tencentcloudapi.common.exception.TencentCloudSDKException in project Ant-Live by PinTeh.

the class AuthServiceImpl method saveAndCheck.

@Override
public ApiResponse saveAndCheck(AuthInfo authInfo) {
    // 正面
    String params = "{\"ImageUrl\":\"" + authInfo.getPositiveUrl() + "\"}";
    IDCardOCRRequest req = IDCardOCRRequest.fromJsonString(params, IDCardOCRRequest.class);
    try {
        IDCardOCRResponse response = ocrClient.IDCardOCR(req);
        log.info("自动审核:" + JSON.toJSONString(response));
        String idNum = response.getIdNum();
        String name = response.getName();
        String advancedInfo = response.getAdvancedInfo();
        String ret = handleAdvanceInfo(advancedInfo);
        if (!StringUtils.isEmpty(ret)) {
            log.info("自动否决");
            authInfo.setStatus(Constants.AuthStatus.REJECT.getCode());
            authInfo.setRejectReason(ret);
            authMapper.insert(authInfo);
            return ApiResponse.ofSuccess();
        }
        // 自动核对信息
        if (idNum.equals(authInfo.getCardNo()) && name.equals(authInfo.getRealName())) {
            log.info("自动审核通过");
            authInfo.setStatus(Constants.AuthStatus.AUTO_PASS.getCode());
        } else {
            log.info("自动否决");
            authInfo.setStatus(Constants.AuthStatus.REJECT.getCode());
            authInfo.setRejectReason("自动否决");
        }
    } catch (TencentCloudSDKException e) {
        e.printStackTrace();
    }
    // 反面
    params = "{\"ImageUrl\":\"" + authInfo.getReverseUrl() + "\"}";
    IDCardOCRRequest ocrRequest = IDCardOCRRequest.fromJsonString(params, IDCardOCRRequest.class);
    try {
        IDCardOCRResponse response = ocrClient.IDCardOCR(ocrRequest);
        String advancedInfo = response.getAdvancedInfo();
        log.info("高级信息:" + advancedInfo);
        String ret = handleAdvanceInfo(advancedInfo);
        if (!StringUtils.isEmpty(ret)) {
            log.info("自动否决:" + ret);
            authInfo.setStatus(Constants.AuthStatus.REJECT.getCode());
            authInfo.setRejectReason(ret);
            authMapper.insert(authInfo);
            return ApiResponse.ofSuccess();
        }
    } catch (TencentCloudSDKException e) {
        e.printStackTrace();
    }
    authMapper.insert(authInfo);
    return ApiResponse.ofSuccess();
}
Also used : IDCardOCRRequest(com.tencentcloudapi.ocr.v20181119.models.IDCardOCRRequest) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) IDCardOCRResponse(com.tencentcloudapi.ocr.v20181119.models.IDCardOCRResponse)

Example 3 with TencentCloudSDKException

use of com.tencentcloudapi.common.exception.TencentCloudSDKException in project cmq-java-sdk by tencentyun.

the class Account method listQueue.

/**
 * list queue
 *
 * @param searchWord String
 * @param offset     int
 * @param limit      int
 * @param queueList  List<String>
 * @return totalCount int
 * @throws Exception
 * @throws CMQClientException
 * @throws CMQServerException
 */
public int listQueue(String searchWord, int offset, int limit, List<String> queueList) {
    try {
        CmqConfig cmqConfig = client.getCmqConfig();
        Credential cred = new Credential(cmqConfig.getSecretId(), cmqConfig.getSecretKey());
        String endPoint = cmqConfig.getEndpoint();
        String region = CMQTool.convertRegion(endPoint);
        DescribeCmqQueuesRequest req = new DescribeCmqQueuesRequest();
        if (offset > 0) {
            req.setOffset((long) offset);
        }
        if (limit > 0) {
            req.setLimit((long) limit);
        }
        if (null != searchWord && !"".equals(searchWord)) {
            req.setQueueName(searchWord);
        }
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint(cmqConfig.getManagerEndpoint());
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        TdmqClient client = new TdmqClient(cred, region, clientProfile);
        DescribeCmqQueuesResponse resp = client.DescribeCmqQueues(req);
        CmqQueue[] cmqQueues = resp.getQueueList();
        int totalCount = resp.getTotalCount().intValue();
        if (cmqQueues.length > 0) {
            for (CmqQueue queue : resp.getQueueList()) {
                queueList.add(queue.getQueueName());
            }
        }
        return totalCount;
    } catch (TencentCloudSDKException e) {
        System.out.println(e.toString());
    }
    return 0;
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) TdmqClient(com.tencentcloudapi.tdmq.v20200217.TdmqClient) CmqConfig(com.qcloud.cmq.entity.CmqConfig) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) DescribeCmqQueuesRequest(com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueuesRequest) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) DescribeCmqQueuesResponse(com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueuesResponse) CmqQueue(com.tencentcloudapi.tdmq.v20200217.models.CmqQueue)

Example 4 with TencentCloudSDKException

use of com.tencentcloudapi.common.exception.TencentCloudSDKException in project cmq-java-sdk by tencentyun.

the class Queue method getQueueAttributes.

/**
 * 获取队列属性
 *
 * @return 返回的队列属性参数
 */
public QueueMeta getQueueAttributes() {
    QueueMeta meta = new QueueMeta();
    try {
        CmqConfig cmqConfig = client.getCmqConfig();
        Credential cred = new Credential(cmqConfig.getSecretId(), cmqConfig.getSecretKey());
        String endPoint = cmqConfig.getEndpoint();
        String region = CMQTool.convertRegion(endPoint);
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint(cmqConfig.getManagerEndpoint());
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        TdmqClient client = new TdmqClient(cred, region, clientProfile);
        DescribeCmqQueueDetailRequest req = new DescribeCmqQueueDetailRequest();
        req.setQueueName(this.queueName);
        DescribeCmqQueueDetailResponse resp = client.DescribeCmqQueueDetail(req);
        CmqQueue cmqQueue = resp.getQueueDescribe();
        meta.maxMsgHeapNum = cmqQueue.getMaxMsgHeapNum().intValue();
        meta.pollingWaitSeconds = cmqQueue.getPollingWaitSeconds().intValue();
        meta.visibilityTimeout = cmqQueue.getVisibilityTimeout().intValue();
        meta.maxMsgSize = cmqQueue.getMaxMsgSize().intValue();
        meta.msgRetentionSeconds = cmqQueue.getMsgRetentionSeconds().intValue();
        meta.createTime = (int) (cmqQueue.getCreateTime() / 1000);
        meta.lastModifyTime = (int) (cmqQueue.getLastModifyTime() / 1000);
        meta.activeMsgNum = cmqQueue.getActiveMsgNum().intValue();
        meta.inactiveMsgNum = cmqQueue.getInactiveMsgNum().intValue();
        if (null != cmqQueue.getRewindMsgNum()) {
            meta.rewindmsgNum = cmqQueue.getRewindMsgNum().intValue();
        }
        if (null != cmqQueue.getMinMsgTime()) {
            meta.minMsgTime = cmqQueue.getMinMsgTime().intValue();
        }
        if (null != cmqQueue.getDelayMsgNum()) {
            meta.delayMsgNum = cmqQueue.getDelayMsgNum().intValue();
        }
        meta.rewindSeconds = cmqQueue.getRewindSeconds().intValue();
    } catch (TencentCloudSDKException e) {
        System.out.println(e.toString());
    }
    return meta;
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) TdmqClient(com.tencentcloudapi.tdmq.v20200217.TdmqClient) CmqConfig(com.qcloud.cmq.entity.CmqConfig) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) DescribeCmqQueueDetailRequest(com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueueDetailRequest) DescribeCmqQueueDetailResponse(com.tencentcloudapi.tdmq.v20200217.models.DescribeCmqQueueDetailResponse) CmqQueue(com.tencentcloudapi.tdmq.v20200217.models.CmqQueue)

Example 5 with TencentCloudSDKException

use of com.tencentcloudapi.common.exception.TencentCloudSDKException in project easyj by easyj-projects.

the class TencentEasyjIdCardOcrTemplateImpl method idCardOcr.

@NonNull
@Override
public IdCardOcrResponse idCardOcr(@NonNull IdCardOcrRequest request) throws IdCardOcrSdkException {
    Assert.notNull(request, "'request' must not be null");
    Assert.isTrue(StringUtils.isNotBlank(request.getImage()), "'image' must not be null");
    // 提取参数
    String image = request.getImage();
    CardSide cardSide = request.getCardSide();
    IdCardOcrAdvanced[] advancedArr = request.getAdvancedArr();
    Map<String, Object> configs = request.getConfigs();
    // 将入参配置与通用配置合并,生成当前请求所使用的配置
    TencentCloudIdCardOcrConfig config = ObjectUtils.mergeData(this.tencentCloudIdCardOcrService.getGlobalConfig(), configs);
    // 为两面时,重置为null
    if (CardSide.BOTH == cardSide) {
        cardSide = null;
    }
    // region 构建请求
    // 创建request builder
    IdCardOcrRequestBuilder builder = OcrRequestBuilder.idCardOcrRequestBuilder().image(// 图片
    image).cardSide(// 卡片正反面,可以为空
    cardSide);
    this.setAdvanced(builder, advancedArr);
    // 构建request
    IDCardOCRRequest req = builder.build();
    // endregion
    // region 发送请求,返回响应
    IDCardOCRResponse resp;
    try {
        resp = tencentCloudIdCardOcrService.doIdCardOcr(req, config);
    } catch (TencentCloudSDKException e) {
        String errorCode = e.getErrorCode();
        String errorMsg = "身份证识别失败" + (StringUtils.isNotEmpty(errorCode) ? ":" + errorCode : "");
        throw new IdCardOcrSdkServerException(errorMsg, errorCode, e);
    } catch (IdCardOcrSdkException e) {
        throw e;
    } catch (RuntimeException e) {
        throw new IdCardOcrSdkClientException("身份证识别出现未知异常", ErrorCodeConstants.UNKNOWN, e);
    }
    // endregion
    // region 读取响应信息
    // 转换为当前接口的响应类型
    IdCardOcrResponse response = new IdCardOcrResponse();
    // 设置正反面枚举
    if (StringUtils.isNotBlank(resp.getName())) {
        response.setCardSide(CardSide.FRONT);
    } else if (StringUtils.isNotBlank(resp.getAuthority())) {
        response.setCardSide(CardSide.BACK);
    } else {
        throw new IdCardOcrSdkServerException("未知的身份证正反面信息", "UNKNOWN_CARD_SIDE");
    }
    // 校验是否与入参一致
    if (cardSide != null && cardSide != response.getCardSide()) {
        throw new IdCardOcrSdkServerException("当前身份证图片不是" + cardSide.sideName() + "照", "WRONG_CARD_SIDE");
    }
    // 设置正面信息
    if (CardSide.FRONT == response.getCardSide()) {
        response.setName(resp.getName());
        response.setSex(resp.getSex());
        response.setNation(resp.getNation());
        this.setBirthday(response, resp.getBirth());
        response.setAddress(resp.getAddress());
        response.setIdNum(resp.getIdNum());
    }
    // 设置反面信息
    if (CardSide.BACK == response.getCardSide()) {
        response.setAuthority(resp.getAuthority());
        this.setValidDate(response, resp.getValidDate());
    }
    // 设置高级功能信息
    this.setResponseAdvancedInfo(response, resp.getAdvancedInfo(), config.getMinQuality());
    // 返回响应
    return response;
}
Also used : IdCardOcrSdkException(icu.easyj.sdk.ocr.idcardocr.IdCardOcrSdkException) IDCardOCRRequest(com.tencentcloudapi.ocr.v20181119.models.IDCardOCRRequest) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) IdCardOcrSdkClientException(icu.easyj.sdk.ocr.idcardocr.IdCardOcrSdkClientException) IdCardOcrAdvanced(icu.easyj.sdk.ocr.idcardocr.IdCardOcrAdvanced) IdCardOcrSdkServerException(icu.easyj.sdk.ocr.idcardocr.IdCardOcrSdkServerException) TencentCloudIdCardOcrConfig(icu.easyj.sdk.tencent.cloud.ocr.idcardocr.TencentCloudIdCardOcrConfig) IdCardOcrRequestBuilder(icu.easyj.sdk.tencent.cloud.ocr.idcardocr.IdCardOcrRequestBuilder) IdCardOcrResponse(icu.easyj.sdk.ocr.idcardocr.IdCardOcrResponse) CardSide(icu.easyj.sdk.ocr.CardSide) IDCardOCRResponse(com.tencentcloudapi.ocr.v20181119.models.IDCardOCRResponse) NonNull(org.springframework.lang.NonNull)

Aggregations

TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)10463 JsonSyntaxException (com.google.gson.JsonSyntaxException)10379 Type (java.lang.reflect.Type)10377 JsonResponseModel (com.tencentcloudapi.common.JsonResponseModel)10373 Credential (com.tencentcloudapi.common.Credential)39 ClientProfile (com.tencentcloudapi.common.profile.ClientProfile)26 HttpProfile (com.tencentcloudapi.common.profile.HttpProfile)26 CloudSDKException (com.mizhousoft.cloudsdk.CloudSDKException)12 CvmClient (com.tencentcloudapi.cvm.v20170312.CvmClient)12 DescribeInstancesRequest (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest)12 HashMap (java.util.HashMap)12 DescribeInstancesResponse (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse)10 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)9 IOException (java.io.IOException)8 CommonClient (com.tencentcloudapi.common.CommonClient)7 Test (org.junit.Test)7 MediaType (com.squareup.okhttp.MediaType)6 Request (com.squareup.okhttp.Request)6 TciClient (com.tencentcloudapi.tci.v20190318.TciClient)6 UnsupportedEncodingException (java.io.UnsupportedEncodingException)6