第三方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.

96 lines
3.1 KiB

  1. package zhimeng
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/md"
  4. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  5. "encoding/json"
  6. )
  7. func KuaiShouGoods(tikTokArgs map[string]interface{}) []map[string]string {
  8. var goods = make([]map[string]string, 0)
  9. args := map[string]interface{}{
  10. "appkey": tikTokArgs["appkey"],
  11. "secret_key": tikTokArgs["secret_key"],
  12. "title": tikTokArgs["keyword"],
  13. "first_cids": tikTokArgs["category_id"],
  14. "price_min": zhios_third_party_utils.AnyToString(tikTokArgs["start_price"]),
  15. "price_max": zhios_third_party_utils.AnyToString(tikTokArgs["end_price"]),
  16. "sell_num_min": zhios_third_party_utils.AnyToString(tikTokArgs["start_sales"]),
  17. "sell_num_max": zhios_third_party_utils.AnyToString(tikTokArgs["end_sales"]),
  18. "sort": tikTokArgs["sort"],
  19. "cos_ratio_min": zhios_third_party_utils.AnyToString(tikTokArgs["start_commission"]),
  20. "cos_ratio_max": zhios_third_party_utils.AnyToString(tikTokArgs["end_commission"]),
  21. "page": tikTokArgs["p"],
  22. "page_size": tikTokArgs["size"],
  23. }
  24. for k, v := range args {
  25. if v == nil || v == "<nil>" {
  26. args[k] = ""
  27. }
  28. }
  29. resp, err := Send("kuaishou", "getGoods", args)
  30. if err != nil {
  31. return goods
  32. }
  33. var tmp struct {
  34. Data []TikTokData `json:"data"`
  35. }
  36. if err = json.Unmarshal(resp, &tmp); err != nil {
  37. return goods
  38. }
  39. for _, v := range tmp.Data {
  40. var tmp = map[string]string{
  41. "img_list": zhios_third_party_utils.SerializeStr(v.Imgs),
  42. "gid": v.GoodsID,
  43. "title": v.GoodsTitle,
  44. "img": v.GoodsImg,
  45. "sales": v.GoodsSales,
  46. "price": v.Price,
  47. "cost_price": v.CostPrice,
  48. "coupon": v.YhqPrice,
  49. "commission_rate": zhios_third_party_utils.AnyToString(v.Commission),
  50. "commission": zhios_third_party_utils.Float64ToStr(zhios_third_party_utils.StrToFloat64(v.Price) * (zhios_third_party_utils.AnyToFloat64(v.Commission) / 100)),
  51. "pvd": md.PVD_KUAISHOU,
  52. "share_content": "",
  53. }
  54. goods = append(goods, tmp)
  55. }
  56. return goods
  57. }
  58. func KuaiShouKlGoods(tikTokArgs map[string]interface{}) (*TikTokDetailData, error) {
  59. args := map[string]interface{}{
  60. "appkey": tikTokArgs["appkey"],
  61. "secret_key": tikTokArgs["secret_key"],
  62. "content": tikTokArgs["content"],
  63. }
  64. resp, err := Send("kuaishou", "getKlGoods", args)
  65. if err != nil {
  66. return nil, err
  67. }
  68. var tmp struct {
  69. Data TikTokDetailData `json:"data"`
  70. }
  71. if err = json.Unmarshal(resp, &tmp); err != nil {
  72. return nil, err
  73. }
  74. return &tmp.Data, nil
  75. }
  76. func KuaiShouDetail(tikTokArgs map[string]interface{}) (*TikTokDetailData, error) {
  77. args := map[string]interface{}{
  78. "appkey": tikTokArgs["appkey"],
  79. "secret_key": tikTokArgs["secret_key"],
  80. "id": tikTokArgs["gid"],
  81. }
  82. resp, err := Send("kuaishou", "getGoodsDetail", args)
  83. if err != nil {
  84. return nil, err
  85. }
  86. var tmp struct {
  87. Data TikTokDetailData `json:"data"`
  88. }
  89. if err = json.Unmarshal(resp, &tmp); err != nil {
  90. return nil, err
  91. }
  92. return &tmp.Data, nil
  93. }