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

recommend.go 3.7 KiB

1 year ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package pdd
  2. import (
  3. "encoding/json"
  4. )
  5. type PddRecommendItem struct {
  6. CouponRemainQuantity int `json:"coupon_remain_quantity"`
  7. PromotionRate int `json:"promotion_rate"`
  8. CatIds []int `json:"cat_ids"`
  9. CouponMinOrderAmount int `json:"coupon_min_order_amount"`
  10. MallID int `json:"mall_id"`
  11. MallName string `json:"mall_name"`
  12. CouponTotalQuantity int `json:"coupon_total_quantity"`
  13. MerchantType string `json:"merchant_type"`
  14. LgstTxt string `json:"lgst_txt"`
  15. GoodsName string `json:"goods_name"`
  16. SalesTip string `json:"sales_tip"`
  17. GoodsID string `json:"goods_sign"`
  18. DescTxt string `json:"desc_txt"`
  19. PredictPromotionRate int `json:"predict_promotion_rate"`
  20. GoodsDesc string `json:"goods_desc"`
  21. OptName string `json:"opt_name"`
  22. GoodsThumbnailURL string `json:"goods_thumbnail_url"`
  23. OptID string `json:"opt_id"`
  24. OptIds []int `json:"opt_ids"`
  25. SearchID string `json:"search_id"`
  26. GoodsImageURL string `json:"goods_image_url"`
  27. HasCoupon bool `json:"has_coupon"`
  28. MinNormalPrice float64 `json:"min_normal_price"`
  29. ServTxt string `json:"serv_txt"`
  30. CouponStartTime int `json:"coupon_start_time"`
  31. MinGroupPrice float64 `json:"min_group_price"`
  32. CouponDiscount int `json:"coupon_discount"`
  33. CouponEndTime int `json:"coupon_end_time"`
  34. }
  35. type PddRecommend struct {
  36. GoodsBasicDetailResponse struct {
  37. Total int `json:"total"`
  38. ListID string `json:"list_id"`
  39. List []PddRecommendItem `json:"list"`
  40. RequestID string `json:"request_id"`
  41. SearchID string `json:"search_id"`
  42. } `json:"goods_basic_detail_response"`
  43. }
  44. // 多多进宝API
  45. // https://open.pinduoduo.com/application/document/api?id=pdd.ddk.goods.recommend.get
  46. func Recommend(page, size, id, gid, cid string) (*PddRecommend, error) {
  47. method := "pdd.ddk.goods.recommend.get"
  48. args := map[string]interface{}{
  49. //"channel_type": id, // 非必填, 0-1.9包邮, 1-今日爆款, 2-品牌清仓,3-相似商品推荐,4-猜你喜欢,5-实时热销,6-实时收益,7-今日畅销,8-高佣榜单,默认1
  50. "limit": size, // 非必填, 请求数量;默认值 : 400
  51. "offset": page, // 非必填, 从多少位置开始请求;默认值 : 0,offset需是limit的整数倍,仅支持整页翻页
  52. //"list_id": "", // 非必填,翻页时建议填写前页返回的list_id值
  53. }
  54. //fmt.Println(gid)
  55. if id != "" {
  56. args["channel_type"] = id
  57. }
  58. if gid != "" {
  59. args["goods_ids"] = []string{gid}
  60. args["channel_type"] = "3"
  61. }
  62. if cid != "" {
  63. //20100-百货,20200-母婴,20300-食品,20400-女装,20500-电器,20600-鞋包,20700-内衣,20800-美妆,20900-男装,21000-水果,21100-家纺,21200-文具,21300-运动,21400-虚拟,21500-汽车,21600-家装,21700-家具,21800-医药;
  64. args["cat_id"] = cid
  65. args["channel_type"] = "4"
  66. }
  67. // fmt.Println(args)
  68. data, err := send(args, method)
  69. if err != nil {
  70. return nil, err
  71. }
  72. // fmt.Println(string(data))
  73. r := new(PddRecommend)
  74. if err := json.Unmarshal(data, &r); err != nil {
  75. return nil, err
  76. }
  77. return r, nil
  78. }
  79. // 爆款排行商品接口
  80. //func Hot() {
  81. // method := "pdd.ddk.top.goods.list.query"
  82. // args := map[string]interface{}{
  83. // "limit": 400, // 非必填, 请求数量;默认值 : 400
  84. // "offset": 400, // 非必填, 从多少位置开始请求;默认值 : 0,offset需是limit的整数倍,仅支持整页翻页
  85. // "sort_type": "", // 非必填, 1-实时热销榜;2-实时收益榜
  86. // }
  87. //}