new
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -24,3 +24,48 @@ type DecryptCommand struct {
|
||||
EncryptedData string `json:"encrypted_data" binding:"required"`
|
||||
SecretKey string `json:"secret_key" binding:"required"`
|
||||
}
|
||||
|
||||
// SaveApiCallCommand 保存API调用命令
|
||||
type SaveApiCallCommand struct {
|
||||
ApiCallID string `json:"api_call_id"`
|
||||
UserID string `json:"user_id"`
|
||||
ProductID string `json:"product_id"`
|
||||
TransactionID string `json:"transaction_id"`
|
||||
Status string `json:"status"`
|
||||
Cost float64 `json:"cost"`
|
||||
ErrorType string `json:"error_type"`
|
||||
ErrorMsg string `json:"error_msg"`
|
||||
ClientIP string `json:"client_ip"`
|
||||
}
|
||||
|
||||
// ProcessDeductionCommand 处理扣款命令
|
||||
type ProcessDeductionCommand struct {
|
||||
UserID string `json:"user_id"`
|
||||
Amount string `json:"amount"`
|
||||
ApiCallID string `json:"api_call_id"`
|
||||
TransactionID string `json:"transaction_id"`
|
||||
ProductID string `json:"product_id"`
|
||||
}
|
||||
|
||||
// UpdateUsageStatsCommand 更新使用统计命令
|
||||
type UpdateUsageStatsCommand struct {
|
||||
SubscriptionID string `json:"subscription_id"`
|
||||
UserID string `json:"user_id"`
|
||||
ProductID string `json:"product_id"`
|
||||
Increment int `json:"increment"`
|
||||
}
|
||||
|
||||
// RecordApiLogCommand 记录API日志命令
|
||||
type RecordApiLogCommand struct {
|
||||
TransactionID string `json:"transaction_id"`
|
||||
UserID string `json:"user_id"`
|
||||
ApiName string `json:"api_name"`
|
||||
ClientIP string `json:"client_ip"`
|
||||
ResponseSize int64 `json:"response_size"`
|
||||
}
|
||||
|
||||
// ProcessCompensationCommand 处理补偿命令
|
||||
type ProcessCompensationCommand struct {
|
||||
TransactionID string `json:"transaction_id"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
96
internal/application/api/dto/api_call_validation.go
Normal file
96
internal/application/api/dto/api_call_validation.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
api_entities "tyapi-server/internal/domains/api/entities"
|
||||
product_entities "tyapi-server/internal/domains/product/entities"
|
||||
|
||||
"github.com/shopspring/decimal"
|
||||
)
|
||||
|
||||
// ApiCallValidationResult API调用验证结果
|
||||
type ApiCallValidationResult struct {
|
||||
UserID string `json:"user_id"`
|
||||
ProductID string `json:"product_id"`
|
||||
SubscriptionID string `json:"subscription_id"`
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
SecretKey string `json:"secret_key"`
|
||||
IsValid bool `json:"is_valid"`
|
||||
ErrorMessage string `json:"error_message"`
|
||||
|
||||
// 新增字段
|
||||
ContractCode string `json:"contract_code"`
|
||||
ApiCall *api_entities.ApiCall `json:"api_call"`
|
||||
RequestParams map[string]interface{} `json:"request_params"`
|
||||
Product *product_entities.Product `json:"product"`
|
||||
}
|
||||
|
||||
// GetUserID 获取用户ID
|
||||
func (r *ApiCallValidationResult) GetUserID() string {
|
||||
return r.UserID
|
||||
}
|
||||
|
||||
// GetProductID 获取产品ID
|
||||
func (r *ApiCallValidationResult) GetProductID() string {
|
||||
return r.ProductID
|
||||
}
|
||||
|
||||
// GetSubscriptionID 获取订阅ID
|
||||
func (r *ApiCallValidationResult) GetSubscriptionID() string {
|
||||
return r.SubscriptionID
|
||||
}
|
||||
|
||||
// GetAmount 获取金额
|
||||
func (r *ApiCallValidationResult) GetAmount() decimal.Decimal {
|
||||
return r.Amount
|
||||
}
|
||||
|
||||
// GetSecretKey 获取密钥
|
||||
func (r *ApiCallValidationResult) GetSecretKey() string {
|
||||
return r.SecretKey
|
||||
}
|
||||
|
||||
// IsValidResult 检查是否有效
|
||||
func (r *ApiCallValidationResult) IsValidResult() bool {
|
||||
return r.IsValid
|
||||
}
|
||||
|
||||
// GetErrorMessage 获取错误消息
|
||||
func (r *ApiCallValidationResult) GetErrorMessage() string {
|
||||
return r.ErrorMessage
|
||||
}
|
||||
|
||||
// NewApiCallValidationResult 创建新的API调用验证结果
|
||||
func NewApiCallValidationResult() *ApiCallValidationResult {
|
||||
return &ApiCallValidationResult{
|
||||
IsValid: true,
|
||||
RequestParams: make(map[string]interface{}),
|
||||
}
|
||||
}
|
||||
|
||||
// SetApiUser 设置API用户
|
||||
func (r *ApiCallValidationResult) SetApiUser(apiUser *api_entities.ApiUser) {
|
||||
r.UserID = apiUser.UserId
|
||||
r.SecretKey = apiUser.SecretKey
|
||||
}
|
||||
|
||||
// SetProduct 设置产品
|
||||
func (r *ApiCallValidationResult) SetProduct(product *product_entities.Product) {
|
||||
r.ProductID = product.ID
|
||||
r.Amount = product.Price
|
||||
r.Product = product
|
||||
}
|
||||
|
||||
// SetApiCall 设置API调用
|
||||
func (r *ApiCallValidationResult) SetApiCall(apiCall *api_entities.ApiCall) {
|
||||
r.ApiCall = apiCall
|
||||
}
|
||||
|
||||
// SetRequestParams 设置请求参数
|
||||
func (r *ApiCallValidationResult) SetRequestParams(params map[string]interface{}) {
|
||||
r.RequestParams = params
|
||||
}
|
||||
|
||||
// SetContractCode 设置合同代码
|
||||
func (r *ApiCallValidationResult) SetContractCode(code string) {
|
||||
r.ContractCode = code
|
||||
}
|
||||
@@ -4,38 +4,46 @@ import "errors"
|
||||
|
||||
// API调用相关错误类型
|
||||
var (
|
||||
ErrQueryEmpty = errors.New("查询为空")
|
||||
ErrSystem = errors.New("接口异常")
|
||||
ErrDecryptFail = errors.New("解密失败")
|
||||
ErrRequestParam = errors.New("请求参数结构不正确")
|
||||
ErrInvalidParam = errors.New("参数校验不正确")
|
||||
ErrInvalidIP = errors.New("未经授权的IP")
|
||||
ErrMissingAccessId = errors.New("缺少Access-Id")
|
||||
ErrInvalidAccessId = errors.New("未经授权的AccessId")
|
||||
ErrFrozenAccount = errors.New("账户已冻结")
|
||||
ErrArrears = errors.New("账户余额不足,无法请求")
|
||||
ErrProductNotFound = errors.New("产品不存在")
|
||||
ErrProductDisabled = errors.New("产品已停用")
|
||||
ErrNotSubscribed = errors.New("未订阅此产品")
|
||||
ErrBusiness = errors.New("业务失败")
|
||||
ErrQueryEmpty = errors.New("查询为空")
|
||||
ErrSystem = errors.New("接口异常")
|
||||
ErrDecryptFail = errors.New("解密失败")
|
||||
ErrRequestParam = errors.New("请求参数结构不正确")
|
||||
ErrInvalidParam = errors.New("参数校验不正确")
|
||||
ErrInvalidIP = errors.New("未经授权的IP")
|
||||
ErrMissingAccessId = errors.New("缺少Access-Id")
|
||||
ErrInvalidAccessId = errors.New("未经授权的AccessId")
|
||||
ErrFrozenAccount = errors.New("账户已冻结")
|
||||
ErrArrears = errors.New("账户余额不足,无法请求")
|
||||
ErrInsufficientBalance = errors.New("钱包余额不足")
|
||||
ErrProductNotFound = errors.New("产品不存在")
|
||||
ErrProductDisabled = errors.New("产品已停用")
|
||||
ErrNotSubscribed = errors.New("未订阅此产品")
|
||||
ErrProductNotSubscribed = errors.New("未订阅此产品")
|
||||
ErrSubscriptionExpired = errors.New("订阅已过期")
|
||||
ErrSubscriptionSuspended = errors.New("订阅已暂停")
|
||||
ErrBusiness = errors.New("业务失败")
|
||||
)
|
||||
|
||||
// 错误码映射 - 严格按照用户要求
|
||||
var ErrorCodeMap = map[error]int{
|
||||
ErrQueryEmpty: 1000,
|
||||
ErrSystem: 1001,
|
||||
ErrDecryptFail: 1002,
|
||||
ErrRequestParam: 1003,
|
||||
ErrInvalidParam: 1003,
|
||||
ErrInvalidIP: 1004,
|
||||
ErrMissingAccessId: 1005,
|
||||
ErrInvalidAccessId: 1006,
|
||||
ErrFrozenAccount: 1007,
|
||||
ErrArrears: 1007,
|
||||
ErrProductNotFound: 1008,
|
||||
ErrProductDisabled: 1008,
|
||||
ErrNotSubscribed: 1008,
|
||||
ErrBusiness: 2001,
|
||||
ErrQueryEmpty: 1000,
|
||||
ErrSystem: 1001,
|
||||
ErrDecryptFail: 1002,
|
||||
ErrRequestParam: 1003,
|
||||
ErrInvalidParam: 1003,
|
||||
ErrInvalidIP: 1004,
|
||||
ErrMissingAccessId: 1005,
|
||||
ErrInvalidAccessId: 1006,
|
||||
ErrFrozenAccount: 1007,
|
||||
ErrArrears: 1007,
|
||||
ErrInsufficientBalance: 1007,
|
||||
ErrProductNotFound: 1008,
|
||||
ErrProductDisabled: 1008,
|
||||
ErrNotSubscribed: 1008,
|
||||
ErrProductNotSubscribed: 1008,
|
||||
ErrSubscriptionExpired: 1008,
|
||||
ErrSubscriptionSuspended: 1008,
|
||||
ErrBusiness: 2001,
|
||||
}
|
||||
|
||||
// GetErrorCode 获取错误对应的错误码
|
||||
|
||||
Reference in New Issue
Block a user