This commit is contained in:
2025-08-27 22:19:19 +08:00
parent 4031277a91
commit 5051aea55c
93 changed files with 2025 additions and 1168 deletions

View File

@@ -34,7 +34,7 @@ type ZhichaResp struct {
type ZhichaConfig struct {
URL string
AppID string
AppSecret string
AppSecret string
EncryptKey string
}
@@ -94,7 +94,7 @@ func (z *ZhichaService) CallAPI(ctx context.Context, proID string, params map[st
jsonData, marshalErr := json.Marshal(params)
if marshalErr != nil {
err = fmt.Errorf("%w: %s", ErrSystem, marshalErr.Error())
err = errors.Join(ErrSystem, marshalErr)
if z.logger != nil {
z.logger.LogError(requestID, transactionID, proID, err, params)
}
@@ -104,7 +104,7 @@ func (z *ZhichaService) CallAPI(ctx context.Context, proID string, params map[st
// 创建HTTP POST请求
req, err := http.NewRequestWithContext(ctx, "POST", z.config.URL, bytes.NewBuffer(jsonData))
if err != nil {
err = fmt.Errorf("%w: %s", ErrSystem, err.Error())
err = errors.Join(ErrSystem, err)
if z.logger != nil {
z.logger.LogError(requestID, transactionID, proID, err, params)
}
@@ -126,7 +126,7 @@ func (z *ZhichaService) CallAPI(ctx context.Context, proID string, params map[st
// 发送请求
response, err := client.Do(req)
if err != nil {
err = fmt.Errorf("%w: %s", ErrSystem, err.Error())
err = errors.Join(ErrSystem, err)
if z.logger != nil {
z.logger.LogError(requestID, transactionID, proID, err, params)
}
@@ -137,7 +137,7 @@ func (z *ZhichaService) CallAPI(ctx context.Context, proID string, params map[st
// 读取响应
respBody, err := io.ReadAll(response.Body)
if err != nil {
err = fmt.Errorf("%w: %s", ErrSystem, err.Error())
err = errors.Join(ErrSystem, err)
if z.logger != nil {
z.logger.LogError(requestID, transactionID, proID, err, params)
}
@@ -152,7 +152,7 @@ func (z *ZhichaService) CallAPI(ctx context.Context, proID string, params map[st
// 检查HTTP状态码
if response.StatusCode != http.StatusOK {
err = fmt.Errorf("%w: HTTP状态码 %d", ErrDatasource, response.StatusCode)
err = errors.Join(ErrDatasource, fmt.Errorf("HTTP状态码 %d", response.StatusCode))
if z.logger != nil {
z.logger.LogError(requestID, transactionID, proID, err, params)
}
@@ -162,7 +162,7 @@ func (z *ZhichaService) CallAPI(ctx context.Context, proID string, params map[st
// 解析响应
var zhichaResp ZhichaResp
if err := json.Unmarshal(respBody, &zhichaResp); err != nil {
err = fmt.Errorf("%w: 响应解析失败: %s", ErrSystem, err.Error())
err = errors.Join(ErrSystem, fmt.Errorf("响应解析失败: %s", err.Error()))
if z.logger != nil {
z.logger.LogError(requestID, transactionID, proID, err, params)
}