Passed
Push — v6 ( 68f5c0...1bc81c )
by 光春
04:57
created

TbkService::setMethod()   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 1
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
     * 自定义接口
843
     * @param string $method
844
     * @return $this
845
     */
846
    public function setMethod($method = ''): self
847
    {
848
        $this->method = $method;
849
        return $this;
850
    }
851
852
    /**
853
     * 返回Array
854
     * @return array|mixed
855
     * @throws DtaException
856
     */
857
    public function toArray()
858
    {
859
        //首先检测是否支持curl
860
        if (!extension_loaded("curl")) {
861
            throw new HttpException(404, '请开启curl模块!');
862
        }
863
        $this->format = "json";
864
        if (empty($this->app_key)) {
865
            $this->getConfig();
866
        }
867
        if (empty($this->app_key)) {
868
            throw new DtaException('请检查app_key参数');
869
        }
870
        if (empty($this->method)) {
871
            throw new DtaException('请检查method参数');
872
        }
873
        $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...
874
        $this->param['method'] = $this->method;
875
        $this->param['format'] = $this->format;
876
        $this->param['v'] = $this->v;
877
        $this->param['sign_method'] = $this->sign_method;
878
        $this->param['timestamp'] = Times::getData();
879
        $this->http();
880
        if (isset($this->output['error_response'])) {
881
            // 错误
882
            if (is_array($this->output)) {
883
                return $this->output;
884
            }
885
            if (is_object($this->output)) {
886
                $this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
887
            }
888
            return json_decode($this->output, true);
889
        }
890
891
        // 正常
892
        if (is_array($this->output)) {
893
            return $this->output;
894
        }
895
        if (is_object($this->output)) {
896
            $this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
897
        }
898
        $this->output = json_decode($this->output, true);
899
        return $this->output;
900
    }
901
902
    /**
903
     * 返回Xml
904
     * @return mixed
905
     * @throws DtaException
906
     */
907
    public function toXml()
908
    {
909
        //首先检测是否支持curl
910
        if (!extension_loaded("curl")) {
911
            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

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