-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush.php
119 lines (100 loc) · 3.16 KB
/
push.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
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* @file
* sample_push.php
*
* Push demo
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://code.google.com/p/apns-php/wiki/License
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author (C) 2010 Aldo Armiento ([email protected])
* @version $Id: sample_push.php 65 2010-12-13 18:38:39Z aldo.armiento $
*/
// Adjust to your timezone
date_default_timezone_set('Europe/Rome');
if(isset($_POST['submit'])){
// Report all PHP errors
echo "<pre>";
error_reporting(-1);
// Using Autoload all classes are loaded on-demand
require_once 'ApnsPHP/Autoload.php';
// Instanciate a new ApnsPHP_Push object
$push = new ApnsPHP_Push(
ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
'server_certificates_bundle_sandbox.pem'
);
// Set the Root Certificate Autority to verify the Apple remote peer
$push->setRootCertificationAuthority('entrust.pem');
// Connect to the Apple Push Notification Service
$push->connect();
// Instantiate a new Message with a single recipient
$tujuan = $_POST['tujuan'];
$tujuan = str_replace(" ",'',$tujuan);
$message = new ApnsPHP_Message($tujuan);
// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
// over a ApnsPHP_Message object retrieved with the getErrors() message.
$message->setCustomIdentifier("Message-Badge-3");
// Set badge icon to "3"
$message->setBadge(intval($_POST['badge']));
// Set a simple welcome text
$message->setText($_POST['pesan']);
// Play the default sound
$message->setSound();
// Set a custom property
if(isset($_POST['property'])){
$message->setCustomProperty($_POST['property'], json_decode("$_POST[property_content]"));
}
// Set another custom property
//$message->setCustomProperty('acme3', array('bing', 'bong'));
// Set the expiry value to 30 seconds
$message->setExpiry(30);
// Add the message to the message queue
$push->add($message);
// Send all messages in the message queue
$push->send();
// Disconnect from the Apple Push Notification Service
$push->disconnect();
// Examine the error message container
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
var_dump($aErrorQueue);
}
echo "</pre>";
}
?>
<form method="post" action="push.php">
<table>
<tr>
<td>Tujuan : </td>
<td><input type="text" name="tujuan" value="<?= $tujuan?>" style="width:200px" /></td>
</tr>
<tr>
<td>Pesan : </td>
<td><textarea name="pesan" style="width:200px"></textarea></td>
</tr>
<tr>
<td>Badge Number : </td>
<td><textarea name="badge" style="width:200px"></textarea></td>
</tr>
<tr>
<td>Custom Property Name : </td>
<td><input type="text" name="property" style="width:200px" /></td>
</tr>
<tr>
<td>Custom Property Content : </td>
<td><textarea name="property_content" style="width:200px" ></textarea></td>
</tr>
<tr>
<td colspan="2" align="right">
<input type="submit" name="submit" />
</td>
</tr>
</form>