hk-service/pkg/util/172/goods_v2.go
2025-02-20 17:32:53 +08:00

51 lines
1.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package _72
import (
"encoding/json"
"fmt"
"hk/pkg/util/httpUtil"
"time"
)
const ()
// ProductV2Resp 定义商品套餐的结构
type ProductV2Resp struct {
ProductID int64 `json:"productID"`
ProductName string `json:"productName"`
MainPic string `json:"mainPic"`
Area string `json:"area"`
DisableArea string `json:"disableArea"`
LittlePicture string `json:"littlepicture"`
NetAddr string `json:"netAddr"`
Flag bool `json:"flag"`
NumberSel int `json:"numberSel"`
}
// GetProductV2 获取单个商品信息
func GetProductV2(params GoodsReq) (ApiResponse[[]ProductV2Resp], error) {
// 设置时间戳
timestamp := fmt.Sprintf("%d", time.Now().Unix()) // 当前时间戳长度为10位
params.Timestamp = timestamp
// 生成 MD5 签名
userSign := generateMD5SignV2(params, params.UserSign)
formParams := map[string]string{
"ProductID": params.ProductID,
"user_id": params.UserID,
"Timestamp": params.Timestamp,
"user_sign": userSign,
}
body, err := httpUtil.NewRequest().SendFormData(productsV2Url, nil, formParams)
// 解析 JSON 响应
var apiResponse ApiResponse[[]ProductV2Resp]
err = json.Unmarshal([]byte(body), &apiResponse)
if err != nil {
return ApiResponse[[]ProductV2Resp]{}, fmt.Errorf("解析响应体时发生错误: %v", err)
}
// 返回解析后的响应
return apiResponse, nil
}