瀏覽代碼

商品详情,pid创建

k.zhang 4 年之前
父節點
當前提交
71e65eb80e

+ 2 - 0
apis/pdd/base.go

@@ -7,5 +7,7 @@ func InitPddDdkRouter(engine *gin.RouterGroup) {
 	v1 := engine.Group("v1")
 	{
 		v1.POST("/pdd/ddk/search", PddDdkGoodsSearch) //多多客  商品查询
+		v1.POST("/pdd/ddk/detail", PddDdkGoodsDetail) //多多客  商品详情
+		v1.POST("/pdd/pid/generate", PddDdkGoodsPidGenerate)
 	}
 }

+ 67 - 0
apis/pdd/pdd.ddk.goods.detail.go

@@ -0,0 +1,67 @@
+package pdd
+
+import (
+	"duoduo/conf"
+	"duoduo/models/pdd"
+	"duoduo/tools"
+	"duoduo/tools/app"
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"time"
+)
+
+func PddDdkGoodsDetail(c *gin.Context) {
+	var inData pdd.PddDdkGoodsDetailRequest
+	var outData pdd.PddDdkGoodsDetailResponse
+	var pddErr pdd.ErrorPddResponse
+
+	confIni, err := conf.ConnIni()
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	err = c.ShouldBindJSON(&inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	inData.ClientId = confIni.MustValue("pdd", "client_id")
+	inData.Type = "pdd.ddk.goods.detail"
+	inData.Timestamp = fmt.Sprintf("%d", time.Now().Unix())
+	inData.DataType = "JSON"
+	inData.Sign = ""
+
+	sign, err := DDKSign(inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	inData.Sign = sign
+	val, err := PostDDk(inData, nil)
+
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	err = tools.JsonUnmarshal(val, &pddErr)
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+	if pddErr.ErrorResponse.ErrorCode != 0 {
+		app.Error(c, 500, err, pddErr.ErrorResponse.ErrorMsg)
+		return
+	}
+
+	err = tools.JsonUnmarshal(val, &outData)
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+
+	app.OK(c, outData, app.Success)
+}

+ 67 - 0
apis/pdd/pdd.ddk.goods.pid.generate.go

@@ -0,0 +1,67 @@
+package pdd
+
+import (
+	"duoduo/conf"
+	"duoduo/models/pdd"
+	"duoduo/tools"
+	"duoduo/tools/app"
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"time"
+)
+
+func PddDdkGoodsPidGenerate(c *gin.Context) {
+	var inData pdd.PddDdkGoodsPidGenerateRequest
+	var outData pdd.PddDdkGoodsPidGenerateResponse
+	var pddErr pdd.ErrorPddResponse
+
+	confIni, err := conf.ConnIni()
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	err = c.ShouldBindJSON(&inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	inData.ClientId = confIni.MustValue("pdd", "client_id")
+	inData.Type = "pdd.ddk.goods.pid.generate"
+	inData.Timestamp = fmt.Sprintf("%d", time.Now().Unix())
+	inData.DataType = "JSON"
+	inData.Sign = ""
+
+	sign, err := DDKSign(inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	inData.Sign = sign
+	val, err := PostDDk(inData, nil)
+
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	err = tools.JsonUnmarshal(val, &pddErr)
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+	if pddErr.ErrorResponse.ErrorCode != 0 {
+		app.Error(c, 500, err, pddErr.ErrorResponse.ErrorMsg)
+		return
+	}
+
+	err = tools.JsonUnmarshal(val, &outData)
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+
+	app.OK(c, outData, app.Success)
+}

+ 0 - 1
conf/conf.ini

@@ -2,4 +2,3 @@
 client_id = a5d05569c6584a50bfb6600b2d150bae
 client_secret = 1d4d5dd30f665c0ed3b315275f81fe358c3da609
 api_http = https://gw-api.pinduoduo.com/api/router
-

+ 8 - 0
models/pdd/base.go

@@ -10,3 +10,11 @@ type ErrorResponse struct {
 	ErrorCode int    `json:"error_code"`
 	RequestID string `json:"request_id"`
 }
+
+type PddDdkBase struct {
+	ClientId  string `json:"client_id"`
+	Type      string `json:"type"`
+	Timestamp string `json:"timestamp"`
+	DataType  string `json:"data_type"`
+	Sign      string `json:"sign"`
+}

+ 66 - 0
models/pdd/pdd.ddk.goods.detail.go

@@ -0,0 +1,66 @@
+package pdd
+
+type PddDdkGoodsDetailRequest struct {
+	PddDdkBase
+	GoodsSign string `json:"goods_sign"`
+	SearchId  string `json:"search_id"`
+}
+
+type PddDdkGoodsDetailResponse struct {
+	GoodsDetailResponse GoodsDetailResponse `json:"goods_detail_response"`
+}
+type GoodsDetails struct {
+	CategoryName                string        `json:"category_name"`
+	CouponRemainQuantity        int           `json:"coupon_remain_quantity"`
+	PromotionRate               int           `json:"promotion_rate"`
+	ServiceTags                 []int         `json:"service_tags"`
+	MallID                      int           `json:"mall_id"`
+	MallName                    string        `json:"mall_name"`
+	MallCouponEndTime           int           `json:"mall_coupon_end_time"`
+	LgstTxt                     string        `json:"lgst_txt"`
+	GoodsName                   string        `json:"goods_name"`
+	GoodsGalleryUrls            []string      `json:"goods_gallery_urls"`
+	GoodsID                     int64         `json:"goods_id"`
+	BrandName                   string        `json:"brand_name"`
+	PredictPromotionRate        int           `json:"predict_promotion_rate"`
+	GoodsDesc                   string        `json:"goods_desc"`
+	OptName                     string        `json:"opt_name"`
+	ShareRate                   int           `json:"share_rate"`
+	OptIds                      []int         `json:"opt_ids"`
+	GoodsImageURL               string        `json:"goods_image_url"`
+	MallImgURL                  string        `json:"mall_img_url"`
+	HasMallCoupon               bool          `json:"has_mall_coupon"`
+	UnifiedTags                 []string      `json:"unified_tags"`
+	VideoUrls                   []interface{} `json:"video_urls"`
+	CouponStartTime             int           `json:"coupon_start_time"`
+	MinGroupPrice               int           `json:"min_group_price"`
+	CouponDiscount              int           `json:"coupon_discount"`
+	CouponEndTime               int           `json:"coupon_end_time"`
+	ZsDuoID                     int           `json:"zs_duo_id"`
+	MallCouponRemainQuantity    int           `json:"mall_coupon_remain_quantity"`
+	PlanType                    int           `json:"plan_type"`
+	CatIds                      []int         `json:"cat_ids"`
+	CouponMinOrderAmount        int           `json:"coupon_min_order_amount"`
+	CategoryID                  int           `json:"category_id"`
+	MallCouponDiscountPct       int           `json:"mall_coupon_discount_pct"`
+	CouponTotalQuantity         int           `json:"coupon_total_quantity"`
+	MallCouponMinOrderAmount    int           `json:"mall_coupon_min_order_amount"`
+	MerchantType                int           `json:"merchant_type"`
+	SalesTip                    string        `json:"sales_tip"`
+	OnlySceneAuth               bool          `json:"only_scene_auth"`
+	DescTxt                     string        `json:"desc_txt"`
+	GoodsThumbnailURL           string        `json:"goods_thumbnail_url"`
+	OptID                       int           `json:"opt_id"`
+	HasCoupon                   bool          `json:"has_coupon"`
+	MinNormalPrice              int           `json:"min_normal_price"`
+	MallCouponStartTime         int           `json:"mall_coupon_start_time"`
+	ServTxt                     string        `json:"serv_txt"`
+	MallCouponTotalQuantity     int           `json:"mall_coupon_total_quantity"`
+	MallCouponMaxDiscountAmount int           `json:"mall_coupon_max_discount_amount"`
+	MallCps                     int           `json:"mall_cps"`
+	GoodsSign                   string        `json:"goods_sign"`
+}
+type GoodsDetailResponse struct {
+	GoodsDetails []GoodsDetails `json:"goods_details"`
+	RequestID    string         `json:"request_id"`
+}

+ 21 - 0
models/pdd/pdd.ddk.goods.pid.generate.go

@@ -0,0 +1,21 @@
+package pdd
+
+type PddDdkGoodsPidGenerateRequest struct {
+	PddDdkBase
+	Number string `json:"number"` //生成数量
+}
+
+type PddDdkGoodsPidGenerateResponse struct {
+	PIDGenerateResponse PIDGenerateResponse `json:"p_id_generate_response"`
+}
+type PIDList struct {
+	CreateTime int    `json:"create_time"`
+	MediaID    int    `json:"media_id"`
+	PidName    string `json:"pid_name"`
+	PID        string `json:"p_id"`
+}
+type PIDGenerateResponse struct {
+	PIDList        []PIDList `json:"p_id_list"`
+	RemainPidCount int       `json:"remain_pid_count"`
+	RequestID      string    `json:"request_id"`
+}