yidun检测、查询
This commit is contained in:
53
service/yidun/yidun_client.go
Normal file
53
service/yidun/yidun_client.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package yidun
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/yidun/yidun-golang-sdk/yidun/service/antispam/image/v5"
|
||||
text "github.com/yidun/yidun-golang-sdk/yidun/service/antispam/text"
|
||||
"github.com/yidun/yidun-golang-sdk/yidun/service/antispam/videosolution"
|
||||
)
|
||||
|
||||
// YidunClients 易盾客户端集合(直接使用SDK客户端)
|
||||
type YidunClients struct {
|
||||
TextClient *text.TextClient
|
||||
ImageClient *image.ImageClient
|
||||
VideoClient *videosolution.VideoSolutionClient
|
||||
}
|
||||
|
||||
var DefaultClients *YidunClients
|
||||
|
||||
// InitYidunClients 初始化所有易盾客户端
|
||||
func InitYidunClients(ctx context.Context) error {
|
||||
clients := &YidunClients{}
|
||||
|
||||
// 文本检测
|
||||
secretId := g.Cfg().MustGet(ctx, "yidun.text.secret_id").String()
|
||||
secretKey := g.Cfg().MustGet(ctx, "yidun.text.secret_key").String()
|
||||
if secretId != "" && secretKey != "" {
|
||||
clients.TextClient = text.NewTextClientWithAccessKey(secretId, secretKey)
|
||||
g.Log().Info(ctx, "文本检测客户端初始化成功")
|
||||
}
|
||||
|
||||
// 图片检测
|
||||
secretId = g.Cfg().MustGet(ctx, "yidun.image.secret_id").String()
|
||||
secretKey = g.Cfg().MustGet(ctx, "yidun.image.secret_key").String()
|
||||
businessId := g.Cfg().MustGet(ctx, "yidun.image.business_id").String()
|
||||
if secretId != "" && secretKey != "" {
|
||||
clients.ImageClient = image.NewImageClientWithAccessKey(secretId, secretKey)
|
||||
g.Log().Infof(ctx, "图片检测客户端初始化成功, business_id: %s", businessId)
|
||||
}
|
||||
|
||||
// 视频检测
|
||||
secretId = g.Cfg().MustGet(ctx, "yidun.video.secret_id").String()
|
||||
secretKey = g.Cfg().MustGet(ctx, "yidun.video.secret_key").String()
|
||||
businessId = g.Cfg().MustGet(ctx, "yidun.video.business_id").String()
|
||||
if secretId != "" && secretKey != "" {
|
||||
clients.VideoClient = videosolution.NewVideoSolutionClientWithAccessKey(secretId, secretKey)
|
||||
g.Log().Infof(ctx, "视频检测客户端初始化成功, business_id: %s", businessId)
|
||||
}
|
||||
|
||||
DefaultClients = clients
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user