第三方api接口
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

134 wiersze
4.1 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. var goodsList = make([]tik_tok.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 []tik_tok.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. tmp := tik_tok.CommGoodsDetail(v)
  86. goodsList = append(goodsList, tmp)
  87. }
  88. return goodsList
  89. }
  90. //商品详情接口
  91. func GoodsDetail(args map[string]string) (string, error) {
  92. params := map[string]interface{}{}
  93. if args["product_ids"] != "" {
  94. ex := strings.Split(args["product_ids"], ",")
  95. ids := make([]int, 0)
  96. for _, v := range ex {
  97. ids = append(ids, zhios_third_party_utils.StrToInt(v))
  98. }
  99. params["product_ids"] = ids
  100. }
  101. send, err := Send(args["app_id"], args["app_secret"], "product/detail", params)
  102. fmt.Println(send)
  103. fmt.Println(err)
  104. return send, err
  105. }
  106. //3.2.2 商品转链接口
  107. func GoodsLink(args map[string]string) (string, error) {
  108. params := map[string]interface{}{
  109. "product_url": args["product_url"],
  110. "product_ext": args["product_ext"],
  111. "external_info": args["external_info"],
  112. }
  113. if args["share_type"] != "" {
  114. ex := strings.Split(args["share_type"], ",")
  115. ids := make([]int, 0)
  116. for _, v := range ex {
  117. ids = append(ids, zhios_third_party_utils.StrToInt(v))
  118. }
  119. params["share_type"] = ids
  120. }
  121. send, err := Send(args["app_id"], args["app_secret"], "product/link", params)
  122. fmt.Println(send)
  123. fmt.Println(err)
  124. return send, err
  125. }