init
This commit is contained in:
50
pkg/util/172/goods_v2.go
Normal file
50
pkg/util/172/goods_v2.go
Normal file
@ -0,0 +1,50 @@
|
||||
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
|
||||
}
|
Reference in New Issue
Block a user