-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEJPushMessage.php
106 lines (91 loc) · 2.13 KB
/
EJPushMessage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* Created by PhpStorm.
* User: leoliang
* Date: 14-4-21
* Time: 下午5:23
*/
class EJPushMessage
{
const CODE_AT = 1;
const CODE_FEEDS_COMMENT = 2;
const CODE_CHAT = 3;
const CODE_GARTEN = 4;
const CODE_UNIT = 5;
const CODE_SCHOOL = 6;
const CODE_NEW = 7;
const CODE_THIRD = 8;
const CODE_TASK = 9;
const CODE_TASK_COMMENT = 10;
private $_id = null;
private $content = '';
private $extras = array(
'c' => 0,
'd' => ''
);
private $ios = array(
'badge' => 1
);
public function __construct($content = '')
{
$this->setContent($content);
}
public function getExtras()
{
return array_merge($this->extras, array('ios' => $this->ios));
}
public function getId()
{
if ($this->_id === null) {
$this->_id = Yii::app()->cache->getMemCache()->increment('push_msg', 1);
if ($this->_id === false) {
//init
Yii::app()->cache->getMemCache()->set('push_msg', 1, 0);
$this->_id = 1;
}
}
return $this->_id;
}
public function setId($id)
{
$this->_id = $id;
}
public function setExtras($k, $v)
{
if (is_array($k)) {
$this->extras = $k;
} else {
$this->extras[$k] = $v;
}
}
public function setIosPrototype($k, $v)
{
$this->ios[$k] = $v;
}
public function setSilent()
{
$this->content = '';
$this->setIosPrototype('content-available', 1);
$this->setBadge(0);
}
public function setBadge($num = 0)
{
$this->setIosPrototype('badge', $num);
}
public function getContent()
{
return mb_strlen($this->content) > 40 ? (mb_substr($this->content, 0, 40, 'utf-8') . '...') : $this->content;
}
public function setContent($content)
{
$this->content = $content;
}
public function setCode($code)
{
$this->setExtras('c', $code);
}
public function setData($data)
{
$this->setExtras('d', (string)$data);
}
}