This commit is contained in:
2025-11-26 18:23:02 +08:00
parent 4b0ab842f4
commit 785818f73d
44 changed files with 533 additions and 2565 deletions

View File

@@ -21,13 +21,13 @@ var (
// APIEndpoints 天眼查 API 端点映射
var APIEndpoints = map[string]string{
"VerifyThreeElements": "/open/ic/verify/2.0", // 企业三要素验证
"InvestHistory": "/open/hi/invest/2.0", // 对外投资历史
"FinancingHistory": "/open/cd/findHistoryRongzi/2.0", // 融资历史
"PunishmentInfo": "/open/mr/punishmentInfo/3.0", // 行政处罚
"AbnormalInfo": "/open/mr/abnormal/2.0", // 经营异常
"OwnTax": "/open/mr/ownTax", // 欠税公告
"TaxContravention": "/open/mr/taxContravention", // 税收违法
"VerifyThreeElements": "/open/ic/verify/2.0", // 企业三要素验证
"InvestHistory": "/open/hi/invest/2.0", // 对外投资历史
"FinancingHistory": "/open/cd/findHistoryRongzi/2.0", // 融资历史
"PunishmentInfo": "/open/mr/punishmentInfo/3.0", // 行政处罚
"AbnormalInfo": "/open/mr/abnormal/2.0", // 经营异常
"OwnTax": "/open/mr/ownTax", // 欠税公告
"TaxContravention": "/open/mr/taxContravention", // 税收违法
}
// TianYanChaConfig 天眼查配置
@@ -56,6 +56,7 @@ type TianYanChaResponse struct {
Reason string `json:"reason"`
Result interface{} `json:"result"`
}
// NewTianYanChaService 创建天眼查服务实例
func NewTianYanChaService(baseURL, token string, timeout time.Duration) *TianYanChaService {
if timeout == 0 {
@@ -118,14 +119,13 @@ func (t *TianYanChaService) CallAPI(ctx context.Context, apiCode string, params
isTimeout = true
} else if netErr, ok := err.(interface{ Timeout() bool }); ok && netErr.Timeout() {
isTimeout = true
} else if errStr := err.Error();
errStr == "context deadline exceeded" ||
errStr == "timeout" ||
errStr == "Client.Timeout exceeded" ||
errStr == "net/http: request canceled" {
} else if errStr := err.Error(); errStr == "context deadline exceeded" ||
errStr == "timeout" ||
errStr == "Client.Timeout exceeded" ||
errStr == "net/http: request canceled" {
isTimeout = true
}
if isTimeout {
return nil, errors.Join(ErrDatasource, fmt.Errorf("API请求超时: %v", err))
}
@@ -156,7 +156,7 @@ func (t *TianYanChaService) CallAPI(ctx context.Context, apiCode string, params
if tianYanChaResp.ErrorCode == 300000 {
return nil, errors.Join(ErrNotFound, fmt.Errorf("天眼查查询为空: %s", tianYanChaResp.Reason))
}
return &APIResponse{
Success: false,
Code: tianYanChaResp.ErrorCode,

View File

@@ -55,7 +55,7 @@ func NewYushanService(url, apiKey, acctID string, logger *external_logger.Extern
func (y *YushanService) CallAPI(ctx context.Context, code string, params map[string]interface{}) (respBytes []byte, err error) {
startTime := time.Now()
requestID := y.generateRequestID()
// 从ctx中获取transactionId
var transactionID string
if ctxTransactionID, ok := ctx.Value("transaction_id").(string); ok {
@@ -131,14 +131,13 @@ func (y *YushanService) CallAPI(ctx context.Context, code string, params map[str
isTimeout = true
} else if netErr, ok := err.(interface{ Timeout() bool }); ok && netErr.Timeout() {
isTimeout = true
} else if errStr := err.Error();
errStr == "context deadline exceeded" ||
errStr == "timeout" ||
errStr == "Client.Timeout exceeded" ||
errStr == "net/http: request canceled" {
} else if errStr := err.Error(); errStr == "context deadline exceeded" ||
errStr == "timeout" ||
errStr == "Client.Timeout exceeded" ||
errStr == "net/http: request canceled" {
isTimeout = true
}
if isTimeout {
err = errors.Join(ErrDatasource, fmt.Errorf("API请求超时: %v", err))
} else {