|
@@ -4,7 +4,9 @@ import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
"github.com/lin-jim-leon/kuaishou"
|
|
|
+ "math/rand"
|
|
|
"strconv"
|
|
|
+ "time"
|
|
|
"youngee_b_api/consts"
|
|
|
"youngee_b_api/db"
|
|
|
"youngee_b_api/model/gorm_model"
|
|
@@ -172,14 +174,32 @@ func (*product) GetAllProduct(ctx context.Context, req *http_model.GetAllProduct
|
|
|
|
|
|
// QueryKuaishouProduct 通过快手商品ID从SDK拉取快手商品信息
|
|
|
func (*product) QueryKuaishouProduct(ctx context.Context, newKuaishouProduct http_model.FindKuaishouProductRequest) (*http_model.FindKuaishouProductData, error) {
|
|
|
- AccessToken := "ChFvYXV0aC5hY2Nlc3NUb2tlbhJgpNyhn_OyOXO-hSkJDAmlssr8lCAzT0CePeh-9-NyQEK3quECYOVm40RG0ppGMSnV0xq-_hlLrO7BoBOj-ai75oD4hzJ1QDNWChUhEZaXWwv9BtHAPp4Hioa08mw3ZiakGhI3fO2jrXtNfq7z9Xoxtovjx-YiINfD-RUDsg0A2tscTHxuBVd4yaWdtWWbN9QNeaTOLf31KAUwAQ"
|
|
|
appKey := "ks651333097154138217"
|
|
|
signSecret := "bf6393dce0a2b669ee348bebb837b0da"
|
|
|
- kuaishouProduct, err := kuaishou.Queryselectiondetail(appKey, signSecret, AccessToken, newKuaishouProduct.ItemList)
|
|
|
+ //var SignSecret string = "dBt0rVRhTpUqcrOYGGpv0A"
|
|
|
+
|
|
|
+ // 1. 拿到快手的AccessToken
|
|
|
+ kuaishouUserInfo, userErr := db.FindUserInfoByTalentId(ctx, "214300313")
|
|
|
+ if userErr != nil {
|
|
|
+ return nil, userErr
|
|
|
+ }
|
|
|
+ fmt.Println(kuaishouUserInfo.Gender)
|
|
|
+
|
|
|
+ // 2. 可能需要刷新Token
|
|
|
+ //newAccessToken, Tokenerr := kuaishou.RefreshAccessToken(kuaishouUserInfo.RefreshToken, appKey, SignSecret)
|
|
|
+ //if Tokenerr != nil {
|
|
|
+ // return nil, Tokenerr
|
|
|
+ //}
|
|
|
+ //fmt.Println(newAccessToken.AccessToken)
|
|
|
+
|
|
|
+ // 3. 查找对应的快手商品
|
|
|
+ kuaishouProduct, err := kuaishou.Queryselectiondetail(appKey, signSecret, "ChFvYXV0aC5hY2Nlc3NUb2tlbhJgVUcKpMMPhw6IsRe6j49Z_u5HNB4X4mEcFrPKQ6S4adSCGiJ_fnoNzQOfv5hv2iCI3jEU380e44aG0fH5cqVrghZWQxs-LlatHGWltM2einjuMdOLU-hw_-7gAgg46DHaGhJwAv7lQ4RI-YbDWturzqUxgFYiIH7EzXN1tK4s3OnxyrD227gtYmLoDs0jsnXzYvhocbBeKAUwAQ", newKuaishouProduct.ItemList)
|
|
|
if err != nil {
|
|
|
+ fmt.Println("快手错误信息: ", err)
|
|
|
return nil, err
|
|
|
}
|
|
|
- fmt.Println("kuaishouProduct: ", kuaishouProduct)
|
|
|
+
|
|
|
+ // 4. 组织返回数据
|
|
|
findKuaishouProductData := http_model.FindKuaishouProductData{
|
|
|
ProductName: kuaishouProduct.ItemList[0].ItemTitle,
|
|
|
ProductPrice: float64(kuaishouProduct.ItemList[0].ItemPrice) * 0.01,
|
|
@@ -191,6 +211,87 @@ func (*product) QueryKuaishouProduct(ctx context.Context, newKuaishouProduct htt
|
|
|
MerchantSoldCountThirtyDays: kuaishouProduct.ItemList[0].MerchantSoldCountThirtyDays,
|
|
|
KuaishouProductId: kuaishouProduct.ItemList[0].ItemID,
|
|
|
}
|
|
|
- // print("kuaoshou_product: ", findKuaishouProductData.ProductName)
|
|
|
+
|
|
|
+ // 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
|
|
|
}
|
|
|
+
|
|
|
+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 {
|
|
|
+ CreatedAt time.Time `json:"CreatedAt"`
|
|
|
+ UpdatedAt time.Time `json:"UpdatedAt"`
|
|
|
+ ProductUrl string `json:"ProductUrl"`
|
|
|
+ SalesCount string `json:"SalesCount"`
|
|
|
+ ProductId int `json:"product_id"`
|
|
|
+ ProductName string `json:"ProductName"`
|
|
|
+ ProductType int `json:"ProductType"`
|
|
|
+ EnterpriseID string `json:"EnterpriseID"`
|
|
|
+ ProductPrice int `json:"ProductPrice"`
|
|
|
+ SubAccountID int `json:"SubAccountID"`
|
|
|
+ ProductDetail string `json:"ProductDetail"`
|
|
|
+ CommissionPrice int `json:"CommissionPrice"`
|
|
|
+ ProductCategory string `json:"ProductCategory"`
|
|
|
+ PublicCommission int `json:"PublicCommission"`
|
|
|
+ KuaishouProductId string `json:"KuaishouProductId"`
|
|
|
+ ExclusiveCommission int `json:"ExclusiveCommission"`
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+type T struct {
|
|
|
+ Symbol int `json:"Symbol"`
|
|
|
+ StoreID int `json:"StoreID"`
|
|
|
+ PhotoUid string `json:"PhotoUid"`
|
|
|
+ PhotoUrl string `json:"PhotoUrl"`
|
|
|
+ CreatedAt time.Time `json:"CreatedAt"`
|
|
|
+ ProductID int `json:"ProductID"`
|
|
|
+ TeamBuyingID int `json:"TeamBuyingID"`
|
|
|
+ ProductPhotoID int `json:"ProductPhotoID"`
|
|
|
+ ProductPhotoType int `json:"ProductPhotoType"`
|
|
|
+}
|
|
|
+
|
|
|
+*/
|