123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- <?php
- namespace App\Http\Utils\Pdd;
- use App\Http\Bean\Util\Pdd\Ddk\GoodsDetailParamBean;
- use App\Http\Bean\Util\Pdd\Ddk\GoodsPromotionUrlGenerateParamBean;
- use App\Http\Bean\Util\Pdd\Ddk\GoodsRecommendGetParamBean;
- use App\Http\Bean\Util\Pdd\Ddk\GoodsSearchParamBean;
- use App\Http\Bean\Util\Pdd\Ddk\OrderListIncrementGetParamBean;
- use App\Http\Bean\Util\Pdd\Ddk\OrderListRangeGetParamBean;
- use App\Http\Bean\Util\Pdd\Ddk\ResourceUrlGenParamBean;
- use App\Http\Utils\BaseUtil;
- use Tool\ShanTaoTool\HttpCurl;
- class DuoDuoKeUtil extends BaseUtil
- {
- /**
- * 拼多多请求地址
- * @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"] = json_encode($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);
- // dump(self::$url);
- // dd($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;
- }
- /**
- * 查询是否绑定备案
- * @param $p_id string 推广位ID
- * @return mixed
- */
- public static function memberAuthorityQuery($p_id)
- {
- $params = [
- "type"=>"pdd.ddk.member.authority.query",
- "pid"=>$p_id
- ];
- $params = self::getSign($params);
- $res = HttpCurl::postCurl(self::$url,$params);
- return $res;
- }
- /**
- * 获取拼多多增量订单
- * @param OrderListIncrementGetParamBean $orderListIncrementGetParamBean
- * @return mixed
- */
- public static function orderListIncrementGet(OrderListIncrementGetParamBean $orderListIncrementGetParamBean)
- {
- $params = [
- "type"=>"pdd.ddk.order.list.increment.get",
- ];
- if ($orderListIncrementGetParamBean->getCashGiftOrder()){
- $params["cash_gift_order"] = $orderListIncrementGetParamBean->getCashGiftOrder();
- }
- if($orderListIncrementGetParamBean->getPage()){
- $params["page"] = $orderListIncrementGetParamBean->getPage();
- }
- if($orderListIncrementGetParamBean->getPageSize()){
- $params["page_size"] = $orderListIncrementGetParamBean->getPageSize();
- }
- if($orderListIncrementGetParamBean->getEndUpdateTime()){
- $params["end_update_time"] = $orderListIncrementGetParamBean->getEndUpdateTime();
- }
- if($orderListIncrementGetParamBean->getStartUpdateTime()){
- $params["start_update_time"] = $orderListIncrementGetParamBean->getStartUpdateTime();
- }
- if($orderListIncrementGetParamBean->getReturnCount()){
- $params["return_count"] = $orderListIncrementGetParamBean->getReturnCount();
- }
- if($orderListIncrementGetParamBean->getQueryOrderType()){
- $params["query_order_type"] = $orderListIncrementGetParamBean->getQueryOrderType();
- }
- $params = self::getSign($params);
- $res = HttpCurl::postCurl(self::$url,$params);
- return $res;
- }
- }
|