Passed
Push — v6 ( bd826f...f71c30 )
by 光春
02:55
created

TbkService::itemRecommendGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
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
     * @var string
86
     */
87
    private $protocol = 'http';
88
89
    /**
90
     * 设置安全协议
91
     * @param string $protocol
92
     * @return $this
93
     */
94
    public function setProtocol($protocol = 'http'): self
95
    {
96
        $this->protocol = $protocol;
97
        return $this;
98
    }
99
100
    /**
101
     * 是否为沙箱
102
     * @return $this
103
     */
104
    public function sandbox(): self
105
    {
106
        $this->sandbox = true;
107
        return $this;
108
    }
109
110
    /**
111
     * 配置应用的AppKey
112
     * @param string $appKey
113
     * @return $this
114
     */
115
    public function appKey(string $appKey): self
116
    {
117
        $this->app_key = $appKey;
118
        return $this;
119
    }
120
121
    /**
122
     * 应用AppSecret
123
     * @param string $appSecret
124
     * @return $this
125
     */
126
    public function appSecret(string $appSecret): self
127
    {
128
        $this->app_secret = $appSecret;
129
        return $this;
130
    }
131
132
    /**
133
     * API接口名称
134
     * @param string $signMethod
135
     * @return $this
136
     */
137
    public function signMethod(string $signMethod): self
138
    {
139
        $this->sign_method = $signMethod;
140
        return $this;
141
    }
142
143
    /**
144
     * 请求参数
145
     * @param array $param
146
     * @return $this
147
     */
148
    public function param(array $param): self
149
    {
150
        $this->param = $param;
151
        return $this;
152
    }
153
154
    /**
155
     * 获取配置信息
156
     * @return $this
157
     */
158
    private function getConfig(): self
159
    {
160
        $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...
161
        $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...
162
        return $this;
163
    }
164
165
    /**
166
     * 淘宝客-推广者-所有订单查询
167
     * @return $this
168
     */
169
    public function orderDetailsGet(): self
170
    {
171
        $this->method = 'taobao.tbk.order.details.get';
172
        return $this;
173
    }
174
175
    /**
176
     * 淘宝客-服务商-所有订单查询
177
     * @return $this
178
     */
179
    public function scOrderDetailsGet(): self
180
    {
181
        $this->method = 'taobao.tbk.sc.order.details.get';
182
        return $this;
183
    }
184
185
    /**
186
     * 淘宝客-服务商-淘口令解析&转链
187
     * @return $this
188
     */
189
    public function scTpwdConvert(): self
190
    {
191
        $this->method = 'taobao.tbk.sc.tpwd.convert';
192
        return $this;
193
    }
194
195
    /**
196
     * 淘宝客-服务商-维权退款订单查询
197
     * @return $this
198
     */
199
    public function scRelationRefund(): self
200
    {
201
        $this->method = 'taobao.tbk.sc.relation.refund';
202
        return $this;
203
    }
204
205
    /**
206
     * 淘宝客-服务商-店铺链接转换
207
     * @return $this
208
     */
209
    public function scShopConvert(): self
210
    {
211
        $this->method = 'taobao.tbk.sc.shop.convert';
212
        return $this;
213
    }
214
215
    /**
216
     * 淘宝客-推广者-官办找福利页
217
     * @return $this
218
     */
219
    public function jzfConvert(): self
220
    {
221
        $this->method = 'taobao.tbk.jzf.convert';
222
        return $this;
223
    }
224
225
    /**
226
     * 淘宝客-推广者-维权退款订单查询
227
     * @return $this
228
     */
229
    public function relationRefund(): self
230
    {
231
        $this->method = 'taobao.tbk.relation.refund';
232
        return $this;
233
    }
234
235
    /**
236
     * 淘宝客-服务商-淘礼金创建
237
     * @return $this
238
     */
239
    public function scVegasTljCreate(): self
240
    {
241
        $this->method = 'taobao.tbk.sc.vegas.tlj.create';
242
        return $this;
243
    }
244
245
    /**
246
     * 淘宝客商品展示规则获取
247
     * @return $this
248
     */
249
    public function itemRuleGet(): self
250
    {
251
        $this->method = 'qimen.taobao.tbk.item.rule.get';
252
        return $this;
253
    }
254
255
    /**
256
     * 淘宝客-推广者-处罚订单查询
257
     * @return $this
258
     */
259
    public function dgPunishOrderGet(): self
260
    {
261
        $this->method = 'taobao.tbk.dg.punish.order.get';
262
        return $this;
263
    }
264
265
    /**
266
     * 淘宝客-公用-淘口令解析出原链接
267
     * @return $this
268
     */
269
    public function tpwdParse(): self
270
    {
271
        $this->method = 'taobao.tbk.tpwd.parse';
272
        return $this;
273
    }
274
275
    /**
276
     * 淘宝客-推广者-新用户订单明细查询
277
     * @return $this
278
     */
279
    public function dgNewUserOrderGet(): self
280
    {
281
        $this->method = 'taobao.tbk.dg.newuser.order.get';
282
        return $this;
283
    }
284
285
    /**
286
     * 淘宝客-服务商-新用户订单明细查询
287
     * @return $this
288
     */
289
    public function scNewuserOrderGet(): self
290
    {
291
        $this->method = 'taobao.tbk.sc.newuser.order.get';
292
        return $this;
293
    }
294
295
    /**
296
     * 淘宝客-推广者-拉新活动对应数据查询
297
     * @return $this
298
     */
299
    public function dgNewUserOrderSum(): self
300
    {
301
        $this->method = 'taobao.tbk.dg.newuser.order.sum';
302
        return $this;
303
    }
304
305
    /**
306
     * 超级红包发放个数 - 淘宝客-推广者-查询超级红包发放个数
307
     * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=47593&docType=2
308
     * @return $this
309
     */
310
    public function dgVegasSendReport(): self
311
    {
312
        $this->method = 'taobao.tbk.dg.vegas.send.report';
313
        return $this;
314
    }
315
316
    /**
317
     * 淘宝客-推广者-官方活动转链
318
     * @return $this
319
     */
320
    public function activityInfoGet(): self
321
    {
322
        $this->method = 'taobao.tbk.activity.info.get';
323
        return $this;
324
    }
325
326
    /**
327
     * 淘宝客-服务商-官方活动转链
328
     * @return $this
329
     */
330
    public function scActivityInfoGet(): self
331
    {
332
        $this->method = 'taobao.tbk.sc.activity.info.get';
333
        return $this;
334
    }
335
336
    /**
337
     * 淘宝客-推广者-联盟口令生成
338
     * @return $this
339
     */
340
    public function textTpwdCreate(): self
341
    {
342
        $this->method = 'taobao.tbk.text.tpwd.create';
343
        return $this;
344
    }
345
346
    /**
347
     * 淘宝客-推广者-官方活动转链(2020.9.30下线)
348
     * @return $this
349
     */
350
    public function activityLinkGet(): self
351
    {
352
        $this->method = 'taobao.tbk.activitylink.get';
353
        return $this;
354
    }
355
356
    /**
357
     * 淘宝客-公用-淘口令生成
358
     * @return $this
359
     */
360
    public function tpWdCreate(): self
361
    {
362
        $this->method = 'taobao.tbk.tpwd.create';
363
        return $this;
364
    }
365
366
    /**
367
     * 淘宝客-公用-长链转短链
368
     * @return $this
369
     */
370
    public function spreadGet(): self
371
    {
372
        $this->method = 'taobao.tbk.spread.get';
373
        return $this;
374
    }
375
376
    /**
377
     * 聚划算商品搜索接口
378
     * https://open.taobao.com/api.htm?docId=28762&docType=2&scopeId=16517
379
     * @return $this
380
     */
381
    public function itemsSearch(): self
382
    {
383
        $this->method = 'taobao.ju.items.search';
384
        return $this;
385
    }
386
387
    /**
388
     * 淘抢购api(2020.9.30下线)
389
     * @return $this
390
     */
391
    public function juTqgGet(): self
392
    {
393
        $this->method = 'taobao.tbk.ju.tqg.get';
394
        return $this;
395
    }
396
397
    /**
398
     * 淘宝客-推广者-淘礼金创建
399
     * @return $this
400
     */
401
    public function dgVegasTljCreate(): self
402
    {
403
        $this->method = 'taobao.tbk.dg.vegas.tlj.create';
404
        return $this;
405
    }
406
407
    /**
408
     * 淘宝客-推广者-轻店铺淘口令解析
409
     * @return $this
410
     */
411
    public function lightshopTbpswdParse(): self
412
    {
413
        $this->method = 'taobao.tbk.lightshop.tbpswd.parse';
414
        return $this;
415
    }
416
417
    /**
418
     * 淘宝客-推广者-淘礼金发放及使用报表
419
     * @return $this
420
     */
421
    public function dgVegasTljInstanceReport(): self
422
    {
423
        $this->method = 'taobao.tbk.dg.vegas.tlj.instance.report';
424
        return $this;
425
    }
426
427
    /**
428
     * 淘宝客-服务商-手淘群发单
429
     * @return $this
430
     */
431
    public function scGroupchatMessageSend(): self
432
    {
433
        $this->method = 'taobao.tbk.sc.groupchat.message.send';
434
        return $this;
435
    }
436
437
    /**
438
     * 淘宝客-服务商-手淘群创建
439
     * @return $this
440
     */
441
    public function scGroupchatCreate(): self
442
    {
443
        $this->method = 'taobao.tbk.sc.groupchat.create';
444
        return $this;
445
    }
446
447
    /**
448
     * 淘宝客-服务商-手淘群查询
449
     * @return $this
450
     */
451
    public function scGroupchatGet(): self
452
    {
453
        $this->method = 'taobao.tbk.sc.groupchat.get';
454
        return $this;
455
    }
456
457
    /**
458
     * 淘宝客-公用-手淘注册用户判定
459
     * @return $this
460
     */
461
    public function tbinfoGet(): self
462
    {
463
        $this->method = 'taobao.tbk.tbinfo.get';
464
        return $this;
465
    }
466
467
    /**
468
     * 淘宝客-公用-pid校验
469
     * @return $this
470
     */
471
    public function tbkinfoGet(): self
472
    {
473
        $this->method = 'taobao.tbk.tbkinfo.get';
474
        return $this;
475
    }
476
477
    /**
478
     * 淘宝客-公用-私域用户邀请码生成
479
     * @return $this
480
     */
481
    public function scInvIteCodeGet(): self
482
    {
483
        $this->method = 'taobao.tbk.sc.invitecode.get';
484
        return $this;
485
    }
486
487
    /**
488
     * 淘宝客-公用-私域用户备案信息查询
489
     * @return $this
490
     */
491
    public function scPublisherInfoGet(): self
492
    {
493
        $this->method = 'taobao.tbk.sc.publisher.info.get';
494
        return $this;
495
    }
496
497
    /**
498
     * 淘宝客-公用-私域用户备案
499
     * @return $this
500
     */
501
    public function scPublisherInfoSave(): self
502
    {
503
        $this->method = 'taobao.tbk.sc.publisher.info.save';
504
        return $this;
505
    }
506
507
    /**
508
     * 淘宝客-公用-淘宝客商品详情查询(简版)
509
     * @return $this
510
     */
511
    public function itemInfoGet(): self
512
    {
513
        $this->method = 'taobao.tbk.item.info.get';
514
        return $this;
515
    }
516
517
    /**
518
     * 淘宝客-公用-阿里妈妈推广券详情查询
519
     * @return $this
520
     */
521
    public function couponGet(): self
522
    {
523
        $this->method = 'taobao.tbk.coupon.get';
524
        return $this;
525
    }
526
527
    /**
528
     * 淘宝客-推广者-物料搜索
529
     * @return $this
530
     */
531
    public function dgMaterialOptional(): self
532
    {
533
        $this->method = 'taobao.tbk.dg.material.optional';
534
        return $this;
535
    }
536
537
    /**
538
     * 淘宝客-推广者-店铺搜索
539
     * @return $this
540
     */
541
    public function shopGet(): self
542
    {
543
        $this->method = 'taobao.tbk.shop.get';
544
        return $this;
545
    }
546
547
    /**
548
     * 淘宝客-推广者-物料精选
549
     * @return $this
550
     */
551
    public function dgOpTiUsMaterial(): self
552
    {
553
        $this->method = 'taobao.tbk.dg.optimus.material';
554
        return $this;
555
    }
556
557
    /**
558
     * 淘宝客-推广者-图文内容输出(2020.9.30下线)
559
     * @return $this
560
     */
561
    public function contentGet(): self
562
    {
563
        $this->method = 'taobao.tbk.content.get';
564
        return $this;
565
    }
566
567
    /**
568
     * 淘宝客-推广者-图文内容效果数据(2020.9.30下线)
569
     * @return $this
570
     */
571
    public function contentEffectGet(): self
572
    {
573
        $this->method = 'taobao.tbk.content.effect.get';
574
        return $this;
575
    }
576
577
578
    /**
579
     * 淘宝客-推广者-商品出词
580
     * @return $this
581
     */
582
    public function itemWordGet(): self
583
    {
584
        $this->method = 'taobao.tbk.item.word.get';
585
        return $this;
586
    }
587
588
    /**
589
     * 淘宝客-推广者-商品链接转换
590
     * @return $this
591
     */
592
    public function itemConvert(): self
593
    {
594
        $this->method = 'taobao.tbk.item.convert';
595
        return $this;
596
    }
597
598
    /**
599
     * 淘宝客-公用-链接解析出商品id
600
     * @return $this
601
     */
602
    public function itemClickExtract(): self
603
    {
604
        $this->method = 'taobao.tbk.item.click.extract';
605
        return $this;
606
    }
607
608
    /**
609
     * 淘宝客-公用-商品关联推荐(2020.9.30下线)
610
     * @return $this
611
     */
612
    public function itemRecommendGet(): self
613
    {
614
        $this->method = 'taobao.tbk.item.recommend.get';
615
        return $this;
616
    }
617
618
    /**
619
     * 淘宝客-公用-店铺关联推荐
620
     * @return $this
621
     */
622
    public function shopRecommendGet(): self
623
    {
624
        $this->method = 'taobao.tbk.shop.recommend.get';
625
        return $this;
626
    }
627
628
    /**
629
     * 淘宝客-推广者-选品库宝贝信息(2020.9.30下线)
630
     * @return $this
631
     */
632
    public function uaTmFavoritesItemGet(): self
633
    {
634
        $this->method = 'taobao.tbk.uatm.favorites.item.get';
635
        return $this;
636
    }
637
638
    /**
639
     * 淘宝客-推广者-选品库宝贝列表(2020.9.30下线)
640
     * @return $this
641
     */
642
    public function uaTmFavoritesGet(): self
643
    {
644
        $this->method = 'taobao.tbk.uatm.favorites.get';
645
        return $this;
646
    }
647
648
    /**
649
     * 淘宝客-服务商-官方活动转链(2020.9.30下线)
650
     * @return $this
651
     */
652
    public function scActivityLinkToolGet(): self
653
    {
654
        $this->method = 'taobao.tbk.sc.activitylink.toolget';
655
        return $this;
656
    }
657
658
    /**
659
     * 淘宝客-服务商-处罚订单查询
660
     * @return $this
661
     */
662
    public function scPunishOrderGet(): self
663
    {
664
        $this->method = 'taobao.tbk.sc.punish.order.get';
665
        return $this;
666
    }
667
668
    /**
669
     * 淘宝客-推广者-创建推广位
670
     * @return $this
671
     */
672
    public function adZoneCreate(): self
673
    {
674
        $this->method = 'taobao.tbk.adzone.create';
675
        return $this;
676
    }
677
678
    /**
679
     * 淘宝客文本淘口令
680
     * @return $this
681
     */
682
    public function tpwdMixCreate(): self
683
    {
684
        $this->method = 'taobao.tbk.tpwd.mix.create';
685
        return $this;
686
    }
687
688
    /**
689
     * 淘宝客-推广者-b2c平台用户行为跟踪服务商
690
     * @return $this
691
     */
692
    public function traceBtocAddtrace(): self
693
    {
694
        $this->method = 'taobao.tbk.trace.btoc.addtrace';
695
        return $this;
696
    }
697
698
    /**
699
     * 淘宝客-推广者-登陆信息跟踪服务商
700
     * @return $this
701
     */
702
    public function traceLogininfoAdd(): self
703
    {
704
        $this->method = 'taobao.tbk.trace.logininfo.add';
705
        return $this;
706
    }
707
708
    /**
709
     * 淘宝客-推广者-用户行为跟踪服务商
710
     * @return $this
711
     */
712
    public function traceShopitemAddtrace(): self
713
    {
714
        $this->method = 'taobao.tbk.trace.shopitem.addtrace';
715
        return $this;
716
    }
717
718
    /**
719
     * 淘宝客-推广者-商品三方分成链接转换
720
     * @return $this
721
     */
722
    public function itemShareConvert(): self
723
    {
724
        $this->method = 'taobao.tbk.item.share.convert';
725
        return $this;
726
    }
727
728
    /**
729
     * 淘宝客-推广者-店铺链接转换
730
     * @return $this
731
     */
732
    public function shopConvert(): self
733
    {
734
        $this->method = 'taobao.tbk.shop.convert';
735
        return $this;
736
    }
737
738
    /**
739
     * 淘宝客-推广者-店铺三方分成链接转换
740
     * @return $this
741
     */
742
    public function shopShareConvert(): self
743
    {
744
        $this->method = 'taobao.tbk.shop.share.convert';
745
        return $this;
746
    }
747
748
    /**
749
     * 淘宝客-推广者-返利商家授权查询
750
     * @return $this
751
     */
752
    public function rebateAuthGet(): self
753
    {
754
        $this->method = 'taobao.tbk.rebate.auth.get';
755
        return $this;
756
    }
757
758
    /**
759
     * 淘宝客-推广者-返利订单查询
760
     * @return $this
761
     */
762
    public function rebateOrderGet(): self
763
    {
764
        $this->method = 'taobao.tbk.rebate.order.get';
765
        return $this;
766
    }
767
768
    /**
769
     * 淘宝客-推广者-根据宝贝id批量查询优惠券
770
     * @return $this
771
     */
772
    public function itemidCouponGet(): self
773
    {
774
        $this->method = 'taobao.tbk.itemid.coupon.get';
775
        return $this;
776
    }
777
778
    /**
779
     * 淘宝客-服务商-保护门槛
780
     * @return $this
781
     */
782
    public function dataReport(): self
783
    {
784
        $this->method = 'taobao.tbk.data.report';
785
        return $this;
786
    }
787
788
    /**
789
     * 淘宝客-推广者-单品券高效转链
790
     * @return $this
791
     */
792
    public function couponConvert(): self
793
    {
794
        $this->method = 'taobao.tbk.coupon.convert';
795
        return $this;
796
    }
797
798
    /**
799
     * 淘宝客-推广者-淘口令解析&三方分成转链
800
     * @return $this
801
     */
802
    public function tpwdShareConvert(): self
803
    {
804
        $this->method = 'taobao.tbk.tpwd.share.convert';
805
        return $this;
806
    }
807
808
    /**
809
     * 淘宝客-推广者-淘口令解析&转链
810
     * @return $this
811
     */
812
    public function tpwdConvert(): self
813
    {
814
        $this->method = 'taobao.tbk.tpwd.convert';
815
        return $this;
816
    }
817
818
    /**
819
     * 淘宝客-服务商-创建推广者位
820
     * @return $this
821
     */
822
    public function scAdzoneCreate(): self
823
    {
824
        $this->method = 'taobao.tbk.sc.adzone.create';
825
        return $this;
826
    }
827
828
    /**
829
     * 淘宝客-服务商-物料精选
830
     * @return $this
831
     */
832
    public function scOptimusMaterial(): self
833
    {
834
        $this->method = 'taobao.tbk.sc.optimus.material';
835
        return $this;
836
    }
837
838
    /**
839
     * 淘宝客-服务商-物料搜索
840
     * @return $this
841
     */
842
    public function scMaterialOptional(): self
843
    {
844
        $this->method = 'taobao.tbk.sc.material.optional';
845
        return $this;
846
    }
847
848
    /**
849
     * 淘宝客-服务商-拉新活动数据查询
850
     * @return $this
851
     */
852
    public function scNewuserOrderSum(): self
853
    {
854
        $this->method = 'taobao.tbk.sc.newuser.order.sum';
855
        return $this;
856
    }
857
858
    /**
859
     * 自定义接口
860
     * @param string $method
861
     * @return $this
862
     */
863
    public function setMethod($method = ''): self
864
    {
865
        $this->method = $method;
866
        return $this;
867
    }
868
869
    /**
870
     * 返回Array
871
     * @return array|mixed
872
     * @throws DtaException
873
     */
874
    public function toArray()
875
    {
876
        //首先检测是否支持curl
877
        if (!extension_loaded("curl")) {
878
            throw new HttpException(404, '请开启curl模块!');
879
        }
880
        $this->format = "json";
881
        if (empty($this->app_key)) {
882
            $this->getConfig();
883
        }
884
        if (empty($this->app_key)) {
885
            throw new DtaException('请检查app_key参数');
886
        }
887
        if (empty($this->method)) {
888
            throw new DtaException('请检查method参数');
889
        }
890
        $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...
891
        $this->param['method'] = $this->method;
892
        $this->param['format'] = $this->format;
893
        $this->param['v'] = $this->v;
894
        $this->param['sign_method'] = $this->sign_method;
895
        $this->param['timestamp'] = Times::getData();
896
        $this->http();
897
        if (isset($this->output['error_response'])) {
898
            // 错误
899
            if (is_array($this->output)) {
900
                return $this->output;
901
            }
902
            if (is_object($this->output)) {
903
                $this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
904
            }
905
            return json_decode($this->output, true);
906
        }
907
908
        // 正常
909
        if (is_array($this->output)) {
910
            return $this->output;
911
        }
912
        if (is_object($this->output)) {
913
            $this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
914
        }
915
        $this->output = json_decode($this->output, true);
916
        return $this->output;
917
    }
918
919
    /**
920
     * 返回Xml
921
     * @return mixed
922
     * @throws DtaException
923
     */
924
    public function toXml()
925
    {
926
        //首先检测是否支持curl
927
        if (!extension_loaded("curl")) {
928
            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

928
            throw new HttpException(/** @scrutinizer ignore-type */ '请开启curl模块!', E_USER_DEPRECATED);
Loading history...
929
        }
930
        $this->format = "xml";
931
        $this->http();
932
        return $this->output;
933
    }
934
935
    /**
936
     * 网络请求
937
     * @throws DtaException
938
     */
939
    private function http(): void
940
    {
941
        //生成签名
942
        $sign = $this->createSign();
943
        //组织参数
944
        $strParam = $this->createStrParam();
945
        $strParam .= 'sign=' . $sign;
946
        //访问服务
947
        if ($this->protocol === 'http') {
948
            if (empty($this->sandbox)) {
949
                $url = 'http://gw.api.taobao.com/router/rest?' . $strParam;
950
            } else {
951
                $url = 'http://gw.api.tbsandbox.com/router/rest?' . $strParam;
952
            }
953
        }
954
        if ($this->protocol === 'https') {
955
            if (empty($this->sandbox)) {
956
                $url = 'https://eco.taobao.com/router/rest?' . $strParam;
957
            } else {
958
                $url = 'https://gw.api.tbsandbox.com/router/rest?' . $strParam;
959
            }
960
        }
961
        $result = file_get_contents($url);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $url does not seem to be defined for all execution paths leading up to this point.
Loading history...
962
        $result = json_decode($result, true);
963
        $this->output = $result;
964
    }
965
966
    /**
967
     * 签名
968
     * @return string
969
     * @throws DtaException
970
     */
971
    private function createSign(): string
972
    {
973
        if (empty($this->app_secret)) {
974
            $this->getConfig();
975
        }
976
        if (empty($this->app_secret)) {
977
            throw new DtaException('请检查app_secret参数');
978
        }
979
        $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...
980
        ksort($this->param);
981
        foreach ($this->param as $key => $val) {
982
            if ($key !== '' && $val !== '') {
983
                $sign .= $key . $val;
984
            }
985
        }
986
        $sign .= $this->app_secret;
987
        $sign = strtoupper(md5($sign));
988
        return $sign;
989
    }
990
991
    /**
992
     * 组参
993
     * @return string
994
     */
995
    private function createStrParam(): string
996
    {
997
        $strParam = '';
998
        foreach ($this->param as $key => $val) {
999
            if ($key !== '' && $val !== '') {
1000
                $strParam .= $key . '=' . urlencode($val) . '&';
1001
            }
1002
        }
1003
        return $strParam;
1004
    }
1005
1006
    /**
1007
     * 获取活动物料
1008
     * @return array[]
1009
     */
1010
    public function getActivityMaterialIdList(): array
1011
    {
1012
        return [
1013
            [
1014
                // https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10628646?_k=tcswm1
1015
                'name' => '口碑',
1016
                'list' => [
1017
                    [
1018
                        'name' => '口碑主会场活动(2.3%佣金起)',
1019
                        'material_id' => 1583739244161
1020
                    ],
1021
                    [
1022
                        'name' => '生活服务分会场活动(2.3%佣金起)',
1023
                        'material_id' => 1583739244162
1024
                    ]
1025
                ]
1026
            ],
1027
            [
1028
                // https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10628647?_k=hwggf9
1029
                // https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10630427?_k=sdet4e
1030
                // https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10630361?_k=nq6zgt
1031
                'name' => '饿了么',
1032
                'list' => [
1033
                    [
1034
                        'name' => '聚合页(6%佣金起)',
1035
                        'material_id' => 1571715733668
1036
                    ],
1037
                    [
1038
                        'name' => '新零售(4%佣金起)',
1039
                        'material_id' => 1585018034441
1040
                    ],
1041
                    [
1042
                        'name' => '餐饮',
1043
                        'material_id' => 1579491209717
1044
                    ],
1045
                ]
1046
            ],
1047
            [
1048
                // https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10634663?_k=zqgq01
1049
                'name' => '卡券(饭票)',
1050
                'list' => [
1051
                    [
1052
                        'name' => '饿了么卡券(1元以下商品)',
1053
                        'material_id' => 32469
1054
                    ],
1055
                    [
1056
                        'name' => '饿了么卡券投放全网商品库',
1057
                        'material_id' => 32470
1058
                    ],
1059
                    [
1060
                        'name' => '饿了么卡券(5折以下)',
1061
                        'material_id' => 32603
1062
                    ],
1063
                    [
1064
                        'name' => '饿了么头部全国KA商品库',
1065
                        'material_id' => 32663
1066
                    ],
1067
                    [
1068
                        'name' => '饿了么卡券招商爆品库',
1069
                        'material_id' => 32738
1070
                    ],
1071
                ]
1072
            ],
1073
        ];
1074
    }
1075
1076
    /**
1077
     * 获取官方物料API汇总
1078
     * https://market.m.taobao.com/app/qn/toutiao-new/index-pc.html#/detail/10628875?_k=gpov9a
1079
     * @return array
1080
     */
1081
    public function getMaterialIdList(): array
1082
    {
1083
        return [
1084
            [
1085
                'name' => '相似推荐',
1086
                'list' => [
1087
                    [
1088
                        'name' => '相似推荐',
1089
                        'material_id' => 13256
1090
                    ]
1091
                ]
1092
            ],
1093
            [
1094
                'name' => '官方推荐',
1095
                'list' => [
1096
                    [
1097
                        'name' => '聚划算满减满折',
1098
                        'material_id' => 32366
1099
                    ],
1100
                    [
1101
                        'name' => '猫超满减满折',
1102
                        'material_id' => 27160
1103
                    ]
1104
                ]
1105
            ],
1106
            [
1107
                'name' => '猜你喜欢',
1108
                'list' => [
1109
                    [
1110
                        'name' => '含全部商品',
1111
                        'material_id' => 6708
1112
                    ],
1113
                    [
1114
                        'name' => '营销商品库商品(此为具备“私域用户管理-会员运营管理功能”的媒体专用)',
1115
                        'material_id' => 28017
1116
                    ]
1117
                ]
1118
            ],
1119
            [
1120
                'name' => '好券直播',
1121
                'list' => [
1122
                    [
1123
                        'name' => '综合',
1124
                        'material_id' => 3756
1125
                    ],
1126
                    [
1127
                        'name' => '女装',
1128
                        'material_id' => 3767
1129
                    ],
1130
                    [
1131
                        'name' => '家居家装',
1132
                        'material_id' => 3758
1133
                    ],
1134
                    [
1135
                        'name' => '数码家电',
1136
                        'material_id' => 3759
1137
                    ],
1138
                    [
1139
                        'name' => '鞋包配饰',
1140
                        'material_id' => 3762
1141
                    ],
1142
                    [
1143
                        'name' => '美妆个护',
1144
                        'material_id' => 3763
1145
                    ],
1146
                    [
1147
                        'name' => '男装',
1148
                        'material_id' => 3764
1149
                    ],
1150
                    [
1151
                        'name' => '内衣',
1152
                        'material_id' => 3765
1153
                    ],
1154
                    [
1155
                        'name' => '母婴',
1156
                        'material_id' => 3760
1157
                    ],
1158
                    [
1159
                        'name' => '食品',
1160
                        'material_id' => 3761
1161
                    ],
1162
                    [
1163
                        'name' => '运动户外',
1164
                        'material_id' => 3766
1165
                    ]
1166
                ]
1167
            ],
1168
            [
1169
                'name' => '实时热销榜',
1170
                'list' => [
1171
                    [
1172
                        'name' => '综合',
1173
                        'material_id' => 28026
1174
                    ],
1175
                    [
1176
                        'name' => '大服饰',
1177
                        'material_id' => 28029
1178
                    ],
1179
                    [
1180
                        'name' => '大快消',
1181
                        'material_id' => 28027
1182
                    ],
1183
                    [
1184
                        'name' => '电器美家',
1185
                        'material_id' => 28028
1186
                    ]
1187
                ]
1188
            ],
1189
            [
1190
                'name' => '本地化生活',
1191
                'list' => [
1192
                    [
1193
                        'name' => '今日爆款(综合类目)',
1194
                        'material_id' => 30443
1195
                    ],
1196
                    [
1197
                        'name' => '淘票票(电影代金券)',
1198
                        'material_id' => 19812
1199
                    ],
1200
                    [
1201
                        'name' => '大麦网(演出/演唱会/剧目/会展)',
1202
                        'material_id' => 25378
1203
                    ],
1204
                    [
1205
                        'name' => '优酷会员(视频年卡)',
1206
                        'material_id' => 28636
1207
                    ],
1208
                    [
1209
                        'name' => '有声内容(喜马拉雅年卡,儿童节目等)',
1210
                        'material_id' => 29105
1211
                    ],
1212
                    [
1213
                        'name' => '阿里健康(hpv疫苗预约)',
1214
                        'material_id' => 25885
1215
                    ],
1216
                    [
1217
                        'name' => '阿里健康(体检)',
1218
                        'material_id' => 25886
1219
                    ],
1220
                    [
1221
                        'name' => '阿里健康(口腔)',
1222
                        'material_id' => 25888
1223
                    ],
1224
                    [
1225
                        'name' => '阿里健康(基因检测)',
1226
                        'material_id' => 25890
1227
                    ],
1228
                    [
1229
                        'name' => '飞猪(签证)',
1230
                        'material_id' => 26077
1231
                    ],
1232
                    [
1233
                        'name' => '飞猪(酒店)',
1234
                        'material_id' => 27913
1235
                    ],
1236
                    [
1237
                        'name' => '飞猪(自助餐)',
1238
                        'material_id' => 27914
1239
                    ],
1240
                    [
1241
                        'name' => '飞猪(门票)',
1242
                        'material_id' => 19811
1243
                    ],
1244
                    [
1245
                        'name' => '口碑(肯德基/必胜客/麦当劳)',
1246
                        'material_id' => 19810
1247
                    ],
1248
                    [
1249
                        'name' => '口碑(生活服务)',
1250
                        'material_id' => 28888
1251
                    ],
1252
                    [
1253
                        'name' => '天猫无忧购(家政服务)',
1254
                        'material_id' => 19814
1255
                    ],
1256
                    [
1257
                        'name' => '汽车定金(汽车定金)',
1258
                        'material_id' => 28397
1259
                    ],
1260
                ]
1261
            ],
1262
            [
1263
                'name' => '大额券',
1264
                'list' => [
1265
                    [
1266
                        'name' => '综合',
1267
                        'material_id' => 27446
1268
                    ],
1269
                    [
1270
                        'name' => '女装',
1271
                        'material_id' => 27448
1272
                    ],
1273
                    [
1274
                        'name' => '食品',
1275
                        'material_id' => 27451
1276
                    ],
1277
                    [
1278
                        'name' => '美妆个护',
1279
                        'material_id' => 27453
1280
                    ],
1281
                    [
1282
                        'name' => '家居家装',
1283
                        'material_id' => 27798
1284
                    ],
1285
                    [
1286
                        'name' => '母婴',
1287
                        'material_id' => 27454
1288
                    ]
1289
                ]
1290
            ],
1291
            [
1292
                'name' => '高佣榜',
1293
                'list' => [
1294
                    [
1295
                        'name' => '综合',
1296
                        'material_id' => 13366
1297
                    ],
1298
                    [
1299
                        'name' => '女装',
1300
                        'material_id' => 13367
1301
                    ],
1302
                    [
1303
                        'name' => '家居家装',
1304
                        'material_id' => 13368
1305
                    ],
1306
                    [
1307
                        'name' => '数码家电',
1308
                        'material_id' => 13369
1309
                    ],
1310
                    [
1311
                        'name' => '鞋包配饰',
1312
                        'material_id' => 13370
1313
                    ],
1314
                    [
1315
                        'name' => '美妆个护',
1316
                        'material_id' => 13371
1317
                    ],
1318
                    [
1319
                        'name' => '男装',
1320
                        'material_id' => 13372
1321
                    ],
1322
                    [
1323
                        'name' => '内衣',
1324
                        'material_id' => 13373
1325
                    ],
1326
                    [
1327
                        'name' => '母婴',
1328
                        'material_id' => 13374
1329
                    ],
1330
                    [
1331
                        'name' => '食品',
1332
                        'material_id' => 13375
1333
                    ],
1334
                    [
1335
                        'name' => '运动户外',
1336
                        'material_id' => 13376
1337
                    ]
1338
                ]
1339
            ],
1340
            [
1341
                'name' => '品牌券',
1342
                'list' => [
1343
                    [
1344
                        'name' => '综合',
1345
                        'material_id' => 3786
1346
                    ],
1347
                    [
1348
                        'name' => '女装',
1349
                        'material_id' => 3788
1350
                    ],
1351
                    [
1352
                        'name' => '家居家装',
1353
                        'material_id' => 3792
1354
                    ],
1355
                    [
1356
                        'name' => '数码家电',
1357
                        'material_id' => 3793
1358
                    ],
1359
                    [
1360
                        'name' => '鞋包配饰',
1361
                        'material_id' => 3796
1362
                    ],
1363
                    [
1364
                        'name' => '美妆个护',
1365
                        'material_id' => 3794
1366
                    ],
1367
                    [
1368
                        'name' => '男装',
1369
                        'material_id' => 3790
1370
                    ],
1371
                    [
1372
                        'name' => '内衣',
1373
                        'material_id' => 3787
1374
                    ],
1375
                    [
1376
                        'name' => '母婴',
1377
                        'material_id' => 3789
1378
                    ],
1379
                    [
1380
                        'name' => '食品',
1381
                        'material_id' => 3791
1382
                    ],
1383
                    [
1384
                        'name' => '运动户外',
1385
                        'material_id' => 3795
1386
                    ],
1387
                ]
1388
            ],
1389
            [
1390
                'name' => '猫超优质爆款',
1391
                'list' => [
1392
                    [
1393
                        'name' => '猫超1元购凑单',
1394
                        'material_id' => 27162
1395
                    ],
1396
                    [
1397
                        'name' => '猫超第二件0元',
1398
                        'material_id' => 27161
1399
                    ],
1400
                    [
1401
                        'name' => '猫超单件满减包邮',
1402
                        'material_id' => 27160
1403
                    ],
1404
                ]
1405
            ],
1406
            [
1407
                'name' => '聚划算单品爆款',
1408
                'list' => [
1409
                    [
1410
                        'name' => '开团热卖中',
1411
                        'material_id' => 31371
1412
                    ],
1413
                    [
1414
                        'name' => '预热',
1415
                        'material_id' => 31370
1416
                    ],
1417
                ]
1418
            ],
1419
            [
1420
                'name' => '天天特卖',
1421
                'list' => [
1422
                    [
1423
                        'name' => '开团热卖中',
1424
                        'material_id' => 31362
1425
                    ],
1426
                ]
1427
            ],
1428
            [
1429
                'name' => '母婴主题',
1430
                'list' => [
1431
                    [
1432
                        'name' => '备孕',
1433
                        'material_id' => 4040
1434
                    ],
1435
                    [
1436
                        'name' => '0至6个月',
1437
                        'material_id' => 4041
1438
                    ],
1439
                    [
1440
                        'name' => '4至6岁',
1441
                        'material_id' => 4044
1442
                    ],
1443
                    [
1444
                        'name' => '7至12个月',
1445
                        'material_id' => 4042
1446
                    ],
1447
                    [
1448
                        'name' => '1至3岁',
1449
                        'material_id' => 4043
1450
                    ],
1451
                    [
1452
                        'name' => '7至12岁',
1453
                        'material_id' => 4045
1454
                    ],
1455
                ]
1456
            ],
1457
            [
1458
                'name' => '有好货',
1459
                'list' => [
1460
                    [
1461
                        'name' => '有好货',
1462
                        'material_id' => 4092
1463
                    ],
1464
                ]
1465
            ],
1466
            [
1467
                'name' => '潮流范',
1468
                'list' => [
1469
                    [
1470
                        'name' => '潮流范',
1471
                        'material_id' => 4093
1472
                    ],
1473
                ]
1474
            ],
1475
            [
1476
                'name' => '特惠',
1477
                'list' => [
1478
                    [
1479
                        'name' => '特惠',
1480
                        'material_id' => 4094
1481
                    ],
1482
                ]
1483
            ],
1484
        ];
1485
    }
1486
}
1487