parent
943f867594
commit
4a3828b709
@ -1,5 +1,5 @@
|
|||||||
package go_library
|
package go_library
|
||||||
|
|
||||||
func Version() string {
|
func Version() string {
|
||||||
return "v1.0.35"
|
return "v1.0.36"
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
package pinduoduo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/dtapps/go-library/utils/gohttp"
|
||||||
|
"github.com/dtapps/go-library/utils/gostring"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// App 公共请求参数
|
||||||
|
type App struct {
|
||||||
|
ClientId string // POP分配给应用的client_id
|
||||||
|
ClientSecret string // POP分配给应用的client_secret
|
||||||
|
Pid string // 推广位
|
||||||
|
}
|
||||||
|
|
||||||
|
type ErrResp struct {
|
||||||
|
ErrorResponse struct {
|
||||||
|
ErrorMsg string `json:"error_msg"`
|
||||||
|
SubMsg string `json:"sub_msg"`
|
||||||
|
SubCode interface{} `json:"sub_code"`
|
||||||
|
ErrorCode int `json:"error_code"`
|
||||||
|
RequestId string `json:"request_id"`
|
||||||
|
} `json:"error_response"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CustomParametersResult struct {
|
||||||
|
Sid string `json:"sid"`
|
||||||
|
Uid string `json:"uid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) request(params map[string]interface{}) (resp []byte, err error) {
|
||||||
|
// 签名
|
||||||
|
app.Sign(params)
|
||||||
|
// 发送请求
|
||||||
|
httpGet, err := gohttp.Get("https://gw-api.pinduoduo.com/api/router", params)
|
||||||
|
// 检查错误
|
||||||
|
var errResp ErrResp
|
||||||
|
_ = json.Unmarshal(httpGet.Body, &errResp)
|
||||||
|
return httpGet.Body, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) SalesTipParseInt64(salesTip string) int64 {
|
||||||
|
parseInt, err := strconv.ParseInt(salesTip, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
salesTipStr := salesTip
|
||||||
|
if strings.Contains(salesTip, "万+") {
|
||||||
|
salesTipStr = strings.Replace(salesTip, "万+", "0000", -1)
|
||||||
|
} else if strings.Contains(salesTip, "万") {
|
||||||
|
salesTipStr = strings.Replace(salesTip, "万", "000", -1)
|
||||||
|
}
|
||||||
|
re := regexp.MustCompile("[0-9]+")
|
||||||
|
SalesTipMap := re.FindAllString(salesTipStr, -1)
|
||||||
|
if len(SalesTipMap) == 2 {
|
||||||
|
return gostring.ToInt64(fmt.Sprintf("%s%s", SalesTipMap[0], SalesTipMap[1]))
|
||||||
|
} else if len(SalesTipMap) == 1 {
|
||||||
|
return gostring.ToInt64(SalesTipMap[0])
|
||||||
|
} else {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return parseInt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) CommissionIntegralToInt64(GoodsPrice, CouponProportion int64) int64 {
|
||||||
|
return (GoodsPrice * CouponProportion) / 1000
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package pinduoduo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 签名
|
||||||
|
func createSign(signStr string) string {
|
||||||
|
h := md5.New()
|
||||||
|
h.Write([]byte(signStr))
|
||||||
|
cipherStr := h.Sum(nil)
|
||||||
|
return strings.ToUpper(hex.EncodeToString(cipherStr))
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package pinduoduo
|
||||||
|
|
||||||
|
// CommonGenCustomParameters 自定义参数
|
||||||
|
type CommonGenCustomParameters struct {
|
||||||
|
Uid string `json:"uid"`
|
||||||
|
Sid string `json:"sid"`
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
package pinduoduo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/url"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Params 请求参数
|
||||||
|
type Params map[string]interface{}
|
||||||
|
|
||||||
|
func NewParams() Params {
|
||||||
|
p := make(Params)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewParamsWithType(_type string, params ...Params) Params {
|
||||||
|
p := make(Params)
|
||||||
|
p["type"] = _type
|
||||||
|
p["timestamp"] = strconv.FormatInt(time.Now().Unix(), 10)
|
||||||
|
for _, v := range params {
|
||||||
|
p.SetParams(v)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) Sign(p Params) {
|
||||||
|
p["client_id"] = app.ClientId
|
||||||
|
// 排序所有的 key
|
||||||
|
var keys []string
|
||||||
|
for key := range p {
|
||||||
|
keys = append(keys, key)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
signStr := app.ClientSecret
|
||||||
|
for _, key := range keys {
|
||||||
|
signStr += key + getString(p[key])
|
||||||
|
}
|
||||||
|
signStr += app.ClientSecret
|
||||||
|
p["sign"] = createSign(signStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) Set(key string, value interface{}) {
|
||||||
|
p[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) SetParams(params Params) {
|
||||||
|
for key, value := range params {
|
||||||
|
p[key] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) SetCustomParameters(uid string, sid string) {
|
||||||
|
p["custom_parameters"] = map[string]interface{}{
|
||||||
|
"uid": uid,
|
||||||
|
"sid": sid,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) GetQuery() string {
|
||||||
|
u := url.Values{}
|
||||||
|
for k, v := range p {
|
||||||
|
u.Set(k, getString(v))
|
||||||
|
}
|
||||||
|
return u.Encode()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getString(i interface{}) string {
|
||||||
|
switch v := i.(type) {
|
||||||
|
case string:
|
||||||
|
return v
|
||||||
|
case []byte:
|
||||||
|
return string(v)
|
||||||
|
case int:
|
||||||
|
return strconv.Itoa(v)
|
||||||
|
case bool:
|
||||||
|
return strconv.FormatBool(v)
|
||||||
|
default:
|
||||||
|
|
||||||
|
bytes, _ := json.Marshal(v)
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package pinduoduo
|
||||||
|
|
||||||
|
// GoodsPidGenerateResult 返回参数
|
||||||
|
type GoodsPidGenerateResult struct {
|
||||||
|
PIdGenerateResponse struct {
|
||||||
|
PIdList []struct {
|
||||||
|
CreateTime int `json:"create_time,omitempty"` // 推广位创建时间
|
||||||
|
PidName string `json:"pid_name,omitempty"` // 推广位名称
|
||||||
|
PId string `json:"p_id,omitempty"` // 调用方推广位ID
|
||||||
|
MediaId int `json:"media_id,omitempty"` // 媒体id
|
||||||
|
} `json:"p_id_list"`
|
||||||
|
RemainPidCount int `json:"remain_pid_count"` // PID剩余数量
|
||||||
|
} `json:"p_id_generate_response"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GoodsPidGenerate 创建多多进宝推广位 https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.pid.generate
|
||||||
|
func (app *App) GoodsPidGenerate(notMustParams ...Params) (body []byte, err error) {
|
||||||
|
// 参数
|
||||||
|
params := NewParamsWithType("pdd.ddk.goods.pid.generate", notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err = app.request(params)
|
||||||
|
return
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package pinduoduo
|
||||||
|
|
||||||
|
// GoodsRecommendGetResult 返回参数
|
||||||
|
type GoodsRecommendGetResult struct {
|
||||||
|
GoodsBasicDetailResponse struct {
|
||||||
|
List []struct {
|
||||||
|
ActivityPromotionRate int `json:"activity_promotion_rate"`
|
||||||
|
ActivityTags []int `json:"activity_tags"`
|
||||||
|
BrandName string `json:"brand_name"`
|
||||||
|
CashGiftAmount int `json:"cash_gift_amount"`
|
||||||
|
CatId string `json:"cat_id"`
|
||||||
|
CatIds []int `json:"cat_ids"`
|
||||||
|
CouponDiscount int64 `json:"coupon_discount"`
|
||||||
|
CouponEndTime int `json:"coupon_end_time"`
|
||||||
|
CouponMinOrderAmount int `json:"coupon_min_order_amount"`
|
||||||
|
CouponPrice int `json:"coupon_price"`
|
||||||
|
CouponRemainQuantity int `json:"coupon_remain_quantity"`
|
||||||
|
CouponStartTime int `json:"coupon_start_time"`
|
||||||
|
CouponTotalQuantity int `json:"coupon_total_quantity"`
|
||||||
|
CreateAt int `json:"create_at"`
|
||||||
|
DescTxt string `json:"desc_txt"`
|
||||||
|
ExtraCouponAmount int `json:"extra_coupon_amount"`
|
||||||
|
GoodsDesc string `json:"goods_desc"`
|
||||||
|
GoodsImageUrl string `json:"goods_image_url"`
|
||||||
|
GoodsLabels []int `json:"goods_labels"`
|
||||||
|
GoodsName string `json:"goods_name"`
|
||||||
|
GoodsRate int `json:"goods_rate"`
|
||||||
|
GoodsSign string `json:"goods_sign"`
|
||||||
|
GoodsThumbnailUrl string `json:"goods_thumbnail_url"`
|
||||||
|
GoodsType int `json:"goods_type"`
|
||||||
|
HasCoupon bool `json:"has_coupon"`
|
||||||
|
HasMaterial bool `json:"has_material"`
|
||||||
|
LgstTxt string `json:"lgst_txt"`
|
||||||
|
MallId int64 `json:"mall_id"`
|
||||||
|
MallName string `json:"mall_name"`
|
||||||
|
MarketFee int `json:"market_fee"`
|
||||||
|
MerchantType string `json:"merchant_type"`
|
||||||
|
MinGroupPrice int64 `json:"min_group_price"`
|
||||||
|
MinNormalPrice int `json:"min_normal_price"`
|
||||||
|
OptId string `json:"opt_id"`
|
||||||
|
OptIds []int `json:"opt_ids"`
|
||||||
|
OptName string `json:"opt_name"`
|
||||||
|
PredictPromotionRate int `json:"predict_promotion_rate"`
|
||||||
|
PromotionRate int64 `json:"promotion_rate"`
|
||||||
|
QrCodeImageUrl string `json:"qr_code_image_url"`
|
||||||
|
RealtimeSalesTip string `json:"realtime_sales_tip"`
|
||||||
|
SalesTip string `json:"sales_tip"`
|
||||||
|
SearchId string `json:"search_id"`
|
||||||
|
ServTxt string `json:"serv_txt"`
|
||||||
|
ShareDesc string `json:"share_desc"`
|
||||||
|
ShareRate int `json:"share_rate"`
|
||||||
|
SubsidyAmount int `json:"subsidy_amount"`
|
||||||
|
SubsidyDuoAmountTenMillion int `json:"subsidy_duo_amount_ten_million"`
|
||||||
|
UnifiedTags []string `json:"unified_tags"`
|
||||||
|
GoodsId int64 `json:"goods_id"`
|
||||||
|
CategoryId string `json:"category_id"`
|
||||||
|
CategoryName string `json:"category_name"`
|
||||||
|
} `json:"list"`
|
||||||
|
ListId string `json:"list_id"`
|
||||||
|
SearchId string `json:"search_id"`
|
||||||
|
Total int `json:"total"`
|
||||||
|
} `json:"goods_basic_detail_response"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GoodsRecommendGet 多多进宝商品推荐API https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.recommend.get
|
||||||
|
func (app *App) GoodsRecommendGet(notMustParams ...Params) (body []byte, err error) {
|
||||||
|
// 参数
|
||||||
|
params := NewParamsWithType("pdd.ddk.goods.recommend.get", notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err = app.request(params)
|
||||||
|
return
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
package pinduoduo
|
||||||
|
|
||||||
|
type GoodsSearchResult struct {
|
||||||
|
GoodsSearchResponse struct {
|
||||||
|
GoodsList []struct {
|
||||||
|
ActivityPromotionRate int `json:"activity_promotion_rate"`
|
||||||
|
ActivityTags []int `json:"activity_tags"`
|
||||||
|
ActivityType int `json:"activity_type"`
|
||||||
|
BrandName string `json:"brand_name"`
|
||||||
|
CashGiftAmount int `json:"cash_gift_amount"`
|
||||||
|
CatIds []int `json:"cat_ids"`
|
||||||
|
CltCpnBatchSn string `json:"clt_cpn_batch_sn"`
|
||||||
|
CltCpnDiscount int `json:"clt_cpn_discount"`
|
||||||
|
CltCpnEndTime int `json:"clt_cpn_end_time"`
|
||||||
|
CltCpnMinAmt int `json:"clt_cpn_min_amt"`
|
||||||
|
CltCpnQuantity int `json:"clt_cpn_quantity"`
|
||||||
|
CltCpnRemainQuantity int `json:"clt_cpn_remain_quantity"`
|
||||||
|
CltCpnStartTime int `json:"clt_cpn_start_time"`
|
||||||
|
CouponDiscount int64 `json:"coupon_discount"`
|
||||||
|
CouponEndTime int `json:"coupon_end_time"`
|
||||||
|
CouponMinOrderAmount int `json:"coupon_min_order_amount"`
|
||||||
|
CouponRemainQuantity int `json:"coupon_remain_quantity"`
|
||||||
|
CouponStartTime int `json:"coupon_start_time"`
|
||||||
|
CouponTotalQuantity int `json:"coupon_total_quantity"`
|
||||||
|
CreateAt int `json:"create_at"`
|
||||||
|
DescTxt string `json:"desc_txt"`
|
||||||
|
ExtraCouponAmount int `json:"extra_coupon_amount"`
|
||||||
|
GoodsDesc string `json:"goods_desc"`
|
||||||
|
GoodsImageUrl string `json:"goods_image_url"`
|
||||||
|
GoodsLabels []int `json:"goods_labels"`
|
||||||
|
GoodsName string `json:"goods_name"`
|
||||||
|
GoodsSign string `json:"goods_sign"`
|
||||||
|
GoodsThumbnailUrl string `json:"goods_thumbnail_url"`
|
||||||
|
HasCoupon bool `json:"has_coupon"`
|
||||||
|
HasMallCoupon bool `json:"has_mall_coupon"`
|
||||||
|
HasMaterial bool `json:"has_material"`
|
||||||
|
LgstTxt string `json:"lgst_txt"`
|
||||||
|
MallCouponDiscountPct int `json:"mall_coupon_discount_pct"`
|
||||||
|
MallCouponEndTime int `json:"mall_coupon_end_time"`
|
||||||
|
MallCouponId int `json:"mall_coupon_id"`
|
||||||
|
MallCouponMaxDiscountAmount int `json:"mall_coupon_max_discount_amount"`
|
||||||
|
MallCouponMinOrderAmount int `json:"mall_coupon_min_order_amount"`
|
||||||
|
MallCouponRemainQuantity int `json:"mall_coupon_remain_quantity"`
|
||||||
|
MallCouponStartTime int `json:"mall_coupon_start_time"`
|
||||||
|
MallCouponTotalQuantity int `json:"mall_coupon_total_quantity"`
|
||||||
|
MallCps int `json:"mall_cps"`
|
||||||
|
MallId int64 `json:"mall_id"`
|
||||||
|
MallName string `json:"mall_name"`
|
||||||
|
MerchantType int `json:"merchant_type"`
|
||||||
|
MinGroupPrice int64 `json:"min_group_price"`
|
||||||
|
MinNormalPrice int `json:"min_normal_price"`
|
||||||
|
OnlySceneAuth bool `json:"only_scene_auth"`
|
||||||
|
OptId int `json:"opt_id"`
|
||||||
|
OptIds []int `json:"opt_ids"`
|
||||||
|
OptName string `json:"opt_name"`
|
||||||
|
PlanType int `json:"plan_type"`
|
||||||
|
PredictPromotionRate int `json:"predict_promotion_rate"`
|
||||||
|
PromotionRate int64 `json:"promotion_rate"`
|
||||||
|
SalesTip string `json:"sales_tip"`
|
||||||
|
SearchId string `json:"search_id"`
|
||||||
|
ServTxt string `json:"serv_txt"`
|
||||||
|
ServiceTags []int `json:"service_tags"`
|
||||||
|
ShareRate int `json:"share_rate"`
|
||||||
|
SubsidyAmount int `json:"subsidy_amount"`
|
||||||
|
SubsidyDuoAmountTenMillion int `json:"subsidy_duo_amount_ten_million"`
|
||||||
|
UnifiedTags []string `json:"unified_tags"`
|
||||||
|
ZsDuoId int `json:"zs_duo_id"`
|
||||||
|
GoodsId int64 `json:"goods_id"`
|
||||||
|
CategoryId int64 `json:"category_id"`
|
||||||
|
CategoryName string `json:"category_name"`
|
||||||
|
} `json:"goods_list"`
|
||||||
|
ListId string `json:"list_id"`
|
||||||
|
SearchId string `json:"search_id"`
|
||||||
|
TotalCount int `json:"total_count"`
|
||||||
|
} `json:"goods_search_response"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GoodsSearch 多多进宝商品查询 https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.search
|
||||||
|
func (app *App) GoodsSearch(notMustParams ...Params) (body []byte, err error) {
|
||||||
|
// 参数
|
||||||
|
params := NewParamsWithType("pdd.ddk.goods.search", notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err = app.request(params)
|
||||||
|
return
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package pinduoduo
|
||||||
|
|
||||||
|
type OrderListIncrementGetResult struct {
|
||||||
|
OrderListGetResponse struct {
|
||||||
|
TotalCount int `json:"total_count"`
|
||||||
|
OrderList []struct {
|
||||||
|
SepMarketFee int `json:"sep_market_fee"`
|
||||||
|
GoodsPrice int64 `json:"goods_price"`
|
||||||
|
SepDuoId int `json:"sep_duo_id"`
|
||||||
|
PromotionRate int64 `json:"promotion_rate"`
|
||||||
|
Type int `json:"type"`
|
||||||
|
SubsidyDuoAmountLevel int `json:"subsidy_duo_amount_level"`
|
||||||
|
CatIds []int `json:"cat_ids"`
|
||||||
|
OrderStatus int `json:"order_status"`
|
||||||
|
OrderCreateTime int `json:"order_create_time"`
|
||||||
|
IsDirect int `json:"is_direct"`
|
||||||
|
OrderGroupSuccessTime int `json:"order_group_success_time"`
|
||||||
|
MallId int `json:"mall_id"`
|
||||||
|
OrderAmount int64 `json:"order_amount"`
|
||||||
|
PriceCompareStatus int `json:"price_compare_status"`
|
||||||
|
OrderModifyAt int `json:"order_modify_at"`
|
||||||
|
AuthDuoId int `json:"auth_duo_id"`
|
||||||
|
CpaNew int `json:"cpa_new"`
|
||||||
|
GoodsName string `json:"goods_name"`
|
||||||
|
BatchNo string `json:"batch_no"`
|
||||||
|
RedPacketType int `json:"red_packet_type"`
|
||||||
|
GoodsQuantity int `json:"goods_quantity"`
|
||||||
|
FailReason string `json:"fail_reason,omitempty"`
|
||||||
|
GoodsId int64 `json:"goods_id"`
|
||||||
|
SepParameters string `json:"sep_parameters"`
|
||||||
|
SepRate int `json:"sep_rate"`
|
||||||
|
SubsidyType int `json:"subsidy_type"`
|
||||||
|
CustomParameters string `json:"custom_parameters"`
|
||||||
|
GoodsThumbnailUrl string `json:"goods_thumbnail_url"`
|
||||||
|
ShareRate int `json:"share_rate"`
|
||||||
|
PromotionAmount int64 `json:"promotion_amount"`
|
||||||
|
OrderPayTime int64 `json:"order_pay_time"`
|
||||||
|
OrderReceiveTime int64 `json:"order_receive_time"`
|
||||||
|
OrderSettleTime int64 `json:"order_settle_time"`
|
||||||
|
ActivityTags []int `json:"activity_tags"`
|
||||||
|
GroupId int64 `json:"group_id"`
|
||||||
|
SepPid string `json:"sep_pid"`
|
||||||
|
OrderStatusDesc string `json:"order_status_desc"`
|
||||||
|
ShareAmount int `json:"share_amount"`
|
||||||
|
OrderId string `json:"order_id"`
|
||||||
|
GoodsSign string `json:"goods_sign"`
|
||||||
|
OrderSn string `json:"order_sn"`
|
||||||
|
OrderVerifyTime int64 `json:"order_verify_time"`
|
||||||
|
PId string `json:"p_id"`
|
||||||
|
ZsDuoId int `json:"zs_duo_id"`
|
||||||
|
} `json:"order_list"`
|
||||||
|
RequestId string `json:"request_id"`
|
||||||
|
} `json:"order_list_get_response"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) OrderListIncrementGet(notMustParams ...Params) (body []byte, err error) {
|
||||||
|
// 参数
|
||||||
|
params := NewParamsWithType("pdd.ddk.order.list.increment.get", notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err = app.request(params)
|
||||||
|
return
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package pinduoduo
|
||||||
|
|
||||||
|
// ResourceUrlGenResult 返回参数
|
||||||
|
type ResourceUrlGenResult struct {
|
||||||
|
ResourceUrlResponse struct {
|
||||||
|
MultiUrlList struct {
|
||||||
|
ShortUrl string `json:"short_url"` // 频道推广短链接
|
||||||
|
Url string `json:"url"` // 频道推广长链接
|
||||||
|
} `json:"multi_url_list"` // 多人团链接
|
||||||
|
Sign string `json:"sign,omitempty"` // sign
|
||||||
|
SingleUrlList struct {
|
||||||
|
ShortUrl string `json:"short_url"` // 频道推广短链接
|
||||||
|
Url string `json:"url"` // 频道推广长链接
|
||||||
|
} `json:"single_url_list"` // 单人团链接
|
||||||
|
WeAppInfo struct {
|
||||||
|
AppId string `json:"app_id"` // 小程序id
|
||||||
|
BannerUrl string `json:"banner_url"` // Banner图
|
||||||
|
Desc string `json:"desc"` // 描述
|
||||||
|
PagePath string `json:"page_path"` // 小程序path值
|
||||||
|
SourceDisplayName string `json:"source_display_name"` // 来源名
|
||||||
|
Title string `json:"title"` // 小程序标题
|
||||||
|
UserName string `json:"user_name"` // 用户名
|
||||||
|
WeAppIconUrl string `json:"we_app_icon_url"` // 小程序icon
|
||||||
|
} `json:"we_app_info"` // 拼多多福利券微信小程序信息
|
||||||
|
} `json:"resource_url_response"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResourceUrlGen 创建多多进宝推广位 https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.pid.generate
|
||||||
|
func (app *App) ResourceUrlGen(notMustParams ...Params) (body []byte, err error) {
|
||||||
|
// 参数
|
||||||
|
params := NewParamsWithType("pdd.ddk.resource.url.gen", notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err = app.request(params)
|
||||||
|
return
|
||||||
|
}
|
@ -1,95 +0,0 @@
|
|||||||
package pinduoduo
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"crypto/md5"
|
|
||||||
"encoding/hex"
|
|
||||||
"github.com/bitly/go-simplejson"
|
|
||||||
"github.com/dtapps/go-library/utils/goparams"
|
|
||||||
"io"
|
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
|
||||||
"net/url"
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const api = "https://gw-api.pinduoduo.com/api/router"
|
|
||||||
|
|
||||||
// Parameter 参数
|
|
||||||
type Parameter map[string]interface{}
|
|
||||||
|
|
||||||
// ParameterEncode 参数
|
|
||||||
type ParameterEncode []string
|
|
||||||
|
|
||||||
// PinDuoDuo 公共请求参数
|
|
||||||
type PinDuoDuo struct {
|
|
||||||
ClientId string //必填 POP分配给应用的client_id
|
|
||||||
ClientSecret string //必填 POP分配给应用的client_secret
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *PinDuoDuo) Send(method string, param Parameter) (*simplejson.Json, error) {
|
|
||||||
// 处理数据
|
|
||||||
param["type"] = method
|
|
||||||
param.setRequestData(d)
|
|
||||||
// 请求
|
|
||||||
resp, err := http.Post(api, "application/x-www-form-urlencoded;charset=utf-8", strings.NewReader(param.getRequestData()))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
// 返回结果
|
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
|
||||||
respJson, err := simplejson.NewJson(body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return respJson, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 签名数据
|
|
||||||
func sign(params Parameter, clientSecret string) string {
|
|
||||||
// 参数按照参数名的字典升序排列
|
|
||||||
var keys []string
|
|
||||||
for k := range params {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
sort.Strings(keys)
|
|
||||||
// 拼接参数
|
|
||||||
query := bytes.NewBufferString(clientSecret)
|
|
||||||
for _, k := range keys {
|
|
||||||
query.WriteString(k)
|
|
||||||
query.WriteString(goparams.GetParamsString(params[k]))
|
|
||||||
}
|
|
||||||
query.WriteString(clientSecret)
|
|
||||||
// MD5加密
|
|
||||||
h := md5.New()
|
|
||||||
io.Copy(h, query)
|
|
||||||
// 把二进制转化为大写的十六进制
|
|
||||||
return strings.ToUpper(hex.EncodeToString(h.Sum(nil)))
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置请求数据
|
|
||||||
func (p Parameter) setRequestData(d *PinDuoDuo) {
|
|
||||||
hh, _ := time.ParseDuration("8h")
|
|
||||||
loc := time.Now().UTC().Add(hh)
|
|
||||||
p["timestamp"] = strconv.FormatInt(loc.Unix(), 10)
|
|
||||||
p["client_id"] = d.ClientId
|
|
||||||
p["data_type"] = "JSON"
|
|
||||||
p["version"] = "v1"
|
|
||||||
// 设置签名
|
|
||||||
p["sign"] = sign(p, d.ClientSecret)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取请求数据
|
|
||||||
func (p Parameter) getRequestData() string {
|
|
||||||
// 公共参数
|
|
||||||
args := url.Values{}
|
|
||||||
// 请求参数
|
|
||||||
for key, val := range p {
|
|
||||||
args.Set(key, goparams.GetParamsString(val))
|
|
||||||
}
|
|
||||||
return args.Encode()
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package _type
|
|
||||||
|
|
||||||
const (
|
|
||||||
GoodsPidGenerate = "pdd.ddk.goods.pid.generate"
|
|
||||||
GoodsSearch = "pdd.ddk.goods.search" // 多多进宝商品查询 https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.search
|
|
||||||
GoodsDetail = "pdd.ddk.goods.detail" // 多多进宝商品详情查询 https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.detail
|
|
||||||
)
|
|
Loading…
Reference in new issue