fix 车辆维保记录

This commit is contained in:
2025-03-21 15:47:11 +08:00
parent 02a382f911
commit c702894f64
14 changed files with 664 additions and 143 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"qnc-server/app/user/cmd/api/internal/config"
"strings"
@@ -38,14 +39,27 @@ func (t *TianjuService) Request(apiPath string, params map[string]interface{}) (
// 构建完整的URL假设BaseURL已包含https://前缀
fullURL := fmt.Sprintf("%s/%s/index", strings.TrimRight(t.config.BaseURL, "/"), apiPath)
// 将请求数据转换为JSON
messageBytes, err := json.Marshal(reqParams)
if err != nil {
return nil, fmt.Errorf("参数序列化失败: %w", err)
// 构建表单数据
formData := url.Values{}
for k, v := range reqParams {
// 将不同类型的值转换为字符串
switch val := v.(type) {
case string:
formData.Add(k, val)
case int, int64, float64:
formData.Add(k, fmt.Sprintf("%v", val))
default:
// 对于复杂类型转为JSON字符串
jsonBytes, err := json.Marshal(val)
if err != nil {
return nil, fmt.Errorf("参数值序列化失败: %w", err)
}
formData.Add(k, string(jsonBytes))
}
}
// 发起HTTP请求
resp, err := http.Post(fullURL, "application/json", strings.NewReader(string(messageBytes)))
// 发起HTTP请求 - 使用表单数据
resp, err := http.PostForm(fullURL, formData)
if err != nil {
return nil, fmt.Errorf("发送请求失败: %w", err)
}