package com.stylefeng.guns.modular.system.util;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.huaweicloud.sdk.core.auth.ICredential;
|
import com.huaweicloud.sdk.core.auth.BasicCredentials;
|
import com.huaweicloud.sdk.core.exception.ConnectionException;
|
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
|
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
|
import com.huaweicloud.sdk.moderation.v3.region.ModerationRegion;
|
import com.huaweicloud.sdk.moderation.v3.*;
|
import com.huaweicloud.sdk.moderation.v3.model.*;
|
import org.springframework.stereotype.Component;
|
|
import java.util.List;
|
import java.util.ArrayList;
|
@Component
|
public class AuditUtil {
|
|
// 根据作业id查询视频是否通过审核
|
public String audit(String id){
|
String temp ="";
|
// The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
|
// In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
|
String ak = "DRJFJRVQ9KVLQUSJUROI";
|
String sk = "3zpPkULh0a8CTTYjKL4f7szQZECkvVol4SwNab0f";
|
ICredential auth = new BasicCredentials()
|
.withAk(ak)
|
.withSk(sk);
|
ModerationClient client = ModerationClient.newBuilder()
|
.withCredential(auth)
|
.withRegion(ModerationRegion.valueOf("cn-north-4"))
|
.build();
|
RunQueryVideoModerationJobRequest request = new RunQueryVideoModerationJobRequest();
|
request.withJobId(id);
|
try {
|
RunQueryVideoModerationJobResponse response = client.runQueryVideoModerationJob(request);
|
temp = response.getStatus().getValue();
|
System.out.println(response.toString());
|
return temp;
|
} catch (ConnectionException e) {
|
e.printStackTrace();
|
} catch (RequestTimeoutException e) {
|
e.printStackTrace();
|
} catch (ServiceResponseException e) {
|
e.printStackTrace();
|
System.out.println(e.getHttpStatusCode());
|
System.out.println(e.getRequestId());
|
System.out.println(e.getErrorCode());
|
System.out.println(e.getErrorMsg());
|
}
|
return temp;
|
}
|
public String video(String text){
|
// The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
|
// In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
|
String ak = "DRJFJRVQ9KVLQUSJUROI";
|
String sk = "3zpPkULh0a8CTTYjKL4f7szQZECkvVol4SwNab0f";
|
ICredential auth = new BasicCredentials()
|
.withAk(ak)
|
.withSk(sk);
|
ModerationClient client = ModerationClient.newBuilder()
|
.withCredential(auth)
|
.withRegion(ModerationRegion.valueOf("cn-north-4"))
|
.build();
|
RunCreateVideoModerationJobRequest request = new RunCreateVideoModerationJobRequest();
|
VideoCreateRequest body = new VideoCreateRequest();
|
List<VideoCreateRequest.AudioCategoriesEnum> listbodyAudioCategories = new ArrayList<>();
|
listbodyAudioCategories.add(VideoCreateRequest.AudioCategoriesEnum.fromValue("porn"));
|
listbodyAudioCategories.add(VideoCreateRequest.AudioCategoriesEnum.fromValue("ad"));
|
listbodyAudioCategories.add(VideoCreateRequest.AudioCategoriesEnum.fromValue("politics"));
|
listbodyAudioCategories.add(VideoCreateRequest.AudioCategoriesEnum.fromValue("politics"));
|
listbodyAudioCategories.add(VideoCreateRequest.AudioCategoriesEnum.fromValue("abuse"));
|
List<VideoCreateRequest.ImageCategoriesEnum> listbodyImageCategories = new ArrayList<>();
|
listbodyImageCategories.add(VideoCreateRequest.ImageCategoriesEnum.fromValue("porn"));
|
listbodyImageCategories.add(VideoCreateRequest.ImageCategoriesEnum.fromValue("politics"));
|
listbodyImageCategories.add(VideoCreateRequest.ImageCategoriesEnum.fromValue("terrorism"));
|
listbodyImageCategories.add(VideoCreateRequest.ImageCategoriesEnum.fromValue("image_text"));
|
VideoCreateRequestData databody = new VideoCreateRequestData();
|
databody.withUrl(text).withFrameInterval(20)
|
.withLanguage(VideoCreateRequestData.LanguageEnum.fromValue("zh"));
|
body.withAudioCategories(listbodyAudioCategories);
|
body.withImageCategories(listbodyImageCategories);
|
body.withEventType(VideoCreateRequest.EventTypeEnum.fromValue("default"));
|
body.withBizType("a123");
|
body.withData(databody);
|
request.withBody(body);
|
try {
|
RunCreateVideoModerationJobResponse response = client.runCreateVideoModerationJob(request);
|
return response.getJobId();
|
} catch (ConnectionException e) {
|
e.printStackTrace();
|
} catch (RequestTimeoutException e) {
|
e.printStackTrace();
|
} catch (ServiceResponseException e) {
|
e.printStackTrace();
|
System.out.println(e.getHttpStatusCode());
|
System.out.println(e.getRequestId());
|
System.out.println(e.getErrorCode());
|
System.out.println(e.getErrorMsg());
|
}
|
return "";
|
}
|
|
public AuditVO content(String text){
|
AuditVO auditVO = new AuditVO();
|
|
Boolean temp = true;
|
String ak = "DRJFJRVQ9KVLQUSJUROI";
|
String sk = "3zpPkULh0a8CTTYjKL4f7szQZECkvVol4SwNab0f";
|
ICredential auth = new BasicCredentials()
|
.withAk(ak)
|
.withSk(sk);
|
ModerationClient client = ModerationClient.newBuilder()
|
.withCredential(auth)
|
.withRegion(ModerationRegion.valueOf("cn-north-4"))
|
.build();
|
RunTextModerationRequest request = new RunTextModerationRequest();
|
TextDetectionReq body = new TextDetectionReq();
|
TextDetectionDataReq databody = new TextDetectionDataReq();
|
databody.withText(text)
|
.withLanguage(TextDetectionDataReq.LanguageEnum.fromValue("zh"));
|
// List<String> listbodyGlossaryNames = new ArrayList<>();
|
// listbodyGlossaryNames.add("txt1");
|
// body.withGlossaryNames(listbodyGlossaryNames);
|
body.withBizType("a123");
|
body.withData(databody);
|
body.withEventType("comment");
|
request.withBody(body);
|
try {
|
RunTextModerationResponse response = client.runTextModeration(request);
|
System.err.println(response.toString());
|
TextDetectionResult result = response.getResult();
|
auditVO.setType(result.getLabel());
|
if (!result.getSuggestion().equals("pass")){
|
// 审核不通过
|
temp = false;
|
}
|
} catch (ConnectionException e) {
|
e.printStackTrace();
|
} catch (RequestTimeoutException e) {
|
e.printStackTrace();
|
} catch (ServiceResponseException e) {
|
e.printStackTrace();
|
System.out.println(e.getHttpStatusCode());
|
System.out.println(e.getRequestId());
|
System.out.println(e.getErrorCode());
|
System.out.println(e.getErrorMsg());
|
}
|
auditVO.setTemp(temp);
|
return auditVO;
|
}
|
public AuditVO image(String image){
|
|
AuditVO auditVO = new AuditVO();
|
String ak = "DRJFJRVQ9KVLQUSJUROI";
|
String sk = "3zpPkULh0a8CTTYjKL4f7szQZECkvVol4SwNab0f";
|
ICredential auth = new BasicCredentials()
|
.withAk(ak)
|
.withSk(sk);
|
ModerationClient client = ModerationClient.newBuilder()
|
.withCredential(auth)
|
.withRegion(ModerationRegion.valueOf("cn-north-4"))
|
.build();
|
CheckImageModerationRequest request = new CheckImageModerationRequest();
|
ImageDetectionReq body = new ImageDetectionReq();
|
List<String> listbodyCategories = new ArrayList<>();
|
listbodyCategories.add("porn");
|
listbodyCategories.add("terrorism");
|
listbodyCategories.add("image_text");
|
body.withLanguage(ImageDetectionReq.LanguageEnum.fromValue("zh"));
|
body.withBizType("a123");
|
// 图片地址
|
body.withUrl(image);
|
body.withCategories(listbodyCategories);
|
body.withEventType("album");
|
request.withBody(body);
|
try {
|
CheckImageModerationResponse response = client.checkImageModeration(request);
|
if (!response.getResult().getSuggestion().equals("pass")){
|
auditVO.setType(response.getResult().getCategory());
|
}else{
|
auditVO.setType("pass");
|
}
|
System.out.println(response.toString());
|
} catch (ConnectionException e) {
|
e.printStackTrace();
|
} catch (RequestTimeoutException e) {
|
e.printStackTrace();
|
} catch (ServiceResponseException e) {
|
e.printStackTrace();
|
System.out.println(e.getHttpStatusCode());
|
System.out.println(e.getRequestId());
|
System.out.println(e.getErrorCode());
|
System.out.println(e.getErrorMsg());
|
}
|
return auditVO;
|
}
|
|
//
|
}
|