Completed
Push — master ( 751e2d...bcf3cd )
by Elf
05:59
created

MessageIOS::isValid()   F

Complexity

Conditions 33
Paths 2075

Size

Total Lines 67
Code Lines 45

Duplication

Lines 39
Ratio 58.21 %

Importance

Changes 0
Metric Value
cc 33
eloc 45
nc 2075
nop 0
dl 39
loc 67
rs 2.9062
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
16
    const DEVICE_ALL = 0;
17
    const DEVICE_BROWSER = 1;
18
    const DEVICE_PC = 2;
19
    const DEVICE_ANDROID = 3;
20
    const DEVICE_IOS = 4;
21
    const DEVICE_WINPHONE = 5;
22
23
    const IOSENV_PROD = 1;
24
    const IOSENV_DEV = 2;
25
26
    const IOS_MIN_ID = 2200000000;
27
28
    public function __construct($accessId, $secretKey)
29
    {
30
        assert(isset($accessId) && isset($secretKey));
31
32
        $this->accessId = $accessId;
33
        $this->secretKey = $secretKey;
34
    }
35
36
    public function __destruct()
37
    {
38
    }
39
40
    /**
41
     * 使用默认设置推送消息给单个android设备
42
     */
43
    public static function PushTokenAndroid($accessId, $secretKey, $title, $content, $token)
44
    {
45
        $push = new XingeApp($accessId, $secretKey);
46
        $mess = new Message();
47
        $mess->setTitle($title);
48
        $mess->setContent($content);
49
        $mess->setType(Message::TYPE_NOTIFICATION);
50
        $mess->setStyle(new Style(0, 1, 1, 1, 0));
51
        $action = new ClickAction();
52
        $action->setActionType(ClickAction::TYPE_ACTIVITY);
53
        $mess->setAction($action);
54
        $ret = $push->PushSingleDevice($token, $mess);
55
        return $ret;
56
    }
57
58
    /**
59
     * 使用默认设置推送消息给单个ios设备
60
     */
61 View Code Duplication
    public static function PushTokenIos($accessId, $secretKey, $content, $token, $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...
62
    {
63
        $push = new XingeApp($accessId, $secretKey);
64
        $mess = new MessageIOS();
65
        $mess->setAlert($content);
66
        $ret = $push->PushSingleDevice($token, $mess, $environment);
67
        return $ret;
68
    }
69
70
    /**
71
     * 使用默认设置推送消息给单个android版账户
72
     */
73 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...
74
    {
75
        $push = new XingeApp($accessId, $secretKey);
76
        $mess = new Message();
77
        $mess->setTitle($title);
78
        $mess->setContent($content);
79
        $mess->setType(Message::TYPE_NOTIFICATION);
80
        $mess->setStyle(new Style(0, 1, 1, 1, 0));
81
        $action = new ClickAction();
82
        $action->setActionType(ClickAction::TYPE_ACTIVITY);
83
        $mess->setAction($action);
84
        $ret = $push->PushSingleAccount(0, $account, $mess);
85
        return $ret;
86
    }
87
88
    /**
89
     * 使用默认设置推送消息给单个ios版账户
90
     */
91 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...
92
    {
93
        $push = new XingeApp($accessId, $secretKey);
94
        $mess = new MessageIOS();
95
        $mess->setAlert($content);
96
        $ret = $push->PushSingleAccount(0, $account, $mess, $environment);
97
        return $ret;
98
    }
99
100
    /**
101
     * 使用默认设置推送消息给所有设备android版
102
     */
103 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...
104
    {
105
        $push = new XingeApp($accessId, $secretKey);
106
        $mess = new Message();
107
        $mess->setTitle($title);
108
        $mess->setContent($content);
109
        $mess->setType(Message::TYPE_NOTIFICATION);
110
        $mess->setStyle(new Style(0, 1, 1, 1, 0));
111
        $action = new ClickAction();
112
        $action->setActionType(ClickAction::TYPE_ACTIVITY);
113
        $mess->setAction($action);
114
        $ret = $push->PushAllDevices(0, $mess);
115
        return $ret;
116
    }
117
118
    /**
119
     * 使用默认设置推送消息给所有设备ios版
120
     */
121 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...
122
    {
123
        $push = new XingeApp($accessId, $secretKey);
124
        $mess = new MessageIOS();
125
        $mess->setAlert($content);
126
        $ret = $push->PushAllDevices(0, $mess, $environment);
127
        return $ret;
128
    }
129
130
    /**
131
     * 使用默认设置推送消息给标签选中设备android版
132
     */
133 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...
134
    {
135
        $push = new XingeApp($accessId, $secretKey);
136
        $mess = new Message();
137
        $mess->setTitle($title);
138
        $mess->setContent($content);
139
        $mess->setType(Message::TYPE_NOTIFICATION);
140
        $mess->setStyle(new Style(0, 1, 1, 1, 0));
141
        $action = new ClickAction();
142
        $action->setActionType(ClickAction::TYPE_ACTIVITY);
143
        $mess->setAction($action);
144
        $ret = $push->PushTags(0, array(0 => $tag), 'OR', $mess);
145
        return $ret;
146
    }
147
148
    /**
149
     * 使用默认设置推送消息给标签选中设备ios版
150
     */
151
    public static function PushTagIos($accessId, $secretKey, $content, $tag, $environment)
152
    {
153
        $push = new XingeApp($accessId, $secretKey);
154
        $mess = new MessageIOS();
155
        $mess->setAlert($content);
156
        $ret = $push->PushTags(0, array(0 => $tag), 'OR', $mess, $environment);
157
        return $ret;
158
    }
159
160
    /**
161
     * 推送消息给单个设备
162
     */
163 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...
164
    {
165
        $ret = array('ret_code' => -1, 'err_msg' => 'message not valid');
166
167
        if (!($message instanceof Message) && !($message instanceof MessageIOS)) return $ret;
168
        if (!$this->ValidateMessageType($message)) {
169
            $ret['err_msg'] = 'message type not fit accessId';
170
            return $ret;
171
        }
172
        if ($message instanceof MessageIOS) {
173
            if ($environment != XingeApp::IOSENV_DEV && $environment != XingeApp::IOSENV_PROD) {
174
                $ret['err_msg'] = "ios message environment invalid";
175
                return $ret;
176
            }
177
        }
178
        if (!$message->isValid()) return $ret;
179
        $params = array();
180
        $params['access_id'] = $this->accessId;
181
        $params['expire_time'] = $message->getExpireTime();
182
        $params['send_time'] = $message->getSendTime();
183
        if ($message instanceof Message) $params['multi_pkg'] = $message->getMultiPkg();
184
        $params['device_token'] = $deviceToken;
185
        $params['message_type'] = $message->getType();
186
        $params['message'] = $message->toJson();
187
        $params['timestamp'] = time();
188
        $params['environment'] = $environment;
189
190
        return $this->callRestful(self::RESTAPI_PUSHSINGLEDEVICE, $params);
191
    }
192
193
    /**
194
     * 推送消息给单个账户
195
     */
196
    public function PushSingleAccount($deviceType, $account, $message, $environment = 0)
197
    {
198
        $ret = array('ret_code' => -1);
199 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...
200
            $ret['err_msg'] = 'deviceType not valid';
201
            return $ret;
202
        }
203
        if (!is_string($account) || empty($account)) {
204
            $ret['err_msg'] = 'account not valid';
205
            return $ret;
206
        }
207
        if (!($message instanceof Message) && !($message instanceof MessageIOS)) {
208
            $ret['err_msg'] = 'message is not android or ios';
209
            return $ret;
210
        }
211
        if (!$this->ValidateMessageType($message)) {
212
            $ret['err_msg'] = 'message type not fit accessId';
213
            return $ret;
214
        }
215
        if ($message instanceof MessageIOS) {
216
            if ($environment != XingeApp::IOSENV_DEV && $environment != XingeApp::IOSENV_PROD) {
217
                $ret['err_msg'] = "ios message environment invalid";
218
                return $ret;
219
            }
220
        }
221
        if (!$message->isValid()) {
222
            $ret['err_msg'] = 'message not valid';
223
            return $ret;
224
        }
225
        $params = array();
226
        $params['access_id'] = $this->accessId;
227
        $params['expire_time'] = $message->getExpireTime();
228
        $params['send_time'] = $message->getSendTime();
229
        if ($message instanceof Message)
230
            $params['multi_pkg'] = $message->getMultiPkg();
231
        $params['device_type'] = $deviceType;
232
        $params['account'] = $account;
233
        $params['message_type'] = $message->getType();
234
        $params['message'] = $message->toJson();
235
        $params['timestamp'] = time();
236
        $params['environment'] = $environment;
237
238
        return $this->callRestful(self::RESTAPI_PUSHSINGLEACCOUNT, $params);
239
    }
240
241
    /**
242
     * 推送消息给多个账户
243
     */
244
    public function PushAccountList($deviceType, $accountList, $message, $environment = 0)
245
    {
246
        $ret = array('ret_code' => -1);
247 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...
248
            $ret['err_msg'] = 'deviceType not valid';
249
            return $ret;
250
        }
251
        if (!is_array($accountList) || empty($accountList)) {
252
            $ret['err_msg'] = 'accountList not valid';
253
            return $ret;
254
        }
255
        if (!($message instanceof Message) && !($message instanceof MessageIOS)) {
256
            $ret['err_msg'] = 'message is not android or ios';
257
            return $ret;
258
        }
259
        if (!$this->ValidateMessageType($message)) {
260
            $ret['err_msg'] = 'message type not fit accessId';
261
            return $ret;
262
        }
263
        if ($message instanceof MessageIOS) {
264
            if ($environment != XingeApp::IOSENV_DEV && $environment != XingeApp::IOSENV_PROD) {
265
                $ret['err_msg'] = "ios message environment invalid";
266
                return $ret;
267
            }
268
        }
269
        if (!$message->isValid()) {
270
            $ret['err_msg'] = 'message not valid';
271
            return $ret;
272
        }
273
        $params = array();
274
        $params['access_id'] = $this->accessId;
275
        $params['expire_time'] = $message->getExpireTime();
276
        if ($message instanceof Message)
277
            $params['multi_pkg'] = $message->getMultiPkg();
278
        $params['device_type'] = $deviceType;
279
        $params['account_list'] = json_encode($accountList);
280
        $params['message_type'] = $message->getType();
281
        $params['message'] = $message->toJson();
282
        $params['timestamp'] = time();
283
        $params['environment'] = $environment;
284
285
        return $this->callRestful(self::RESTAPI_PUSHACCOUNTLIST, $params);
286
    }
287
288
    /**
289
     * 推送消息给APP所有设备
290
     */
291
    public function PushAllDevices($deviceType, $message, $environment = 0)
292
    {
293
        $ret = array('ret_code' => -1, 'err_msg' => 'message not valid');
294 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...
295
            $ret['err_msg'] = 'deviceType not valid';
296
            return $ret;
297
        }
298
299
        if (!($message instanceof Message) && !($message instanceof MessageIOS)) return $ret;
300
        if (!$this->ValidateMessageType($message)) {
301
            $ret['err_msg'] = 'message type not fit accessId';
302
            return $ret;
303
        }
304
        if ($message instanceof MessageIOS) {
305
            if ($environment != XingeApp::IOSENV_DEV && $environment != XingeApp::IOSENV_PROD) {
306
                $ret['err_msg'] = "ios message environment invalid";
307
                return $ret;
308
            }
309
        }
310
        if (!$message->isValid()) return $ret;
311
        $params = array();
312
        $params['access_id'] = $this->accessId;
313
        $params['expire_time'] = $message->getExpireTime();
314
        $params['send_time'] = $message->getSendTime();
315
        if ($message instanceof Message) $params['multi_pkg'] = $message->getMultiPkg();
316
        $params['device_type'] = $deviceType;
317
        $params['message_type'] = $message->getType();
318
        $params['message'] = $message->toJson();
319
        $params['timestamp'] = time();
320
        $params['environment'] = $environment;
321
322 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...
323
            && !is_null($message->getLoopTimes()) && $message->getLoopTimes() > 0
324
        ) {
325
            $params['loop_interval'] = $message->getLoopInterval();
326
            $params['loop_times'] = $message->getLoopTimes();
327
        }
328
        //var_dump($params);
329
330
        return $this->callRestful(self::RESTAPI_PUSHALLDEVICE, $params);
331
    }
332
333
    /**
334
     * 推送消息给指定tags的设备
335
     * 若要推送的tagList只有一项,则tagsOp应为OR
336
     */
337
    public function PushTags($deviceType, $tagList, $tagsOp, $message, $environment = 0)
338
    {
339
        $ret = array('ret_code' => -1, 'err_msg' => 'message not valid');
340 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...
341
            $ret['err_msg'] = 'deviceType not valid';
342
            return $ret;
343
        }
344
        if (!is_array($tagList) || empty($tagList)) {
345
            $ret['err_msg'] = 'tagList not valid';
346
            return $ret;
347
        }
348
        if (!is_string($tagsOp) || ($tagsOp != 'AND' && $tagsOp != 'OR')) {
349
            $ret['err_msg'] = 'tagsOp not valid';
350
            return $ret;
351
        }
352
353
        if (!($message instanceof Message) && !($message instanceof MessageIOS)) return $ret;
354
        if (!$this->ValidateMessageType($message)) {
355
            $ret['err_msg'] = 'message type not fit accessId';
356
            return $ret;
357
        }
358
        if ($message instanceof MessageIOS) {
359
            if ($environment != XingeApp::IOSENV_DEV && $environment != XingeApp::IOSENV_PROD) {
360
                $ret['err_msg'] = "ios message environment invalid";
361
                return $ret;
362
            }
363
        }
364
        if (!$message->isValid()) return $ret;
365
366
        $params = array();
367
        $params['access_id'] = $this->accessId;
368
        $params['expire_time'] = $message->getExpireTime();
369
        $params['send_time'] = $message->getSendTime();
370
        if ($message instanceof Message) $params['multi_pkg'] = $message->getMultiPkg();
371
        $params['device_type'] = $deviceType;
372
        $params['message_type'] = $message->getType();
373
        $params['tags_list'] = json_encode($tagList);
374
        $params['tags_op'] = $tagsOp;
375
        $params['message'] = $message->toJson();
376
        $params['timestamp'] = time();
377
        $params['environment'] = $environment;
378
379 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...
380
            && !is_null($message->getLoopTimes()) && $message->getLoopTimes() > 0
381
        ) {
382
            $params['loop_interval'] = $message->getLoopInterval();
383
            $params['loop_times'] = $message->getLoopTimes();
384
        }
385
386
        return $this->callRestful(self::RESTAPI_PUSHTAGS, $params);
387
    }
388
389
    /**
390
     * 创建批量推送任务
391
     */
392 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...
393
    {
394
        $ret = array('ret_code' => -1);
395
        if (!($message instanceof Message) && !($message instanceof MessageIOS)) {
396
            $ret['err_msg'] = 'message is not android or ios';
397
            return $ret;
398
        }
399
        if (!$this->ValidateMessageType($message)) {
400
            $ret['err_msg'] = 'message type not fit accessId';
401
            return $ret;
402
        }
403
        if ($message instanceof MessageIOS) {
404
            if ($environment != XingeApp::IOSENV_DEV && $environment != XingeApp::IOSENV_PROD) {
405
                $ret['err_msg'] = "ios message environment invalid";
406
                return $ret;
407
            }
408
        }
409
        if (!$message->isValid()) {
410
            $ret['err_msg'] = 'message not valid';
411
            return $ret;
412
        }
413
        $params = array();
414
        $params['access_id'] = $this->accessId;
415
        $params['expire_time'] = $message->getExpireTime();
416
        if ($message instanceof Message)
417
            $params['multi_pkg'] = $message->getMultiPkg();
418
        $params['message_type'] = $message->getType();
419
        $params['message'] = $message->toJson();
420
        $params['timestamp'] = time();
421
        $params['environment'] = $environment;
422
423
        return $this->callRestful(self::RESTAPI_CREATEMULTIPUSH, $params);
424
    }
425
426
    /**
427
     * 按帐号大批量推送
428
     */
429 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...
430
    {
431
        $pushId = intval($pushId);
432
        $ret = array('ret_code' => -1);
433
        if ($pushId <= 0) {
434
            $ret['err_msg'] = 'pushId not valid';
435
            return $ret;
436
        }
437
        if (!is_array($accountList) || empty($accountList)) {
438
            $ret['err_msg'] = 'accountList not valid';
439
            return $ret;
440
        }
441
        $params = array();
442
        $params['access_id'] = $this->accessId;
443
        $params['push_id'] = $pushId;
444
        $params['account_list'] = json_encode($accountList);
445
        $params['timestamp'] = time();
446
447
        return $this->callRestful(self::RESTAPI_PUSHACCOUNTLISTMULTIPLE, $params);
448
    }
449
450
    /**
451
     * 按Token大批量推送
452
     */
453 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...
454
    {
455
        $pushId = intval($pushId);
456
        $ret = array('ret_code' => -1);
457
        if ($pushId <= 0) {
458
            $ret['err_msg'] = 'pushId not valid';
459
            return $ret;
460
        }
461
        if (!is_array($deviceList) || empty($deviceList)) {
462
            $ret['err_msg'] = 'deviceList not valid';
463
            return $ret;
464
        }
465
        $params = array();
466
        $params['access_id'] = $this->accessId;
467
        $params['push_id'] = $pushId;
468
        $params['device_list'] = json_encode($deviceList);
469
        $params['timestamp'] = time();
470
471
        return $this->callRestful(self::RESTAPI_PUSHDEVICELISTMULTIPLE, $params);
472
    }
473
474
    /**
475
     * 查询消息推送状态
476
     * @param array $pushIdList pushId(string)数组
477
     */
478
    public function QueryPushStatus($pushIdList)
479
    {
480
        $ret = array('ret_code' => -1);
481
        $idList = array();
482
        if (!is_array($pushIdList) || empty($pushIdList)) {
483
            $ret['err_msg'] = 'pushIdList not valid';
484
            return $ret;
485
        }
486
        foreach ($pushIdList as $pushId) {
487
            $idList[] = array('push_id' => $pushId);
488
        }
489
        $params = array();
490
        $params['access_id'] = $this->accessId;
491
        $params['push_ids'] = json_encode($idList);
492
        $params['timestamp'] = time();
493
494
        return $this->callRestful(self::RESTAPI_QUERYPUSHSTATUS, $params);
495
    }
496
497
    /**
498
     * 查询应用覆盖的设备数
499
     */
500 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...
501
    {
502
        $params = array();
503
        $params['access_id'] = $this->accessId;
504
        $params['timestamp'] = time();
505
506
        return $this->callRestful(self::RESTAPI_QUERYDEVICECOUNT, $params);
507
    }
508
509
    /**
510
     * 查询应用标签
511
     */
512 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...
513
    {
514
        $ret = array('ret_code' => -1);
515
        if (!is_int($start) || !is_int($limit)) {
516
            $ret['err_msg'] = 'start or limit not valid';
517
            return $ret;
518
        }
519
        $params = array();
520
        $params['access_id'] = $this->accessId;
521
        $params['start'] = $start;
522
        $params['limit'] = $limit;
523
        $params['timestamp'] = time();
524
525
        return $this->callRestful(self::RESTAPI_QUERYTAGS, $params);
526
    }
527
528
    /**
529
     * 查询标签下token数量
530
     */
531 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...
532
    {
533
        $ret = array('ret_code' => -1);
534
        if (!is_string($tag)) {
535
            $ret['err_msg'] = 'tag is not valid';
536
            return $ret;
537
        }
538
        $params = array();
539
        $params['access_id'] = $this->accessId;
540
        $params['tag'] = $tag;
541
        $params['timestamp'] = time();
542
543
        return $this->callRestful(self::RESTAPI_QUERYTAGTOKENNUM, $params);
544
    }
545
546
    /**
547
     * 查询token的标签
548
     */
549 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...
550
    {
551
        $ret = array('ret_code' => -1);
552
        if (!is_string($deviceToken)) {
553
            $ret['err_msg'] = 'deviceToken is not valid';
554
            return $ret;
555
        }
556
        $params = array();
557
        $params['access_id'] = $this->accessId;
558
        $params['device_token'] = $deviceToken;
559
        $params['timestamp'] = time();
560
561
        return $this->callRestful(self::RESTAPI_QUERYTOKENTAGS, $params);
562
    }
563
564
    /**
565
     * 取消定时发送
566
     */
567 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...
568
    {
569
        $ret = array('ret_code' => -1);
570
        if (!is_string($pushId) || empty($pushId)) {
571
            $ret['err_msg'] = 'pushId not valid';
572
            return $ret;
573
        }
574
        $params = array();
575
        $params['access_id'] = $this->accessId;
576
        $params['push_id'] = $pushId;
577
        $params['timestamp'] = time();
578
579
        return $this->callRestful(self::RESTAPI_CANCELTIMINGPUSH, $params);
580
    }
581
582
    //json转换为数组
583
    protected function json2Array($json)
584
    {
585
        $json = stripslashes($json);
586
        return json_decode($json, true);
587
    }
588
589
    protected function callRestful($url, $params)
590
    {
591
        $paramsBase = new ParamsBase($params);
592
        $sign = $paramsBase->generateSign(RequestBase::METHOD_POST, $url, $this->secretKey);
593
        $params['sign'] = $sign;
594
595
        $requestBase = new RequestBase();
596
        $ret = $this->json2Array($requestBase->exec($url, $params, RequestBase::METHOD_POST));
597
598
        return $ret;
599
    }
600
601
    private function ValidateToken($token)
602
    {
603
        if (intval($this->accessId) >= 2200000000) {
604
            return strlen($token) == 64;
605
        } else {
606
            return (strlen($token) == 40 || strlen($token) == 64);
607
        }
608
    }
609
610 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...
611
    {
612
613
        $params = array();
614
        $params['access_id'] = $this->accessId;
615
        $params['timestamp'] = time();
616
617
        return $params;
618
    }
619
620 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...
621
    {
622
        $ret = array('ret_code' => -1);
623
624
        foreach ($tagTokenPairs as $pair) {
625
            if (!($pair instanceof TagTokenPair)) {
626
                $ret['err_msg'] = 'tag-token pair type error!';
627
                return $ret;
628
            }
629
            if (!$this->ValidateToken($pair->token)) {
630
                $ret['err_msg'] = sprintf("invalid token %s", $pair->token);
631
                return $ret;
632
            }
633
        }
634
        $params = $this->InitParams();
635
636
        $tag_token_list = array();
637
        foreach ($tagTokenPairs as $pair) {
638
            array_push($tag_token_list, array($pair->tag, $pair->token));
639
        }
640
        $params['tag_token_list'] = json_encode($tag_token_list);
641
642
        return $this->callRestful(self::RESTAPI_BATCHSETTAG, $params);
643
    }
644
645 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...
646
    {
647
        $ret = array('ret_code' => -1);
648
649
        foreach ($tagTokenPairs as $pair) {
650
            if (!($pair instanceof TagTokenPair)) {
651
                $ret['err_msg'] = 'tag-token pair type error!';
652
                return $ret;
653
            }
654
            if (!$this->ValidateToken($pair->token)) {
655
                $ret['err_msg'] = sprintf("invalid token %s", $pair->token);
656
                return $ret;
657
            }
658
        }
659
        $params = $this->InitParams();
660
661
        $tag_token_list = array();
662
        foreach ($tagTokenPairs as $pair) {
663
            array_push($tag_token_list, array($pair->tag, $pair->token));
664
        }
665
        $params['tag_token_list'] = json_encode($tag_token_list);
666
667
        return $this->callRestful(self::RESTAPI_BATCHDELTAG, $params);
668
    }
669
670 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...
671
    {
672
        $ret = array('ret_code' => -1);
673
        if (!is_string($deviceToken)) {
674
            $ret['err_msg'] = 'deviceToken is not valid';
675
            return $ret;
676
        }
677
        $params = array();
678
        $params['access_id'] = $this->accessId;
679
        $params['device_token'] = $deviceToken;
680
        $params['timestamp'] = time();
681
682
        return $this->callRestful(self::RESTAPI_QUERYINFOOFTOKEN, $params);
683
    }
684
685 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...
686
    {
687
        $ret = array('ret_code' => -1);
688
        if (!is_string($account)) {
689
            $ret['err_msg'] = 'account is not valid';
690
            return $ret;
691
        }
692
        $params = array();
693
        $params['access_id'] = $this->accessId;
694
        $params['account'] = $account;
695
        $params['timestamp'] = time();
696
697
        return $this->callRestful(self::RESTAPI_QUERYTOKENSOFACCOUNT, $params);
698
    }
699
700 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...
701
    {
702
        $ret = array('ret_code' => -1);
703
        if (!is_string($account) || !is_string($deviceToken)) {
704
            $ret['err_msg'] = 'account or deviceToken is not valid';
705
            return $ret;
706
        }
707
        $params = array();
708
        $params['access_id'] = $this->accessId;
709
        $params['account'] = $account;
710
        $params['device_token'] = $deviceToken;
711
        $params['timestamp'] = time();
712
713
        return $this->callRestful(self::RESTAPI_DELETETOKENOFACCOUNT, $params);
714
    }
715
716 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...
717
    {
718
        $ret = array('ret_code' => -1);
719
        if (!is_string($account)) {
720
            $ret['err_msg'] = 'account is not valid';
721
            return $ret;
722
        }
723
        $params = array();
724
        $params['access_id'] = $this->accessId;
725
        $params['account'] = $account;
726
        $params['timestamp'] = time();
727
728
        return $this->callRestful(self::RESTAPI_DELETEALLTOKENSOFACCOUNT, $params);
729
    }
730
731
    private function ValidateMessageType($message)
732
    {
733
        if (intval($this->accessId) >= XingeApp::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...
734
            return true;
735
        else if (intval($this->accessId) < XingeApp::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...
736
            return true;
737
        else
738
            return false;
739
    }
740
741
    public $accessId = ''; //应用的接入Id
742
    public $secretKey = ''; //应用的skey
743
744
    const RESTAPI_PUSHSINGLEDEVICE = 'http://openapi.xg.qq.com/v2/push/single_device';
745
    const RESTAPI_PUSHSINGLEACCOUNT = 'http://openapi.xg.qq.com/v2/push/single_account';
746
    const RESTAPI_PUSHACCOUNTLIST = 'http://openapi.xg.qq.com/v2/push/account_list';
747
    const RESTAPI_PUSHALLDEVICE = 'http://openapi.xg.qq.com/v2/push/all_device';
748
    const RESTAPI_PUSHTAGS = 'http://openapi.xg.qq.com/v2/push/tags_device';
749
    const RESTAPI_QUERYPUSHSTATUS = 'http://openapi.xg.qq.com/v2/push/get_msg_status';
750
    const RESTAPI_QUERYDEVICECOUNT = 'http://openapi.xg.qq.com/v2/application/get_app_device_num';
751
    const RESTAPI_QUERYTAGS = 'http://openapi.xg.qq.com/v2/tags/query_app_tags';
752
    const RESTAPI_CANCELTIMINGPUSH = 'http://openapi.xg.qq.com/v2/push/cancel_timing_task';
753
    const RESTAPI_BATCHSETTAG = 'http://openapi.xg.qq.com/v2/tags/batch_set';
754
    const RESTAPI_BATCHDELTAG = 'http://openapi.xg.qq.com/v2/tags/batch_del';
755
    const RESTAPI_QUERYTOKENTAGS = 'http://openapi.xg.qq.com/v2/tags/query_token_tags';
756
    const RESTAPI_QUERYTAGTOKENNUM = 'http://openapi.xg.qq.com/v2/tags/query_tag_token_num';
757
    const RESTAPI_CREATEMULTIPUSH = 'http://openapi.xg.qq.com/v2/push/create_multipush';
758
    const RESTAPI_PUSHACCOUNTLISTMULTIPLE = 'http://openapi.xg.qq.com/v2/push/account_list_multiple';
759
    const RESTAPI_PUSHDEVICELISTMULTIPLE = 'http://openapi.xg.qq.com/v2/push/device_list_multiple';
760
    const RESTAPI_QUERYINFOOFTOKEN = 'http://openapi.xg.qq.com/v2/application/get_app_token_info';
761
    const RESTAPI_QUERYTOKENSOFACCOUNT = 'http://openapi.xg.qq.com/v2/application/get_app_account_tokens';
762
    const RESTAPI_DELETETOKENOFACCOUNT = 'http://openapi.xg.qq.com/v2/application/del_app_account_tokens';
763
    const RESTAPI_DELETEALLTOKENSOFACCOUNT = 'http://openapi.xg.qq.com/v2/application/del_app_account_all_tokens';
764
765
}
766
767
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...
768
{
769
770
    public function __construct($tag, $token)
771
    {
772
        $this->tag = strval($tag);
773
        $this->token = strval($token);
774
    }
775
776
    public function __destruct()
777
    {
778
    }
779
780
    public $tag;
781
    public $token;
782
}
783
784
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...
785
{
786
787
    public function __construct()
788
    {
789
        $this->m_acceptTimes = array();
790
        $this->m_multiPkg = 0;
791
        $this->m_raw = "";
792
        $this->m_style = new Style(0);
793
        $this->m_action = new ClickAction();
794
    }
795
796
    public function __destruct()
797
    {
798
    }
799
800
    public function setTitle($title)
801
    {
802
        $this->m_title = $title;
803
    }
804
805
    public function setContent($content)
806
    {
807
        $this->m_content = $content;
808
    }
809
810
    public function setExpireTime($expireTime)
811
    {
812
        $this->m_expireTime = $expireTime;
813
    }
814
815
    public function getExpireTime()
816
    {
817
        return $this->m_expireTime;
818
    }
819
820
    public function setSendTime($sendTime)
821
    {
822
        $this->m_sendTime = $sendTime;
823
    }
824
825
    public function getSendTime()
826
    {
827
        return $this->m_sendTime;
828
    }
829
830
    public function addAcceptTime($acceptTime)
831
    {
832
        $this->m_acceptTimes[] = $acceptTime;
833
    }
834
835
    public function acceptTimeToJson()
836
    {
837
        $ret = array();
838
        foreach ($this->m_acceptTimes as $acceptTime) {
839
            $ret[] = $acceptTime->toArray();
840
        }
841
        return $ret;
842
    }
843
844
    /**
845
     * 消息类型
846
     * @param int $type 1:通知 2:透传消息
847
     */
848
    public function setType($type)
849
    {
850
        $this->m_type = $type;
851
    }
852
853
    public function getType()
854
    {
855
        return $this->m_type;
856
    }
857
858
    public function setMultiPkg($multiPkg)
859
    {
860
        $this->m_multiPkg = $multiPkg;
861
    }
862
863
    public function getMultiPkg()
864
    {
865
        return $this->m_multiPkg;
866
    }
867
868
    public function setStyle($style)
869
    {
870
        $this->m_style = $style;
871
    }
872
873
    public function setAction($action)
874
    {
875
        $this->m_action = $action;
876
    }
877
878
    public function setCustom($custom)
879
    {
880
        $this->m_custom = $custom;
881
    }
882
883
    public function setRaw($raw)
884
    {
885
        $this->m_raw = $raw;
886
    }
887
888
    public function getLoopInterval()
889
    {
890
        return $this->m_loopInterval;
891
    }
892
893
    public function setLoopInterval($loopInterval)
894
    {
895
        $this->m_loopInterval = $loopInterval;
896
    }
897
898
    public function getLoopTimes()
899
    {
900
        return $this->m_loopTimes;
901
    }
902
903
    public function setLoopTimes($loopTimes)
904
    {
905
        $this->m_loopTimes = $loopTimes;
906
    }
907
908
    public function toJson()
909
    {
910
        if (!empty($this->m_raw)) return $this->m_raw;
911
        $ret = array();
912
        if ($this->m_type == self::TYPE_NOTIFICATION) {
913
            $ret['title'] = $this->m_title;
914
            $ret['content'] = $this->m_content;
915
            $ret['accept_time'] = $this->acceptTimeToJson();
916
            $ret['builder_id'] = $this->m_style->getBuilderId();
917
            $ret['ring'] = $this->m_style->getRing();
918
            $ret['vibrate'] = $this->m_style->getVibrate();
919
            $ret['clearable'] = $this->m_style->getClearable();
920
            $ret['n_id'] = $this->m_style->getNId();
921
922
            if (!is_null($this->m_style->getRingRaw())) {
923
                $ret['ring_raw'] = $this->m_style->getRingRaw();
924
            }
925
            $ret['lights'] = $this->m_style->getLights();
926
            $ret['icon_type'] = $this->m_style->getIconType();
927
            if (!is_null($this->m_style->getIconRes())) {
928
                $ret['icon_res'] = $this->m_style->getIconRes();
929
            }
930
            $ret['style_id'] = $this->m_style->getStyleId();
931
            if (!is_null($this->m_style->getSmallIcon())) {
932
                $ret['small_icon'] = $this->m_style->getSmallIcon();
933
            }
934
935
            $ret['action'] = $this->m_action->toJson();
936
937
        } else if ($this->m_type == self::TYPE_MESSAGE) {
938
            $ret['title'] = $this->m_title;
939
            $ret['content'] = $this->m_content;
940
            $ret['accept_time'] = $this->acceptTimeToJson();
941
        }
942
        $ret['custom_content'] = $this->m_custom;
943
        return json_encode($ret);
944
    }
945
946
    public function isValid()
947
    {
948
        if (is_string($this->m_raw) && !empty($this->raw)) return true;
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...
949 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...
950
            $this->m_title = "";
951
        else if (!is_string($this->m_title) || empty($this->m_title))
952
            return false;
953 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...
954
            $this->m_content = "";
955
        else if (!is_string($this->m_content) || empty($this->m_content))
956
            return false;
957 View Code Duplication
        if (!is_int($this->m_type) || $this->m_type < self::TYPE_NOTIFICATION || $this->m_type > self::TYPE_MESSAGE) return false;
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...
958
        if (!is_int($this->m_multiPkg) || $this->m_multiPkg < 0 || $this->m_multiPkg > 1) return false;
959
        if ($this->m_type == self::TYPE_NOTIFICATION) {
960
            if (!($this->m_style instanceof Style) || !($this->m_action instanceof ClickAction))
961
                return false;
962
            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...
963
                return false;
964
        }
965 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...
966
            if (!is_int($this->m_expireTime) || $this->m_expireTime > 3 * 24 * 60 * 60)
967
                return false;
968
        } else {
969
            $this->m_expireTime = 0;
970
        }
971
972 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...
973
            if (strtotime($this->m_sendTime) === false) return false;
974
        } else {
975
            $this->m_sendTime = "2013-12-19 17:49:00";
976
        }
977
978 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...
979
            if (!($value instanceof TimeInterval) || !$value->isValid())
980
                return false;
981
        }
982
983 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...
984
            if (!is_array($this->m_custom))
985
                return false;
986
        } else {
987
            $this->m_custom = array();
988
        }
989
990 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...
991
            if (!(is_int($this->m_loopInterval) && $this->m_loopInterval > 0)) {
992
                return false;
993
            }
994
        }
995
996 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...
997
            if (!(is_int($this->m_loopTimes) && $this->m_loopTimes > 0)) {
998
                return false;
999
            }
1000
        }
1001
1002 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...
1003
            if (($this->m_loopTimes - 1) * $this->m_loopInterval + 1 > self::MAX_LOOP_TASK_DAYS) {
1004
                return false;
1005
            }
1006
        }
1007
1008
        return true;
1009
    }
1010
1011
    private $m_title;
1012
    private $m_content;
1013
    private $m_expireTime;
1014
    private $m_sendTime;
1015
    private $m_acceptTimes;
1016
    private $m_type;
1017
    private $m_multiPkg;
1018
    private $m_style;
1019
    private $m_action;
1020
    private $m_custom;
1021
    private $m_raw;
1022
    private $m_loopInterval;
1023
    private $m_loopTimes;
1024
1025
    const TYPE_NOTIFICATION = 1;
1026
    const TYPE_MESSAGE = 2;
1027
    const MAX_LOOP_TASK_DAYS = 15;
1028
}
1029
1030
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...
1031
{
1032
    public function __construct()
1033
    {
1034
        $this->m_acceptTimes = array();
1035
        $this->m_type = self::TYPE_APNS_NOTIFICATION;
1036
    }
1037
1038
    public function __destruct()
1039
    {
1040
    }
1041
1042
    public function setExpireTime($expireTime)
1043
    {
1044
        $this->m_expireTime = $expireTime;
1045
    }
1046
1047
    public function getExpireTime()
1048
    {
1049
        return $this->m_expireTime;
1050
    }
1051
1052
    public function setSendTime($sendTime)
1053
    {
1054
        $this->m_sendTime = $sendTime;
1055
    }
1056
1057
    public function getSendTime()
1058
    {
1059
        return $this->m_sendTime;
1060
    }
1061
1062
    public function addAcceptTime($acceptTime)
1063
    {
1064
        $this->m_acceptTimes[] = $acceptTime;
1065
    }
1066
1067
    public function acceptTimeToJson()
1068
    {
1069
        $ret = array();
1070
        foreach ($this->m_acceptTimes as $acceptTime) {
1071
            $ret[] = $acceptTime->toArray();
1072
        }
1073
        return $ret;
1074
    }
1075
1076
    public function setCustom($custom)
1077
    {
1078
        $this->m_custom = $custom;
1079
    }
1080
1081
    public function setRaw($raw)
1082
    {
1083
        $this->m_raw = $raw;
1084
    }
1085
1086
    public function setAlert($alert)
1087
    {
1088
        $this->m_alert = $alert;
1089
    }
1090
1091
    public function setBadge($badge)
1092
    {
1093
        $this->m_badge = $badge;
1094
    }
1095
1096
    public function setSound($sound)
1097
    {
1098
        $this->m_sound = $sound;
1099
    }
1100
1101
    /**
1102
     * 消息类型
1103
     * @param int $type 1:通知 2:静默通知
1104
     */
1105
    public function setType($type)
1106
    {
1107
        $this->m_type = $type;
1108
    }
1109
1110
    public function getType()
1111
    {
1112
        return $this->m_type;
1113
    }
1114
1115
    public function getCategory()
1116
    {
1117
        return $this->m_category;
1118
    }
1119
1120
    public function setCategory($category)
1121
    {
1122
        $this->m_category = $category;
1123
    }
1124
1125
    public function getLoopInterval()
1126
    {
1127
        return $this->m_loopInterval;
1128
    }
1129
1130
    public function setLoopInterval($loopInterval)
1131
    {
1132
        $this->m_loopInterval = $loopInterval;
1133
    }
1134
1135
    public function getLoopTimes()
1136
    {
1137
        return $this->m_loopTimes;
1138
    }
1139
1140
    public function setLoopTimes($loopTimes)
1141
    {
1142
        $this->m_loopTimes = $loopTimes;
1143
    }
1144
1145
    public function toJson()
1146
    {
1147
        if (!empty($this->m_raw)) return $this->m_raw;
1148
        $ret = $this->m_custom;
1149
        $ret['accept_time'] = $this->acceptTimeToJson();
1150
1151
        $aps = array();
1152
        if ($this->m_type == self::TYPE_APNS_NOTIFICATION) {
1153
            $aps['alert'] = $this->m_alert;
1154
            if (isset($this->m_badge)) $aps['badge'] = $this->m_badge;
1155
            if (isset($this->m_sound)) $aps['sound'] = $this->m_sound;
1156
            if (isset($this->m_category)) $aps['category'] = $this->m_category;
1157
        } else if ($this->m_type == self::TYPE_REMOTE_NOTIFICATION) {
1158
            $aps['content-available'] = 1;
1159
        }
1160
        $ret['aps'] = $aps;
1161
        return json_encode($ret);
1162
    }
1163
1164
    public function isValid()
1165
    {
1166 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...
1167
            if (!is_int($this->m_expireTime) || $this->m_expireTime > 3 * 24 * 60 * 60)
1168
                return false;
1169
        } else {
1170
            $this->m_expireTime = 0;
1171
        }
1172
1173 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...
1174
            if (strtotime($this->m_sendTime) === false) return false;
1175
        } else {
1176
            $this->m_sendTime = "2014-03-13 12:00:00";
1177
        }
1178
1179
        if (!empty($this->m_raw)) {
1180
            if (is_string($this->m_raw))
1181
                return true;
1182
            else
1183
                return false;
1184
        }
1185 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...
1186
            return false;
1187
        }
1188
1189 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...
1190
            if (!($value instanceof TimeInterval) || !$value->isValid())
1191
                return false;
1192
        }
1193
1194 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...
1195
            if (!is_array($this->m_custom))
1196
                return false;
1197
        } else {
1198
            $this->m_custom = array();
1199
        }
1200
        if ($this->m_type == self::TYPE_APNS_NOTIFICATION) {
1201
            if (!isset($this->m_alert)) return false;
1202
            if (!is_string($this->m_alert) && !is_array($this->m_alert))
1203
                return false;
1204
        }
1205
        if (isset($this->m_badge)) {
1206
            if (!is_int($this->m_badge))
1207
                return false;
1208
        }
1209
        if (isset($this->m_sound)) {
1210
            if (!is_string($this->m_sound))
1211
                return false;
1212
        }
1213 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...
1214
            if (!(is_int($this->m_loopInterval) && $this->m_loopInterval > 0)) {
1215
                return false;
1216
            }
1217
        }
1218 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...
1219
            if (!(is_int($this->m_loopTimes) && $this->m_loopTimes > 0)) {
1220
                return false;
1221
            }
1222
        }
1223 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...
1224
            if (($this->m_loopTimes - 1) * $this->m_loopInterval + 1 > self::MAX_LOOP_TASK_DAYS) {
1225
                return false;
1226
            }
1227
        }
1228
1229
        return true;
1230
    }
1231
1232
1233
    private $m_expireTime;
1234
    private $m_sendTime;
1235
    private $m_acceptTimes;
1236
    private $m_custom;
1237
    private $m_raw;
1238
    private $m_type;
1239
    private $m_alert;
1240
    private $m_badge;
1241
    private $m_sound;
1242
    private $m_category;
1243
    private $m_loopInterval;
1244
    private $m_loopTimes;
1245
1246
    const TYPE_APNS_NOTIFICATION = 11;
1247
    const TYPE_REMOTE_NOTIFICATION = 12;
1248
    const MAX_LOOP_TASK_DAYS = 15;
1249
}
1250
1251
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...
1252
{
1253
    /**
1254
     * 动作类型
1255
     * @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...
1256
     */
1257
    public function __construct()
1258
    {
1259
        $this->m_atyAttrIntentFlag = 0;
1260
        $this->m_atyAttrPendingIntentFlag = 0;
1261
        $this->m_confirmOnPackageDownloadUrl = 1;
1262
    }
1263
1264
    public function setActionType($actionType)
1265
    {
1266
        $this->m_actionType = $actionType;
1267
    }
1268
1269
    public function setUrl($url)
1270
    {
1271
        $this->m_url = $url;
1272
    }
1273
1274
    public function setComfirmOnUrl($comfirmOnUrl)
1275
    {
1276
        $this->m_confirmOnUrl = $comfirmOnUrl;
1277
    }
1278
1279
    public function setActivity($activity)
1280
    {
1281
        $this->m_activity = $activity;
1282
    }
1283
1284
    public function setIntent($intent)
1285
    {
1286
        $this->m_intent = $intent;
1287
    }
1288
1289
    public function setAtyAttrIntentFlag($atyAttrIntentFlag)
1290
    {
1291
        $this->m_atyAttrIntentFlag = $atyAttrIntentFlag;
1292
    }
1293
1294
    public function setAtyAttrPendingIntentFlag($atyAttrPendingIntentFlag)
1295
    {
1296
        $this->m_atyAttrPendingIntentFlag = $atyAttrPendingIntentFlag;
1297
    }
1298
1299
    public function setPackageDownloadUrl($packageDownloadUrl)
1300
    {
1301
        $this->m_packageDownloadUrl = $packageDownloadUrl;
1302
    }
1303
1304
    public function setConfirmOnPackageDownloadUrl($confirmOnPackageDownloadUrl)
1305
    {
1306
        $this->m_confirmOnPackageDownloadUrl = $confirmOnPackageDownloadUrl;
1307
    }
1308
1309
    public function setPackageName($packageName)
1310
    {
1311
        $this->m_packageName = $packageName;
1312
    }
1313
1314
    public function toJson()
1315
    {
1316
        $ret = array();
1317
        $ret['action_type'] = $this->m_actionType;
1318
        $ret['browser'] = array('url' => $this->m_url, 'confirm' => $this->m_confirmOnUrl);
1319
        $ret['activity'] = $this->m_activity;
1320
        $ret['intent'] = $this->m_intent;
1321
1322
        $aty_attr = array();
1323
        if (isset($this->m_atyAttrIntentFlag)) {
1324
            $aty_attr['if'] = $this->m_atyAttrIntentFlag;
1325
        }
1326
        if (isset($this->m_atyAttrPendingIntentFlag)) {
1327
            $aty_attr['pf'] = $this->m_atyAttrPendingIntentFlag;
1328
        }
1329
        $ret['aty_attr'] = $aty_attr;
1330
1331
        return $ret;
1332
    }
1333
1334
    public function isValid()
1335
    {
1336
        if (!isset($this->m_actionType)) $this->m_actionType = self::TYPE_ACTIVITY;
1337
        if (!is_int($this->m_actionType)) return false;
1338
        if ($this->m_actionType < self::TYPE_ACTIVITY || $this->m_actionType > self::TYPE_INTENT)
1339
            return false;
1340
1341
        if ($this->m_actionType == self::TYPE_ACTIVITY) {
1342
            if (!isset($this->m_activity)) {
1343
                $this->m_activity = "";
1344
                return true;
1345
            }
1346
            if (isset($this->m_atyAttrIntentFlag)) {
1347
                if (!is_int($this->m_atyAttrIntentFlag)) {
1348
                    return false;
1349
                }
1350
            }
1351
            if (isset($this->m_atyAttrPendingIntentFlag)) {
1352
                if (!is_int($this->m_atyAttrPendingIntentFlag)) {
1353
                    return false;
1354
                }
1355
            }
1356
1357
            if (is_string($this->m_activity) && !empty($this->m_activity))
1358
                return true;
1359
            return false;
1360
        }
1361
1362
        if ($this->m_actionType == self::TYPE_URL) {
1363
            if (is_string($this->m_url) && !empty($this->m_url) &&
1364
                is_int($this->m_confirmOnUrl) &&
1365
                $this->m_confirmOnUrl >= 0 && $this->m_confirmOnUrl <= 1
1366
            )
1367
                return true;
1368
            return false;
1369
        }
1370
1371
        if ($this->m_actionType == self::TYPE_INTENT) {
1372
            if (is_string($this->m_intent) && !empty($this->m_intent))
1373
                return true;
1374
            return false;
1375
        }
1376
    }
1377
1378
    private $m_actionType;
1379
    private $m_url;
1380
    private $m_confirmOnUrl;
1381
    private $m_activity;
1382
    private $m_intent;
1383
    private $m_atyAttrIntentFlag;
1384
    private $m_atyAttrPendingIntentFlag;
1385
    private $m_packageDownloadUrl;
1386
    private $m_confirmOnPackageDownloadUrl;
1387
    private $m_packageName;
1388
1389
    const TYPE_ACTIVITY = 1;
1390
    const TYPE_URL = 2;
1391
    const TYPE_INTENT = 3;
1392
}
1393
1394
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...
1395
{
1396
    public function __construct($builderId, $ring = 0, $vibrate = 0, $clearable = 1, $nId = 0, $lights = 1, $iconType = 0, $styleId = 1)
1397
    {
1398
        $this->m_builderId = $builderId;
1399
        $this->m_ring = $ring;
1400
        $this->m_vibrate = $vibrate;
1401
        $this->m_clearable = $clearable;
1402
        $this->m_nId = $nId;
1403
        $this->m_lights = $lights;
1404
        $this->m_iconType = $iconType;
1405
        $this->m_styleId = $styleId;
1406
    }
1407
1408
    public function __destruct()
1409
    {
1410
    }
1411
1412
    public function getBuilderId()
1413
    {
1414
        return $this->m_builderId;
1415
    }
1416
1417
    public function getRing()
1418
    {
1419
        return $this->m_ring;
1420
    }
1421
1422
    public function getVibrate()
1423
    {
1424
        return $this->m_vibrate;
1425
    }
1426
1427
    public function getClearable()
1428
    {
1429
        return $this->m_clearable;
1430
    }
1431
1432
    public function getNId()
1433
    {
1434
        return $this->m_nId;
1435
    }
1436
1437
    public function getLights()
1438
    {
1439
        return $this->m_lights;
1440
    }
1441
1442
    public function getIconType()
1443
    {
1444
        return $this->m_iconType;
1445
    }
1446
1447
    public function getStyleId()
1448
    {
1449
        return $this->m_styleId;
1450
    }
1451
1452
    public function setRingRaw($ringRaw)
1453
    {
1454
        return $this->m_ringRaw = $ringRaw;
1455
    }
1456
1457
    public function getRingRaw()
1458
    {
1459
        return $this->m_ringRaw;
1460
    }
1461
1462
    public function setIconRes($iconRes)
1463
    {
1464
        return $this->m_iconRes = $iconRes;
1465
    }
1466
1467
    public function getIconRes()
1468
    {
1469
        return $this->m_iconRes;
1470
    }
1471
1472
    public function setSmallIcon($smallIcon)
1473
    {
1474
        return $this->m_smallIcon = $smallIcon;
1475
    }
1476
1477
    public function getSmallIcon()
1478
    {
1479
        return $this->m_smallIcon;
1480
    }
1481
1482
    public function isValid()
1483
    {
1484
        if (!is_int($this->m_builderId) || !is_int($this->m_ring) ||
1485
            !is_int($this->m_vibrate) || !is_int($this->m_clearable) ||
1486
            !is_int($this->m_lights) || !is_int($this->m_iconType) ||
1487
            !is_int($this->m_styleId)
1488
        )
1489
            return false;
1490
        if ($this->m_ring < 0 || $this->m_ring > 1) return false;
1491
        if ($this->m_vibrate < 0 || $this->m_vibrate > 1) return false;
1492
        if ($this->m_clearable < 0 || $this->m_clearable > 1) return false;
1493
        if ($this->m_lights < 0 || $this->m_lights > 1) return false;
1494
        if ($this->m_iconType < 0 || $this->m_iconType > 1) return false;
1495
        if ($this->m_styleId < 0 || $this->m_styleId > 1) return false;
1496
1497
        return true;
1498
    }
1499
1500
    private $m_builderId;
1501
    private $m_ring;
1502
    private $m_vibrate;
1503
    private $m_clearable;
1504
    private $m_nId;
1505
    private $m_ringRaw;
1506
    private $m_lights;
1507
    private $m_iconType;
1508
    private $m_iconRes;
1509
    private $m_styleId;
1510
    private $m_smallIcon;
1511
}
1512
1513
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...
1514
{
1515
    public function __construct($startHour, $startMin, $endHour, $endMin)
1516
    {
1517
        $this->m_startHour = $startHour;
1518
        $this->m_startMin = $startMin;
1519
        $this->m_endHour = $endHour;
1520
        $this->m_endMin = $endMin;
1521
    }
1522
1523
    public function __destruct()
1524
    {
1525
    }
1526
1527
    public function toArray()
1528
    {
1529
        return array(
1530
            'start' => array('hour' => strval($this->m_startHour), 'min' => strval($this->m_startMin)),
1531
            'end' => array('hour' => strval($this->m_endHour), 'min' => strval($this->m_endMin))
1532
        );
1533
    }
1534
1535
    public function isValid()
1536
    {
1537
        if (!is_int($this->m_startHour) || !is_int($this->m_startMin) ||
1538
            !is_int($this->m_endHour) || !is_int($this->m_endMin)
1539
        )
1540
            return false;
1541
1542
        if ($this->m_startHour >= 0 && $this->m_startHour <= 23 &&
1543
            $this->m_startMin >= 0 && $this->m_startMin <= 59 &&
1544
            $this->m_endHour >= 0 && $this->m_endHour <= 23 &&
1545
            $this->m_endMin >= 0 && $this->m_endMin <= 59
1546
        )
1547
            return true;
1548
        else
1549
            return false;
1550
    }
1551
1552
    private $m_startHour;
1553
    private $m_startMin;
1554
    private $m_endHour;
1555
    private $m_endMin;
1556
}
1557
1558
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...
1559
{
1560
1561
    /**
1562
     * @var array 当前传入的参数列表
1563
     */
1564
    public $_params = array();
1565
1566
    /**
1567
     * 构造函数
1568
     */
1569
    public function __construct($params)
1570
    {
1571
        if (!is_array($params)) {
1572
            return array();
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...
1573
        }
1574
        foreach ($params as $key => $value) {
1575
            //如果是非法的key值,则不使用这个key
1576
            $this->_params[$key] = $value;
1577
        }
1578
    }
1579
1580
    public function set($k, $v)
1581
    {
1582
        if (!isset($k) || !isset($v)) {
1583
            return;
1584
        }
1585
        $this->_params[$k] = $v;
1586
    }
1587
1588
    /**
1589
     * 根据实例化传入的参数生成签名
1590
     */
1591
    public function generateSign($method, $url, $secret_key)
1592
    {
1593
        //将参数进行升序排序
1594
        $param_str = '';
1595
        $method = strtoupper($method);
1596
        $url_arr = parse_url($url);
1597
        if (isset($url_arr['host']) && isset($url_arr['path'])) {
1598
            $url = $url_arr['host'] . $url_arr['path'];
1599
        }
1600
        if (!empty($this->_params)) {
1601
            ksort($this->_params);
1602
            foreach ($this->_params as $key => $value) {
1603
                $param_str .= $key . '=' . $value;
1604
            }
1605
        }
1606
        //print $method.$url.$param_str.$secret_key."\n";
1607
        return md5($method . $url . $param_str . $secret_key);
1608
    }
1609
1610
}
1611
1612
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...
1613
{
1614
1615
    //get请求方式
1616
    const METHOD_GET = 'get';
1617
    //post请求方式
1618
    const METHOD_POST = 'post';
1619
1620
    /**
1621
     * 发起一个get或post请求
1622
     * @param $url 请求的url
1623
     * @param int $method 请求方式
1624
     * @param array $params 请求参数
1625
     * @param array $extra_conf curl配置, 高级需求可以用, 如
1626
     * $extra_conf = array(
1627
     *    CURLOPT_HEADER => true,
1628
     *    CURLOPT_RETURNTRANSFER = false
1629
     * )
1630
     * @return bool|mixed 成功返回数据,失败返回false
1631
     * @throws Exception
1632
     */
1633
    public static function exec($url, $params = array(), $method = self::METHOD_GET, $extra_conf = array())
1634
    {
1635
        $params = is_array($params) ? http_build_query($params) : $params;
1636
        //如果是get请求,直接将参数附在url后面
1637
        if ($method == self::METHOD_GET) {
1638
            $url .= (strpos($url, '?') === false ? '?' : '&') . $params;
1639
        }
1640
1641
        //默认配置
1642
        $curl_conf = array(
1643
            CURLOPT_URL => $url,  //请求url
1644
            CURLOPT_HEADER => false,  //不输出头信息
1645
            CURLOPT_RETURNTRANSFER => true, //不输出返回数据
1646
            CURLOPT_CONNECTTIMEOUT => 3 // 连接超时时间
1647
        );
1648
1649
        //配置post请求额外需要的配置项
1650
        if ($method == self::METHOD_POST) {
1651
            //使用post方式
1652
            $curl_conf[CURLOPT_POST] = true;
1653
            //post参数
1654
            $curl_conf[CURLOPT_POSTFIELDS] = $params;
1655
        }
1656
1657
        //添加额外的配置
1658
        foreach ($extra_conf as $k => $v) {
1659
            $curl_conf[$k] = $v;
1660
        }
1661
1662
        $data = false;
1663
        try {
1664
            //初始化一个curl句柄
1665
            $curl_handle = curl_init();
1666
            //设置curl的配置项
1667
            curl_setopt_array($curl_handle, $curl_conf);
1668
            //发起请求
1669
            $data = curl_exec($curl_handle);
1670
            if ($data === false) {
1671
                throw new Exception('CURL ERROR: ' . curl_error($curl_handle));
1672
            }
1673
        } 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...
1674
            echo $e->getMessage();
1675
        }
1676
        curl_close($curl_handle);
1677
1678
        return $data;
1679
    }
1680
}
1681
1682
1683
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
1684