Passed
Push — v6 ( 6aa863...3dc3c0 )
by 光春
02:30
created

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

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