Skip to main content

Send push motification to iphone and android code

Send push motification to iphone and android code


function sendIphoneAdminPush($token,$message)
{
$streamContext = stream_context_create();
$badge = 0;
//$message = "Here is the new deal having 50% discount for business ABC.";
//$token = "ghjkghkgkghkghkjghkghkghjkhkghkghjkhkhgjkhgj";
stream_context_set_option($streamContext, 'ssl', 'local_cert', $_SERVER['DOCUMENT_ROOT'].'/nodatapp/pem/pushNew.pem');
$apns = stream_socket_client(
//'ssl://gateway.sandbox.push.apple.com:2195',
'ssl://gateway.push.apple.com:2195',
$error,
$errorString,
60,
STREAM_CLIENT_CONNECT, $streamContext);
$load = array(
  'aps' => array(
  'alert' => $message,
  'badge' => $badge,
  'sound' => 'default',
  'data' => array(
'push_type' => "IphonePush"
)
  )
  );

$payload = json_encode($load);
$apnsMessage = chr(0) . chr(0) . chr(32);
$apnsMessage .= pack('H*', $token);
$apnsMessage .= chr(0) . chr(strlen($payload)) . $payload;
  $bytes = fwrite($apns, $apnsMessage);
$payload = json_encode($load);
//print_r($payload);
fclose($apns);
//return true;
}

function sendAndroidAdminPush($token,$busisId,$message,$msgBody)
{
//Testing
$APIKey= 'AAAAODAx1tY:APA91bG5wfaeghjkghkghjkghk3bt4LLa7p8gJSUBZ0eywiYUbkZPYvckViQeKtOvVkFh4zWo8eqEQurW5Y54rjanV2Jihgjghjkghjkgjkghjkgh5_3Ux_ScSY4YMfkTELwBl';



    $fields = array(
    'to' => $token,
    'notification' => array('title' => $message, 'body' => $msgBody,'business_id' => $busisId,'click_action' => '.activity.HomeActivity'),
    'data' => array('title' => $message,'business_id' => $busisId)
    );
    $headers = array
            (
            'Authorization: key='. $APIKey,
            'Content-Type: application/json'
            );
    $ch = curl_init();
    curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/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 );
    return true;
}

Comments

Post a Comment

Popular posts from this blog

Error: ios-deploy was not found. Please download, build and install version 1.9.0 or greater from https://github.com/phonegap/ios-deploy into your path, or do 'npm install -g ios-deploy' solution this solved the issue sudo npm install -g ios-deploy -unsafe-perm

Error: ios-deploy was not found. Please download, build and install version 1.9.0 or greater from https://github.com/phonegap/ios-deploy into your path, or do 'npm install -g ios-deploy' solution this solved the issue sudo npm install -g ios-deploy -unsafe-perm

How to revoke code from github?

How to revoke code from github? https://stackoverflow.com/questions/6655052/is-there-a-way-to-rollback-my-last-push-to-git Since you are the only user: git reset --hard HEAD@{1} git push -f git reset --hard HEAD@{1} ( basically, go back one commit, force push to the repo, then go back again - remove the last step if you don't care about the commit ) Without doing any changes to your local repo, you can also do something like: git push -f origin <sha_of_previous_commit>:master

preg expression regular expression details and introduction

preg expression regular expression details and introduction Useful regex examples Reference: http://www.catswhocode.com/blog/15-php-regular-expressions-for-web-developers REGULAR EXPRESSIONS SYNTAX Regular Expression Will match… foo The string “foo” ^foo “foo” at the start of a string foo$ “foo” at the end of a string ^foo$ “foo” when it is alone on a string [abc] a, b, or c [a-z] Any lowercase letter [^A-Z] Any character that is not a uppercase letter (gif|jpg) Matches either “gif” or “jpg” [a-z]+ One or more lowercase letters [0-9.-] Аny number, dot, or minus sign ^[a-zA-Z0-9_]{1,}$ Any word of at least one letter, number or _ ([wx])([yz]) wy, wz, xy, or xz [^A-Za-z0-9] Any symbol (not a number or a letter) ([A-Z]{3}|[0-9]{4}) Matches three letters or four numbers PHP REGULAR EXPRESSION FUNCTIONS Function Description preg_match() The preg_match() function searches string for pattern, returning true if pattern exists, and false otherwise. preg_match_