I am a android developer so i don't know that much about PHP.
we are developing exam paper app in Android and IOS. and create notification functionality its works perfectly. But problem is IOS use Push notification and android use GCM. And these two are use different api.
My question is how to combine these two api. I want to combine this two api (webservice) in one. When admin upload paper then all user get notify using notification weather it is android or IOS device.
What should i do? Help much appreciate thanks in advance. i am using this LINK
Here is my effort
Android API
<?php
require_once('connect.php');
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'AIzaSyBWcc6ONXvNEHECxzLwFDSDCTKDTjEhfT8' );
//$registrationIds = array( $_GET['id'] );
$conn = new mysqli('host name', 'server name', 'password', 'database name');
$select_qury = "SELECT gcm_registration_id FROM gtu_registration";
$result = $conn->query($select_qury);
$registrationIds = array();
while($row = $result->fetch_assoc()){
array_push($registrationIds, $row['gcm_registration_id']);
}
// prep the bundle
$msg = array
(
'message' => 'here is a message. message',
'title' => 'This is a title. title',
'subtitle' => 'This is a subtitle. subtitle',
'tickerText'=> 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
//Creating a new array fileds and adding the msg array and registration token array here
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
//Adding the api key in one more array header
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
//Decoding json from result
$res = json_decode($result);
$flag = $res->success;
//if success is 1 means message is sent
if($flag == 1){
//Redirecting back to our form with a request success
header('Location: index.php?success');
}else{
//Redirecting back to our form with a request failure
header('Location: index.php?failure');
}
echo $result;
IOS API
<?php
$token ='f1088d1c0603218b31b5a26210c4b0e60e4884225235c7f5c2e55c47b937a03d';
$deviceToken = $token; // token dell'iPhone a cui inviare la notifica
// Passphrase for the private key (ck.pem file)
$pass = "mac12345";
// Get the parameters from http get or from command line
$message = 'Notification text';
$badge = 1;
$sound = 'default';
// Construct the notification payload
$body = array();
$body['aps'] = array('alert' => $message);
if ($badge)
$body['aps']['badge'] = $badge;
if ($sound)
$body['aps']['sound'] = $sound;
/ End of Configurable Items /
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl','local_cert', 'Gtuck.pem');
// assume the private key passphase was removed.
stream_context_set_option($ctx, 'ssl', 'passphrase', $pass);
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 120, STREAM_CLIENT_CONNECT, $ctx);
$payload = json_encode($body);
$msg = chr(0).pack('n',32).pack('H*', str_replace(' ', '', $deviceToken)).pack('n',strlen($payload)).$payload;
print "" . $payload . "
";
fwrite($fp, $msg);
fclose($fp);
?>
Is it possible or not?? if any suggestion or other way to get this done please tell me.