Files
cid/service/yidun/yidun_client.go
2026-05-08 09:33:40 +08:00

54 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}