add
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"tyapi-server/internal/shared/external_logger"
|
||||
@@ -76,9 +77,10 @@ func (j *JiguangService) generateRequestID() string {
|
||||
}
|
||||
|
||||
// CallAPI 调用极光API
|
||||
// apiCode: API服务编码(如 marriage-single-v2)
|
||||
// apiCode: API服务编码(如 marriage-single-v2),用于请求头
|
||||
// apiPath: API路径(如 marriage/single-v2),用于URL路径
|
||||
// params: 请求参数(会作为JSON body发送)
|
||||
func (j *JiguangService) CallAPI(ctx context.Context, apiCode string, params map[string]interface{}) (resp []byte, err error) {
|
||||
func (j *JiguangService) CallAPI(ctx context.Context, apiCode string, apiPath string, params map[string]interface{}) (resp []byte, err error) {
|
||||
startTime := time.Now()
|
||||
requestID := j.generateRequestID()
|
||||
|
||||
@@ -101,9 +103,12 @@ func (j *JiguangService) CallAPI(ctx context.Context, apiCode string, params map
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 构建完整的请求URL,使用apiPath作为路径
|
||||
requestURL := strings.TrimSuffix(j.config.URL, "/") + "/" + strings.TrimPrefix(apiPath, "/")
|
||||
|
||||
// 记录请求日志
|
||||
if j.logger != nil {
|
||||
j.logger.LogRequest(requestID, transactionID, apiCode, j.config.URL, params)
|
||||
j.logger.LogRequest(requestID, transactionID, apiCode, requestURL, params)
|
||||
}
|
||||
|
||||
// 将请求参数转换为JSON
|
||||
@@ -117,7 +122,7 @@ func (j *JiguangService) CallAPI(ctx context.Context, apiCode string, params map
|
||||
}
|
||||
|
||||
// 创建HTTP POST请求
|
||||
req, newRequestErr := http.NewRequestWithContext(ctx, "POST", j.config.URL, bytes.NewBuffer(jsonData))
|
||||
req, newRequestErr := http.NewRequestWithContext(ctx, "POST", requestURL, bytes.NewBuffer(jsonData))
|
||||
if newRequestErr != nil {
|
||||
err = errors.Join(ErrSystem, newRequestErr)
|
||||
if j.logger != nil {
|
||||
|
||||
Reference in New Issue
Block a user