|
@@ -4,7 +4,9 @@ import (
|
|
"context"
|
|
"context"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/lin-jim-leon/kuaishou"
|
|
"github.com/lin-jim-leon/kuaishou"
|
|
|
|
+ "math/rand"
|
|
"strconv"
|
|
"strconv"
|
|
|
|
+ "time"
|
|
"youngee_b_api/consts"
|
|
"youngee_b_api/consts"
|
|
"youngee_b_api/db"
|
|
"youngee_b_api/db"
|
|
"youngee_b_api/model/gorm_model"
|
|
"youngee_b_api/model/gorm_model"
|
|
@@ -191,7 +193,7 @@ func (*product) QueryKuaishouProduct(ctx context.Context, newKuaishouProduct htt
|
|
//fmt.Println(newAccessToken.AccessToken)
|
|
//fmt.Println(newAccessToken.AccessToken)
|
|
|
|
|
|
// 3. 查找对应的快手商品
|
|
// 3. 查找对应的快手商品
|
|
- kuaishouProduct, err := kuaishou.Queryselectiondetail(appKey, signSecret, "ChFvYXV0aC5hY2Nlc3NUb2tlbhJgl2DZPM2ZSVHLUoU-t4425Bznh2b2QjIJkTjxF5tY6XYfjJ9X0bG4sB9W5if90iC22glyHe7ZbOQ22ndVHCKgCgYEc7QXN0w-lHlTCnKLsKmh1u46gZ0ivhHqf0QEQcLrGhLiICkHPKJFr7JGeErh7m5jzagiIKZOZcTU8A6KIgJoqCLbADf7fRlv7aYWcwEdfjGl6T8YKAUwAQ", newKuaishouProduct.ItemList)
|
|
|
|
|
|
+ kuaishouProduct, err := kuaishou.Queryselectiondetail(appKey, signSecret, "ChFvYXV0aC5hY2Nlc3NUb2tlbhJgVUcKpMMPhw6IsRe6j49Z_u5HNB4X4mEcFrPKQ6S4adSCGiJ_fnoNzQOfv5hv2iCI3jEU380e44aG0fH5cqVrghZWQxs-LlatHGWltM2einjuMdOLU-hw_-7gAgg46DHaGhJwAv7lQ4RI-YbDWturzqUxgFYiIH7EzXN1tK4s3OnxyrD227gtYmLoDs0jsnXzYvhocbBeKAUwAQ", newKuaishouProduct.ItemList)
|
|
if err != nil {
|
|
if err != nil {
|
|
fmt.Println("快手错误信息: ", err)
|
|
fmt.Println("快手错误信息: ", err)
|
|
return nil, err
|
|
return nil, err
|
|
@@ -209,9 +211,56 @@ func (*product) QueryKuaishouProduct(ctx context.Context, newKuaishouProduct htt
|
|
MerchantSoldCountThirtyDays: kuaishouProduct.ItemList[0].MerchantSoldCountThirtyDays,
|
|
MerchantSoldCountThirtyDays: kuaishouProduct.ItemList[0].MerchantSoldCountThirtyDays,
|
|
KuaishouProductId: kuaishouProduct.ItemList[0].ItemID,
|
|
KuaishouProductId: kuaishouProduct.ItemList[0].ItemID,
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // 5. 图片数据结构化
|
|
|
|
+ // 5.1. 主图
|
|
|
|
+ var currProductMainPhoto *http_model.ProductPhoto
|
|
|
|
+ rand.Seed(time.Now().UnixNano())
|
|
|
|
+ currProductMainPhoto = &http_model.ProductPhoto{
|
|
|
|
+ PhotoUrl: findKuaishouProductData.KuaishouMainPhoto,
|
|
|
|
+ PhotoUid: generateRandomString(10),
|
|
|
|
+ Symbol: 1,
|
|
|
|
+ }
|
|
|
|
+ findKuaishouProductData.ProductPhotos = append(findKuaishouProductData.ProductPhotos, currProductMainPhoto)
|
|
|
|
+
|
|
|
|
+ // 5.2. 轮播图
|
|
|
|
+ for _, url := range findKuaishouProductData.KuaishouCarousePhotoList {
|
|
|
|
+ var currProductPhoto *http_model.ProductPhoto
|
|
|
|
+ rand.Seed(time.Now().UnixNano())
|
|
|
|
+ currProductPhoto = &http_model.ProductPhoto{
|
|
|
|
+ PhotoUrl: url,
|
|
|
|
+ PhotoUid: generateRandomString(10),
|
|
|
|
+ Symbol: 2,
|
|
|
|
+ }
|
|
|
|
+ findKuaishouProductData.ProductPhotos = append(findKuaishouProductData.ProductPhotos, currProductPhoto)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 5.3. 详情图
|
|
|
|
+ for _, url := range findKuaishouProductData.KuaishouDetailPhotoList {
|
|
|
|
+ var currProductPhoto *http_model.ProductPhoto
|
|
|
|
+ rand.Seed(time.Now().UnixNano())
|
|
|
|
+ currProductPhoto = &http_model.ProductPhoto{
|
|
|
|
+ PhotoUrl: url,
|
|
|
|
+ PhotoUid: generateRandomString(10),
|
|
|
|
+ Symbol: 4,
|
|
|
|
+ }
|
|
|
|
+ findKuaishouProductData.ProductPhotos = append(findKuaishouProductData.ProductPhotos, currProductPhoto)
|
|
|
|
+ }
|
|
return &findKuaishouProductData, err
|
|
return &findKuaishouProductData, err
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
|
|
+
|
|
|
|
+var seededRand *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
+
|
|
|
|
+func generateRandomString(length int) string {
|
|
|
|
+ b := make([]byte, length)
|
|
|
|
+ for i := range b {
|
|
|
|
+ b[i] = charset[seededRand.Intn(len(charset))]
|
|
|
|
+ }
|
|
|
|
+ return string(b)
|
|
|
|
+}
|
|
|
|
+
|
|
/*
|
|
/*
|
|
type T struct {
|
|
type T struct {
|
|
CreatedAt time.Time `json:"CreatedAt"`
|
|
CreatedAt time.Time `json:"CreatedAt"`
|