第三方api接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

goods.go 5.4 KiB

10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
11 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
10 months ago
11 months ago
11 months ago
7 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. package tik_tok
  2. import (
  3. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  4. "encoding/json"
  5. "fmt"
  6. "github.com/tidwall/gjson"
  7. "strings"
  8. )
  9. //商品类目
  10. func CsjpGoodsCate(args map[string]string) (string, error) {
  11. params := map[string]interface{}{"parent_id": zhios_third_party_utils.StrToInt(args["parent_id"])}
  12. send, err := CsjpSend(args["app_id"], args["app_secret"], "product/category", params)
  13. fmt.Println(send)
  14. fmt.Println(err)
  15. return send, err
  16. }
  17. //3.2.1 商品列表接口
  18. func CsjpGoodsList(args map[string]string) []TikTokGoods {
  19. params := map[string]interface{}{
  20. "page": zhios_third_party_utils.StrToInt(args["page"]),
  21. "page_size": zhios_third_party_utils.StrToInt(args["page_size"]),
  22. }
  23. if args["title"] != "" {
  24. params["title"] = args["title"]
  25. }
  26. if args["first_cids"] != "" {
  27. ex := strings.Split(args["first_cids"], ",")
  28. ids := make([]int, 0)
  29. for _, v := range ex {
  30. ids = append(ids, zhios_third_party_utils.StrToInt(v))
  31. }
  32. params["first_cids"] = ids
  33. }
  34. if args["price_min"] != "" {
  35. params["price_min"] = int(zhios_third_party_utils.StrToFloat64(args["price_min"]) * 100)
  36. }
  37. if args["price_max"] != "" {
  38. params["price_max"] = int(zhios_third_party_utils.StrToFloat64(args["price_max"]) * 100)
  39. }
  40. if args["sell_num_min"] != "" {
  41. params["sell_num_min"] = zhios_third_party_utils.StrToInt(args["sell_num_min"])
  42. }
  43. if args["sell_num_max"] != "" {
  44. params["sell_num_max"] = zhios_third_party_utils.StrToInt(args["sell_num_max"])
  45. }
  46. if args["search_type"] != "" {
  47. params["search_type"] = zhios_third_party_utils.StrToInt(args["search_type"])
  48. }
  49. if args["order_type"] != "" {
  50. params["order_type"] = zhios_third_party_utils.StrToInt(args["order_type"])
  51. }
  52. if args["cos_fee_min"] != "" {
  53. params["cos_fee_min"] = int(zhios_third_party_utils.StrToFloat64(args["cos_fee_min"]) * 100)
  54. }
  55. if args["cos_fee_max"] != "" {
  56. params["cos_fee_max"] = int(zhios_third_party_utils.StrToFloat64(args["cos_fee_max"]) * 100)
  57. }
  58. if args["cos_ratio_min"] != "" {
  59. params["cos_ratio_min"] = int(zhios_third_party_utils.StrToFloat64(args["cos_ratio_min"]) * 100)
  60. }
  61. if args["cos_ratio_max"] != "" {
  62. params["cos_ratio_max"] = int(zhios_third_party_utils.StrToFloat64(args["cos_ratio_max"]) * 100)
  63. }
  64. if args["activity_id"] != "" {
  65. params["activity_id"] = zhios_third_party_utils.StrToInt(args["activity_id"])
  66. }
  67. send, err := CsjpSend(args["app_id"], args["app_secret"], "product/search", params)
  68. fmt.Println(send)
  69. var goodsList = make([]TikTokGoods, 0)
  70. product := gjson.Get(send, "data.products").String()
  71. if err != nil || product == "" {
  72. return goodsList
  73. }
  74. var lmData struct {
  75. Data struct {
  76. Products []TikTokGoodsLm `json:"products"`
  77. } `json:"data"`
  78. }
  79. err = json.Unmarshal([]byte(send), &lmData)
  80. if err != nil {
  81. fmt.Println("抖音商品1", err)
  82. return goodsList
  83. }
  84. for _, v := range lmData.Data.Products {
  85. v.CosRatio = v.CosRatio / 100
  86. tmp := CommGoodsDetail(v)
  87. goodsList = append(goodsList, tmp)
  88. }
  89. return goodsList
  90. }
  91. //商品详情接口
  92. func CsjpGoodsDetail(args map[string]string) TikTokGoods {
  93. params := map[string]interface{}{}
  94. if args["product_ids"] != "" {
  95. ex := strings.Split(args["product_ids"], ",")
  96. ids := make([]int, 0)
  97. for _, v := range ex {
  98. ids = append(ids, zhios_third_party_utils.StrToInt(v))
  99. }
  100. params["product_ids"] = ids
  101. }
  102. send, err := CsjpSend(args["app_id"], args["app_secret"], "product/detail", params)
  103. var goodsList = TikTokGoods{}
  104. product := gjson.Get(send, "data.products").String()
  105. if err != nil || product == "" {
  106. return goodsList
  107. }
  108. var lmData struct {
  109. Data struct {
  110. Products []TikTokGoodsLm `json:"products"`
  111. } `json:"data"`
  112. }
  113. err = json.Unmarshal([]byte(send), &lmData)
  114. if err != nil {
  115. return goodsList
  116. }
  117. for _, v := range lmData.Data.Products {
  118. v.CosRatio = v.CosRatio / 100
  119. tmp := CommGoodsDetail(v)
  120. if tmp.GoodsID == args["product_ids"] {
  121. return tmp
  122. }
  123. }
  124. //
  125. return goodsList
  126. }
  127. func CsjpGoodsDetailMore(args map[string]string) []TikTokGoods {
  128. params := map[string]interface{}{}
  129. if args["product_ids"] != "" {
  130. ex := strings.Split(args["product_ids"], ",")
  131. ids := make([]int, 0)
  132. for _, v := range ex {
  133. ids = append(ids, zhios_third_party_utils.StrToInt(v))
  134. }
  135. params["product_ids"] = ids
  136. }
  137. send, err := CsjpSend(args["app_id"], args["app_secret"], "product/detail", params)
  138. var goodsList = make([]TikTokGoods, 0)
  139. product := gjson.Get(send, "data.products").String()
  140. if err != nil || product == "" {
  141. return goodsList
  142. }
  143. var lmData struct {
  144. Data struct {
  145. Products []TikTokGoodsLm `json:"products"`
  146. } `json:"data"`
  147. }
  148. err = json.Unmarshal([]byte(send), &lmData)
  149. if err != nil {
  150. return goodsList
  151. }
  152. for _, v := range lmData.Data.Products {
  153. v.CosRatio = v.CosRatio / 100
  154. tmp := CommGoodsDetail(v)
  155. goodsList = append(goodsList, tmp)
  156. }
  157. //
  158. return goodsList
  159. }
  160. //3.2.2 商品转链接口
  161. func CsjpGoodsLink(args map[string]string) (string, error) {
  162. params := map[string]interface{}{
  163. "product_url": args["product_url"],
  164. "product_ext": args["product_ext"],
  165. "external_info": args["external_info"],
  166. }
  167. if args["share_type"] != "" {
  168. ex := strings.Split(args["share_type"], ",")
  169. ids := make([]int, 0)
  170. for _, v := range ex {
  171. ids = append(ids, zhios_third_party_utils.StrToInt(v))
  172. }
  173. params["share_type"] = ids
  174. }
  175. send, err := CsjpSend(args["app_id"], args["app_secret"], "product/link", params)
  176. fmt.Println(send)
  177. fmt.Println(err)
  178. return send, err
  179. }