73 lines
2.4 KiB
Go
Raw Normal View History

2025-02-20 17:32:53 +08:00
package _72
import (
"encoding/json"
"fmt"
"hk/pkg/util/httpUtil"
"time"
)
const (
productsUrl = "https://haokaopenapi.lot-ml.com/api/order/GetProducts" // 商品列表查询Url
productsV2Url = "https://haokaopenapi.lot-ml.com/api/order/GetProductsV2" // 商品信息查询Url
pickNumberUrl = "https://haokaopenapi.lot-ml.com/api/order/PickNumber" // 商品选号Url
blackUserUrl = "https://haokaopenapi.lot-ml.com/api/black/BlackCheckCus" // 用户黑名单Url
blackAgentUrl = "https://haokaopenapi.lot-ml.com/api/black/BlackCheckAgent" // 代理黑名单Url
upFileUrl = "https://haokaopenapi.lot-ml.com/api/order/UpPicFile" // 证件照上传Url
addOrderUrl = "https://haokaopenapi.lot-ml.com/api/order/ApiToOrder" // 下单Url
orderInfoUrl = "https://haokaopenapi.lot-ml.com/api/order/GetOrderInfo" // 订单查询Url
)
type BaseParams struct {
Timestamp string `json:"Timestamp"` // Y 时间戳
UserID string `json:"user_id"` // Y 用户ID
UserSign string `json:"user_sign"` // Y 密钥
}
// GoodsReq 商品请求参数
type GoodsReq struct {
ProductID string `json:"ProductID"`
BaseParams
// Timestamp string `json:"Timestamp"` // Y 时间戳
// UserID string `json:"user_id"` // Y 用户ID
// UserSign string `json:"user_sign"` // Y 密钥
}
// ProductResp 定义产品信息的结构体
type ProductResp struct {
ProductID int64 `json:"productID"`
ProductName string `json:"productName"`
Flag string `json:"flag"` // 上架中
}
// GetProduct 获取上架中商品列表
func GetProduct(params GoodsReq) (ApiResponse[[]ProductResp], 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,
"Timestamp": params.Timestamp,
"user_sign": userSign,
"user_id": params.UserID,
}
body, err := httpUtil.NewRequest().SendFormData(productsUrl, nil, formParams)
if err != nil {
return ApiResponse[[]ProductResp]{}, err
}
// 解析 JSON 响应
var apiResponse ApiResponse[[]ProductResp]
err = json.Unmarshal([]byte(body), &apiResponse)
if err != nil {
fmt.Println("解析响应体时发生错误:", err)
return ApiResponse[[]ProductResp]{}, err
}
return apiResponse, nil
}