This commit is contained in:
2026-01-12 16:43:08 +08:00
parent dc747139c9
commit 3c6e2683f5
110 changed files with 9630 additions and 481 deletions

View File

@@ -33,19 +33,22 @@ func generateAuthDateRange() string {
}
type ApiRequestService struct {
config config.Config
featureModel model.FeatureModel
productFeatureModel model.ProductFeatureModel
tianyuanapi *tianyuanapi.Client
config config.Config
featureModel model.FeatureModel
productFeatureModel model.ProductFeatureModel
userFeatureWhitelistModel model.UserFeatureWhitelistModel
whitelistService *WhitelistService
tianyuanapi *tianyuanapi.Client
}
// NewApiRequestService 是一个构造函数,用于初始化 ApiRequestService
func NewApiRequestService(c config.Config, featureModel model.FeatureModel, productFeatureModel model.ProductFeatureModel, tianyuanapi *tianyuanapi.Client) *ApiRequestService {
func NewApiRequestService(c config.Config, featureModel model.FeatureModel, productFeatureModel model.ProductFeatureModel, userFeatureWhitelistModel model.UserFeatureWhitelistModel, tianyuanapi *tianyuanapi.Client) *ApiRequestService {
return &ApiRequestService{
config: c,
featureModel: featureModel,
productFeatureModel: productFeatureModel,
tianyuanapi: tianyuanapi,
config: c,
featureModel: featureModel,
productFeatureModel: productFeatureModel,
userFeatureWhitelistModel: userFeatureWhitelistModel,
tianyuanapi: tianyuanapi,
}
}
@@ -61,6 +64,13 @@ type APIResponseData struct {
func (a *ApiRequestService) ProcessRequests(params []byte, productID string) ([]byte, error) {
var ctx, cancel = context.WithCancel(context.Background())
defer cancel()
// 从params中提取id_card用于白名单检查
idCard := gjson.GetBytes(params, "id_card").String()
// 查询白名单如果提供了id_card集中由 WhitelistService 处理
whitelistedFeatureApiIds, _ := a.whitelistService.GetWhitelistedFeatureApisByIdCard(ctx, idCard)
build := a.productFeatureModel.SelectBuilder().Where(squirrel.Eq{
"product_id": productID,
})
@@ -109,6 +119,18 @@ func (a *ApiRequestService) ProcessRequests(params []byte, productID string) ([]
Success: false,
}
timestamp := time.Now().Format("2006-01-02 15:04:05")
// 检查是否在白名单中
if whitelistedFeatureApiIds[feature.ApiId] {
// 在白名单中返回空结构data 为 null保持与正常返回结构一致
// 直接设置 data 为 null 的 JSON 字节
result.Data = []byte("null")
result.Success = true
result.Timestamp = timestamp
resultsCh <- result
return
}
var (
resp json.RawMessage
preprocessErr error