Completed
Push — master ( bcf3cd...1065a5 )
by Elf
07:16 queued 04:50
created

MessageIOS::setSound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Support\Tencent\XgPush;
4
5
/*
6
 * Copyright ? 1998 - 2014 Tencent. All Rights Reserved. 腾讯公司 版权所有
7
 */
8
9
/**
10
 * @version 1.1.8
11
 * @see http://xg.qq.com/xg/ctr_index/download
12
 */
13
class XingeApp
14
{
15
    const DEVICE_ALL = 0;
16
    const DEVICE_BROWSER = 1;
17
    const DEVICE_PC = 2;
18
    const DEVICE_ANDROID = 3;
19
    const DEVICE_IOS = 4;
20
    const DEVICE_WINPHONE = 5;
21
22
    const IOSENV_PROD = 1;
23
    const IOSENV_DEV = 2;
24
25
    const IOS_MIN_ID = 2200000000;
26
27
    public function __construct($accessId, $secretKey)
28
    {
29
        assert(isset($accessId) && isset($secretKey));
30
31
        $this->accessId = $accessId;
32
        $this->secretKey = $secretKey;
33
    }
34
35
    public function __destruct()
36
    {
37
    }
38
39
    /**
40
     * 使用默认设置推送消息给单个android设备.
41
     */
42
    public static function PushTokenAndroid($accessId, $secretKey, $title, $content, $token)
43
    {
44
        $push = new self($accessId, $secretKey);
45
        $mess = new Message();
46
        $mess->setTitle($title);
47
        $mess->setContent($content);
48
        $mess->setType(Message::TYPE_NOTIFICATION);
49
        $mess->setStyle(new Style(0, 1, 1, 1, 0));
50
        $action = new ClickAction();
51
        $action->setActionType(ClickAction::TYPE_ACTIVITY);
52
        $mess->setAction($action);
53
        $ret = $push->PushSingleDevice($token, $mess);
54
55
        return $ret;
56
    }
57
58
    /**
59
     * 使用默认设置推送消息给单个ios设备.
60
     */
61
    public static function PushTokenIos($accessId, $secretKey, $content, $token, $environment)
62
    {
63
        $push = new self($accessId, $secretKey);
64
        $mess = new MessageIOS();
65
        $mess->setAlert($content);
66
        $ret = $push->PushSingleDevice($token, $mess, $environment);
67
68
        return $ret;
69
    }
70
71
    /**
72
     * 使用默认设置推送消息给单个android版账户.
73
     */
74 View Code Duplication
    public static function PushAccountAndroid($accessId, $secretKey, $title, $content, $account)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $push = new self($accessId, $secretKey);
77
        $mess = new Message();
78
        $mess->setTitle($title);
79
        $mess->setContent($content);
80
        $mess->setType(Message::TYPE_NOTIFICATION);
81
        $mess->setStyle(new Style(0, 1, 1, 1, 0));
82
        $action = new ClickAction();
83
        $action->setActionType(ClickAction::TYPE_ACTIVITY);
84
        $mess->setAction($action);
85
        $ret = $push->PushSingleAccount(0, $account, $mess);
86
87
        return $ret;
88
    }
89
90
    /**
91
     * 使用默认设置推送消息给单个ios版账户.
92
     */
93 View Code Duplication
    public static function PushAccountIos($accessId, $secretKey, $content, $account, $environment)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        $push = new self($accessId, $secretKey);
96
        $mess = new MessageIOS();
97
        $mess->setAlert($content);
98
        $ret = $push->PushSingleAccount(0, $account, $mess, $environment);
99
100
        return $ret;
101
    }
102
103
    /**
104
     * 使用默认设置推送消息给所有设备android版.
105
     */
106 View Code Duplication
    public static function PushAllAndroid($accessId, $secretKey, $title, $content)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
    {
108
        $push = new self($accessId, $secretKey);
109
        $mess = new Message();
110
        $mess->setTitle($title);
111
        $mess->setContent($content);
112
        $mess->setType(Message::TYPE_NOTIFICATION);
113
        $mess->setStyle(new Style(0, 1, 1, 1, 0));
114
        $action = new ClickAction();
115
        $action->setActionType(ClickAction::TYPE_ACTIVITY);
116
        $mess->setAction($action);
117
        $ret = $push->PushAllDevices(0, $mess);
118
119
        return $ret;
120
    }
121
122
    /**
123
     * 使用默认设置推送消息给所有设备ios版.
124
     */
125 View Code Duplication
    public static function PushAllIos($accessId, $secretKey, $content, $environment)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
    {
127
        $push = new self($accessId, $secretKey);
128
        $mess = new MessageIOS();
129
        $mess->setAlert($content);
130
        $ret = $push->PushAllDevices(0, $mess, $environment);
131
132
        return $ret;
133
    }
134
135
    /**
136
     * 使用默认设置推送消息给标签选中设备android版.
137
     */
138 View Code Duplication
    public static function PushTagAndroid($accessId, $secretKey, $title, $content, $tag)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
139
    {
140
        $push = new self($accessId, $secretKey);
141
        $mess = new Message();
142
        $mess->setTitle($title);
143
        $mess->setContent($content);
144
        $mess->setType(Message::TYPE_NOTIFICATION);
145
        $mess->setStyle(new Style(0, 1, 1, 1, 0));
146
        $action = new ClickAction();
147
        $action->setActionType(ClickAction::TYPE_ACTIVITY);
148
        $mess->setAction($action);
149
        $ret = $push->PushTags(0, [0 => $tag], 'OR', $mess);
150
151
        return $ret;
152
    }
153
154
    /**
155
     * 使用默认设置推送消息给标签选中设备ios版.
156
     */
157 View Code Duplication
    public static function PushTagIos($accessId, $secretKey, $content, $tag, $environment)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
    {
159
        $push = new self($accessId, $secretKey);
160
        $mess = new MessageIOS();
161
        $mess->setAlert($content);
162
        $ret = $push->PushTags(0, [0 => $tag], 'OR', $mess, $environment);
163
164
        return $ret;
165
    }
166
167
    /**
168
     * 推送消息给单个设备.
169
     */
170 View Code Duplication
    public function PushSingleDevice($deviceToken, $message, $environment = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
171
    {
172
        $ret = ['ret_code' => -1, 'err_msg' => 'message not valid'];
173
174
        if (! ($message instanceof Message) && ! ($message instanceof MessageIOS)) {
175
            return $ret;
176
        }
177
        if (! $this->ValidateMessageType($message)) {
178
            $ret['err_msg'] = 'message type not fit accessId';
179
180
            return $ret;
181
        }
182
        if ($message instanceof MessageIOS) {
183
            if ($environment != self::IOSENV_DEV && $environment != self::IOSENV_PROD) {
184
                $ret['err_msg'] = 'ios message environment invalid';
185
186
                return $ret;
187
            }
188
        }
189
        if (! $message->isValid()) {
190
            return $ret;
191
        }
192
        $params = [];
193
        $params['access_id'] = $this->accessId;
194
        $params['expire_time'] = $message->getExpireTime();
195
        $params['send_time'] = $message->getSendTime();
196
        if ($message instanceof Message) {
197
            $params['multi_pkg'] = $message->getMultiPkg();
198
        }
199
        $params['device_token'] = $deviceToken;
200
        $params['message_type'] = $message->getType();
201
        $params['message'] = $message->toJson();
202
        $params['timestamp'] = time();
203
        $params['environment'] = $environment;
204
205
        return $this->callRestful(self::RESTAPI_PUSHSINGLEDEVICE, $params);
206
    }
207
208
    /**
209
     * 推送消息给单个账户.
210
     */
211
    public function PushSingleAccount($deviceType, $account, $message, $environment = 0)
212
    {
213
        $ret = ['ret_code' => -1];
214 View Code Duplication
        if (! is_int($deviceType) || $deviceType < 0 || $deviceType > 5) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
215
            $ret['err_msg'] = 'deviceType not valid';
216
217
            return $ret;
218
        }
219
        if (! is_string($account) || empty($account)) {
220
            $ret['err_msg'] = 'account not valid';
221
222
            return $ret;
223
        }
224
        if (! ($message instanceof Message) && ! ($message instanceof MessageIOS)) {
225
            $ret['err_msg'] = 'message is not android or ios';
226
227
            return $ret;
228
        }
229
        if (! $this->ValidateMessageType($message)) {
230
            $ret['err_msg'] = 'message type not fit accessId';
231
232
            return $ret;
233
        }
234
        if ($message instanceof MessageIOS) {
235
            if ($environment != self::IOSENV_DEV && $environment != self::IOSENV_PROD) {
236
                $ret['err_msg'] = 'ios message environment invalid';
237
238
                return $ret;
239
            }
240
        }
241
        if (! $message->isValid()) {
242
            $ret['err_msg'] = 'message not valid';
243
244
            return $ret;
245
        }
246
        $params = [];
247
        $params['access_id'] = $this->accessId;
248
        $params['expire_time'] = $message->getExpireTime();
249
        $params['send_time'] = $message->getSendTime();
250
        if ($message instanceof Message) {
251
            $params['multi_pkg'] = $message->getMultiPkg();
252
        }
253
        $params['device_type'] = $deviceType;
254
        $params['account'] = $account;
255
        $params['message_type'] = $message->getType();
256
        $params['message'] = $message->toJson();
257
        $params['timestamp'] = time();
258
        $params['environment'] = $environment;
259
260
        return $this->callRestful(self::RESTAPI_PUSHSINGLEACCOUNT, $params);
261
    }
262
263
    /**
264
     * 推送消息给多个账户.
265
     */
266
    public function PushAccountList($deviceType, $accountList, $message, $environment = 0)
267
    {
268
        $ret = ['ret_code' => -1];
269 View Code Duplication
        if (! is_int($deviceType) || $deviceType < 0 || $deviceType > 5) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
270
            $ret['err_msg'] = 'deviceType not valid';
271
272
            return $ret;
273
        }
274
        if (! is_array($accountList) || empty($accountList)) {
275
            $ret['err_msg'] = 'accountList not valid';
276
277
            return $ret;
278
        }
279
        if (! ($message instanceof Message) && ! ($message instanceof MessageIOS)) {
280
            $ret['err_msg'] = 'message is not android or ios';
281
282
            return $ret;
283
        }
284
        if (! $this->ValidateMessageType($message)) {
285
            $ret['err_msg'] = 'message type not fit accessId';
286
287
            return $ret;
288
        }
289
        if ($message instanceof MessageIOS) {
290
            if ($environment != self::IOSENV_DEV && $environment != self::IOSENV_PROD) {
291
                $ret['err_msg'] = 'ios message environment invalid';
292
293
                return $ret;
294
            }
295
        }
296
        if (! $message->isValid()) {
297
            $ret['err_msg'] = 'message not valid';
298
299
            return $ret;
300
        }
301
        $params = [];
302
        $params['access_id'] = $this->accessId;
303
        $params['expire_time'] = $message->getExpireTime();
304
        if ($message instanceof Message) {
305
            $params['multi_pkg'] = $message->getMultiPkg();
306
        }
307
        $params['device_type'] = $deviceType;
308
        $params['account_list'] = json_encode($accountList);
309
        $params['message_type'] = $message->getType();
310
        $params['message'] = $message->toJson();
311
        $params['timestamp'] = time();
312
        $params['environment'] = $environment;
313
314
        return $this->callRestful(self::RESTAPI_PUSHACCOUNTLIST, $params);
315
    }
316
317
    /**
318
     * 推送消息给APP所有设备.
319
     */
320
    public function PushAllDevices($deviceType, $message, $environment = 0)
321
    {
322
        $ret = ['ret_code' => -1, 'err_msg' => 'message not valid'];
323 View Code Duplication
        if (! is_int($deviceType) || $deviceType < 0 || $deviceType > 5) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
324
            $ret['err_msg'] = 'deviceType not valid';
325
326
            return $ret;
327
        }
328
329
        if (! ($message instanceof Message) && ! ($message instanceof MessageIOS)) {
330
            return $ret;
331
        }
332
        if (! $this->ValidateMessageType($message)) {
333
            $ret['err_msg'] = 'message type not fit accessId';
334
335
            return $ret;
336
        }
337
        if ($message instanceof MessageIOS) {
338
            if ($environment != self::IOSENV_DEV && $environment != self::IOSENV_PROD) {
339
                $ret['err_msg'] = 'ios message environment invalid';
340
341
                return $ret;
342
            }
343
        }
344
        if (! $message->isValid()) {
345
            return $ret;
346
        }
347
        $params = [];
348
        $params['access_id'] = $this->accessId;
349
        $params['expire_time'] = $message->getExpireTime();
350
        $params['send_time'] = $message->getSendTime();
351
        if ($message instanceof Message) {
352
            $params['multi_pkg'] = $message->getMultiPkg();
353
        }
354
        $params['device_type'] = $deviceType;
355
        $params['message_type'] = $message->getType();
356
        $params['message'] = $message->toJson();
357
        $params['timestamp'] = time();
358
        $params['environment'] = $environment;
359
360 View Code Duplication
        if (! is_null($message->getLoopInterval()) && $message->getLoopInterval() > 0
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
361
            && ! is_null($message->getLoopTimes()) && $message->getLoopTimes() > 0
362
        ) {
363
            $params['loop_interval'] = $message->getLoopInterval();
364
            $params['loop_times'] = $message->getLoopTimes();
365
        }
366
        //var_dump($params);
367
368
        return $this->callRestful(self::RESTAPI_PUSHALLDEVICE, $params);
369
    }
370
371
    /**
372
     * 推送消息给指定tags的设备
373
     * 若要推送的tagList只有一项,则tagsOp应为OR.
374
     */
375
    public function PushTags($deviceType, $tagList, $tagsOp, $message, $environment = 0)
376
    {
377
        $ret = ['ret_code' => -1, 'err_msg' => 'message not valid'];
378 View Code Duplication
        if (! is_int($deviceType) || $deviceType < 0 || $deviceType > 5) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
379
            $ret['err_msg'] = 'deviceType not valid';
380
381
            return $ret;
382
        }
383
        if (! is_array($tagList) || empty($tagList)) {
384
            $ret['err_msg'] = 'tagList not valid';
385
386
            return $ret;
387
        }
388
        if (! is_string($tagsOp) || ($tagsOp != 'AND' && $tagsOp != 'OR')) {
389
            $ret['err_msg'] = 'tagsOp not valid';
390
391
            return $ret;
392
        }
393
394
        if (! ($message instanceof Message) && ! ($message instanceof MessageIOS)) {
395
            return $ret;
396
        }
397
        if (! $this->ValidateMessageType($message)) {
398
            $ret['err_msg'] = 'message type not fit accessId';
399
400
            return $ret;
401
        }
402
        if ($message instanceof MessageIOS) {
403
            if ($environment != self::IOSENV_DEV && $environment != self::IOSENV_PROD) {
404
                $ret['err_msg'] = 'ios message environment invalid';
405
406
                return $ret;
407
            }
408
        }
409
        if (! $message->isValid()) {
410
            return $ret;
411
        }
412
413
        $params = [];
414
        $params['access_id'] = $this->accessId;
415
        $params['expire_time'] = $message->getExpireTime();
416
        $params['send_time'] = $message->getSendTime();
417
        if ($message instanceof Message) {
418
            $params['multi_pkg'] = $message->getMultiPkg();
419
        }
420
        $params['device_type'] = $deviceType;
421
        $params['message_type'] = $message->getType();
422
        $params['tags_list'] = json_encode($tagList);
423
        $params['tags_op'] = $tagsOp;
424
        $params['message'] = $message->toJson();
425
        $params['timestamp'] = time();
426
        $params['environment'] = $environment;
427
428 View Code Duplication
        if (! is_null($message->getLoopInterval()) && $message->getLoopInterval() > 0
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
429
            && ! is_null($message->getLoopTimes()) && $message->getLoopTimes() > 0
430
        ) {
431
            $params['loop_interval'] = $message->getLoopInterval();
432
            $params['loop_times'] = $message->getLoopTimes();
433
        }
434
435
        return $this->callRestful(self::RESTAPI_PUSHTAGS, $params);
436
    }
437
438
    /**
439
     * 创建批量推送任务
440
     */
441 View Code Duplication
    public function CreateMultipush($message, $environment = 0)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
442
    {
443
        $ret = ['ret_code' => -1];
444
        if (! ($message instanceof Message) && ! ($message instanceof MessageIOS)) {
445
            $ret['err_msg'] = 'message is not android or ios';
446
447
            return $ret;
448
        }
449
        if (! $this->ValidateMessageType($message)) {
450
            $ret['err_msg'] = 'message type not fit accessId';
451
452
            return $ret;
453
        }
454
        if ($message instanceof MessageIOS) {
455
            if ($environment != self::IOSENV_DEV && $environment != self::IOSENV_PROD) {
456
                $ret['err_msg'] = 'ios message environment invalid';
457
458
                return $ret;
459
            }
460
        }
461
        if (! $message->isValid()) {
462
            $ret['err_msg'] = 'message not valid';
463
464
            return $ret;
465
        }
466
        $params = [];
467
        $params['access_id'] = $this->accessId;
468
        $params['expire_time'] = $message->getExpireTime();
469
        if ($message instanceof Message) {
470
            $params['multi_pkg'] = $message->getMultiPkg();
471
        }
472
        $params['message_type'] = $message->getType();
473
        $params['message'] = $message->toJson();
474
        $params['timestamp'] = time();
475
        $params['environment'] = $environment;
476
477
        return $this->callRestful(self::RESTAPI_CREATEMULTIPUSH, $params);
478
    }
479
480
    /**
481
     * 按帐号大批量推送
482
     */
483 View Code Duplication
    public function PushAccountListMultiple($pushId, $accountList)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
484
    {
485
        $pushId = intval($pushId);
486
        $ret = ['ret_code' => -1];
487
        if ($pushId <= 0) {
488
            $ret['err_msg'] = 'pushId not valid';
489
490
            return $ret;
491
        }
492
        if (! is_array($accountList) || empty($accountList)) {
493
            $ret['err_msg'] = 'accountList not valid';
494
495
            return $ret;
496
        }
497
        $params = [];
498
        $params['access_id'] = $this->accessId;
499
        $params['push_id'] = $pushId;
500
        $params['account_list'] = json_encode($accountList);
501
        $params['timestamp'] = time();
502
503
        return $this->callRestful(self::RESTAPI_PUSHACCOUNTLISTMULTIPLE, $params);
504
    }
505
506
    /**
507
     * 按Token大批量推送
508
     */
509 View Code Duplication
    public function PushDeviceListMultiple($pushId, $deviceList)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
510
    {
511
        $pushId = intval($pushId);
512
        $ret = ['ret_code' => -1];
513
        if ($pushId <= 0) {
514
            $ret['err_msg'] = 'pushId not valid';
515
516
            return $ret;
517
        }
518
        if (! is_array($deviceList) || empty($deviceList)) {
519
            $ret['err_msg'] = 'deviceList not valid';
520
521
            return $ret;
522
        }
523
        $params = [];
524
        $params['access_id'] = $this->accessId;
525
        $params['push_id'] = $pushId;
526
        $params['device_list'] = json_encode($deviceList);
527
        $params['timestamp'] = time();
528
529
        return $this->callRestful(self::RESTAPI_PUSHDEVICELISTMULTIPLE, $params);
530
    }
531
532
    /**
533
     * 查询消息推送状态
534
     * @param array $pushIdList pushId(string)数组
535
     */
536
    public function QueryPushStatus($pushIdList)
537
    {
538
        $ret = ['ret_code' => -1];
539
        $idList = [];
540
        if (! is_array($pushIdList) || empty($pushIdList)) {
541
            $ret['err_msg'] = 'pushIdList not valid';
542
543
            return $ret;
544
        }
545
        foreach ($pushIdList as $pushId) {
546
            $idList[] = ['push_id' => $pushId];
547
        }
548
        $params = [];
549
        $params['access_id'] = $this->accessId;
550
        $params['push_ids'] = json_encode($idList);
551
        $params['timestamp'] = time();
552
553
        return $this->callRestful(self::RESTAPI_QUERYPUSHSTATUS, $params);
554
    }
555
556
    /**
557
     * 查询应用覆盖的设备数.
558
     */
559 View Code Duplication
    public function QueryDeviceCount()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
560
    {
561
        $params = [];
562
        $params['access_id'] = $this->accessId;
563
        $params['timestamp'] = time();
564
565
        return $this->callRestful(self::RESTAPI_QUERYDEVICECOUNT, $params);
566
    }
567
568
    /**
569
     * 查询应用标签.
570
     */
571 View Code Duplication
    public function QueryTags($start = 0, $limit = 100)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
572
    {
573
        $ret = ['ret_code' => -1];
574
        if (! is_int($start) || ! is_int($limit)) {
575
            $ret['err_msg'] = 'start or limit not valid';
576
577
            return $ret;
578
        }
579
        $params = [];
580
        $params['access_id'] = $this->accessId;
581
        $params['start'] = $start;
582
        $params['limit'] = $limit;
583
        $params['timestamp'] = time();
584
585
        return $this->callRestful(self::RESTAPI_QUERYTAGS, $params);
586
    }
587
588
    /**
589
     * 查询标签下token数量.
590
     */
591 View Code Duplication
    public function QueryTagTokenNum($tag)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
592
    {
593
        $ret = ['ret_code' => -1];
594
        if (! is_string($tag)) {
595
            $ret['err_msg'] = 'tag is not valid';
596
597
            return $ret;
598
        }
599
        $params = [];
600
        $params['access_id'] = $this->accessId;
601
        $params['tag'] = $tag;
602
        $params['timestamp'] = time();
603
604
        return $this->callRestful(self::RESTAPI_QUERYTAGTOKENNUM, $params);
605
    }
606
607
    /**
608
     * 查询token的标签.
609
     */
610 View Code Duplication
    public function QueryTokenTags($deviceToken)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
611
    {
612
        $ret = ['ret_code' => -1];
613
        if (! is_string($deviceToken)) {
614
            $ret['err_msg'] = 'deviceToken is not valid';
615
616
            return $ret;
617
        }
618
        $params = [];
619
        $params['access_id'] = $this->accessId;
620
        $params['device_token'] = $deviceToken;
621
        $params['timestamp'] = time();
622
623
        return $this->callRestful(self::RESTAPI_QUERYTOKENTAGS, $params);
624
    }
625
626
    /**
627
     * 取消定时发送
628
     */
629 View Code Duplication
    public function CancelTimingPush($pushId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
630
    {
631
        $ret = ['ret_code' => -1];
632
        if (! is_string($pushId) || empty($pushId)) {
633
            $ret['err_msg'] = 'pushId not valid';
634
635
            return $ret;
636
        }
637
        $params = [];
638
        $params['access_id'] = $this->accessId;
639
        $params['push_id'] = $pushId;
640
        $params['timestamp'] = time();
641
642
        return $this->callRestful(self::RESTAPI_CANCELTIMINGPUSH, $params);
643
    }
644
645
    //json转换为数组
646
    protected function json2Array($json)
647
    {
648
        $json = stripslashes($json);
649
650
        return json_decode($json, true);
651
    }
652
653
    protected function callRestful($url, $params)
654
    {
655
        $paramsBase = new ParamsBase($params);
656
        $sign = $paramsBase->generateSign(RequestBase::METHOD_POST, $url, $this->secretKey);
657
        $params['sign'] = $sign;
658
659
        $requestBase = new RequestBase();
660
        $ret = $this->json2Array($requestBase->exec($url, $params, RequestBase::METHOD_POST));
661
662
        return $ret;
663
    }
664
665
    private function ValidateToken($token)
666
    {
667
        if (intval($this->accessId) >= 2200000000) {
668
            return strlen($token) == 64;
669
        } else {
670
            return strlen($token) == 40 || strlen($token) == 64;
671
        }
672
    }
673
674 View Code Duplication
    public function InitParams()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
675
    {
676
        $params = [];
677
        $params['access_id'] = $this->accessId;
678
        $params['timestamp'] = time();
679
680
        return $params;
681
    }
682
683 View Code Duplication
    public function BatchSetTag($tagTokenPairs)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
684
    {
685
        $ret = ['ret_code' => -1];
686
687
        foreach ($tagTokenPairs as $pair) {
688
            if (! ($pair instanceof TagTokenPair)) {
689
                $ret['err_msg'] = 'tag-token pair type error!';
690
691
                return $ret;
692
            }
693
            if (! $this->ValidateToken($pair->token)) {
694
                $ret['err_msg'] = sprintf('invalid token %s', $pair->token);
695
696
                return $ret;
697
            }
698
        }
699
        $params = $this->InitParams();
700
701
        $tag_token_list = [];
702
        foreach ($tagTokenPairs as $pair) {
703
            array_push($tag_token_list, [$pair->tag, $pair->token]);
704
        }
705
        $params['tag_token_list'] = json_encode($tag_token_list);
706
707
        return $this->callRestful(self::RESTAPI_BATCHSETTAG, $params);
708
    }
709
710 View Code Duplication
    public function BatchDelTag($tagTokenPairs)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
711
    {
712
        $ret = ['ret_code' => -1];
713
714
        foreach ($tagTokenPairs as $pair) {
715
            if (! ($pair instanceof TagTokenPair)) {
716
                $ret['err_msg'] = 'tag-token pair type error!';
717
718
                return $ret;
719
            }
720
            if (! $this->ValidateToken($pair->token)) {
721
                $ret['err_msg'] = sprintf('invalid token %s', $pair->token);
722
723
                return $ret;
724
            }
725
        }
726
        $params = $this->InitParams();
727
728
        $tag_token_list = [];
729
        foreach ($tagTokenPairs as $pair) {
730
            array_push($tag_token_list, [$pair->tag, $pair->token]);
731
        }
732
        $params['tag_token_list'] = json_encode($tag_token_list);
733
734
        return $this->callRestful(self::RESTAPI_BATCHDELTAG, $params);
735
    }
736
737 View Code Duplication
    public function QueryInfoOfToken($deviceToken)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
738
    {
739
        $ret = ['ret_code' => -1];
740
        if (! is_string($deviceToken)) {
741
            $ret['err_msg'] = 'deviceToken is not valid';
742
743
            return $ret;
744
        }
745
        $params = [];
746
        $params['access_id'] = $this->accessId;
747
        $params['device_token'] = $deviceToken;
748
        $params['timestamp'] = time();
749
750
        return $this->callRestful(self::RESTAPI_QUERYINFOOFTOKEN, $params);
751
    }
752
753 View Code Duplication
    public function QueryTokensOfAccount($account)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
754
    {
755
        $ret = ['ret_code' => -1];
756
        if (! is_string($account)) {
757
            $ret['err_msg'] = 'account is not valid';
758
759
            return $ret;
760
        }
761
        $params = [];
762
        $params['access_id'] = $this->accessId;
763
        $params['account'] = $account;
764
        $params['timestamp'] = time();
765
766
        return $this->callRestful(self::RESTAPI_QUERYTOKENSOFACCOUNT, $params);
767
    }
768
769 View Code Duplication
    public function DeleteTokenOfAccount($account, $deviceToken)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
770
    {
771
        $ret = ['ret_code' => -1];
772
        if (! is_string($account) || ! is_string($deviceToken)) {
773
            $ret['err_msg'] = 'account or deviceToken is not valid';
774
775
            return $ret;
776
        }
777
        $params = [];
778
        $params['access_id'] = $this->accessId;
779
        $params['account'] = $account;
780
        $params['device_token'] = $deviceToken;
781
        $params['timestamp'] = time();
782
783
        return $this->callRestful(self::RESTAPI_DELETETOKENOFACCOUNT, $params);
784
    }
785
786 View Code Duplication
    public function DeleteAllTokensOfAccount($account)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
787
    {
788
        $ret = ['ret_code' => -1];
789
        if (! is_string($account)) {
790
            $ret['err_msg'] = 'account is not valid';
791
792
            return $ret;
793
        }
794
        $params = [];
795
        $params['access_id'] = $this->accessId;
796
        $params['account'] = $account;
797
        $params['timestamp'] = time();
798
799
        return $this->callRestful(self::RESTAPI_DELETEALLTOKENSOFACCOUNT, $params);
800
    }
801
802
    private function ValidateMessageType($message)
803
    {
804
        if (intval($this->accessId) >= self::IOS_MIN_ID and $message instanceof MessageIOS) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
805
            return true;
806
        } elseif (intval($this->accessId) < self::IOS_MIN_ID and $message instanceof Message) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
807
            return true;
808
        } else {
809
            return false;
810
        }
811
    }
812
813
    public $accessId = ''; //应用的接入Id
814
    public $secretKey = ''; //应用的skey
815
816
    const RESTAPI_PUSHSINGLEDEVICE = 'http://openapi.xg.qq.com/v2/push/single_device';
817
    const RESTAPI_PUSHSINGLEACCOUNT = 'http://openapi.xg.qq.com/v2/push/single_account';
818
    const RESTAPI_PUSHACCOUNTLIST = 'http://openapi.xg.qq.com/v2/push/account_list';
819
    const RESTAPI_PUSHALLDEVICE = 'http://openapi.xg.qq.com/v2/push/all_device';
820
    const RESTAPI_PUSHTAGS = 'http://openapi.xg.qq.com/v2/push/tags_device';
821
    const RESTAPI_QUERYPUSHSTATUS = 'http://openapi.xg.qq.com/v2/push/get_msg_status';
822
    const RESTAPI_QUERYDEVICECOUNT = 'http://openapi.xg.qq.com/v2/application/get_app_device_num';
823
    const RESTAPI_QUERYTAGS = 'http://openapi.xg.qq.com/v2/tags/query_app_tags';
824
    const RESTAPI_CANCELTIMINGPUSH = 'http://openapi.xg.qq.com/v2/push/cancel_timing_task';
825
    const RESTAPI_BATCHSETTAG = 'http://openapi.xg.qq.com/v2/tags/batch_set';
826
    const RESTAPI_BATCHDELTAG = 'http://openapi.xg.qq.com/v2/tags/batch_del';
827
    const RESTAPI_QUERYTOKENTAGS = 'http://openapi.xg.qq.com/v2/tags/query_token_tags';
828
    const RESTAPI_QUERYTAGTOKENNUM = 'http://openapi.xg.qq.com/v2/tags/query_tag_token_num';
829
    const RESTAPI_CREATEMULTIPUSH = 'http://openapi.xg.qq.com/v2/push/create_multipush';
830
    const RESTAPI_PUSHACCOUNTLISTMULTIPLE = 'http://openapi.xg.qq.com/v2/push/account_list_multiple';
831
    const RESTAPI_PUSHDEVICELISTMULTIPLE = 'http://openapi.xg.qq.com/v2/push/device_list_multiple';
832
    const RESTAPI_QUERYINFOOFTOKEN = 'http://openapi.xg.qq.com/v2/application/get_app_token_info';
833
    const RESTAPI_QUERYTOKENSOFACCOUNT = 'http://openapi.xg.qq.com/v2/application/get_app_account_tokens';
834
    const RESTAPI_DELETETOKENOFACCOUNT = 'http://openapi.xg.qq.com/v2/application/del_app_account_tokens';
835
    const RESTAPI_DELETEALLTOKENSOFACCOUNT = 'http://openapi.xg.qq.com/v2/application/del_app_account_all_tokens';
836
}
837
838
class TagTokenPair
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
839
{
840
    public function __construct($tag, $token)
841
    {
842
        $this->tag = strval($tag);
843
        $this->token = strval($token);
844
    }
845
846
    public function __destruct()
847
    {
848
    }
849
850
    public $tag;
851
    public $token;
852
}
853
854
class Message
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
855
{
856
    public function __construct()
857
    {
858
        $this->m_acceptTimes = [];
859
        $this->m_multiPkg = 0;
860
        $this->m_raw = '';
861
        $this->m_style = new Style(0);
862
        $this->m_action = new ClickAction();
863
    }
864
865
    public function __destruct()
866
    {
867
    }
868
869
    public function setTitle($title)
870
    {
871
        $this->m_title = $title;
872
    }
873
874
    public function setContent($content)
875
    {
876
        $this->m_content = $content;
877
    }
878
879
    public function setExpireTime($expireTime)
880
    {
881
        $this->m_expireTime = $expireTime;
882
    }
883
884
    public function getExpireTime()
885
    {
886
        return $this->m_expireTime;
887
    }
888
889
    public function setSendTime($sendTime)
890
    {
891
        $this->m_sendTime = $sendTime;
892
    }
893
894
    public function getSendTime()
895
    {
896
        return $this->m_sendTime;
897
    }
898
899
    public function addAcceptTime($acceptTime)
900
    {
901
        $this->m_acceptTimes[] = $acceptTime;
902
    }
903
904
    public function acceptTimeToJson()
905
    {
906
        $ret = [];
907
        foreach ($this->m_acceptTimes as $acceptTime) {
908
            $ret[] = $acceptTime->toArray();
909
        }
910
911
        return $ret;
912
    }
913
914
    /**
915
     * 消息类型.
916
     * @param int $type 1:通知 2:透传消息
917
     */
918
    public function setType($type)
919
    {
920
        $this->m_type = $type;
921
    }
922
923
    public function getType()
924
    {
925
        return $this->m_type;
926
    }
927
928
    public function setMultiPkg($multiPkg)
929
    {
930
        $this->m_multiPkg = $multiPkg;
931
    }
932
933
    public function getMultiPkg()
934
    {
935
        return $this->m_multiPkg;
936
    }
937
938
    public function setStyle($style)
939
    {
940
        $this->m_style = $style;
941
    }
942
943
    public function setAction($action)
944
    {
945
        $this->m_action = $action;
946
    }
947
948
    public function setCustom($custom)
949
    {
950
        $this->m_custom = $custom;
951
    }
952
953
    public function setRaw($raw)
954
    {
955
        $this->m_raw = $raw;
956
    }
957
958
    public function getLoopInterval()
959
    {
960
        return $this->m_loopInterval;
961
    }
962
963
    public function setLoopInterval($loopInterval)
964
    {
965
        $this->m_loopInterval = $loopInterval;
966
    }
967
968
    public function getLoopTimes()
969
    {
970
        return $this->m_loopTimes;
971
    }
972
973
    public function setLoopTimes($loopTimes)
974
    {
975
        $this->m_loopTimes = $loopTimes;
976
    }
977
978
    public function toJson()
979
    {
980
        if (! empty($this->m_raw)) {
981
            return $this->m_raw;
982
        }
983
        $ret = [];
984
        if ($this->m_type == self::TYPE_NOTIFICATION) {
985
            $ret['title'] = $this->m_title;
986
            $ret['content'] = $this->m_content;
987
            $ret['accept_time'] = $this->acceptTimeToJson();
988
            $ret['builder_id'] = $this->m_style->getBuilderId();
989
            $ret['ring'] = $this->m_style->getRing();
990
            $ret['vibrate'] = $this->m_style->getVibrate();
991
            $ret['clearable'] = $this->m_style->getClearable();
992
            $ret['n_id'] = $this->m_style->getNId();
993
994
            if (! is_null($this->m_style->getRingRaw())) {
995
                $ret['ring_raw'] = $this->m_style->getRingRaw();
996
            }
997
            $ret['lights'] = $this->m_style->getLights();
998
            $ret['icon_type'] = $this->m_style->getIconType();
999
            if (! is_null($this->m_style->getIconRes())) {
1000
                $ret['icon_res'] = $this->m_style->getIconRes();
1001
            }
1002
            $ret['style_id'] = $this->m_style->getStyleId();
1003
            if (! is_null($this->m_style->getSmallIcon())) {
1004
                $ret['small_icon'] = $this->m_style->getSmallIcon();
1005
            }
1006
1007
            $ret['action'] = $this->m_action->toJson();
1008
        } elseif ($this->m_type == self::TYPE_MESSAGE) {
1009
            $ret['title'] = $this->m_title;
1010
            $ret['content'] = $this->m_content;
1011
            $ret['accept_time'] = $this->acceptTimeToJson();
1012
        }
1013
        $ret['custom_content'] = $this->m_custom;
1014
1015
        return json_encode($ret);
1016
    }
1017
1018
    public function isValid()
1019
    {
1020
        if (is_string($this->m_raw) && ! empty($this->raw)) {
1 ignored issue
show
Bug introduced by
The property raw does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
1021
            return true;
1022
        }
1023 View Code Duplication
        if (! isset($this->m_title)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1024
            $this->m_title = '';
1025
        } elseif (! is_string($this->m_title) || empty($this->m_title)) {
1026
            return false;
1027
        }
1028 View Code Duplication
        if (! isset($this->m_content)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1029
            $this->m_content = '';
1030
        } elseif (! is_string($this->m_content) || empty($this->m_content)) {
1031
            return false;
1032
        }
1033 View Code Duplication
        if (! is_int($this->m_type) || $this->m_type < self::TYPE_NOTIFICATION || $this->m_type > self::TYPE_MESSAGE) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1034
            return false;
1035
        }
1036
        if (! is_int($this->m_multiPkg) || $this->m_multiPkg < 0 || $this->m_multiPkg > 1) {
1037
            return false;
1038
        }
1039
        if ($this->m_type == self::TYPE_NOTIFICATION) {
1040
            if (! ($this->m_style instanceof Style) || ! ($this->m_action instanceof ClickAction)) {
1041
                return false;
1042
            }
1043
            if (! $this->m_style->isValid() || ! $this->m_action->isValid()) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->m_action->isValid() of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
1044
                return false;
1045
            }
1046
        }
1047 View Code Duplication
        if (isset($this->m_expireTime)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1048
            if (! is_int($this->m_expireTime) || $this->m_expireTime > 3 * 24 * 60 * 60) {
1049
                return false;
1050
            }
1051
        } else {
1052
            $this->m_expireTime = 0;
1053
        }
1054
1055 View Code Duplication
        if (isset($this->m_sendTime)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1056
            if (strtotime($this->m_sendTime) === false) {
1057
                return false;
1058
            }
1059
        } else {
1060
            $this->m_sendTime = '2013-12-19 17:49:00';
1061
        }
1062
1063 View Code Duplication
        foreach ($this->m_acceptTimes as $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1064
            if (! ($value instanceof TimeInterval) || ! $value->isValid()) {
1065
                return false;
1066
            }
1067
        }
1068
1069 View Code Duplication
        if (isset($this->m_custom)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1070
            if (! is_array($this->m_custom)) {
1071
                return false;
1072
            }
1073
        } else {
1074
            $this->m_custom = [];
1075
        }
1076
1077 View Code Duplication
        if (isset($this->m_loopInterval)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1078
            if (! (is_int($this->m_loopInterval) && $this->m_loopInterval > 0)) {
1079
                return false;
1080
            }
1081
        }
1082
1083 View Code Duplication
        if (isset($this->m_loopTimes)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1084
            if (! (is_int($this->m_loopTimes) && $this->m_loopTimes > 0)) {
1085
                return false;
1086
            }
1087
        }
1088
1089 View Code Duplication
        if (isset($this->m_loopInterval) && isset($this->m_loopTimes)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1090
            if (($this->m_loopTimes - 1) * $this->m_loopInterval + 1 > self::MAX_LOOP_TASK_DAYS) {
1091
                return false;
1092
            }
1093
        }
1094
1095
        return true;
1096
    }
1097
1098
    private $m_title;
1099
    private $m_content;
1100
    private $m_expireTime;
1101
    private $m_sendTime;
1102
    private $m_acceptTimes;
1103
    private $m_type;
1104
    private $m_multiPkg;
1105
    private $m_style;
1106
    private $m_action;
1107
    private $m_custom;
1108
    private $m_raw;
1109
    private $m_loopInterval;
1110
    private $m_loopTimes;
1111
1112
    const TYPE_NOTIFICATION = 1;
1113
    const TYPE_MESSAGE = 2;
1114
    const MAX_LOOP_TASK_DAYS = 15;
1115
}
1116
1117
class MessageIOS
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1118
{
1119
    public function __construct()
1120
    {
1121
        $this->m_acceptTimes = [];
1122
        $this->m_type = self::TYPE_APNS_NOTIFICATION;
1123
    }
1124
1125
    public function __destruct()
1126
    {
1127
    }
1128
1129
    public function setExpireTime($expireTime)
1130
    {
1131
        $this->m_expireTime = $expireTime;
1132
    }
1133
1134
    public function getExpireTime()
1135
    {
1136
        return $this->m_expireTime;
1137
    }
1138
1139
    public function setSendTime($sendTime)
1140
    {
1141
        $this->m_sendTime = $sendTime;
1142
    }
1143
1144
    public function getSendTime()
1145
    {
1146
        return $this->m_sendTime;
1147
    }
1148
1149
    public function addAcceptTime($acceptTime)
1150
    {
1151
        $this->m_acceptTimes[] = $acceptTime;
1152
    }
1153
1154
    public function acceptTimeToJson()
1155
    {
1156
        $ret = [];
1157
        foreach ($this->m_acceptTimes as $acceptTime) {
1158
            $ret[] = $acceptTime->toArray();
1159
        }
1160
1161
        return $ret;
1162
    }
1163
1164
    public function setCustom($custom)
1165
    {
1166
        $this->m_custom = $custom;
1167
    }
1168
1169
    public function setRaw($raw)
1170
    {
1171
        $this->m_raw = $raw;
1172
    }
1173
1174
    public function setAlert($alert)
1175
    {
1176
        $this->m_alert = $alert;
1177
    }
1178
1179
    public function setBadge($badge)
1180
    {
1181
        $this->m_badge = $badge;
1182
    }
1183
1184
    public function setSound($sound)
1185
    {
1186
        $this->m_sound = $sound;
1187
    }
1188
1189
    /**
1190
     * 消息类型.
1191
     * @param int $type 1:通知 2:静默通知
1192
     */
1193
    public function setType($type)
1194
    {
1195
        $this->m_type = $type;
1196
    }
1197
1198
    public function getType()
1199
    {
1200
        return $this->m_type;
1201
    }
1202
1203
    public function getCategory()
1204
    {
1205
        return $this->m_category;
1206
    }
1207
1208
    public function setCategory($category)
1209
    {
1210
        $this->m_category = $category;
1211
    }
1212
1213
    public function getLoopInterval()
1214
    {
1215
        return $this->m_loopInterval;
1216
    }
1217
1218
    public function setLoopInterval($loopInterval)
1219
    {
1220
        $this->m_loopInterval = $loopInterval;
1221
    }
1222
1223
    public function getLoopTimes()
1224
    {
1225
        return $this->m_loopTimes;
1226
    }
1227
1228
    public function setLoopTimes($loopTimes)
1229
    {
1230
        $this->m_loopTimes = $loopTimes;
1231
    }
1232
1233
    public function toJson()
1234
    {
1235
        if (! empty($this->m_raw)) {
1236
            return $this->m_raw;
1237
        }
1238
        $ret = $this->m_custom;
1239
        $ret['accept_time'] = $this->acceptTimeToJson();
1240
1241
        $aps = [];
1242
        if ($this->m_type == self::TYPE_APNS_NOTIFICATION) {
1243
            $aps['alert'] = $this->m_alert;
1244
            if (isset($this->m_badge)) {
1245
                $aps['badge'] = $this->m_badge;
1246
            }
1247
            if (isset($this->m_sound)) {
1248
                $aps['sound'] = $this->m_sound;
1249
            }
1250
            if (isset($this->m_category)) {
1251
                $aps['category'] = $this->m_category;
1252
            }
1253
        } elseif ($this->m_type == self::TYPE_REMOTE_NOTIFICATION) {
1254
            $aps['content-available'] = 1;
1255
        }
1256
        $ret['aps'] = $aps;
1257
1258
        return json_encode($ret);
1259
    }
1260
1261
    public function isValid()
1262
    {
1263 View Code Duplication
        if (isset($this->m_expireTime)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1264
            if (! is_int($this->m_expireTime) || $this->m_expireTime > 3 * 24 * 60 * 60) {
1265
                return false;
1266
            }
1267
        } else {
1268
            $this->m_expireTime = 0;
1269
        }
1270
1271 View Code Duplication
        if (isset($this->m_sendTime)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1272
            if (strtotime($this->m_sendTime) === false) {
1273
                return false;
1274
            }
1275
        } else {
1276
            $this->m_sendTime = '2014-03-13 12:00:00';
1277
        }
1278
1279
        if (! empty($this->m_raw)) {
1280
            if (is_string($this->m_raw)) {
1281
                return true;
1282
            } else {
1283
                return false;
1284
            }
1285
        }
1286 View Code Duplication
        if (! is_int($this->m_type) || $this->m_type < self::TYPE_APNS_NOTIFICATION || $this->m_type > self::TYPE_REMOTE_NOTIFICATION) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1287
            return false;
1288
        }
1289
1290 View Code Duplication
        foreach ($this->m_acceptTimes as $value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1291
            if (! ($value instanceof TimeInterval) || ! $value->isValid()) {
1292
                return false;
1293
            }
1294
        }
1295
1296 View Code Duplication
        if (isset($this->m_custom)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1297
            if (! is_array($this->m_custom)) {
1298
                return false;
1299
            }
1300
        } else {
1301
            $this->m_custom = [];
1302
        }
1303
        if ($this->m_type == self::TYPE_APNS_NOTIFICATION) {
1304
            if (! isset($this->m_alert)) {
1305
                return false;
1306
            }
1307
            if (! is_string($this->m_alert) && ! is_array($this->m_alert)) {
1308
                return false;
1309
            }
1310
        }
1311
        if (isset($this->m_badge)) {
1312
            if (! is_int($this->m_badge)) {
1313
                return false;
1314
            }
1315
        }
1316
        if (isset($this->m_sound)) {
1317
            if (! is_string($this->m_sound)) {
1318
                return false;
1319
            }
1320
        }
1321 View Code Duplication
        if (isset($this->m_loopInterval)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1322
            if (! (is_int($this->m_loopInterval) && $this->m_loopInterval > 0)) {
1323
                return false;
1324
            }
1325
        }
1326 View Code Duplication
        if (isset($this->m_loopTimes)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1327
            if (! (is_int($this->m_loopTimes) && $this->m_loopTimes > 0)) {
1328
                return false;
1329
            }
1330
        }
1331 View Code Duplication
        if (isset($this->m_loopInterval) && isset($this->m_loopTimes)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1332
            if (($this->m_loopTimes - 1) * $this->m_loopInterval + 1 > self::MAX_LOOP_TASK_DAYS) {
1333
                return false;
1334
            }
1335
        }
1336
1337
        return true;
1338
    }
1339
1340
    private $m_expireTime;
1341
    private $m_sendTime;
1342
    private $m_acceptTimes;
1343
    private $m_custom;
1344
    private $m_raw;
1345
    private $m_type;
1346
    private $m_alert;
1347
    private $m_badge;
1348
    private $m_sound;
1349
    private $m_category;
1350
    private $m_loopInterval;
1351
    private $m_loopTimes;
1352
1353
    const TYPE_APNS_NOTIFICATION = 11;
1354
    const TYPE_REMOTE_NOTIFICATION = 12;
1355
    const MAX_LOOP_TASK_DAYS = 15;
1356
}
1357
1358
class ClickAction
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1359
{
1360
    /**
1361
     * 动作类型.
1362
     * @param int $actionType 1打开activity或app本身,2打开url,3打开Intent
0 ignored issues
show
Bug introduced by
There is no parameter named $actionType. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
1363
     */
1364
    public function __construct()
1365
    {
1366
        $this->m_atyAttrIntentFlag = 0;
1367
        $this->m_atyAttrPendingIntentFlag = 0;
1368
        $this->m_confirmOnPackageDownloadUrl = 1;
1369
    }
1370
1371
    public function setActionType($actionType)
1372
    {
1373
        $this->m_actionType = $actionType;
1374
    }
1375
1376
    public function setUrl($url)
1377
    {
1378
        $this->m_url = $url;
1379
    }
1380
1381
    public function setComfirmOnUrl($comfirmOnUrl)
1382
    {
1383
        $this->m_confirmOnUrl = $comfirmOnUrl;
1384
    }
1385
1386
    public function setActivity($activity)
1387
    {
1388
        $this->m_activity = $activity;
1389
    }
1390
1391
    public function setIntent($intent)
1392
    {
1393
        $this->m_intent = $intent;
1394
    }
1395
1396
    public function setAtyAttrIntentFlag($atyAttrIntentFlag)
1397
    {
1398
        $this->m_atyAttrIntentFlag = $atyAttrIntentFlag;
1399
    }
1400
1401
    public function setAtyAttrPendingIntentFlag($atyAttrPendingIntentFlag)
1402
    {
1403
        $this->m_atyAttrPendingIntentFlag = $atyAttrPendingIntentFlag;
1404
    }
1405
1406
    public function setPackageDownloadUrl($packageDownloadUrl)
1407
    {
1408
        $this->m_packageDownloadUrl = $packageDownloadUrl;
1409
    }
1410
1411
    public function setConfirmOnPackageDownloadUrl($confirmOnPackageDownloadUrl)
1412
    {
1413
        $this->m_confirmOnPackageDownloadUrl = $confirmOnPackageDownloadUrl;
1414
    }
1415
1416
    public function setPackageName($packageName)
1417
    {
1418
        $this->m_packageName = $packageName;
1419
    }
1420
1421
    public function toJson()
1422
    {
1423
        $ret = [];
1424
        $ret['action_type'] = $this->m_actionType;
1425
        $ret['browser'] = ['url' => $this->m_url, 'confirm' => $this->m_confirmOnUrl];
1426
        $ret['activity'] = $this->m_activity;
1427
        $ret['intent'] = $this->m_intent;
1428
1429
        $aty_attr = [];
1430
        if (isset($this->m_atyAttrIntentFlag)) {
1431
            $aty_attr['if'] = $this->m_atyAttrIntentFlag;
1432
        }
1433
        if (isset($this->m_atyAttrPendingIntentFlag)) {
1434
            $aty_attr['pf'] = $this->m_atyAttrPendingIntentFlag;
1435
        }
1436
        $ret['aty_attr'] = $aty_attr;
1437
1438
        return $ret;
1439
    }
1440
1441
    public function isValid()
1442
    {
1443
        if (! isset($this->m_actionType)) {
1444
            $this->m_actionType = self::TYPE_ACTIVITY;
1445
        }
1446
        if (! is_int($this->m_actionType)) {
1447
            return false;
1448
        }
1449
        if ($this->m_actionType < self::TYPE_ACTIVITY || $this->m_actionType > self::TYPE_INTENT) {
1450
            return false;
1451
        }
1452
1453
        if ($this->m_actionType == self::TYPE_ACTIVITY) {
1454
            if (! isset($this->m_activity)) {
1455
                $this->m_activity = '';
1456
1457
                return true;
1458
            }
1459
            if (isset($this->m_atyAttrIntentFlag)) {
1460
                if (! is_int($this->m_atyAttrIntentFlag)) {
1461
                    return false;
1462
                }
1463
            }
1464
            if (isset($this->m_atyAttrPendingIntentFlag)) {
1465
                if (! is_int($this->m_atyAttrPendingIntentFlag)) {
1466
                    return false;
1467
                }
1468
            }
1469
1470
            if (is_string($this->m_activity) && ! empty($this->m_activity)) {
1471
                return true;
1472
            }
1473
1474
            return false;
1475
        }
1476
1477
        if ($this->m_actionType == self::TYPE_URL) {
1478
            if (is_string($this->m_url) && ! empty($this->m_url) &&
1479
                is_int($this->m_confirmOnUrl) &&
1480
                $this->m_confirmOnUrl >= 0 && $this->m_confirmOnUrl <= 1
1481
            ) {
1482
                return true;
1483
            }
1484
1485
            return false;
1486
        }
1487
1488
        if ($this->m_actionType == self::TYPE_INTENT) {
1489
            if (is_string($this->m_intent) && ! empty($this->m_intent)) {
1490
                return true;
1491
            }
1492
1493
            return false;
1494
        }
1495
    }
1496
1497
    private $m_actionType;
1498
    private $m_url;
1499
    private $m_confirmOnUrl;
1500
    private $m_activity;
1501
    private $m_intent;
1502
    private $m_atyAttrIntentFlag;
1503
    private $m_atyAttrPendingIntentFlag;
1504
    private $m_packageDownloadUrl;
1505
    private $m_confirmOnPackageDownloadUrl;
1506
    private $m_packageName;
1507
1508
    const TYPE_ACTIVITY = 1;
1509
    const TYPE_URL = 2;
1510
    const TYPE_INTENT = 3;
1511
}
1512
1513
class Style
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1514
{
1515
    public function __construct($builderId, $ring = 0, $vibrate = 0, $clearable = 1, $nId = 0, $lights = 1, $iconType = 0, $styleId = 1)
1516
    {
1517
        $this->m_builderId = $builderId;
1518
        $this->m_ring = $ring;
1519
        $this->m_vibrate = $vibrate;
1520
        $this->m_clearable = $clearable;
1521
        $this->m_nId = $nId;
1522
        $this->m_lights = $lights;
1523
        $this->m_iconType = $iconType;
1524
        $this->m_styleId = $styleId;
1525
    }
1526
1527
    public function __destruct()
1528
    {
1529
    }
1530
1531
    public function getBuilderId()
1532
    {
1533
        return $this->m_builderId;
1534
    }
1535
1536
    public function getRing()
1537
    {
1538
        return $this->m_ring;
1539
    }
1540
1541
    public function getVibrate()
1542
    {
1543
        return $this->m_vibrate;
1544
    }
1545
1546
    public function getClearable()
1547
    {
1548
        return $this->m_clearable;
1549
    }
1550
1551
    public function getNId()
1552
    {
1553
        return $this->m_nId;
1554
    }
1555
1556
    public function getLights()
1557
    {
1558
        return $this->m_lights;
1559
    }
1560
1561
    public function getIconType()
1562
    {
1563
        return $this->m_iconType;
1564
    }
1565
1566
    public function getStyleId()
1567
    {
1568
        return $this->m_styleId;
1569
    }
1570
1571
    public function setRingRaw($ringRaw)
1572
    {
1573
        return $this->m_ringRaw = $ringRaw;
1574
    }
1575
1576
    public function getRingRaw()
1577
    {
1578
        return $this->m_ringRaw;
1579
    }
1580
1581
    public function setIconRes($iconRes)
1582
    {
1583
        return $this->m_iconRes = $iconRes;
1584
    }
1585
1586
    public function getIconRes()
1587
    {
1588
        return $this->m_iconRes;
1589
    }
1590
1591
    public function setSmallIcon($smallIcon)
1592
    {
1593
        return $this->m_smallIcon = $smallIcon;
1594
    }
1595
1596
    public function getSmallIcon()
1597
    {
1598
        return $this->m_smallIcon;
1599
    }
1600
1601
    public function isValid()
1602
    {
1603
        if (! is_int($this->m_builderId) || ! is_int($this->m_ring) ||
1604
            ! is_int($this->m_vibrate) || ! is_int($this->m_clearable) ||
1605
            ! is_int($this->m_lights) || ! is_int($this->m_iconType) ||
1606
            ! is_int($this->m_styleId)
1607
        ) {
1608
            return false;
1609
        }
1610
        if ($this->m_ring < 0 || $this->m_ring > 1) {
1611
            return false;
1612
        }
1613
        if ($this->m_vibrate < 0 || $this->m_vibrate > 1) {
1614
            return false;
1615
        }
1616
        if ($this->m_clearable < 0 || $this->m_clearable > 1) {
1617
            return false;
1618
        }
1619
        if ($this->m_lights < 0 || $this->m_lights > 1) {
1620
            return false;
1621
        }
1622
        if ($this->m_iconType < 0 || $this->m_iconType > 1) {
1623
            return false;
1624
        }
1625
        if ($this->m_styleId < 0 || $this->m_styleId > 1) {
1626
            return false;
1627
        }
1628
1629
        return true;
1630
    }
1631
1632
    private $m_builderId;
1633
    private $m_ring;
1634
    private $m_vibrate;
1635
    private $m_clearable;
1636
    private $m_nId;
1637
    private $m_ringRaw;
1638
    private $m_lights;
1639
    private $m_iconType;
1640
    private $m_iconRes;
1641
    private $m_styleId;
1642
    private $m_smallIcon;
1643
}
1644
1645
class TimeInterval
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1646
{
1647
    public function __construct($startHour, $startMin, $endHour, $endMin)
1648
    {
1649
        $this->m_startHour = $startHour;
1650
        $this->m_startMin = $startMin;
1651
        $this->m_endHour = $endHour;
1652
        $this->m_endMin = $endMin;
1653
    }
1654
1655
    public function __destruct()
1656
    {
1657
    }
1658
1659
    public function toArray()
1660
    {
1661
        return [
1662
            'start' => ['hour' => strval($this->m_startHour), 'min' => strval($this->m_startMin)],
1663
            'end' => ['hour' => strval($this->m_endHour), 'min' => strval($this->m_endMin)],
1664
        ];
1665
    }
1666
1667
    public function isValid()
1668
    {
1669
        if (! is_int($this->m_startHour) || ! is_int($this->m_startMin) ||
1670
            ! is_int($this->m_endHour) || ! is_int($this->m_endMin)
1671
        ) {
1672
            return false;
1673
        }
1674
1675
        if ($this->m_startHour >= 0 && $this->m_startHour <= 23 &&
1676
            $this->m_startMin >= 0 && $this->m_startMin <= 59 &&
1677
            $this->m_endHour >= 0 && $this->m_endHour <= 23 &&
1678
            $this->m_endMin >= 0 && $this->m_endMin <= 59
1679
        ) {
1680
            return true;
1681
        } else {
1682
            return false;
1683
        }
1684
    }
1685
1686
    private $m_startHour;
1687
    private $m_startMin;
1688
    private $m_endHour;
1689
    private $m_endMin;
1690
}
1691
1692
class ParamsBase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1693
{
1694
    /**
1695
     * @var array 当前传入的参数列表
1696
     */
1697
    public $_params = [];
1698
1699
    /**
1700
     * 构造函数.
1701
     */
1702
    public function __construct($params)
1703
    {
1704
        if (! is_array($params)) {
1705
            return [];
0 ignored issues
show
Bug introduced by
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
1706
        }
1707
        foreach ($params as $key => $value) {
1708
            //如果是非法的key值,则不使用这个key
1709
            $this->_params[$key] = $value;
1710
        }
1711
    }
1712
1713
    public function set($k, $v)
1714
    {
1715
        if (! isset($k) || ! isset($v)) {
1716
            return;
1717
        }
1718
        $this->_params[$k] = $v;
1719
    }
1720
1721
    /**
1722
     * 根据实例化传入的参数生成签名.
1723
     */
1724
    public function generateSign($method, $url, $secret_key)
1725
    {
1726
        //将参数进行升序排序
1727
        $param_str = '';
1728
        $method = strtoupper($method);
1729
        $url_arr = parse_url($url);
1730
        if (isset($url_arr['host']) && isset($url_arr['path'])) {
1731
            $url = $url_arr['host'].$url_arr['path'];
1732
        }
1733
        if (! empty($this->_params)) {
1734
            ksort($this->_params);
1735
            foreach ($this->_params as $key => $value) {
1736
                $param_str .= $key.'='.$value;
1737
            }
1738
        }
1739
        //print $method.$url.$param_str.$secret_key."\n";
1740
        return md5($method.$url.$param_str.$secret_key);
1741
    }
1742
}
1743
1744
class RequestBase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1745
{
1746
    //get请求方式
1747
    const METHOD_GET = 'get';
1748
    //post请求方式
1749
    const METHOD_POST = 'post';
1750
1751
    /**
1752
     * 发起一个get或post请求
1753
     * @param $url 请求的url
1754
     * @param int $method 请求方式
1755
     * @param array $params 请求参数
1756
     * @param array $extra_conf curl配置, 高级需求可以用, 如
1757
     * $extra_conf = array(
1758
     *    CURLOPT_HEADER => true,
1759
     *    CURLOPT_RETURNTRANSFER = false
1760
     * )
1761
     * @return bool|mixed 成功返回数据,失败返回false
1762
     * @throws Exception
1763
     */
1764
    public static function exec($url, $params = [], $method = self::METHOD_GET, $extra_conf = [])
1765
    {
1766
        $params = is_array($params) ? http_build_query($params) : $params;
1767
        //如果是get请求,直接将参数附在url后面
1768
        if ($method == self::METHOD_GET) {
1769
            $url .= (strpos($url, '?') === false ? '?' : '&').$params;
1770
        }
1771
1772
        //默认配置
1773
        $curl_conf = [
1774
            CURLOPT_URL => $url,  //请求url
1775
            CURLOPT_HEADER => false,  //不输出头信息
1776
            CURLOPT_RETURNTRANSFER => true, //不输出返回数据
1777
            CURLOPT_CONNECTTIMEOUT => 3, // 连接超时时间
1778
        ];
1779
1780
        //配置post请求额外需要的配置项
1781
        if ($method == self::METHOD_POST) {
1782
            //使用post方式
1783
            $curl_conf[CURLOPT_POST] = true;
1784
            //post参数
1785
            $curl_conf[CURLOPT_POSTFIELDS] = $params;
1786
        }
1787
1788
        //添加额外的配置
1789
        foreach ($extra_conf as $k => $v) {
1790
            $curl_conf[$k] = $v;
1791
        }
1792
1793
        $data = false;
1794
        try {
1795
            //初始化一个curl句柄
1796
            $curl_handle = curl_init();
1797
            //设置curl的配置项
1798
            curl_setopt_array($curl_handle, $curl_conf);
1799
            //发起请求
1800
            $data = curl_exec($curl_handle);
1801
            if ($data === false) {
1802
                throw new Exception('CURL ERROR: '.curl_error($curl_handle));
1803
            }
1804
        } catch (Exception $e) {
0 ignored issues
show
Bug introduced by
The class App\Support\Tencent\XgPush\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
1805
            echo $e->getMessage();
1806
        }
1807
        curl_close($curl_handle);
1808
1809
        return $data;
1810
    }
1811
}
1812