|
@@ -0,0 +1,447 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace Tool\ShanTaoTool\Pdd\Ddk;
|
|
|
+
|
|
|
+
|
|
|
+use Tool\ShanTaoTool\Bean\Pdd\Ddk\GoodsDetailParamBean;
|
|
|
+use Tool\ShanTaoTool\Bean\Pdd\Ddk\GoodsPromotionUrlGenerateParamBean;
|
|
|
+use Tool\ShanTaoTool\Bean\Pdd\Ddk\GoodsRecommendGetParamBean;
|
|
|
+use Tool\ShanTaoTool\Bean\Pdd\Ddk\GoodsSearchParamBean;
|
|
|
+use Tool\ShanTaoTool\Bean\Pdd\Ddk\OrderListRangeGetParamBean;
|
|
|
+use Tool\ShanTaoTool\Bean\Pdd\Ddk\ResourceUrlGenParamBean;
|
|
|
+use Tool\ShanTaoTool\HttpCurl;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 多多客导购服务类
|
|
|
+ * Class DdkDaogouService
|
|
|
+ * @package Tool\ShanTaoTool\Pdd\Ddk
|
|
|
+ */
|
|
|
+class DdkDaogouService
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * 拼多多请求地址
|
|
|
+ * @var string
|
|
|
+ */
|
|
|
+ public static $url = "https://gw-api.pinduoduo.com/api/router";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成签名
|
|
|
+ * @param $params
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public static function getSign($params)
|
|
|
+ {
|
|
|
+ $client_secret = env("PDD_CLIENT_SECRET");
|
|
|
+ //公共参数
|
|
|
+ $commonParams = [
|
|
|
+ "client_id"=>env("PDD_CLIENT_ID"),
|
|
|
+ "timestamp"=>time()
|
|
|
+ ];
|
|
|
+
|
|
|
+ $params = array_merge($commonParams,$params);
|
|
|
+
|
|
|
+ //字典升序排列
|
|
|
+ ksort($params);
|
|
|
+
|
|
|
+ $str = "";
|
|
|
+ foreach ($params as $key=>$val){
|
|
|
+ $str .= $key.$val;
|
|
|
+ }
|
|
|
+ $str = $client_secret.$str.$client_secret;
|
|
|
+ $sign = strtoupper(md5($str));
|
|
|
+ $params["sign"] = $sign;
|
|
|
+ return $params;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成多多进宝频道推广
|
|
|
+ * @param ResourceUrlGenParamBean $resourceUrlGenParamBean
|
|
|
+ */
|
|
|
+ public static function resourceUrlGen(ResourceUrlGenParamBean $resourceUrlGenParamBean)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "type"=>"pdd.ddk.resource.url.gen",
|
|
|
+ "pid"=>$resourceUrlGenParamBean->getPid(),
|
|
|
+ "resource_type"=>$resourceUrlGenParamBean->getResourceType()
|
|
|
+ ];
|
|
|
+ if($resourceUrlGenParamBean->getCustomParameters()){
|
|
|
+ $params["custom_parameters"] = $resourceUrlGenParamBean->getCustomParameters();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($resourceUrlGenParamBean->getGenerateWeApp()){
|
|
|
+ $params["generate_we_app"] = $resourceUrlGenParamBean->getGenerateWeApp();
|
|
|
+ }
|
|
|
+ if($resourceUrlGenParamBean->getUrl()){
|
|
|
+ $params["url"] = $resourceUrlGenParamBean->getUrl();
|
|
|
+ }
|
|
|
+ $params = self::getSign($params);
|
|
|
+ $res = HttpCurl::postCurl(self::$url,$params);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量绑定推广位的媒体id
|
|
|
+ * @param $mediaId int 媒体ID
|
|
|
+ * @param array $pidList 推广位列表
|
|
|
+ */
|
|
|
+ public static function pidMediaidBind($mediaId, array $pidList)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "type"=>"pdd.ddk.pid.mediaid.bind",
|
|
|
+ "media_id"=>$mediaId,
|
|
|
+ "pid_list"=>$pidList
|
|
|
+ ];
|
|
|
+ $params = self::getSign($params);
|
|
|
+ $res = HttpCurl::postCurl(self::$url,$params);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建多多进宝推广位
|
|
|
+ * @param $number int 要生成的推广位数量
|
|
|
+ * @param $pidNameList array 推广位名称['1','2']
|
|
|
+ * @param $mediaId int 媒体ID
|
|
|
+ */
|
|
|
+ public static function goodsPidGenerate($number, $pidNameList=[], $mediaId=0)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "type"=>"pdd.ddk.goods.pid.generate",
|
|
|
+ "number"=>$number
|
|
|
+ ];
|
|
|
+ if ($pidNameList){
|
|
|
+ $params["p_id_name_list"] = $pidNameList;
|
|
|
+ }
|
|
|
+ if($mediaId){
|
|
|
+ $params["media_id"] = $mediaId;
|
|
|
+ }
|
|
|
+ $params = self::getSign($params);
|
|
|
+ $res = HttpCurl::postCurl(self::$url,$params);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $page int 第几页
|
|
|
+ * @param $pageSize int 每页数量
|
|
|
+ * @param $status int 推广位状态
|
|
|
+ */
|
|
|
+ public static function goodsPidQuery($page, $pageSize, $status)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "type"=>"pdd.ddk.goods.pid.query",
|
|
|
+ "page"=>$page,
|
|
|
+ "page_size"=>$pageSize,
|
|
|
+ "status"=>$status
|
|
|
+ ];
|
|
|
+ $params = self::getSign($params);
|
|
|
+ $res = HttpCurl::postCurl(self::$url,$params);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用时间段查询推广订单接口
|
|
|
+ * @param OrderListRangeGetParamBean $orderListRangeGetParamBean
|
|
|
+ */
|
|
|
+ public static function orderListRangeGet(OrderListRangeGetParamBean $orderListRangeGetParamBean)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "type"=>"pdd.ddk.order.list.range.get",
|
|
|
+ "start_time"=>$orderListRangeGetParamBean->getStartTime(),
|
|
|
+ "end_time"=>$orderListRangeGetParamBean->getEndTime(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ if($orderListRangeGetParamBean->getPageSize()){
|
|
|
+ $params["page_size"] = $orderListRangeGetParamBean->getPageSize();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($orderListRangeGetParamBean->getCashGiftOrder()){
|
|
|
+ $params["cash_gift_order"] = $orderListRangeGetParamBean->getCashGiftOrder();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($orderListRangeGetParamBean->getLastOrderId()){
|
|
|
+ $params["last_order_id"] = $orderListRangeGetParamBean->getLastOrderId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($orderListRangeGetParamBean->getQueryOrderType()){
|
|
|
+ $params["query_order_type"] = $orderListRangeGetParamBean->getQueryOrderType();
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = self::getSign($params);
|
|
|
+ $res = HttpCurl::postCurl(self::$url,$params);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询订单详情
|
|
|
+ * @param $orderSn string 订单编号
|
|
|
+ * @param $queryOrderType int 订单类型:1-推广订单;2-直播间订单
|
|
|
+ */
|
|
|
+ public static function orderDetailGet($orderSn, $queryOrderType=0)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "type"=>"pdd.ddk.order.detail.get",
|
|
|
+ "order_sn"=>$orderSn
|
|
|
+ ];
|
|
|
+ if($queryOrderType){
|
|
|
+ $params["query_order_type"] = $queryOrderType;
|
|
|
+ }
|
|
|
+ $params = self::getSign($params);
|
|
|
+ $res = HttpCurl::postCurl(self::$url,$params);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 多多进宝商品详情查询
|
|
|
+ * @param GoodsDetailParamBean $goodsDetailParamBean
|
|
|
+ */
|
|
|
+ public static function goodsDetail(GoodsDetailParamBean $goodsDetailParamBean)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "type"=>"pdd.ddk.goods.detail"
|
|
|
+ ];
|
|
|
+
|
|
|
+ if($goodsDetailParamBean->getCustomParameters()){
|
|
|
+ $params["custom_parameters"] = $goodsDetailParamBean->getCustomParameters();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsDetailParamBean->getGoodsSign()){
|
|
|
+ $params["goods_sign"] = $goodsDetailParamBean->getGoodsSign();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsDetailParamBean->getPid()){
|
|
|
+ $params["pid"] = $goodsDetailParamBean->getPid();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsDetailParamBean->getSearchId()){
|
|
|
+ $params["search_id"] = $goodsDetailParamBean->getSearchId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsDetailParamBean->getZsDuoId()){
|
|
|
+ $params["zs_duo_id"] = $goodsDetailParamBean->getZsDuoId();
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = self::getSign($params);
|
|
|
+ $res = HttpCurl::postCurl(self::$url,$params);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 多多进宝推广链接生成
|
|
|
+ * @param GoodsPromotionUrlGenerateParamBean $goodsPromotionUrlGenerateParamBean
|
|
|
+ */
|
|
|
+ public static function goodsPromotionUrlGenerate(GoodsPromotionUrlGenerateParamBean $goodsPromotionUrlGenerateParamBean)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "type"=>"pdd.ddk.goods.promotion.url.generate",
|
|
|
+ "p_id"=>$goodsPromotionUrlGenerateParamBean->getPId()
|
|
|
+ ];
|
|
|
+
|
|
|
+ if($goodsPromotionUrlGenerateParamBean->getCashGiftId()){
|
|
|
+ $params["cash_gift_id"] = $goodsPromotionUrlGenerateParamBean->getCashGiftId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsPromotionUrlGenerateParamBean->getCashGiftName()){
|
|
|
+ $params["cash_gift_name"] = $goodsPromotionUrlGenerateParamBean->getCashGiftName();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsPromotionUrlGenerateParamBean->getCustomParameters()){
|
|
|
+ $params["custom_parameters"] = $goodsPromotionUrlGenerateParamBean->getCustomParameters();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsPromotionUrlGenerateParamBean->getGenerateAuthorityUrl()){
|
|
|
+ $params["generate_authority_url"] = $goodsPromotionUrlGenerateParamBean->getGenerateAuthorityUrl();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsPromotionUrlGenerateParamBean->getGenerateMallCollectCoupon()){
|
|
|
+ $params["generate_mall_collect_coupon"] = $goodsPromotionUrlGenerateParamBean->getGenerateMallCollectCoupon();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsPromotionUrlGenerateParamBean->getGenerateQqApp()){
|
|
|
+ $params["generate_qq_app"] = $goodsPromotionUrlGenerateParamBean->getGenerateQqApp();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsPromotionUrlGenerateParamBean->getGenerateSchemaUrl()){
|
|
|
+ $params["generate_schema_url"] = $goodsPromotionUrlGenerateParamBean->getGenerateSchemaUrl();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsPromotionUrlGenerateParamBean->getGenerateShortUrl()){
|
|
|
+ $params["generate_short_url"] = $goodsPromotionUrlGenerateParamBean->getGenerateShortUrl();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsPromotionUrlGenerateParamBean->getGenerateWeApp()){
|
|
|
+ $params["generate_we_app"] = $goodsPromotionUrlGenerateParamBean->getGenerateWeApp();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsPromotionUrlGenerateParamBean->getGoodsSignList()){
|
|
|
+ $params["goods_sign_list"] = $goodsPromotionUrlGenerateParamBean->getGoodsSignList();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsPromotionUrlGenerateParamBean->getMultiGroup()){
|
|
|
+ $params["multi_group"] = $goodsPromotionUrlGenerateParamBean->getMultiGroup();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsPromotionUrlGenerateParamBean->getSearchId()){
|
|
|
+ $params["search_id"] = $goodsPromotionUrlGenerateParamBean->getSearchId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsPromotionUrlGenerateParamBean->getZsDuoId()){
|
|
|
+ $params["zs_duo_id"] = $goodsPromotionUrlGenerateParamBean->getZsDuoId();
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = self::getSign($params);
|
|
|
+ $res = HttpCurl::postCurl(self::$url,$params);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 多多进宝商品推荐API
|
|
|
+ * @param GoodsRecommendGetParamBean $goodsRecommendGetParamBean
|
|
|
+ */
|
|
|
+ public static function goodsRecommendGet(GoodsRecommendGetParamBean $goodsRecommendGetParamBean)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "type"=>"pdd.ddk.goods.recommend.get"
|
|
|
+ ];
|
|
|
+
|
|
|
+ if($goodsRecommendGetParamBean->getActivityTags()){
|
|
|
+ $params["activity_tags"] = $goodsRecommendGetParamBean->getActivityTags();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsRecommendGetParamBean->getCatId()){
|
|
|
+ $params["cat_id"] = $goodsRecommendGetParamBean->getCatId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsRecommendGetParamBean->getChannelType()){
|
|
|
+ $params["channel_type"] = $goodsRecommendGetParamBean->getChannelType();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsRecommendGetParamBean->getCustomParameters()){
|
|
|
+ $params["custom_parameters"] = $goodsRecommendGetParamBean->getCustomParameters();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsRecommendGetParamBean->getGoodsSignList()){
|
|
|
+ $params["goods_sign_list"] = $goodsRecommendGetParamBean->getGoodsSignList();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsRecommendGetParamBean->getLimit()){
|
|
|
+ $params["limit"] = $goodsRecommendGetParamBean->getLimit();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsRecommendGetParamBean->getListId()){
|
|
|
+ $params["list_id"] = $goodsRecommendGetParamBean->getListId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsRecommendGetParamBean->getOffset()){
|
|
|
+ $params["offset"] = $goodsRecommendGetParamBean->getOffset();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsRecommendGetParamBean->getPid()){
|
|
|
+ $params["pid"] = $goodsRecommendGetParamBean->getPid();
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = self::getSign($params);
|
|
|
+ $res = HttpCurl::postCurl(self::$url,$params);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 多多进宝商品查询
|
|
|
+ * @param GoodsSearchParamBean $goodsSearchParamBean
|
|
|
+ */
|
|
|
+ public static function goodsSearch(GoodsSearchParamBean $goodsSearchParamBean)
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "type"=>"pdd.ddk.goods.search"
|
|
|
+ ];
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getActivityTags()){
|
|
|
+ $params["activity_tags"] = $goodsSearchParamBean->getActivityTags();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getBlockCats()){
|
|
|
+ $params["block_cats"] = $goodsSearchParamBean->getBlockCats();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getBlockCatPackages()){
|
|
|
+ $params["block_cat_packages"] = $goodsSearchParamBean->getBlockCatPackages();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getCatId()){
|
|
|
+ $params["cat_id"] = $goodsSearchParamBean->getCatId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getCustomParameters()){
|
|
|
+ $params["custom_parameters"] = $goodsSearchParamBean->getCustomParameters();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getGoodsSignList()){
|
|
|
+ $params["goods_sign_list"] = $goodsSearchParamBean->getGoodsSignList();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getIsBrandGoods()){
|
|
|
+ $params["is_brand_goods"] = $goodsSearchParamBean->getIsBrandGoods();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getKeyword()){
|
|
|
+ $params["keyword"] = $goodsSearchParamBean->getKeyword();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getListId()){
|
|
|
+ $params["list_id"] = $goodsSearchParamBean->getListId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getMerchantType()){
|
|
|
+ $params["merchant_type"] = $goodsSearchParamBean->getMerchantType();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getMerchantTypeList()){
|
|
|
+ $params["merchant_type_list"] = $goodsSearchParamBean->getMerchantTypeList();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getOptId()){
|
|
|
+ $params["opt_id"] = $goodsSearchParamBean->getOptId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getPage()){
|
|
|
+ $params["page"] = $goodsSearchParamBean->getPage();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getPageSize()){
|
|
|
+ $params["page_size"] = $goodsSearchParamBean->getPageSize();
|
|
|
+ }
|
|
|
+
|
|
|
+ if($goodsSearchParamBean->getPid()){
|
|
|
+ $params["pid"] = $goodsSearchParamBean->getPid();
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = self::getSign($params);
|
|
|
+ $res = HttpCurl::postCurl(self::$url,$params);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 多多进宝转链接口
|
|
|
+ * @param $pid string 推广位ID
|
|
|
+ * @param $sourceUrl string 商品链接
|
|
|
+ * @param array $customParameters 自定义参数
|
|
|
+ */
|
|
|
+ public static function goodsZsUnitUrlGen($pid,$sourceUrl="",$customParameters=[])
|
|
|
+ {
|
|
|
+ $params = [
|
|
|
+ "type"=>"pdd.ddk.goods.zs.unit.url.gen",
|
|
|
+ "pid"=>$pid
|
|
|
+ ];
|
|
|
+ if ($sourceUrl){
|
|
|
+ $params["source_url"] = $sourceUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($customParameters){
|
|
|
+ $params["custom_parameters"] = $customParameters;
|
|
|
+ }
|
|
|
+
|
|
|
+ $params = self::getSign($params);
|
|
|
+ $res = HttpCurl::postCurl(self::$url,$params);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|