From fe1c01ee18322885fc5368cb34538e7cd8e5a0f2 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Fri, 18 Oct 2024 16:49:30 +0800 Subject: [PATCH] 1 --- chanxuanTikTok/api.go | 81 ++++++++++++++++++++++++++++++++++++ chanxuanTikTok/md.go | 95 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 chanxuanTikTok/api.go create mode 100644 chanxuanTikTok/md.go diff --git a/chanxuanTikTok/api.go b/chanxuanTikTok/api.go new file mode 100644 index 0000000..d5f4893 --- /dev/null +++ b/chanxuanTikTok/api.go @@ -0,0 +1,81 @@ +package chanxuanTikTok + +import ( + zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" + "encoding/json" + "fmt" + "github.com/syyongx/php2go" + "github.com/tidwall/gjson" + "strings" + "time" +) + +const url = "https://open-api.chanmama.com" + +// https://xifld533us.feishu.cn/wiki/wikcnKRYjreG0wr59f1ZrRQ3T7b +func GetGoods(acctoken string, args map[string]string) []ChanxuanTikTokGoods { + send, _ := Send("/jx/v1/partner/product/getGoodsPage", acctoken, args) + var list = make([]ChanxuanTikTokGoods, 0) + str := gjson.Get(send, "data.list").String() + json.Unmarshal([]byte(str), &list) + return list +} +func GetGoodsDetail(acctoken string, args map[string]string) ChanxuanTikTokGoodsDetail { + //goods_id + send, _ := Send("/jx/v1/partner/product/jxGoodsDetails", acctoken, args) + var list ChanxuanTikTokGoodsDetail + str := gjson.Get(send, "data").String() + json.Unmarshal([]byte(str), &list) + return list +} +func GetGoodsUrl(acctoken, userId string, args map[string]string) ChanxuanTikTokGoodsUrl { + //goods_id + args["user_id"] = userId + send, _ := SendPost("/jx/v1/partner/dklive/shareProductLink", acctoken, args) + var list ChanxuanTikTokGoodsUrl + str := gjson.Get(send, "data.data").String() + json.Unmarshal([]byte(str), &list) + return list +} +func GetOrder(acctoken, userId string, args map[string]string) []ChanxuanTikTokOrder { + //goods_id + args["user_id"] = userId + send, _ := Send("/jx/v1/partner/dklive/qryDKOrders", acctoken, args) + var list []ChanxuanTikTokOrder + str := gjson.Get(send, "data.data").String() + json.Unmarshal([]byte(str), &list) + return list +} +func GetToken(appId, secret string) string { + args := map[string]string{ + "app_id": appId, + "timestamp": zhios_third_party_utils.Int64ToStr(time.Now().Unix()), + } + str := "app_id=" + appId + "×tamp=" + args["timestamp"] + "&secret=" + secret + sign := zhios_third_party_utils.Md5(str) + args["sign"] = strings.ToUpper(sign) + post, err := zhios_third_party_utils.CurlPost(url+"/auth/token/get", zhios_third_party_utils.SerializeStr(args), nil) + fmt.Println(string(post)) + fmt.Println(err) + //{"code":0,"message":"success","data":{"access_token":"1cd6b495-fa72-e7f8-bcf9-41aa17a49652","expires_in":7200,"expires_in_v2":1729075821}} + return gjson.Get(string(post), "data").String() +} +func Send(router, acctoken string, args map[string]string) (string, error) { + urlStr := url + router + "?access_token=" + acctoken + for k, v := range args { + urlStr += "&" + k + "=" + php2go.URLEncode(v) + } + post, err := zhios_third_party_utils.CurlGet(urlStr, nil) + fmt.Println(urlStr) + fmt.Println(string(post)) + fmt.Println(err) + return string(post), err +} +func SendPost(router, acctoken string, args map[string]string) (string, error) { + urlStr := url + router + args["access_token"] = acctoken + post, err := zhios_third_party_utils.CurlPost(urlStr, zhios_third_party_utils.SerializeStr(args), nil) + fmt.Println(string(post)) + fmt.Println(err) + return string(post), err +} diff --git a/chanxuanTikTok/md.go b/chanxuanTikTok/md.go new file mode 100644 index 0000000..50d0fab --- /dev/null +++ b/chanxuanTikTok/md.go @@ -0,0 +1,95 @@ +package chanxuanTikTok + +type ChanxuanTikTokGoods struct { + Title string `json:"title"` + Cover string `json:"cover"` + Price int `json:"price"` + OriginPrice int `json:"origin_price"` + CosRatio int `json:"cos_ratio"` + Sales int `json:"sales"` + DetailUrl string `json:"detail_url"` + ProductId string `json:"product_id"` + KolCosRatio int `json:"kol_cos_ratio"` + ActivityCosRatio int `json:"activity_cos_ratio"` + ShopName string `json:"shop_name"` + ActivityId int `json:"activity_id"` + CategoryName string `json:"category_name"` +} +type ChanxuanTikTokGoodsUrl struct { + DkPassword string `json:"dk_password"` + DkCode_img string `json:"dk_code_img"` + DyDeeplink string `json:"dy_deeplink"` + DySharelink string `json:"dy_sharelink"` +} +type ChanxuanTikTokOrder struct { + CommissionRate int `json:"commission_rate"` + CxServiceRate int `json:"cx_service_rate"` + EstimatedCommission int `json:"estimated_commission"` + EstimatedTechServiceFee int `json:"estimated_tech_service_fee"` + FlowPoint string `json:"flow_point"` + ItemNum int `json:"item_num"` + OrderId string `json:"order_id"` + PaySuccessTime string `json:"pay_success_time"` + ProductId string `json:"product_id"` + ProductImg string `json:"product_img"` + ProductName string `json:"product_name"` + RealCommission int `json:"real_commission"` + RefundTime interface{} `json:"refund_time"` + SettleTime interface{} `json:"settle_time"` + SettledTechServiceFee int `json:"settled_tech_service_fee"` + ShopId int `json:"shop_id"` + TotalPayAmount int `json:"total_pay_amount"` + UpdateTime string `json:"update_time"` + VipMsg string `json:"vip_msg"` +} +type ChanxuanTikTokGoodsDetail struct { + ActivityCosRatio int `json:"activity_cos_ratio"` + AwemeList []string `json:"aweme_list"` + AwemesInfo []struct { + AwemeId string `json:"aweme_id"` + AwemeCover string `json:"aweme_cover"` + AwemeUrl string `json:"aweme_url"` + } `json:"awemes_info"` + BrandCode string `json:"brand_code"` + Category string `json:"category"` + CosRatio int `json:"cos_ratio"` + Cover string `json:"cover"` + DescLevel int `json:"desc_level"` + DescScore int `json:"desc_score"` + DetailImages []string `json:"detail_images"` + DetailUrl string `json:"detail_url"` + ExprLevel int `json:"expr_level"` + ExprScore int `json:"expr_score"` + Gain string `json:"gain"` + Images []string `json:"images"` + KolCosRatio int `json:"kol_cos_ratio"` + OriginPrice float64 `json:"origin_price"` + PostLevel int `json:"post_level"` + PostScore float64 `json:"post_score"` + Price float64 `json:"price"` + ProductId int64 `json:"product_id"` + PromotionEndTime string `json:"promotion_end_time"` + PromotionStartTime string `json:"promotion_start_time"` + Sales int `json:"sales"` + SellPoint string `json:"sell_point"` + ServLevel int `json:"serv_level"` + ServScore float64 `json:"serv_score"` + ShopIcon string `json:"shop_icon"` + ShopId int `json:"shop_id"` + ShopName string `json:"shop_name"` + Skus struct { + Field1 struct { + EffectivePrice int `json:"effective_price"` + Price int `json:"price"` + StockNum int `json:"stock_num"` + } `json:"1801560319889520"` + } `json:"skus"` + Spec []struct { + Name string `json:"name"` + SpecItems []struct { + Id string `json:"id"` + Name string `json:"name"` + } `json:"spec_items"` + } `json:"spec"` + Title string `json:"title"` +}