TbkService::scPublisherInfoGet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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

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