Initial commit
[2ch-be.git] / dev-test / mb / simplepush.php
blobf6ec52242edcdc30e268d14c2c4b5fdf4872091a
1 <?php
6 if(!isset($_GET['token']) ) { //&& !isset($_GET['unread'])) {
7 exit;
8 } else if(isset($_GET['token'])) {
9 //$deviceToks = $_GET['token'];
10 $deviceToks = filter_var($_GET['token'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
11 //$unread = $_GET['unread'];
15 $cookie_val = $_COOKIE['DMDM'];
16 $cookie_val2 = $_COOKIE['MDMD'];
17 $opts = array(
18 'http'=>array(
19 'method'=>"GET",
20 'header'=>"Accept-language: en\r\n" .
21 "Cookie: DMDM=" . $cookie_val . "\r\n" .
22 "Cookie: MDMD=" . $cookie_val2
25 $context = stream_context_create($opts);
27 include('../encrypt.php');
28 $email = Decrypt($_COOKIE['DMDM'],KEY);
30 //$gotemail = file_get_contents('http://be.2ch.net/mb/ur.php', TRUE , $context);
33 $gotmessage = file_get_contents('https://be.2ch.net/mb/noti.php?un='.$email, FALSE , $context);
35 if($gotmessage >= 1) {
37 $deviceToken = $deviceToks;
38 // Put your device token here (without spaces):
39 //$deviceToken = str_replace(' ','', $deviceToks);
41 // Put your private key's passphrase here:
42 $passphrase = 'rqibemessenger';
44 // Put your alert message here:
46 /*if(!empty($unread)){
47 $countmessage = $unread . " unread messages!";
48 } else {
49 $countmessage = "";
52 $countmessage = "";
54 $message = 'あなたはBEmessengerから新しいメッセージを得た! ' . $countmessage ;
56 ////////////////////////////////////////////////////////////////////////////////
58 $ctx = stream_context_create();
60 //DISABLED THIS WHEN APP STORE AVAIL
61 stream_context_set_option($ctx, 'ssl', 'local_cert', '/home/auth/secure_html/ckDEV.pem');
63 //ENABLED THIS WHEN APP STORE AVAIL
64 //stream_context_set_option($ctx, 'ssl', 'local_cert', '/home/auth/secure_html/ckDis.pem');
67 stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
69 // Open a connection to the APNS server
70 $fp = stream_socket_client(
71 'ssl://gateway.sandbox.push.apple.com:2195', $err,
72 $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
74 if (!$fp)
75 exit("Failed to connect: $err $errstr" . PHP_EOL);
77 echo 'Connected to APNS' . PHP_EOL;
79 // Create the payload body
80 $body['aps'] = array(
81 'alert' => $message,
82 'sound' => 'default'
85 // Encode the payload as JSON
86 $payload = json_encode($body);
88 // Build the binary notification
89 $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
91 // Send it to the server
92 $result = fwrite($fp, $msg, strlen($msg));
94 if (!$result)
95 echo 'Message not delivered' . PHP_EOL;
96 else
97 echo 'Message successfully delivered' . PHP_EOL;
99 // Close the connection to the server
100 fclose($fp);
102 } else {
103 echo "No message.";