Passed
Push — v6 ( 25b5d7...533a60 )
by 光春
03:05
created

TbkService::toArray()   B

Complexity

Conditions 10
Paths 17

Size

Total Lines 43
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 43
rs 7.6666
cc 10
nc 17
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
// +----------------------------------------------------------------------
4
// | ThinkLibrary 6.0 for ThinkPhP 6.0
5
// +----------------------------------------------------------------------
6
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
7
// +----------------------------------------------------------------------
8
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
9
// +----------------------------------------------------------------------
10
// | 开源协议 ( https://mit-license.org )
11
// +----------------------------------------------------------------------
12
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary
13
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary
14
// | gitlab 仓库地址 :https://gitlab.com/liguangchun/thinklibrary
15
// | weixin 仓库地址 :https://git.weixin.qq.com/liguangchun/ThinkLibrary
16
// | huaweicloud 仓库地址 :https://codehub-cn-south-1.devcloud.huaweicloud.com/composer00001/ThinkLibrary.git
17
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
18
// +----------------------------------------------------------------------
19
20
namespace DtApp\ThinkLibrary\service\taobao;
21
22
use DtApp\ThinkLibrary\exception\DtaException;
23
use DtApp\ThinkLibrary\facade\Strings;
0 ignored issues
show
Bug introduced by
The type DtApp\ThinkLibrary\facade\Strings was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use DtApp\ThinkLibrary\facade\Times;
25
use DtApp\ThinkLibrary\Service;
26
use think\exception\HttpException;
27
28
/**
29
 * 淘宝客
30
 * Class TbkService
31
 * @package DtApp\ThinkLibrary\service\TaoBao
32
 */
33
class TbkService extends Service
34
{
35
    /**
36
     * 是否为沙箱
37
     * @var bool
38
     */
39
    private $sandbox = false;
40
41
    /**
42
     * TOP分配给应用的
43
     * @var string
44
     */
45
    private $app_key, $app_secret = "";
46
47
    /**
48
     * API接口名称
49
     * @var string
50
     */
51
    private $method = '';
52
53
    /**
54
     * 签名的摘要算法
55
     * @var string
56
     */
57
    private $sign_method = "md5";
58
59
    /**
60
     * 需要发送的的参数
61
     * @var
62
     */
63
    private $param;
64
65
    /**
66
     * 响应格式
67
     * @var string
68
     */
69
    private $format = "json";
70
71
    /**
72
     * API协议版本
73
     * @var string
74
     */
75
    private $v = "2.0";
76
77
    /**
78
     * 响应内容
79
     * @var
80
     */
81
    private $output;
82
83
    /**
84
     * 是否为沙箱
85
     * @return $this
86
     */
87
    public function sandbox(): self
88
    {
89
        $this->sandbox = true;
90
        return $this;
91
    }
92
93
    /**
94
     * 配置应用的AppKey
95
     * @param string $appKey
96
     * @return $this
97
     */
98
    public function appKey(string $appKey): self
99
    {
100
        $this->app_key = $appKey;
101
        return $this;
102
    }
103
104
    /**
105
     * 应用AppSecret
106
     * @param string $appSecret
107
     * @return $this
108
     */
109
    public function appSecret(string $appSecret): self
110
    {
111
        $this->app_secret = $appSecret;
112
        return $this;
113
    }
114
115
    /**
116
     * API接口名称
117
     * @param string $signMethod
118
     * @return $this
119
     */
120
    public function signMethod(string $signMethod): self
121
    {
122
        $this->sign_method = $signMethod;
123
        return $this;
124
    }
125
126
    /**
127
     * 请求参数
128
     * @param array $param
129
     * @return $this
130
     */
131
    public function param(array $param): self
132
    {
133
        $this->param = $param;
134
        return $this;
135
    }
136
137
    /**
138
     * 获取配置信息
139
     * @return $this
140
     */
141
    private function getConfig(): self
142
    {
143
        $this->app_key = config('dtapp.taobao.tbk.app_key');
0 ignored issues
show
Documentation Bug introduced by
It seems like config('dtapp.taobao.tbk.app_key') can also be of type boolean. However, the property $app_key is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
144
        $this->app_secret = config('dtapp.taobao.tbk.app_secret');
0 ignored issues
show
Documentation Bug introduced by
It seems like config('dtapp.taobao.tbk.app_secret') can also be of type boolean. However, the property $app_secret is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
145
        return $this;
146
    }
147
148
    /**
149
     * 订单查询 - 淘宝客-推广者-所有订单查询
150
     * https://open.taobao.com/api.htm?spm=a219a.7386797.0.0.263c669aWmp4ds&source=search&docId=43328&docType=2
151
     * @return $this
152
     */
153
    public function orderDetailsGet(): self
154
    {
155
        $this->method = 'taobao.tbk.order.details.get';
156
        return $this;
157
    }
158
159
    /**
160
     * 订单查询 - 淘宝客-推广者-维权退款订单查询
161
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=40173&docType=2
162
     * @return $this
163
     */
164
    public function relationRefund(): self
165
    {
166
        $this->method = 'taobao.tbk.relation.refund';
167
        return $this;
168
    }
169
170
171
    /**
172
     * 处罚订单 - 淘宝客-推广者-处罚订单查询
173
     * https://open.taobao.com/api.htm?spm=a219a.7386797.0.0.120a669amFgNIC&source=search&docId=40121&docType=2
174
     * @return $this
175
     */
176
    public function dgPunishOrderGet(): self
177
    {
178
        $this->method = 'taobao.tbk.dg.punish.order.get';
179
        return $this;
180
    }
181
182
    /**
183
     * 拉新订单&效果 - 淘宝客-推广者-新用户订单明细查询
184
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=33892&docType=2
185
     * @return $this
186
     */
187
    public function DgNewUserOrderGet(): self
188
    {
189
        $this->method = 'taobao.tbk.dg.newuser.order.get';
190
        return $this;
191
    }
192
193
    /**
194
     * 拉新订单&效果 - 淘宝客-推广者-拉新活动对应数据查询
195
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=36836&docType=2
196
     * @return $this
197
     */
198
    public function dgNewUserOrderSum(): self
199
    {
200
        $this->method = 'taobao.tbk.dg.newuser.order.sum';
201
        return $this;
202
    }
203
204
    /**
205
     * 超级红包发放个数 - 淘宝客-推广者-查询超级红包发放个数
206
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=47593&docType=2
207
     * @return $this
208
     */
209
    public function dgVegasSendReport(): self
210
    {
211
        $this->method = 'taobao.tbk.dg.vegas.send.report';
212
        return $this;
213
    }
214
215
    /**
216
     * 活动转链(更新版) - 淘宝客-推广者-官方活动信息获取
217
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=48340&docType=2
218
     * @return $this
219
     */
220
    public function activityInfoGet(): self
221
    {
222
        $this->method = 'taobao.tbk.activity.info.get';
223
        return $this;
224
    }
225
226
    /**
227
     * 活动转链 - 淘宝客-推广者-官方活动转链
228
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=41918&docType=2
229
     * @return $this
230
     */
231
    public function activityLinkGet(): self
232
    {
233
        $this->method = 'taobao.tbk.activitylink.get';
234
        return $this;
235
    }
236
237
    /**
238
     * 淘口令 - 淘宝客-公用-淘口令生成
239
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=31127&docType=2
240
     * @return $this
241
     * @throws DtaException
242
     */
243
    public function tpWdCreate(): self
244
    {
245
        if (isset($this->param['text']) && strlen($this->param['text']) < 5) {
246
            throw new DtaException('请检查text参数长度');
247
        }
248
        $this->method = 'taobao.tbk.tpwd.create';
249
        return $this;
250
    }
251
252
    /**
253
     * 长短链 - 淘宝客-公用-长链转短链
254
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=27832&docType=2
255
     * @return $this
256
     */
257
    public function spreadGet(): self
258
    {
259
        $this->method = 'taobao.tbk.spread.get';
260
        return $this;
261
    }
262
263
    /**
264
     * 聚划算商品搜索接口
265
     * https://open.taobao.com/api.htm?docId=28762&docType=2&scopeId=16517
266
     * @return $this
267
     */
268
    public function itemsSearch(): self
269
    {
270
        $this->method = 'taobao.ju.items.search';
271
        return $this;
272
    }
273
274
    /**
275
     * 淘抢购api
276
     * https://open.taobao.com/api.htm?docId=27543&docType=2&scopeId=16517
277
     * @return $this
278
     */
279
    public function juTqgGet(): self
280
    {
281
        if (!isset($this->param['fields'])) {
282
            $this->param['fields'] = "click_url,pic_url,reserve_price,zk_final_price,total_amount,sold_num,title,category_name,start_time,end_time";
283
        }
284
        $this->method = 'taobao.tbk.ju.tqg.get';
285
        return $this;
286
    }
287
288
    /**
289
     * 淘礼金 - 淘宝客-推广者-淘礼金创建
290
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=40173&docType=2
291
     * @return $this
292
     */
293
    public function dgVegasTljCreate(): self
294
    {
295
        $this->method = 'taobao.tbk.dg.vegas.tlj.create';
296
        return $this;
297
    }
298
299
    /**
300
     * 淘礼金 - 淘宝客-推广者-淘礼金发放及使用报表
301
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=43317&docType=2
302
     * @return $this
303
     */
304
    public function dgVegasTljInstanceReport(): self
305
    {
306
        $this->method = 'taobao.tbk.dg.vegas.tlj.instance.report';
307
        return $this;
308
    }
309
310
    /**
311
     * 私域用户管理 - 淘宝客-公用-私域用户邀请码生成
312
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=38046&docType=2
313
     * @return $this
314
     */
315
    public function scInvIteCodeGet(): self
316
    {
317
        $this->method = 'taobao.tbk.sc.invitecode.get';
318
        return $this;
319
    }
320
321
    /**
322
     * 私域用户管理 - 淘宝客-公用-私域用户备案信息查询
323
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=37989&docType=2
324
     * @return $this
325
     */
326
    public function scPublisherInfoGet(): self
327
    {
328
        $this->method = 'taobao.tbk.sc.publisher.info.get';
329
        return $this;
330
    }
331
332
    /**
333
     * 私域用户管理 - 淘宝客-公用-私域用户备案
334
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=37988&docType=2
335
     * @return $this
336
     */
337
    public function scPublisherInfoSave(): self
338
    {
339
        $this->method = 'taobao.tbk.sc.publisher.info.save';
340
        return $this;
341
    }
342
343
    /**
344
     * 商品详情&券详情查询 - 淘宝客-公用-淘宝客商品详情查询(简版)
345
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=24518&docType=2
346
     * https://open.alimama.com/#!/function?id=25
347
     * @return $this
348
     */
349
    public function itemInfoGet(): self
350
    {
351
        $this->method = 'taobao.tbk.item.info.get';
352
        return $this;
353
    }
354
355
    /**
356
     * 商品详情&券详情查询 - 淘宝客-公用-阿里妈妈推广券详情查询
357
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=31106&docType=2
358
     * https://open.alimama.com/#!/function?id=25
359
     * @return $this
360
     */
361
    public function couponGet(): self
362
    {
363
        $this->method = 'taobao.tbk.coupon.get';
364
        return $this;
365
    }
366
367
    /**
368
     * 商品/店铺搜索 - 淘宝客-推广者-物料搜索
369
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=35896&docType=2
370
     * https://open.alimama.com/#!/function?id=27
371
     * @return $this
372
     */
373
    public function dgMaterialOptional(): self
374
    {
375
        $this->method = 'taobao.tbk.dg.material.optional';
376
        return $this;
377
    }
378
379
    /**
380
     * 商品/店铺搜索 - 淘宝客-推广者-店铺搜索
381
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=24521&docType=2
382
     * https://open.alimama.com/#!/function?id=27
383
     * @return $this
384
     */
385
    public function shopGet(): self
386
    {
387
        if (!isset($this->param['fields'])) {
388
            $this->param['fields'] = "user_id,shop_title,shop_type,seller_nick,pict_url,shop_url";
389
        }
390
        $this->method = 'taobao.tbk.shop.get';
391
        return $this;
392
    }
393
394
    /**
395
     * 商品库/榜单精选 - 淘宝客-推广者-物料精选
396
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=33947&docType=2
397
     * http://wsd.591hufu.com/taokelianmeng/424.html
398
     * https://open.alimama.com/#!/function?id=28
399
     * @return $this
400
     */
401
    public function dgOpTiUsMaterial(): self
402
    {
403
        $this->method = 'taobao.tbk.dg.optimus.material';
404
        return $this;
405
    }
406
407
    /**
408
     * 图文内容 - 淘宝客-推广者-图文内容输出
409
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=31137&docType=2
410
     * https://open.alimama.com/#!/function?id=30
411
     * @return $this
412
     */
413
    public function contentGet(): self
414
    {
415
        $this->method = 'taobao.tbk.content.get';
416
        return $this;
417
    }
418
419
    /**
420
     * 图文内容 - 淘宝客-推广者-图文内容效果数据
421
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=37130&docType=2
422
     * https://open.alimama.com/#!/function?id=30
423
     * @return $this
424
     */
425
    public function contentEffectGet(): self
426
    {
427
        $this->method = 'taobao.tbk.content.effect.get';
428
        return $this;
429
    }
430
431
432
    /**
433
     * 图文内容 - 淘宝客-推广者-商品出词
434
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.178c24advNRYpp&docId=37538&docType=2
435
     * @return $this
436
     */
437
    public function itemWordGet(): self
438
    {
439
        $this->method = 'taobao.tbk.item.word.get';
440
        return $this;
441
    }
442
443
    /**
444
     * 淘宝客-推广者-商品链接转换
445
     * https://open.taobao.com/api.htm?docId=24516&docType=2&scopeId=11653
446
     * @return $this
447
     */
448
    public function itemConvert(): self
449
    {
450
        if (!isset($this->param['fields'])) {
451
            $this->param['fields'] = "num_iid,click_url";
452
        }
453
        $this->method = 'taobao.tbk.item.convert';
454
        return $this;
455
    }
456
457
    /**
458
     * 淘宝客-公用-链接解析出商品id
459
     * https://open.taobao.com/api.htm?docId=28156&docType=2
460
     * @return $this
461
     */
462
    public function itemClickExtract(): self
463
    {
464
        $this->method = 'taobao.tbk.item.click.extract';
465
        return $this;
466
    }
467
468
    /**
469
     * 淘宝客-公用-商品关联推荐
470
     * https://open.taobao.com/api.htm?docId=24517&docType=2
471
     * @return $this
472
     */
473
    public function itemRecommendGet(): self
474
    {
475
        $this->method = 'taobao.tbk.item.recommend.get';
476
        return $this;
477
    }
478
479
    /**
480
     * 淘宝客-公用-店铺关联推荐
481
     * https://open.taobao.com/api.htm?docId=24522&docType=2
482
     * @return $this
483
     */
484
    public function shopRecommendGet(): self
485
    {
486
        $this->method = 'taobao.tbk.shop.recommend.get';
487
        return $this;
488
    }
489
490
    /**
491
     * 淘宝客-推广者-选品库宝贝信息
492
     * https://open.taobao.com/api.htm?docId=26619&docType=2
493
     * @return $this
494
     */
495
    public function uaTmFavoritesItemGet(): self
496
    {
497
        $this->method = 'taobao.tbk.uatm.favorites.item.get';
498
        return $this;
499
    }
500
501
    /**
502
     * 淘宝客-推广者-选品库宝贝列表
503
     * https://open.taobao.com/api.htm?docId=26620&docType=2
504
     * @return $this
505
     */
506
    public function uaTmFavoritesGet(): self
507
    {
508
        $this->method = 'taobao.tbk.uatm.favorites.get';
509
        return $this;
510
    }
511
512
    /**
513
     * 淘宝客-服务商-官方活动转链
514
     * https://open.taobao.com/api.htm?docId=41921&docType=2
515
     * @return $this
516
     */
517
    public function scActivityLinkToolGet(): self
518
    {
519
        $this->method = 'taobao.tbk.sc.activitylink.toolget';
520
        return $this;
521
    }
522
523
    /**
524
     * 返回Array
525
     * @return array|mixed
526
     * @throws DtaException
527
     */
528
    public function toArray()
529
    {
530
        //首先检测是否支持curl
531
        if (!extension_loaded("curl")) {
532
            throw new HttpException(404, '请开启curl模块!');
533
        }
534
        $this->format = "json";
535
        if (empty($this->app_key)) {
536
            $this->getConfig();
537
        }
538
        if (empty($this->app_key)) {
539
            throw new DtaException('请检查app_key参数');
540
        }
541
        if (empty($this->method)) {
542
            throw new DtaException('请检查method参数');
543
        }
544
        $this->param['app_key'] = $this->app_key;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->app_key can also be of type boolean. However, the property $app_key is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
545
        $this->param['method'] = $this->method;
546
        $this->param['format'] = $this->format;
547
        $this->param['v'] = $this->v;
548
        $this->param['sign_method'] = $this->sign_method;
549
        $this->param['timestamp'] = Times::getData();
550
        $this->http();
551
        if (isset($this->output['error_response'])) {
552
            // 错误
553
            if (is_array($this->output)) {
554
                return $this->output;
555
            }
556
            if (is_object($this->output)) {
557
                $this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
558
            }
559
            return json_decode($this->output, true);
560
        }
561
562
        // 正常
563
        if (is_array($this->output)) {
564
            return $this->output;
565
        };
566
        if (is_object($this->output)) {
567
            $this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
568
        }
569
        $this->output = json_decode($this->output, true);
570
        return $this->output;
571
    }
572
573
    /**
574
     * 返回Xml
575
     * @return mixed
576
     * @throws DtaException
577
     */
578
    public function toXml()
579
    {
580
        //首先检测是否支持curl
581
        if (!extension_loaded("curl")) {
582
            throw new HttpException('请开启curl模块!', E_USER_DEPRECATED);
0 ignored issues
show
Bug introduced by
'请开启curl模块!' of type string is incompatible with the type integer expected by parameter $statusCode of think\exception\HttpException::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

582
            throw new HttpException(/** @scrutinizer ignore-type */ '请开启curl模块!', E_USER_DEPRECATED);
Loading history...
583
        }
584
        $this->format = "xml";
585
        $this->http();
586
        return $this->output;
587
    }
588
589
    /**
590
     * 网络请求
591
     * @throws DtaException
592
     */
593
    private function http(): void
594
    {
595
        //生成签名
596
        $sign = $this->createSign();
597
        //组织参数
598
        $strParam = $this->createStrParam();
599
        $strParam .= 'sign=' . $sign;
600
        //访问服务
601
        if (empty($this->sandbox)) {
602
            $url = 'http://gw.api.taobao.com/router/rest?' . $strParam;
603
        } else {
604
            $url = 'http://gw.api.tbsandbox.com/router/rest?' . $strParam;
605
        }
606
        $result = file_get_contents($url);
607
        $result = json_decode($result, true);
608
        $this->output = $result;
609
    }
610
611
    /**
612
     * 签名
613
     * @return string
614
     * @throws DtaException
615
     */
616
    private function createSign(): string
617
    {
618
        if (empty($this->app_secret)) {
619
            $this->getConfig();
620
        }
621
        if (empty($this->app_secret)) {
622
            throw new DtaException('请检查app_secret参数');
623
        }
624
        $sign = $this->app_secret;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->app_secret can also be of type boolean. However, the property $app_secret is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
625
        ksort($this->param);
626
        foreach ($this->param as $key => $val) {
627
            if ($key !== '' && $val !== '') {
628
                $sign .= $key . $val;
629
            }
630
        }
631
        $sign .= $this->app_secret;
632
        $sign = strtoupper(md5($sign));
633
        return $sign;
634
    }
635
636
    /**
637
     * 组参
638
     * @return string
639
     */
640
    private function createStrParam(): string
641
    {
642
        $strParam = '';
643
        foreach ($this->param as $key => $val) {
644
            if ($key !== '' && $val !== '') {
645
                $strParam .= $key . '=' . urlencode($val) . '&';
646
            }
647
        }
648
        return $strParam;
649
    }
650
651
    /**
652
     * 获取活动物料
653
     * @return array[]
654
     */
655
    public function getActivityMaterialIdList(): array
656
    {
657
        return [
658
            [
659
                // https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10628646?_k=tcswm1
660
                'name' => '口碑',
661
                'list' => [
662
                    [
663
                        'name' => '口碑主会场活动(2.3%佣金起)',
664
                        'material_id' => 1583739244161
665
                    ],
666
                    [
667
                        'name' => '生活服务分会场活动(2.3%佣金起)',
668
                        'material_id' => 1583739244162
669
                    ]
670
                ]
671
            ],
672
            [
673
                // https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10628647?_k=hwggf9
674
                // https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10630427?_k=sdet4e
675
                // https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10630361?_k=nq6zgt
676
                'name' => '饿了么',
677
                'list' => [
678
                    [
679
                        'name' => '聚合页(6%佣金起)',
680
                        'material_id' => 1571715733668
681
                    ],
682
                    [
683
                        'name' => '新零售(4%佣金起)',
684
                        'material_id' => 1585018034441
685
                    ],
686
                    [
687
                        'name' => '餐饮',
688
                        'material_id' => 1579491209717
689
                    ],
690
                ]
691
            ],
692
            [
693
                // https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10634663?_k=zqgq01
694
                'name' => '卡券(饭票)',
695
                'list' => [
696
                    [
697
                        'name' => '饿了么卡券(1元以下商品)',
698
                        'material_id' => 32469
699
                    ],
700
                    [
701
                        'name' => '饿了么卡券投放全网商品库',
702
                        'material_id' => 32470
703
                    ],
704
                    [
705
                        'name' => '饿了么卡券(5折以下)',
706
                        'material_id' => 32603
707
                    ],
708
                    [
709
                        'name' => '饿了么头部全国KA商品库',
710
                        'material_id' => 32663
711
                    ],
712
                    [
713
                        'name' => '饿了么卡券招商爆品库',
714
                        'material_id' => 32738
715
                    ],
716
                ]
717
            ],
718
        ];
719
    }
720
721
    /**
722
     * 获取官方物料API汇总
723
     * https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10628875?_k=gpov9a
724
     * @return array
725
     */
726
    public function getMaterialIdList(): array
727
    {
728
        return [
729
            [
730
                'name' => '相似推荐',
731
                'list' => [
732
                    [
733
                        'name' => '相似推荐',
734
                        'material_id' => 13256
735
                    ]
736
                ]
737
            ],
738
            [
739
                'name' => '官方推荐',
740
                'list' => [
741
                    [
742
                        'name' => '聚划算满减满折',
743
                        'material_id' => 32366
744
                    ],
745
                    [
746
                        'name' => '猫超满减满折',
747
                        'material_id' => 27160
748
                    ]
749
                ]
750
            ],
751
            [
752
                'name' => '猜你喜欢',
753
                'list' => [
754
                    [
755
                        'name' => '含全部商品',
756
                        'material_id' => 6708
757
                    ],
758
                    [
759
                        'name' => '营销商品库商品(此为具备“私域用户管理-会员运营管理功能”的媒体专用)',
760
                        'material_id' => 28017
761
                    ]
762
                ]
763
            ],
764
            [
765
                'name' => '好券直播',
766
                'list' => [
767
                    [
768
                        'name' => '综合',
769
                        'material_id' => 3756
770
                    ],
771
                    [
772
                        'name' => '女装',
773
                        'material_id' => 3767
774
                    ],
775
                    [
776
                        'name' => '家居家装',
777
                        'material_id' => 3758
778
                    ],
779
                    [
780
                        'name' => '数码家电',
781
                        'material_id' => 3759
782
                    ],
783
                    [
784
                        'name' => '鞋包配饰',
785
                        'material_id' => 3762
786
                    ],
787
                    [
788
                        'name' => '美妆个护',
789
                        'material_id' => 3763
790
                    ],
791
                    [
792
                        'name' => '男装',
793
                        'material_id' => 3764
794
                    ],
795
                    [
796
                        'name' => '内衣',
797
                        'material_id' => 3765
798
                    ],
799
                    [
800
                        'name' => '母婴',
801
                        'material_id' => 3760
802
                    ],
803
                    [
804
                        'name' => '食品',
805
                        'material_id' => 3761
806
                    ],
807
                    [
808
                        'name' => '运动户外',
809
                        'material_id' => 3766
810
                    ]
811
                ]
812
            ],
813
            [
814
                'name' => '实时热销榜',
815
                'list' => [
816
                    [
817
                        'name' => '综合',
818
                        'material_id' => 28026
819
                    ],
820
                    [
821
                        'name' => '大服饰',
822
                        'material_id' => 28029
823
                    ],
824
                    [
825
                        'name' => '大快消',
826
                        'material_id' => 28027
827
                    ],
828
                    [
829
                        'name' => '电器美家',
830
                        'material_id' => 28028
831
                    ]
832
                ]
833
            ],
834
            [
835
                'name' => '本地化生活',
836
                'list' => [
837
                    [
838
                        'name' => '今日爆款(综合类目)',
839
                        'material_id' => 30443
840
                    ],
841
                    [
842
                        'name' => '淘票票(电影代金券)',
843
                        'material_id' => 19812
844
                    ],
845
                    [
846
                        'name' => '大麦网(演出/演唱会/剧目/会展)',
847
                        'material_id' => 25378
848
                    ],
849
                    [
850
                        'name' => '优酷会员(视频年卡)',
851
                        'material_id' => 28636
852
                    ],
853
                    [
854
                        'name' => '有声内容(喜马拉雅年卡,儿童节目等)',
855
                        'material_id' => 29105
856
                    ],
857
                    [
858
                        'name' => '阿里健康(hpv疫苗预约)',
859
                        'material_id' => 25885
860
                    ],
861
                    [
862
                        'name' => '阿里健康(体检)',
863
                        'material_id' => 25886
864
                    ],
865
                    [
866
                        'name' => '阿里健康(口腔)',
867
                        'material_id' => 25888
868
                    ],
869
                    [
870
                        'name' => '阿里健康(基因检测)',
871
                        'material_id' => 25890
872
                    ],
873
                    [
874
                        'name' => '飞猪(签证)',
875
                        'material_id' => 26077
876
                    ],
877
                    [
878
                        'name' => '飞猪(酒店)',
879
                        'material_id' => 27913
880
                    ],
881
                    [
882
                        'name' => '飞猪(自助餐)',
883
                        'material_id' => 27914
884
                    ],
885
                    [
886
                        'name' => '飞猪(门票)',
887
                        'material_id' => 19811
888
                    ],
889
                    [
890
                        'name' => '口碑(肯德基/必胜客/麦当劳)',
891
                        'material_id' => 19810
892
                    ],
893
                    [
894
                        'name' => '口碑(生活服务)',
895
                        'material_id' => 28888
896
                    ],
897
                    [
898
                        'name' => '天猫无忧购(家政服务)',
899
                        'material_id' => 19814
900
                    ],
901
                    [
902
                        'name' => '汽车定金(汽车定金)',
903
                        'material_id' => 28397
904
                    ],
905
                ]
906
            ],
907
            [
908
                'name' => '大额券',
909
                'list' => [
910
                    [
911
                        'name' => '综合',
912
                        'material_id' => 27446
913
                    ],
914
                    [
915
                        'name' => '女装',
916
                        'material_id' => 27448
917
                    ],
918
                    [
919
                        'name' => '食品',
920
                        'material_id' => 27451
921
                    ],
922
                    [
923
                        'name' => '美妆个护',
924
                        'material_id' => 27453
925
                    ],
926
                    [
927
                        'name' => '家居家装',
928
                        'material_id' => 27798
929
                    ],
930
                    [
931
                        'name' => '母婴',
932
                        'material_id' => 27454
933
                    ]
934
                ]
935
            ],
936
            [
937
                'name' => '高佣榜',
938
                'list' => [
939
                    [
940
                        'name' => '综合',
941
                        'material_id' => 13366
942
                    ],
943
                    [
944
                        'name' => '女装',
945
                        'material_id' => 13367
946
                    ],
947
                    [
948
                        'name' => '家居家装',
949
                        'material_id' => 13368
950
                    ],
951
                    [
952
                        'name' => '数码家电',
953
                        'material_id' => 13369
954
                    ],
955
                    [
956
                        'name' => '鞋包配饰',
957
                        'material_id' => 13370
958
                    ],
959
                    [
960
                        'name' => '美妆个护',
961
                        'material_id' => 13371
962
                    ],
963
                    [
964
                        'name' => '男装',
965
                        'material_id' => 13372
966
                    ],
967
                    [
968
                        'name' => '内衣',
969
                        'material_id' => 13373
970
                    ],
971
                    [
972
                        'name' => '母婴',
973
                        'material_id' => 13374
974
                    ],
975
                    [
976
                        'name' => '食品',
977
                        'material_id' => 13375
978
                    ],
979
                    [
980
                        'name' => '运动户外',
981
                        'material_id' => 13376
982
                    ]
983
                ]
984
            ],
985
            [
986
                'name' => '品牌券',
987
                'list' => [
988
                    [
989
                        'name' => '综合',
990
                        'material_id' => 3786
991
                    ],
992
                    [
993
                        'name' => '女装',
994
                        'material_id' => 3788
995
                    ],
996
                    [
997
                        'name' => '家居家装',
998
                        'material_id' => 3792
999
                    ],
1000
                    [
1001
                        'name' => '数码家电',
1002
                        'material_id' => 3793
1003
                    ],
1004
                    [
1005
                        'name' => '鞋包配饰',
1006
                        'material_id' => 3796
1007
                    ],
1008
                    [
1009
                        'name' => '美妆个护',
1010
                        'material_id' => 3794
1011
                    ],
1012
                    [
1013
                        'name' => '男装',
1014
                        'material_id' => 3790
1015
                    ],
1016
                    [
1017
                        'name' => '内衣',
1018
                        'material_id' => 3787
1019
                    ],
1020
                    [
1021
                        'name' => '母婴',
1022
                        'material_id' => 3789
1023
                    ],
1024
                    [
1025
                        'name' => '食品',
1026
                        'material_id' => 3791
1027
                    ],
1028
                    [
1029
                        'name' => '运动户外',
1030
                        'material_id' => 3795
1031
                    ],
1032
                ]
1033
            ],
1034
            [
1035
                'name' => '猫超优质爆款',
1036
                'list' => [
1037
                    [
1038
                        'name' => '猫超1元购凑单',
1039
                        'material_id' => 27162
1040
                    ],
1041
                    [
1042
                        'name' => '猫超第二件0元',
1043
                        'material_id' => 27161
1044
                    ],
1045
                    [
1046
                        'name' => '猫超单件满减包邮',
1047
                        'material_id' => 27160
1048
                    ],
1049
                ]
1050
            ],
1051
            [
1052
                'name' => '聚划算单品爆款',
1053
                'list' => [
1054
                    [
1055
                        'name' => '开团热卖中',
1056
                        'material_id' => 31371
1057
                    ],
1058
                    [
1059
                        'name' => '预热',
1060
                        'material_id' => 31370
1061
                    ],
1062
                ]
1063
            ],
1064
            [
1065
                'name' => '天天特卖',
1066
                'list' => [
1067
                    [
1068
                        'name' => '开团热卖中',
1069
                        'material_id' => 31362
1070
                    ],
1071
                ]
1072
            ],
1073
            [
1074
                'name' => '母婴主题',
1075
                'list' => [
1076
                    [
1077
                        'name' => '备孕',
1078
                        'material_id' => 4040
1079
                    ],
1080
                    [
1081
                        'name' => '0至6个月',
1082
                        'material_id' => 4041
1083
                    ],
1084
                    [
1085
                        'name' => '4至6岁',
1086
                        'material_id' => 4044
1087
                    ],
1088
                    [
1089
                        'name' => '7至12个月',
1090
                        'material_id' => 4042
1091
                    ],
1092
                    [
1093
                        'name' => '1至3岁',
1094
                        'material_id' => 4043
1095
                    ],
1096
                    [
1097
                        'name' => '7至12岁',
1098
                        'material_id' => 4045
1099
                    ],
1100
                ]
1101
            ],
1102
            [
1103
                'name' => '有好货',
1104
                'list' => [
1105
                    [
1106
                        'name' => '有好货',
1107
                        'material_id' => 4092
1108
                    ],
1109
                ]
1110
            ],
1111
            [
1112
                'name' => '潮流范',
1113
                'list' => [
1114
                    [
1115
                        'name' => '潮流范',
1116
                        'material_id' => 4093
1117
                    ],
1118
                ]
1119
            ],
1120
            [
1121
                'name' => '特惠',
1122
                'list' => [
1123
                    [
1124
                        'name' => '特惠',
1125
                        'material_id' => 4094
1126
                    ],
1127
                ]
1128
            ],
1129
        ];
1130
    }
1131
}
1132