11<?php
22include_once 'jpush_api_php_client/baseClient.php ' ;
33
4- class BaseClent
4+ class JpushClient
55{
66
77 /**
88 *
99 * @var unknown
1010 */
1111 private $ masterSecret ;
12- private $ app_key ;
13- private $ timeToLive ;
12+ private $ time_to_live ;
1413
1514 /**
1615 * 构造函数
1716 * @param String $appKey
1817 * @param String $masterSecret
1918 * @param int $timeToLive
2019 */
21- public function __construct ($ app_key , $ masterSecret , $ timeToLive )
20+ public function __construct ($ masterSecret , $ timeToLive )
2221 {
23- $ this ->app_key = $ app_key ;
2422 $ this ->masterSecret = $ masterSecret ;
25- $ this ->timeToLive = $ timeToLive ;
23+ $ this ->time_to_live = $ timeToLive ;
2624 }
2725
2826 /**
@@ -37,18 +35,17 @@ public function __construct($app_key, $masterSecret, $timeToLive)
3735 * @param Strng $extras
3836 */
3937 public function sendNotificationByTag ($ tag , $ app_key , $ sendno , $ send_description ,
40- $ mes_title , $ mes_content , $ perform , $ extras ,$ override_msg_id ='' )
38+ $ mes_title , $ mes_content , $ platform , $ extras= '' ,$ override_msg_id ='' )
4139 {
4240 $ mes_type = 1 ;
4341 $ msg_content = $ this ->getContent ($ mes_title , $ mes_content , $ mes_type , $ extras );
44- $ receiver_value = tag
42+ $ receiver_value = $ tag;
4543 $ baseClent = new BaseClent ();
4644 $ receiver_type = 2 ;
47- $ msg_type = 1 ;
4845 $ verification_code = $ this ->getVerification_code ($ sendno , $ receiver_type , $ receiver_value );
4946 $ return_str = $ baseClent ->send ($ sendno , $ app_key , $ receiver_type , $ receiver_value , $ verification_code ,
50- $ msg_type , $ msg_content , $ send_description , $ platform , $ this ->time_to_live , $ override_msg_id );
51- echo $ return_str ;
47+ $ mes_type , $ msg_content , $ send_description , $ platform , $ this ->time_to_live , $ override_msg_id );
48+ return $ return_str ;
5249 }
5350
5451 /**
@@ -63,18 +60,17 @@ public function sendNotificationByTag($tag, $app_key, $sendno, $send_descriptio
6360 * @param Strng $extras
6461 */
6562 public function sendCustomMesByTag ($ tag , $ app_key , $ sendno , $ send_description ,
66- $ mes_title , $ mes_content , $ perform , $ extras )
63+ $ mes_title , $ mes_content , $ platform , $ extras= '' , $ override_msg_id = '' )
6764 {
6865 $ mes_type = 2 ;
6966 $ msg_content = $ this ->getContent ($ mes_title , $ mes_content , $ mes_type , $ extras );
70- $ receiver_value = tag
67+ $ receiver_value = $ tag;
7168 $ baseClent = new BaseClent ();
7269 $ receiver_type = 2 ;
73- $ msg_type = 1 ;
7470 $ verification_code = $ this ->getVerification_code ($ sendno , $ receiver_type , $ receiver_value );
7571 $ return_str = $ baseClent ->send ($ sendno , $ app_key , $ receiver_type , $ receiver_value , $ verification_code ,
76- $ msg_type , $ msg_content , $ send_description , $ platform , $ this ->time_to_live , $ override_msg_id );
77- echo $ return_str ;
72+ $ mes_type , $ msg_content , $ send_description , $ platform , $ this ->time_to_live , $ override_msg_id );
73+ return $ return_str ;
7874
7975 }
8076
@@ -90,18 +86,17 @@ public function sendCustomMesByTag($tag, $app_key, $sendno, $send_description,
9086 * @param Strng $extras
9187 */
9288 public function sendNotificationByAlias ($ alias , $ app_key , $ sendno , $ send_description ,
93- $ mes_title , $ mes_content , $ perform , $ extras )
89+ $ mes_title , $ mes_content , $ platform , $ extras= '' , $ override_msg_id = '' )
9490 {
9591 $ mes_type = 1 ;
9692 $ msg_content = $ this ->getContent ($ mes_title , $ mes_content , $ mes_type , $ extras );
97- $ receiver_value = tag
93+ $ receiver_value = $ alias ;
9894 $ baseClent = new BaseClent ();
99- $ receiver_type = 2 ;
100- $ msg_type = 1 ;
95+ $ receiver_type = 3 ;
10196 $ verification_code = $ this ->getVerification_code ($ sendno , $ receiver_type , $ receiver_value );
10297 $ return_str = $ baseClent ->send ($ sendno , $ app_key , $ receiver_type , $ receiver_value , $ verification_code ,
103- $ msg_type , $ msg_content , $ send_description , $ platform , $ this ->time_to_live , $ override_msg_id );
104- echo $ return_str ;
98+ $ mes_type , $ msg_content , $ send_description , $ platform , $ this ->time_to_live , $ override_msg_id );
99+ return $ return_str ;
105100
106101 }
107102
@@ -117,18 +112,17 @@ public function sendNotificationByAlias($alias, $app_key, $sendno, $send_descri
117112 * @param Strng $extras
118113 */
119114 public function sendCustomMesByAlias ($ alias , $ app_key , $ sendno , $ send_description ,
120- $ mes_title , $ mes_content , $ perform , $ extras )
115+ $ mes_title , $ mes_content , $ platform , $ extras= '' , $ override_msg_id = '' )
121116 {
122117 $ mes_type =2 ;
123118 $ msg_content = $ this ->getContent ($ mes_title , $ mes_content , $ mes_type , $ extras );
124- $ receiver_value = tag
119+ $ receiver_value = $ alias ;
125120 $ baseClent = new BaseClent ();
126- $ receiver_type = 2 ;
127- $ msg_type = 1 ;
121+ $ receiver_type = 3 ;
128122 $ verification_code = $ this ->getVerification_code ($ sendno , $ receiver_type , $ receiver_value );
129123 $ return_str = $ baseClent ->send ($ sendno , $ app_key , $ receiver_type , $ receiver_value , $ verification_code ,
130- $ msg_type , $ msg_content , $ send_description , $ platform , $ this ->time_to_live , $ override_msg_id );
131- echo $ return_str ;
124+ $ mes_type , $ msg_content , $ send_description , $ platform , $ this ->time_to_live , $ override_msg_id );
125+ return $ return_str ;
132126
133127 }
134128
@@ -143,18 +137,17 @@ public function sendCustomMesByAlias($alias, $app_key, $sendno, $send_descripti
143137 * @param Strng $extras
144138 */
145139 public function sendNotificationByAppkey ($ app_key , $ sendno , $ send_description ,
146- $ mes_title , $ mes_content , $ perform , $ extras )
140+ $ mes_title , $ mes_content , $ platform , $ extras= '' , $ override_msg_id = '' )
147141 {
148142 $ mes_type = 1 ;
149143 $ msg_content = $ this ->getContent ($ mes_title , $ mes_content , $ mes_type , $ extras );
150- $ receiver_value = tag
144+ $ receiver_value = '' ;
151145 $ baseClent = new BaseClent ();
152- $ receiver_type = 2 ;
153- $ msg_type = 1 ;
146+ $ receiver_type = 4 ;
154147 $ verification_code = $ this ->getVerification_code ($ sendno , $ receiver_type , $ receiver_value );
155148 $ return_str = $ baseClent ->send ($ sendno , $ app_key , $ receiver_type , $ receiver_value , $ verification_code ,
156- $ msg_type , $ msg_content , $ send_description , $ platform , $ this ->time_to_live , $ override_msg_id );
157- echo $ return_str ;
149+ $ mes_type , $ msg_content , $ send_description , $ platform , $ this ->time_to_live , $ override_msg_id );
150+ return $ return_str ;
158151
159152 }
160153
@@ -169,18 +162,17 @@ public function sendNotificationByAppkey($app_key, $sendno, $send_description,
169162 * @param Strng $extras
170163 */
171164 public function sendCustomMesByAppkey ($ app_key , $ sendno , $ send_description ,
172- $ mes_title , $ mes_content , $ perform , $ extras )
165+ $ mes_title , $ mes_content , $ platform , $ extras= '' , $ override_msg_id = '' )
173166 {
174167 $ mes_type = 2 ;
175168 $ msg_content = $ this ->getContent ($ mes_title , $ mes_content , $ mes_type , $ extras );
176- $ receiver_value = tag
169+ $ receiver_value = '' ;
177170 $ baseClent = new BaseClent ();
178- $ receiver_type = 2 ;
179- $ msg_type = 1 ;
171+ $ receiver_type = 4 ;
180172 $ verification_code = $ this ->getVerification_code ($ sendno , $ receiver_type , $ receiver_value );
181173 $ return_str = $ baseClent ->send ($ sendno , $ app_key , $ receiver_type , $ receiver_value , $ verification_code ,
182- $ msg_type , $ msg_content , $ send_description , $ platform , $ this ->time_to_live , $ override_msg_id );
183- echo $ return_str ;
174+ $ mes_type , $ msg_content , $ send_description , $ platform , $ this ->time_to_live , $ override_msg_id );
175+ return $ return_str ;
184176
185177 }
186178
@@ -194,6 +186,7 @@ public function sendCustomMesByAppkey($app_key, $sendno, $send_description,
194186 */
195187 private function getContent ($ mes_title , $ mes_content , $ mes_type , $ extras )
196188 {
189+ //echo "mes_title=".$mes_title."mes_content=".$mes_content."mes_type=".$mes_type."extras=".$extras;
197190 $ content_str = '' ;
198191 if ($ mes_type == 1 )
199192 {
@@ -205,13 +198,14 @@ private function getContent($mes_title, $mes_content, $mes_type, $extras)
205198 $ content = array ('title ' =>$ mes_title , 'message ' =>$ mes_content , 'extras ' =>$ extras );
206199 $ content_str = json_encode ($ content );
207200 }
201+ //echo $content_str;
208202 return $ content_str ;
209203 }
210204
211205
212206 private function getVerification_code ($ sendno , $ receiver_type , $ receiver_value )
213207 {
214- $ verification_str = $ sendno .$ receiver_type .$ receiver_value .$ this ->$ masterSecret ;
208+ $ verification_str = $ sendno .$ receiver_type .$ receiver_value .$ this ->masterSecret ;
215209 $ verification_str = md5 ($ verification_str );
216210 return $ verification_str ;
217211 }
0 commit comments