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;
}
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();
}
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;
}
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;
}
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;
}
Aggregations