|
1 | 1 | <?php |
2 | | - include_once '../jpushv3/JPushClient.php'; |
3 | | - include_once '../jpushv3/Notification.php'; |
4 | | - include_once '../jpushv3/Message.php'; |
| 2 | + include_once '../jpush/JPushClient.php'; |
| 3 | + include_once '../jpush/model/Audience.php'; |
| 4 | + include_once '../jpush/model/Message.php'; |
| 5 | + include_once '../jpush/model/notification/Notification.php'; |
| 6 | + include_once '../jpush/model/notification/IOSNotification.php'; |
| 7 | + include_once '../jpush/model/notification/AndroidNotification.php'; |
| 8 | + include_once '../jpush/model/notification/WinphoneNotification.php'; |
| 9 | + include_once '../jpush/model/Options.php'; |
| 10 | + include_once '../jpush/model/Platform.php'; |
| 11 | + include_once '../jpush/model/PushPayload.php'; |
5 | 12 |
|
6 | 13 | $master_secret = 'd94f733358cca97b18b2cb98'; |
7 | 14 | $app_key='47a3ddda34b2602fa9e17c01'; |
| 15 | + $tag = "tag1,tag2"; |
| 16 | + $tag_and = "tag3,tag4"; |
| 17 | + $alias = "alias1,alias2"; |
| 18 | + $registration_id = "id1,id2"; |
8 | 19 | $client = new JPushClient($app_key, $master_secret); |
9 | 20 |
|
10 | | - $notification = new Notification('This is content'); |
11 | | - $message = new Message("This is content"); |
| 21 | + /* init start */ |
| 22 | + $platform = new Platform(); |
| 23 | + $audience = new Audience(); |
| 24 | + $message = new Message(); |
| 25 | + $options = new Options(); |
| 26 | + |
| 27 | + $notification = new Notification(); |
| 28 | + $ios = new IOSNotification(); |
| 29 | + $android = new AndroidNotification(); |
| 30 | + $winphone = new WinphoneNotification(); |
| 31 | + |
| 32 | + //set platform params |
| 33 | + $platform->ios = true; |
| 34 | + $platform->winphone = true; |
| 35 | + |
| 36 | + |
| 37 | + //set audience params |
| 38 | + $audience->tag = $tag; |
| 39 | + $audience->tag_and = $tag_and; |
| 40 | + $audience->alias = $alias; |
| 41 | + $audience->registration_id = $registration_id; |
| 42 | + |
| 43 | + //set options params |
| 44 | + $options->sendno = 1; |
| 45 | + $options->apns_production = true; |
| 46 | + $options->override_msg_id = 2; |
| 47 | + $options->time_to_live = 60; |
| 48 | + |
| 49 | + //set message params |
| 50 | + $message->msg_content = "message content test"; |
| 51 | + $message->title = "message title test"; |
| 52 | + $message->content_type = "message content type test"; |
| 53 | + $message->extras = array("key1"=>"value1", "key2"=>"value2"); |
| 54 | + |
| 55 | + //set options params |
| 56 | + $options->sendno = 1; |
| 57 | + $options->apns_production = true; |
| 58 | + $options->override_msg_id = 2; |
| 59 | + $options->time_to_live = 60; |
| 60 | + |
| 61 | + //set notification params |
| 62 | + $ios->alert = "ios notification alert test"; |
| 63 | + $ios->sound = "happy"; |
| 64 | + $ios->badge = 1; |
| 65 | + $ios->extras = array("key1"=>"value1", "key2"=>"value2"); |
| 66 | + $ios->content_availabe = 1; |
| 67 | + |
| 68 | + $android->alert = "android notification alert test"; |
| 69 | + $android->title = "android notification title test"; |
| 70 | + $android->builder_id = 1; |
| 71 | + $android->extras = array("key1"=>"value1", "key2"=>"value2"); |
| 72 | + |
| 73 | + $winphone->alert = "winphone notification alert test"; |
| 74 | + $winphone->title = "winphone notification title test"; |
| 75 | + $winphone->_open_page = "/friends.xaml"; |
| 76 | + $winphone->extras = array("key1"=>"value1", "key2"=>"value2"); |
| 77 | + |
| 78 | + $notification->alert = "notification alert test"; |
| 79 | + $notification->android = $android; |
| 80 | + $notification->ios = $ios; |
| 81 | + $notification->winphone = $winphone; |
| 82 | + |
| 83 | + /* init end */ |
| 84 | + |
| 85 | + |
| 86 | + |
12 | 87 |
|
13 | 88 | //发送广播通知 |
14 | | - $result1 = $client->send($notification); |
| 89 | + $payload1 = new PushPayload(); |
| 90 | + $payload1->notification = $notification; |
| 91 | + $result1 = $client->sendPush($payload1); |
15 | 92 |
|
16 | 93 | //发送广播自定义信息 |
17 | | - $result2 = $client->send($message); |
| 94 | + $payload2 = new PushPayload(); |
| 95 | + $payload2->message = $message; |
| 96 | + $result2 = $client->sendPush($payload2); |
18 | 97 |
|
19 | 98 | //发送Tag通知 |
20 | | - $notification->setTag("555,666"); |
21 | | - $result3 = $client->send($notification); |
22 | | - |
23 | | - //其他属性测试 |
24 | | - $notification->setTitle("This is title") |
25 | | - ->setBuilderId(1) |
26 | | - ->setExtras(array("key"=>"value")) |
27 | | - ->setSound("happy") |
28 | | - ->setBadge(1) |
29 | | - ->setContentAvailabe(true) |
30 | | - ->setOpenPage("/friends.xaml"); |
31 | | - $result4 = $client->send($notification); |
32 | | - |
33 | | - //其他属性测试 |
34 | | - $message->setTitle("This is title")->setExtras(array("key"=>"value"))->setContentType("content_type"); |
35 | | - $result5 = $client->send($message); |
| 99 | + $options3 = new Options(); |
| 100 | + $audience3 = new Audience(); |
| 101 | + $notification3 = new Notification(); |
| 102 | + $notification3->alert = "tag tests"; |
| 103 | + $audience3->tag = "555"; |
| 104 | + //$audience3->alias = $alias; |
| 105 | + $options3->sendno = 441740752; |
| 106 | + |
| 107 | + $payload3 = new PushPayload(); |
| 108 | + $payload3->audience = $audience3; |
| 109 | + $payload3->notification = $notification3; |
| 110 | + $payload3->options = $options3; |
| 111 | + $result3 = $client->sendPush($payload3); |
| 112 | + |
| 113 | + |
36 | 114 |
|
37 | 115 | //组装查询统计信息字符串 |
38 | 116 | $msg_ids1 = '636946851'; |
39 | 117 | $msg_ids2 = '636946851,1173817748,636946865'; |
40 | 118 | $result6 = $client->getReport($msg_ids1); |
41 | 119 | $result7 = $client->getReport($msg_ids2); |
42 | 120 |
|
43 | | - //错误测试 |
44 | | - $notification->setTitle(["This is title"]); |
45 | | - $result8 = $client->send($notification); |
46 | | - $notification->setTitle("This is title"); |
47 | | - |
48 | | - $notification->setBadge("1"); |
49 | | - $result9 = $client->send($notification); |
50 | | - $notification->setBadge(1); |
51 | 121 |
|
52 | 122 | ?> |
53 | 123 |
|
|
81 | 151 | <td>发送Tag通知</td> |
82 | 152 | <td><?php echo $result3; ?></td> |
83 | 153 | </tr> |
84 | | - <tr> |
85 | | - <td>其他属性测试</td> |
86 | | - <td><?php echo $result4; ?></td> |
87 | | - </tr> |
88 | | - <tr> |
89 | | - <td>其他属性测试(自定义)</td> |
90 | | - <td><?php echo $result5; ?></td> |
91 | | - </tr> |
| 154 | + |
92 | 155 | </table> |
93 | 156 |
|
94 | 157 | <h3>Report Example</h3> |
|
104 | 167 | </tr> |
105 | 168 | </table> |
106 | 169 |
|
107 | | -<h3>Error Example</h3> |
108 | | -<table> |
109 | | - <tr><th>错误信息</th><th>返回JSON</th></tr> |
110 | | - <tr> |
111 | | - <td>标题错误</td> |
112 | | - <td><?php echo $result8; ?></td> |
113 | | - </tr> |
114 | | - <tr> |
115 | | - <td>Badge错误</td> |
116 | | - <td><?php echo $result9; ?></td> |
117 | | - </tr> |
118 | | - <tr> |
119 | | - <td>更多错误</td> |
120 | | - <td>待添加</td> |
121 | | - </tr> |
122 | 170 |
|
123 | | -</table> |
124 | 171 |
|
125 | 172 |
|
126 | 173 |
|
|
0 commit comments