JinBaoService.php 18.2 KB
Newer Older
李光春's avatar
李光春 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php

// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------

李光春's avatar
李光春 已提交
17
namespace DtApp\ThinkLibrary\service\pinduoduo;
李光春's avatar
李光春 已提交
18

李光春's avatar
李光春 已提交
19
use DtApp\ThinkLibrary\exception\DtaException;
李光春's avatar
李光春 已提交
20
use DtApp\ThinkLibrary\Service;
李光春's avatar
李光春 已提交
21
use think\exception\HttpException;
李光春's avatar
李光春 已提交
22

李光春's avatar
李光春 已提交
23 24 25 26 27
/**
 * 进宝
 * Class JinBaoService
 * @package DtApp\ThinkLibrary\service\PinDuoDuo
 */
李光春's avatar
李光春 已提交
28 29 30 31 32 33 34 35 36 37 38 39
class JinBaoService extends Service
{
    /**
     * 接口地址
     * @var
     */
    private $url = 'http://gw-api.pinduoduo.com/api/router';

    /**
     * API接口名称
     * @var string
     */
李光春's avatar
李光春 已提交
40
    private $type = '';
李光春's avatar
李光春 已提交
41 42

    /**
李光春's avatar
李光春 已提交
43
     * 开放平台分配的
李光春's avatar
李光春 已提交
44 45
     * @var string
     */
李光春's avatar
李光春 已提交
46
    private $client_id, $client_secret = '';
李光春's avatar
李光春 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

    /**
     * 响应格式,即返回数据的格式,JSON或者XML(二选一),默认JSON,注意是大写
     * @var string
     */
    private $data_type = 'JSON';

    /**
     * API协议版本号,默认为V1,可不填
     * @var string
     */
    private $version = 'v1';

    /**
     * 需要发送的的参数
     * @var
     */
    private $param;

    /**
     * 响应内容
     * @var
     */
    private $output;

    /*
     * 配置开放平台分配的clientId
     */
李光春's avatar
李光春 已提交
75
    public function clientId(string $clientId): self
李光春's avatar
李光春 已提交
76 77 78 79 80 81 82 83 84 85
    {
        $this->client_id = $clientId;
        return $this;
    }

    /**
     * 配置开放平台分配的clientSecret
     * @param string $clientSecret
     * @return $this
     */
李光春's avatar
李光春 已提交
86
    public function clientSecret(string $clientSecret): self
李光春's avatar
李光春 已提交
87 88 89 90 91 92 93 94 95 96
    {
        $this->client_secret = $clientSecret;
        return $this;
    }

    /**
     * 响应格式,即返回数据的格式,JSON或者XML(二选一),默认JSON,注意是大写
     * @param string $dataType
     * @return $this
     */
李光春's avatar
李光春 已提交
97
    public function dataType(string $dataType): self
李光春's avatar
李光春 已提交
98 99 100 101 102 103 104 105 106 107
    {
        $this->data_type = $dataType;
        return $this;
    }

    /**
     * 请求参数
     * @param array $param
     * @return $this
     */
李光春's avatar
李光春 已提交
108
    public function param(array $param): self
李光春's avatar
李光春 已提交
109
    {
李光春's avatar
李光春 已提交
110
        $this->param = $param;
李光春's avatar
李光春 已提交
111 112 113 114 115
        return $this;
    }

    /**
     * 网络请求
李光春's avatar
李光春 已提交
116
     * @return $this
李光春's avatar
李光春 已提交
117
     * @throws DtaException
李光春's avatar
李光春 已提交
118
     */
李光春's avatar
李光春 已提交
119
    private function http(): self
李光春's avatar
李光春 已提交
120 121 122 123 124 125 126 127 128 129 130 131 132 133
    {
        //生成签名
        $sign = $this->createSign();
        //组织参数
        $strParam = $this->createStrParam();
        $strParam .= 'sign=' . $sign;
        //访问服务
        $url = "{$this->url}?" . $strParam;
        $result = file_get_contents($url);
        $result = json_decode($result, true);
        $this->output = $result;
        return $this;
    }

134 135 136 137
    /**
     * 获取配置信息
     * @return $this
     */
李光春's avatar
李光春 已提交
138
    private function getConfig(): self
139
    {
李光春's avatar
李光春 已提交
140 141
        $this->client_id = config('dtapp.pinduoduo.jinbao.client_id');
        $this->client_secret = config('dtapp.pinduoduo.jinbao.client_secret');
142 143 144
        return $this;
    }

李光春's avatar
李光春 已提交
145 146 147
    /**
     * 获取商品信息 - 多多进宝商品查询
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.search
李光春's avatar
李光春 已提交
148
     * @return $this
李光春's avatar
李光春 已提交
149
     */
李光春's avatar
李光春 已提交
150
    public function goodsSearch(): self
李光春's avatar
李光春 已提交
151 152 153 154 155 156 157 158
    {
        $this->type = 'pdd.ddk.goods.search';
        return $this;
    }

    /**
     * 新增推广位 - 创建多多进宝推广位
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.pid.generate
李光春's avatar
李光春 已提交
159
     * @return $this
李光春's avatar
李光春 已提交
160
     */
李光春's avatar
李光春 已提交
161
    public function goodsPidGenerate(): self
李光春's avatar
李光春 已提交
162 163 164 165 166 167 168 169
    {
        $this->type = 'pdd.ddk.goods.pid.generate';
        return $this;
    }

    /**
     * 管理推广位 - 查询已经生成的推广位信息
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.pid.query
李光春's avatar
李光春 已提交
170
     * @return $this
李光春's avatar
李光春 已提交
171
     */
李光春's avatar
李光春 已提交
172
    public function goodsPidQuery(): self
李光春's avatar
李光春 已提交
173 174 175 176 177 178 179 180
    {
        $this->type = 'pdd.ddk.goods.pid.query';
        return $this;
    }

    /**
     * CPS订单数据 - 查询订单详情
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.order.detail.get
李光春's avatar
李光春 已提交
181
     * @return $this
李光春's avatar
李光春 已提交
182
     */
李光春's avatar
李光春 已提交
183
    public function orderDetailGet(): self
李光春's avatar
李光春 已提交
184 185 186 187 188 189 190 191
    {
        $this->type = 'pdd.ddk.order.detail.get';
        return $this;
    }

    /**
     * CPS订单数据 - 最后更新时间段增量同步推广订单信息
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.order.list.increment.get
李光春's avatar
李光春 已提交
192
     * @return $this
李光春's avatar
李光春 已提交
193
     */
李光春's avatar
李光春 已提交
194
    public function orderListIncrementGet(): self
李光春's avatar
李光春 已提交
195 196 197 198 199 200 201 202
    {
        $this->type = 'pdd.ddk.order.list.increment.get';
        return $this;
    }

    /**
     * CPS订单数据 - 用时间段查询推广订单接口
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.order.list.range.get
李光春's avatar
李光春 已提交
203
     * @return $this
李光春's avatar
李光春 已提交
204
     */
李光春's avatar
李光春 已提交
205
    public function orderListRangeGet(): self
李光春's avatar
李光春 已提交
206 207 208 209 210 211 212
    {
        $this->type = 'pdd.ddk.order.list.range.get';
        return $this;
    }

    /**
     * CPA效果数据 - 查询CPA数据
李光春's avatar
李光春 已提交
213
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.finance.cpa.query
李光春's avatar
李光春 已提交
214
     * @return $this
李光春's avatar
李光春 已提交
215
     */
李光春's avatar
李光春 已提交
216
    public function financeCpaQuery(): self
李光春's avatar
李光春 已提交
217 218 219 220 221 222 223 224
    {
        $this->type = 'pdd.ddk.finance.cpa.query';
        return $this;
    }

    /**
     * 单品推广- 多多进宝推广链接生成
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.promotion.url.generate
李光春's avatar
李光春 已提交
225
     * @return $this
李光春's avatar
李光春 已提交
226
     */
李光春's avatar
李光春 已提交
227
    public function goodsPromotionUrlGenerate(): self
李光春's avatar
李光春 已提交
228 229 230 231 232 233 234 235
    {
        $this->type = 'pdd.ddk.goods.promotion.url.generate';
        return $this;
    }

    /**
     * 单品推广- 多多客生成单品推广小程序二维码url
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.weapp.qrcode.url.gen
李光春's avatar
李光春 已提交
236
     * @return $this
李光春's avatar
李光春 已提交
237
     */
李光春's avatar
李光春 已提交
238
    public function weAppQrcodeUrlGen(): self
李光春's avatar
李光春 已提交
239 240 241 242 243 244 245 246
    {
        $this->type = 'pdd.ddk.weapp.qrcode.url.gen';
        return $this;
    }

    /**
     * 单品推广- 多多进宝转链接口
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.zs.unit.url.gen
李光春's avatar
李光春 已提交
247
     * @return $this
李光春's avatar
李光春 已提交
248
     */
李光春's avatar
李光春 已提交
249
    public function goodsZsUitUrlGen(): self
李光春's avatar
李光春 已提交
250 251 252 253 254 255 256 257
    {
        $this->type = 'pdd.ddk.goods.zs.unit.url.gen';
        return $this;
    }

    /**
     * 活动转链 - 生成多多进宝频道推广
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.resource.url.gen
李光春's avatar
李光春 已提交
258
     * @return $this
李光春's avatar
李光春 已提交
259
     */
李光春's avatar
李光春 已提交
260
    public function resourceUrlGen(): self
李光春's avatar
李光春 已提交
261 262 263 264 265 266 267 268
    {
        $this->type = 'pdd.ddk.resource.url.gen';
        return $this;
    }

    /**
     * 活动转链 - 多多进宝主题推广链接生成
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.theme.prom.url.generate
李光春's avatar
李光春 已提交
269
     * @return $this
李光春's avatar
李光春 已提交
270
     */
李光春's avatar
李光春 已提交
271
    public function themePromUrlGenerate(): self
李光春's avatar
李光春 已提交
272 273 274 275 276 277 278 279
    {
        $this->type = 'pdd.ddk.theme.prom.url.generate';
        return $this;
    }

    /**
     * 店铺推广 - 多多客生成店铺推广链接
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.mall.url.gen
李光春's avatar
李光春 已提交
280
     * @return $this
李光春's avatar
李光春 已提交
281
     */
李光春's avatar
李光春 已提交
282
    public function mallUrlGen(): self
李光春's avatar
李光春 已提交
283 284 285 286 287 288 289 290
    {
        $this->type = 'pdd.ddk.mall.url.gen';
        return $this;
    }

    /**
     * 营销工具 - 生成营销工具推广链接
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.rp.prom.url.generate
李光春's avatar
李光春 已提交
291
     * @return $this
李光春's avatar
李光春 已提交
292
     */
李光春's avatar
李光春 已提交
293
    public function rpPromUrlGenerate(): self
李光春's avatar
李光春 已提交
294 295 296 297 298 299 300 301
    {
        $this->type = 'pdd.ddk.rp.prom.url.generate';
        return $this;
    }

    /**
     * 获取商品信息 - 多多进宝商品详情查询
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.detail
李光春's avatar
李光春 已提交
302
     * @return $this
李光春's avatar
李光春 已提交
303
     */
李光春's avatar
李光春 已提交
304
    public function goodsDetail(): self
李光春's avatar
李光春 已提交
305 306 307 308 309 310 311 312
    {
        $this->type = 'pdd.ddk.goods.detail';
        return $this;
    }

    /**
     * 获取商品信息 - 查询商品的推广计划
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.unit.query
李光春's avatar
李光春 已提交
313
     * @return $this
李光春's avatar
李光春 已提交
314
     */
李光春's avatar
李光春 已提交
315
    public function goodsUnitQuery(): self
李光春's avatar
李光春 已提交
316 317 318 319 320 321 322 323
    {
        $this->type = 'pdd.ddk.goods.unit.query';
        return $this;
    }

    /**
     * 商品&店铺检索 - 获取商品基本信息接口
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.basic.info.get
李光春's avatar
李光春 已提交
324
     * @return $this
李光春's avatar
李光春 已提交
325
     */
李光春's avatar
李光春 已提交
326
    public function goodsBasicInfoGet(): self
李光春's avatar
李光春 已提交
327 328 329 330 331 332 333 334
    {
        $this->type = 'pdd.ddk.goods.basic.info.get';
        return $this;
    }

    /**
     * 商品&店铺检索 - 查询优惠券信息
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.coupon.info.query
李光春's avatar
李光春 已提交
335
     * @return $this
李光春's avatar
李光春 已提交
336
     */
李光春's avatar
李光春 已提交
337
    public function couponInfoQuery(): self
李光春's avatar
李光春 已提交
338 339 340 341 342 343 344 345
    {
        $this->type = 'pdd.ddk.coupon.info.query';
        return $this;
    }

    /**
     * 商品&店铺检索 - 查询店铺商品
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.mall.goods.list.get
李光春's avatar
李光春 已提交
346
     * @return $this
李光春's avatar
李光春 已提交
347
     */
李光春's avatar
李光春 已提交
348
    public function goodsListGet(): self
李光春's avatar
李光春 已提交
349 350 351 352 353 354 355 356
    {
        $this->type = 'pdd.ddk.mall.goods.list.get';
        return $this;
    }

    /**
     * 多多客获取爆款排行商品接口
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.top.goods.list.query
李光春's avatar
李光春 已提交
357
     * @return $this
李光春's avatar
李光春 已提交
358
     */
李光春's avatar
李光春 已提交
359
    public function topGoodsListQuery(): self
李光春's avatar
李光春 已提交
360 361 362 363 364 365 366 367
    {
        $this->type = 'pdd.ddk.top.goods.list.query';
        return $this;
    }

    /**
     * 爆品推荐 - 多多进宝商品推荐API
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.recommend.get
李光春's avatar
李光春 已提交
368
     * @return $this
李光春's avatar
李光春 已提交
369
     */
李光春's avatar
李光春 已提交
370
    public function goodsRecommendGet(): self
李光春's avatar
李光春 已提交
371 372 373 374 375 376 377 378
    {
        $this->type = 'pdd.ddk.goods.recommend.get';
        return $this;
    }

    /**
     * 爆品推荐 - 多多进宝主题列表查询
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.theme.list.get
李光春's avatar
李光春 已提交
379
     * @return $this
李光春's avatar
李光春 已提交
380
     */
李光春's avatar
李光春 已提交
381
    public function themeListGet(): self
李光春's avatar
李光春 已提交
382 383 384 385 386 387 388 389
    {
        $this->type = 'pdd.ddk.theme.list.get';
        return $this;
    }

    /**
     * 活动选品库 - 多多进宝主题商品查询
     * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.theme.goods.search
李光春's avatar
李光春 已提交
390
     * @return $this
李光春's avatar
李光春 已提交
391
     */
李光春's avatar
李光春 已提交
392
    public function themeGoodsSearch(): self
李光春's avatar
李光春 已提交
393 394
    {
        $this->type = 'pdd.ddk.theme.goods.search';
李光春's avatar
李光春 已提交
395 396 397 398 399 400 401 402
        return $this;
    }

    /**
     * 生成商城-频道推广链接
     * https://open.pinduoduo.com/application/document/api?id=pdd.ddk.cms.prom.url.
     * @return $this
     */
李光春's avatar
李光春 已提交
403
    public function cmsPromUrlGenerate(): self
李光春's avatar
李光春 已提交
404 405 406 407 408 409 410 411 412 413
    {
        $this->type = 'pdd.ddk.cms.prom.url.generate';
        return $this;
    }

    /**
     * 查询直播间详情
     * https://open.pinduoduo.com/application/document/api?id=pdd.ddk.live.detail
     * @return $this
     */
李光春's avatar
李光春 已提交
414
    public function liveDetail(): self
李光春's avatar
李光春 已提交
415 416 417 418 419 420 421 422 423 424
    {
        $this->type = 'pdd.ddk.live.detail';
        return $this;
    }

    /**
     * 查询直播间列表
     * https://open.pinduoduo.com/application/document/api?id=pdd.ddk.live.list
     * @return $this
     */
李光春's avatar
李光春 已提交
425
    public function liveList(): self
李光春's avatar
李光春 已提交
426 427 428 429 430 431 432 433 434 435
    {
        $this->type = 'pdd.ddk.live.list';
        return $this;
    }

    /**
     * 生成直播间推广链接
     * https://open.pinduoduo.com/application/document/api?id=pdd.ddk.live.url.gen
     * @return $this
     */
李光春's avatar
李光春 已提交
436
    public function liveUrlGen(): self
李光春's avatar
李光春 已提交
437 438 439 440 441 442 443 444 445 446
    {
        $this->type = 'pdd.ddk.live.url.gen';
        return $this;
    }

    /**
     * 多多客生成转盘抽免单url
     * https://open.pinduoduo.com/application/document/api?id=pdd.ddk.lottery.url.gen
     * @return $this
     */
李光春's avatar
李光春 已提交
447
    public function lotteryUrlGen(): self
李光春's avatar
李光春 已提交
448 449 450 451 452 453 454 455 456 457
    {
        $this->type = 'pdd.ddk.lottery.url.gen';
        return $this;
    }

    /**
     * 查询是否绑定备案
     * https://open.pinduoduo.com/application/document/api?id=pdd.ddk.member.authority.query
     * @return $this
     */
李光春's avatar
李光春 已提交
458
    public function memberAuthorityQuery(): self
李光春's avatar
李光春 已提交
459 460
    {
        $this->type = 'pdd.ddk.member.authority.query';
李光春's avatar
李光春 已提交
461 462 463
        return $this;
    }

李光春's avatar
李光春 已提交
464 465 466 467 468 469 470 471 472 473 474
    /**
     * 查询商品标签列表
     * https://open.pinduoduo.com/application/document/api?id=pdd.goods.opt.get
     * @return $this
     */
    public function goodsOptGet(): self
    {
        $this->type = 'pdd.goods.opt.get';
        return $this;
    }

475 476 477 478 479 480 481 482 483 484 485 486
    /**
     * 自定义接口
     * @param string $type
     * @return $this
     */
    public function setMethod($type = ''): self
    {
        $this->type = $type;
        return $this;
    }


李光春's avatar
李光春 已提交
487 488 489
    /**
     * 返回数组数据
     * @return array|mixed
李光春's avatar
李光春 已提交
490
     * @throws DtaException
李光春's avatar
李光春 已提交
491 492 493 494
     */
    public function toArray()
    {
        //首先检测是否支持curl
李光春's avatar
李光春 已提交
495 496 497 498 499 500 501 502 503
        if (!extension_loaded("curl")) {
            throw new HttpException(404, '请开启curl模块!');
        }
        if (empty($this->client_id)) {
            $this->getConfig();
        }
        if (empty($this->client_id)) {
            throw new DtaException('请检查client_id参数');
        }
李光春's avatar
李光春 已提交
504 505 506 507 508 509
        $this->param['type'] = $this->type;
        $this->param['client_id'] = $this->client_id;
        $this->param['timestamp'] = time();
        $this->param['data_type'] = $this->data_type;
        $this->param['version'] = $this->version;
        $this->http();
李光春's avatar
李光春 已提交
510 511
        if (isset($this->output['error_response'])) {
            // 错误
李光春's avatar
李光春 已提交
512 513 514 515 516 517
            if (is_array($this->output)) {
                return $this->output;
            }
            if (is_object($this->output)) {
                return $this->object2array($this->output);
            }
李光春's avatar
李光春 已提交
518
            return json_decode($this->output, true);
李光春's avatar
李光春 已提交
519 520 521 522 523 524 525
        }
        // 正常
        if (is_array($this->output)) {
            return $this->output;
        }
        if (is_object($this->output)) {
            $this->output = $this->object2array($this->output);
李光春's avatar
李光春 已提交
526 527
            return $this->output;
        }
李光春's avatar
李光春 已提交
528 529
        $this->output = json_decode($this->output, true);
        return $this->output;
李光春's avatar
李光春 已提交
530 531 532 533 534 535
    }

    /**
     * @param $object
     * @return array
     */
李光春's avatar
李光春 已提交
536
    private function object2array(&$object): array
李光春's avatar
李光春 已提交
537
    {
李光春's avatar
李光春 已提交
538 539 540 541 542
        if (is_object($object)) {
            $arr = (array)($object);
        } else {
            $arr = &$object;
        }
李光春's avatar
李光春 已提交
543 544 545 546 547
        if (is_array($arr)) {
            foreach ($arr as $varName => $varValue) {
                $arr[$varName] = $this->object2array($varValue);
            }
        }
李光春's avatar
李光春 已提交
548 549 550 551 552 553
        return $arr;
    }

    /**
     * 签名
     * @return string
李光春's avatar
李光春 已提交
554
     * @throws DtaException
李光春's avatar
李光春 已提交
555
     */
李光春's avatar
李光春 已提交
556
    private function createSign(): string
李光春's avatar
李光春 已提交
557
    {
李光春's avatar
李光春 已提交
558 559 560 561 562 563
        if (empty($this->client_secret)) {
            $this->getConfig();
        }
        if (empty($this->client_secret)) {
            throw new DtaException('请检查client_secret参数}');
        }
李光春's avatar
李光春 已提交
564 565
        $sign = $this->client_secret;
        ksort($this->param);
李光春's avatar
李光春 已提交
566
        foreach ($this->param as $key => $val) {
李光春's avatar
李光春 已提交
567
            if ($key !== '' && $val !== '') {
李光春's avatar
李光春 已提交
568 569 570
                $sign .= $key . $val;
            }
        }
李光春's avatar
李光春 已提交
571 572 573 574 575 576 577 578 579
        $sign .= $this->client_secret;
        $sign = strtoupper(md5($sign));
        return $sign;
    }

    /**
     * 组参
     * @return string
     */
李光春's avatar
李光春 已提交
580
    private function createStrParam(): string
李光春's avatar
李光春 已提交
581 582
    {
        $strParam = '';
李光春's avatar
李光春 已提交
583
        foreach ($this->param as $key => $val) {
李光春's avatar
李光春 已提交
584
            if ($key !== '' && $val !== '' && !is_array($val)) {
李光春's avatar
李光春 已提交
585 586 587
                $strParam .= $key . '=' . urlencode($val) . '&';
            }
        }
李光春's avatar
李光春 已提交
588 589
        return $strParam;
    }
李光春's avatar
李光春 已提交
590 591

    /**
李光春's avatar
李光春 已提交
592
     * 获取频道ID
李光春's avatar
李光春 已提交
593 594
     * @return array[]
     */
李光春's avatar
李光春 已提交
595
    public function getChannelTypeList(): array
李光春's avatar
李光春 已提交
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
    {
        return [
            [
                // https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.recommend.get
                'name' => '商品推荐',
                'list' => [
                    [
                        'name' => '1.9包邮',
                        'channel_type' => 0
                    ],
                    [
                        'name' => '今日爆款',
                        'channel_type' => 1
                    ],
                    [
                        'name' => '品牌清仓',
                        'channel_type' => 2
                    ],
                    [
                        'name' => '相似商品推荐',
                        'channel_type' => 3
                    ],
                    [
                        'name' => '猜你喜欢',
                        'channel_type' => 4
                    ],
                    [
                        'name' => '实时热销',
                        'channel_type' => 5
                    ],
                    [
                        'name' => '实时收益',
                        'channel_type' => 6
                    ],
                    [
                        'name' => '今日畅销',
                        'channel_type' => 7
                    ],
                    [
                        'name' => '高佣榜单',
                        'channel_type' => 8
                    ],
                ]
            ],
        ];
    }
李光春's avatar
李光春 已提交
642 643 644 645 646

    /**
     * 获取频道来源ID
     * @return array[]
     */
李光春's avatar
李光春 已提交
647
    public function getResourceTypeList(): array
李光春's avatar
李光春 已提交
648 649 650 651 652 653 654 655
    {
        return [
            [
                // https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.resource.url.gen
                'name' => '频道推广',
                'list' => [
                    [
                        'name' => '限时秒杀',
李光春's avatar
李光春 已提交
656
                        'resource_type' => 4
李光春's avatar
李光春 已提交
657 658 659
                    ],
                    [
                        'name' => '充值中心',
李光春's avatar
李光春 已提交
660
                        'resource_type' => 39997
李光春's avatar
李光春 已提交
661 662 663
                    ],
                    [
                        'name' => '转链',
李光春's avatar
李光春 已提交
664
                        'resource_type' => 39998
李光春's avatar
李光春 已提交
665 666 667
                    ],
                    [
                        'name' => '百亿补贴',
李光春's avatar
李光春 已提交
668
                        'resource_type' => 39996
李光春's avatar
李光春 已提交
669 670 671 672 673
                    ],
                ]
            ],
        ];
    }
李光春's avatar
李光春 已提交
674
}