-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathpush.php
122 lines (73 loc) · 2.2 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
120
121
122
#!/usr/bin/php -q
<?php
require __DIR__ . '/vendor/autoload.php';
set_time_limit(60);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
error_reporting(1);
use Pushok\AuthProvider;
use Pushok\Client;
use Pushok\Notification;
use Pushok\Payload;
use Pushok\Payload\Alert;
//change following
$options = [
'key_id' => 'XXXXXXXX',
'team_id' => 'XXXXXXXXXX',
'app_bundle_id' => 'org.sipco.softphone',
'private_key_path' => __DIR__ . '/AuthKey_XXXXXX.p8',
'private_key_secret' => null
];
if (isset($argc)) {
$mysqli = new mysqli("localhost","push_user","push_passwd","pushdb");
// Check connection
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit;
}
$callerdest = $mysqli -> real_escape_string($argv[1]);
$callerid = $mysqli -> real_escape_string($argv[2]);
$callername = $mysqli -> real_escape_string($argv[3]);
$sql = "SELECT p_info,p_device,p_status,p_type,p_updated FROM pushdb_pushkeys WHERE p_device = $callerdest";
if (!$result = $mysqli->query($sql)) {
exit;
}
if ($result->num_rows === 0) {
exit;
}
while ($pushkey = $result->fetch_assoc()) {
$pkey = $pushkey['p_info'];
//
$authProvider = AuthProvider\Token::create($options);
$alert = Alert::create()->setTitle("Call from $callerid");
$alert = $alert->setBody("$callername is Calling");
$payload = Payload::create()->setAlert($alert);
$payload->setSound('louder_ring.caf');
//add custom value to your notification, needs to be customized
//$payload->setCustomValue('key', 'value');
//sreekanth
$deviceTokens = ["$pkey"];
$notifications = [];
foreach ($deviceTokens as $deviceToken) {
$notifications[] = new Notification($payload,$deviceToken);
}
$client = new Client($authProvider, $production = false);
$client->addNotifications($notifications);
$responses = $client->push(); // returns an array of ApnsResponseInterface (one Response per Notification)
foreach ($responses as $response) {
$response->getApnsId();
$response->getStatusCode();
$response->getReasonPhrase();
$response->getErrorReason();
$response->getErrorDescription();
}
}
$result->free();
$mysqli->close();
}
else
{
exit();
}
?>