123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package service
- import (
- "fmt"
- "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
- //region "github.com/huaweicloud/huaweicloud-review_service-go-v3/core/region"
- moderation "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3"
- "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/model"
- moderationRegion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/moderation/v3/region"
- "youngee_b_api/app/vo"
- )
- type ContentService struct{}
- // 内容审核
- func (s ContentService) CheckContent(contentCheckParam *vo.ContentCheckParam) (*string, error) {
- // 认证用的ak和sk硬编码到代码中或者明文存储都有很大的安全风险,建议在配置文件或者环境变量中密文存放,使用时解密,确保安全;
- // 本示例以ak和sk保存在环境变量中来实现身份验证为例,运行本示例前请先在本地环境中设置环境变量HUAWEICLOUD_SDK_AK和HUAWEICLOUD_SDK_SK。
- ak := "CNN8MCCSJFGHL1MXCJRF"
- sk := "91arFGHyO7RrzXnZIFSPcLSC6y4P4MTKtkq3qLIy"
- projectId := "CNN8MCCSJFGHL1MXCJRF"
- eventType := "article"
- auth := basic.NewCredentialsBuilder().
- WithAk(ak).
- WithSk(sk).
- WithProjectId(projectId).
- Build()
- client := moderation.NewModerationClient(
- moderation.ModerationClientBuilder().
- WithRegion(moderationRegion.ValueOf("cn-north-4")). //把xxx替换成服务所在的区域,例如北京四:cn-north-4。
- WithCredential(auth).
- Build())
- //request := &model.RunTextModerationRequest{}
- //request.EnterpriseProjectId = &projectId
- //databody := &model.TextDetectionDataReq{
- // Text: contentCheckParam.Summary,
- //}
- //request.Body = &model.TextDetectionReq{
- // Data: databody,
- // EventType: &eventType,
- //}
- //response, err := client.RunTextModeration(request)
- //if err == nil {
- // fmt.Printf("%+v\n", response)
- //} else {
- // fmt.Println(err)
- //}
- request := &model.CheckImageModerationRequest{}
- var listCategoriesbody = []string{
- "porn", "terrorism",
- }
- eventType = "head_image"
- urlImageDetectionReq := "https://img-s-msn-com.akamaized.net/tenant/amp/entityid/AA1oXRBY.img?w=640&h=360&m=6"
- request.Body = &model.ImageDetectionReq{
- Url: &urlImageDetectionReq,
- Categories: &listCategoriesbody,
- EventType: &eventType,
- }
- response, err := client.CheckImageModeration(request)
- if err == nil {
- fmt.Printf("%+v\n", response)
- } else {
- fmt.Println(err)
- }
- result := response.Result
- fmt.Print(result)
- return nil, nil
- }
|