第三方api接口
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

156 řádky
4.6 KiB

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