DuoDuoKeUtil.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <?php
  2. namespace App\Http\Utils\Pdd;
  3. use App\Http\Bean\Util\Pdd\Ddk\GoodsDetailParamBean;
  4. use App\Http\Bean\Util\Pdd\Ddk\GoodsPromotionUrlGenerateParamBean;
  5. use App\Http\Bean\Util\Pdd\Ddk\GoodsRecommendGetParamBean;
  6. use App\Http\Bean\Util\Pdd\Ddk\GoodsSearchParamBean;
  7. use App\Http\Bean\Util\Pdd\Ddk\OrderListIncrementGetParamBean;
  8. use App\Http\Bean\Util\Pdd\Ddk\OrderListRangeGetParamBean;
  9. use App\Http\Bean\Util\Pdd\Ddk\ResourceUrlGenParamBean;
  10. use App\Http\Utils\BaseUtil;
  11. use Tool\ShanTaoTool\HttpCurl;
  12. class DuoDuoKeUtil extends BaseUtil
  13. {
  14. /**
  15. * 拼多多请求地址
  16. * @var string
  17. */
  18. public static $url = "https://gw-api.pinduoduo.com/api/router";
  19. /**
  20. * 生成签名
  21. * @param $params
  22. * @return array
  23. */
  24. public static function getSign($params)
  25. {
  26. $client_secret = env("PDD_CLIENT_SECRET");
  27. //公共参数
  28. $commonParams = [
  29. "client_id"=>env("PDD_CLIENT_ID"),
  30. "timestamp"=>time()
  31. ];
  32. $params = array_merge($commonParams,$params);
  33. //字典升序排列
  34. ksort($params);
  35. $str = "";
  36. foreach ($params as $key=>$val){
  37. $str .= $key.$val;
  38. }
  39. $str = $client_secret.$str.$client_secret;
  40. $sign = strtoupper(md5($str));
  41. $params["sign"] = $sign;
  42. return $params;
  43. }
  44. /**
  45. * 生成多多进宝频道推广
  46. * @param ResourceUrlGenParamBean $resourceUrlGenParamBean
  47. */
  48. public static function resourceUrlGen(ResourceUrlGenParamBean $resourceUrlGenParamBean)
  49. {
  50. $params = [
  51. "type"=>"pdd.ddk.resource.url.gen",
  52. "pid"=>$resourceUrlGenParamBean->getPid(),
  53. "resource_type"=>$resourceUrlGenParamBean->getResourceType()
  54. ];
  55. if($resourceUrlGenParamBean->getCustomParameters()){
  56. $params["custom_parameters"] = $resourceUrlGenParamBean->getCustomParameters();
  57. }
  58. if($resourceUrlGenParamBean->getGenerateWeApp()){
  59. $params["generate_we_app"] = $resourceUrlGenParamBean->getGenerateWeApp();
  60. }
  61. if($resourceUrlGenParamBean->getUrl()){
  62. $params["url"] = $resourceUrlGenParamBean->getUrl();
  63. }
  64. $params = self::getSign($params);
  65. $res = HttpCurl::postCurl(self::$url,$params);
  66. return $res;
  67. }
  68. /**
  69. * 批量绑定推广位的媒体id
  70. * @param $mediaId int 媒体ID
  71. * @param array $pidList 推广位列表
  72. */
  73. public static function pidMediaidBind($mediaId, array $pidList)
  74. {
  75. $params = [
  76. "type"=>"pdd.ddk.pid.mediaid.bind",
  77. "media_id"=>$mediaId,
  78. "pid_list"=>$pidList
  79. ];
  80. $params = self::getSign($params);
  81. $res = HttpCurl::postCurl(self::$url,$params);
  82. return $res;
  83. }
  84. /**
  85. * 创建多多进宝推广位
  86. * @param $number int 要生成的推广位数量
  87. * @param $pidNameList array 推广位名称['1','2']
  88. * @param $mediaId int 媒体ID
  89. */
  90. public static function goodsPidGenerate($number, $pidNameList=[], $mediaId=0)
  91. {
  92. $params = [
  93. "type"=>"pdd.ddk.goods.pid.generate",
  94. "number"=>$number
  95. ];
  96. if ($pidNameList){
  97. $params["p_id_name_list"] = json_encode($pidNameList);
  98. }
  99. if($mediaId){
  100. $params["media_id"] = $mediaId;
  101. }
  102. $params = self::getSign($params);
  103. $res = HttpCurl::postCurl(self::$url,$params);
  104. return $res;
  105. }
  106. /**
  107. * @param $page int 第几页
  108. * @param $pageSize int 每页数量
  109. * @param $status int 推广位状态
  110. */
  111. public static function goodsPidQuery($page, $pageSize, $status)
  112. {
  113. $params = [
  114. "type"=>"pdd.ddk.goods.pid.query",
  115. "page"=>$page,
  116. "page_size"=>$pageSize,
  117. "status"=>$status
  118. ];
  119. $params = self::getSign($params);
  120. $res = HttpCurl::postCurl(self::$url,$params);
  121. return $res;
  122. }
  123. /**
  124. * 用时间段查询推广订单接口
  125. * @param OrderListRangeGetParamBean $orderListRangeGetParamBean
  126. */
  127. public static function orderListRangeGet(OrderListRangeGetParamBean $orderListRangeGetParamBean)
  128. {
  129. $params = [
  130. "type"=>"pdd.ddk.order.list.range.get",
  131. "start_time"=>$orderListRangeGetParamBean->getStartTime(),
  132. "end_time"=>$orderListRangeGetParamBean->getEndTime(),
  133. ];
  134. if($orderListRangeGetParamBean->getPageSize()){
  135. $params["page_size"] = $orderListRangeGetParamBean->getPageSize();
  136. }
  137. if($orderListRangeGetParamBean->getCashGiftOrder()){
  138. $params["cash_gift_order"] = $orderListRangeGetParamBean->getCashGiftOrder();
  139. }
  140. if($orderListRangeGetParamBean->getLastOrderId()){
  141. $params["last_order_id"] = $orderListRangeGetParamBean->getLastOrderId();
  142. }
  143. if($orderListRangeGetParamBean->getQueryOrderType()){
  144. $params["query_order_type"] = $orderListRangeGetParamBean->getQueryOrderType();
  145. }
  146. $params = self::getSign($params);
  147. $res = HttpCurl::postCurl(self::$url,$params);
  148. return $res;
  149. }
  150. /**
  151. * 查询订单详情
  152. * @param $orderSn string 订单编号
  153. * @param $queryOrderType int 订单类型:1-推广订单;2-直播间订单
  154. */
  155. public static function orderDetailGet($orderSn, $queryOrderType=0)
  156. {
  157. $params = [
  158. "type"=>"pdd.ddk.order.detail.get",
  159. "order_sn"=>$orderSn
  160. ];
  161. if($queryOrderType){
  162. $params["query_order_type"] = $queryOrderType;
  163. }
  164. $params = self::getSign($params);
  165. $res = HttpCurl::postCurl(self::$url,$params);
  166. return $res;
  167. }
  168. /**
  169. * 多多进宝商品详情查询
  170. * @param GoodsDetailParamBean $goodsDetailParamBean
  171. */
  172. public static function goodsDetail(GoodsDetailParamBean $goodsDetailParamBean)
  173. {
  174. $params = [
  175. "type"=>"pdd.ddk.goods.detail"
  176. ];
  177. if($goodsDetailParamBean->getCustomParameters()){
  178. $params["custom_parameters"] = $goodsDetailParamBean->getCustomParameters();
  179. }
  180. if($goodsDetailParamBean->getGoodsSign()){
  181. $params["goods_sign"] = $goodsDetailParamBean->getGoodsSign();
  182. }
  183. if($goodsDetailParamBean->getPid()){
  184. $params["pid"] = $goodsDetailParamBean->getPid();
  185. }
  186. if($goodsDetailParamBean->getSearchId()){
  187. $params["search_id"] = $goodsDetailParamBean->getSearchId();
  188. }
  189. if($goodsDetailParamBean->getZsDuoId()){
  190. $params["zs_duo_id"] = $goodsDetailParamBean->getZsDuoId();
  191. }
  192. $params = self::getSign($params);
  193. $res = HttpCurl::postCurl(self::$url,$params);
  194. return $res;
  195. }
  196. /**
  197. * 多多进宝推广链接生成
  198. * @param GoodsPromotionUrlGenerateParamBean $goodsPromotionUrlGenerateParamBean
  199. */
  200. public static function goodsPromotionUrlGenerate(GoodsPromotionUrlGenerateParamBean $goodsPromotionUrlGenerateParamBean)
  201. {
  202. $params = [
  203. "type"=>"pdd.ddk.goods.promotion.url.generate",
  204. "p_id"=>$goodsPromotionUrlGenerateParamBean->getPId()
  205. ];
  206. if($goodsPromotionUrlGenerateParamBean->getCashGiftId()){
  207. $params["cash_gift_id"] = $goodsPromotionUrlGenerateParamBean->getCashGiftId();
  208. }
  209. if($goodsPromotionUrlGenerateParamBean->getCashGiftName()){
  210. $params["cash_gift_name"] = $goodsPromotionUrlGenerateParamBean->getCashGiftName();
  211. }
  212. if($goodsPromotionUrlGenerateParamBean->getCustomParameters()){
  213. $params["custom_parameters"] = $goodsPromotionUrlGenerateParamBean->getCustomParameters();
  214. }
  215. if($goodsPromotionUrlGenerateParamBean->getGenerateAuthorityUrl()){
  216. $params["generate_authority_url"] = $goodsPromotionUrlGenerateParamBean->getGenerateAuthorityUrl();
  217. }
  218. if($goodsPromotionUrlGenerateParamBean->getGenerateMallCollectCoupon()){
  219. $params["generate_mall_collect_coupon"] = $goodsPromotionUrlGenerateParamBean->getGenerateMallCollectCoupon();
  220. }
  221. if($goodsPromotionUrlGenerateParamBean->getGenerateQqApp()){
  222. $params["generate_qq_app"] = $goodsPromotionUrlGenerateParamBean->getGenerateQqApp();
  223. }
  224. if($goodsPromotionUrlGenerateParamBean->getGenerateSchemaUrl()){
  225. $params["generate_schema_url"] = $goodsPromotionUrlGenerateParamBean->getGenerateSchemaUrl();
  226. }
  227. if($goodsPromotionUrlGenerateParamBean->getGenerateShortUrl()){
  228. $params["generate_short_url"] = $goodsPromotionUrlGenerateParamBean->getGenerateShortUrl();
  229. }
  230. if($goodsPromotionUrlGenerateParamBean->getGenerateWeApp()){
  231. $params["generate_we_app"] = $goodsPromotionUrlGenerateParamBean->getGenerateWeApp();
  232. }
  233. if($goodsPromotionUrlGenerateParamBean->getGoodsSignList()){
  234. $params["goods_sign_list"] = $goodsPromotionUrlGenerateParamBean->getGoodsSignList();
  235. }
  236. if($goodsPromotionUrlGenerateParamBean->getMultiGroup()){
  237. $params["multi_group"] = $goodsPromotionUrlGenerateParamBean->getMultiGroup();
  238. }
  239. if($goodsPromotionUrlGenerateParamBean->getSearchId()){
  240. $params["search_id"] = $goodsPromotionUrlGenerateParamBean->getSearchId();
  241. }
  242. if($goodsPromotionUrlGenerateParamBean->getZsDuoId()){
  243. $params["zs_duo_id"] = $goodsPromotionUrlGenerateParamBean->getZsDuoId();
  244. }
  245. $params = self::getSign($params);
  246. $res = HttpCurl::postCurl(self::$url,$params);
  247. return $res;
  248. }
  249. /**
  250. * 多多进宝商品推荐API
  251. * @param GoodsRecommendGetParamBean $goodsRecommendGetParamBean
  252. */
  253. public static function goodsRecommendGet(GoodsRecommendGetParamBean $goodsRecommendGetParamBean)
  254. {
  255. $params = [
  256. "type"=>"pdd.ddk.goods.recommend.get"
  257. ];
  258. if($goodsRecommendGetParamBean->getActivityTags()){
  259. $params["activity_tags"] = $goodsRecommendGetParamBean->getActivityTags();
  260. }
  261. if($goodsRecommendGetParamBean->getCatId()){
  262. $params["cat_id"] = $goodsRecommendGetParamBean->getCatId();
  263. }
  264. if($goodsRecommendGetParamBean->getChannelType()){
  265. $params["channel_type"] = $goodsRecommendGetParamBean->getChannelType();
  266. }
  267. if($goodsRecommendGetParamBean->getCustomParameters()){
  268. $params["custom_parameters"] = $goodsRecommendGetParamBean->getCustomParameters();
  269. }
  270. if($goodsRecommendGetParamBean->getGoodsSignList()){
  271. $params["goods_sign_list"] = $goodsRecommendGetParamBean->getGoodsSignList();
  272. }
  273. if($goodsRecommendGetParamBean->getLimit()){
  274. $params["limit"] = $goodsRecommendGetParamBean->getLimit();
  275. }
  276. if($goodsRecommendGetParamBean->getListId()){
  277. $params["list_id"] = $goodsRecommendGetParamBean->getListId();
  278. }
  279. if($goodsRecommendGetParamBean->getOffset()){
  280. $params["offset"] = $goodsRecommendGetParamBean->getOffset();
  281. }
  282. if($goodsRecommendGetParamBean->getPid()){
  283. $params["pid"] = $goodsRecommendGetParamBean->getPid();
  284. }
  285. $params = self::getSign($params);
  286. $res = HttpCurl::postCurl(self::$url,$params);
  287. return $res;
  288. }
  289. /**
  290. * 多多进宝商品查询
  291. * @param GoodsSearchParamBean $goodsSearchParamBean
  292. */
  293. public static function goodsSearch(GoodsSearchParamBean $goodsSearchParamBean)
  294. {
  295. $params = [
  296. "type"=>"pdd.ddk.goods.search"
  297. ];
  298. if($goodsSearchParamBean->getActivityTags()){
  299. $params["activity_tags"] = $goodsSearchParamBean->getActivityTags();
  300. }
  301. if($goodsSearchParamBean->getBlockCats()){
  302. $params["block_cats"] = $goodsSearchParamBean->getBlockCats();
  303. }
  304. if($goodsSearchParamBean->getBlockCatPackages()){
  305. $params["block_cat_packages"] = $goodsSearchParamBean->getBlockCatPackages();
  306. }
  307. if($goodsSearchParamBean->getCatId()){
  308. $params["cat_id"] = $goodsSearchParamBean->getCatId();
  309. }
  310. if($goodsSearchParamBean->getCustomParameters()){
  311. $params["custom_parameters"] = $goodsSearchParamBean->getCustomParameters();
  312. }
  313. if($goodsSearchParamBean->getGoodsSignList()){
  314. $params["goods_sign_list"] = $goodsSearchParamBean->getGoodsSignList();
  315. }
  316. if($goodsSearchParamBean->getIsBrandGoods()){
  317. $params["is_brand_goods"] = $goodsSearchParamBean->getIsBrandGoods();
  318. }
  319. if($goodsSearchParamBean->getKeyword()){
  320. $params["keyword"] = $goodsSearchParamBean->getKeyword();
  321. }
  322. if($goodsSearchParamBean->getListId()){
  323. $params["list_id"] = $goodsSearchParamBean->getListId();
  324. }
  325. if($goodsSearchParamBean->getMerchantType()){
  326. $params["merchant_type"] = $goodsSearchParamBean->getMerchantType();
  327. }
  328. if($goodsSearchParamBean->getMerchantTypeList()){
  329. $params["merchant_type_list"] = $goodsSearchParamBean->getMerchantTypeList();
  330. }
  331. if($goodsSearchParamBean->getOptId()){
  332. $params["opt_id"] = $goodsSearchParamBean->getOptId();
  333. }
  334. if($goodsSearchParamBean->getPage()){
  335. $params["page"] = $goodsSearchParamBean->getPage();
  336. }
  337. if($goodsSearchParamBean->getPageSize()){
  338. $params["page_size"] = $goodsSearchParamBean->getPageSize();
  339. }
  340. if($goodsSearchParamBean->getPid()){
  341. $params["pid"] = $goodsSearchParamBean->getPid();
  342. }
  343. $params = self::getSign($params);
  344. // dump(self::$url);
  345. // dd($params);
  346. $res = HttpCurl::postCurl(self::$url,$params);
  347. return $res;
  348. }
  349. /**
  350. * 多多进宝转链接口
  351. * @param $pid string 推广位ID
  352. * @param $sourceUrl string 商品链接
  353. * @param array $customParameters 自定义参数
  354. */
  355. public static function goodsZsUnitUrlGen($pid,$sourceUrl="",$customParameters=[])
  356. {
  357. $params = [
  358. "type"=>"pdd.ddk.goods.zs.unit.url.gen",
  359. "pid"=>$pid
  360. ];
  361. if ($sourceUrl){
  362. $params["source_url"] = $sourceUrl;
  363. }
  364. if($customParameters){
  365. $params["custom_parameters"] = $customParameters;
  366. }
  367. $params = self::getSign($params);
  368. $res = HttpCurl::postCurl(self::$url,$params);
  369. return $res;
  370. }
  371. /**
  372. * 查询是否绑定备案
  373. * @param $p_id string 推广位ID
  374. * @return mixed
  375. */
  376. public static function memberAuthorityQuery($p_id)
  377. {
  378. $params = [
  379. "type"=>"pdd.ddk.member.authority.query",
  380. "pid"=>$p_id
  381. ];
  382. $params = self::getSign($params);
  383. $res = HttpCurl::postCurl(self::$url,$params);
  384. return $res;
  385. }
  386. /**
  387. * 获取拼多多增量订单
  388. * @param OrderListIncrementGetParamBean $orderListIncrementGetParamBean
  389. * @return mixed
  390. */
  391. public static function orderListIncrementGet(OrderListIncrementGetParamBean $orderListIncrementGetParamBean)
  392. {
  393. $params = [
  394. "type"=>"pdd.ddk.order.list.increment.get",
  395. ];
  396. if ($orderListIncrementGetParamBean->getCashGiftOrder()){
  397. $params["cash_gift_order"] = $orderListIncrementGetParamBean->getCashGiftOrder();
  398. }
  399. if($orderListIncrementGetParamBean->getPage()){
  400. $params["page"] = $orderListIncrementGetParamBean->getPage();
  401. }
  402. if($orderListIncrementGetParamBean->getPageSize()){
  403. $params["page_size"] = $orderListIncrementGetParamBean->getPageSize();
  404. }
  405. if($orderListIncrementGetParamBean->getEndUpdateTime()){
  406. $params["end_update_time"] = $orderListIncrementGetParamBean->getEndUpdateTime();
  407. }
  408. if($orderListIncrementGetParamBean->getStartUpdateTime()){
  409. $params["start_update_time"] = $orderListIncrementGetParamBean->getStartUpdateTime();
  410. }
  411. if($orderListIncrementGetParamBean->getReturnCount()){
  412. $params["return_count"] = $orderListIncrementGetParamBean->getReturnCount();
  413. }
  414. if($orderListIncrementGetParamBean->getQueryOrderType()){
  415. $params["query_order_type"] = $orderListIncrementGetParamBean->getQueryOrderType();
  416. }
  417. $params = self::getSign($params);
  418. $res = HttpCurl::postCurl(self::$url,$params);
  419. return $res;
  420. }
  421. }