Sending Push notification through pushwoosh from php

PHP Pushwoosh notification using Pushwoosh API
To send Pushwoosh notification on mobile application using PHP, we need push auth and push application id that we will get from https://www.pushwoosh.com/ and by using those credentials we can easily send push notification to application or other web.

 
    $push_auth = 'XXXXXXXXXXXXXXXX';
    $push_app_id = 'XXXXX-XXXXX';
    $push_debug = false;
    $title = ''; // pushwoosh title
    $banner = ''; // pushwoosh banner
    $send_date = 'now'; // pushwoosh date
    $android_header = '';    // pushwoosh android header 
    $android_custom_icon = '' pushwoosh notification icon;


    sendpush('createMessage', array(
                        'application' => $push_app_id,
                        'auth' => $push_auth,
                        'notifications' => array(
                            array(
                                'send_date' => $send_date,
                                'content' => $title,
                                'android_header'=>$android_header,
                                'android_custom_icon' =>$android_custom_icon,
                                'android_badges' => 2,
                                'android_vibration' => 1,                
                                'android_priority' => 1,
                                'data' => array('custom' => 'json data'),
                            ),
                        )
            ));
    		
    function sendpush($method, $data) {
                $url = 'https://cp.pushwoosh.com/json/1.3/' . $method;
                $request = json_encode(['request' => $data]);
             
                $ch = curl_init($url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
                curl_setopt($ch, CURLOPT_HEADER, true);
                curl_setopt($ch, CURLOPT_POST, true);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
             
                $response = curl_exec($ch);            
                $info = curl_getinfo($ch);
                curl_close($ch);
             
                if (defined('PW_DEBUG') && self::$push_de) {
                    print "[PW] request: $request\n";
                    print "[PW] response: $response\n";
                    print "[PW] info: " . print_r($info, true);
                }
                
                return $info;
        }
    }

For more information click here

Pankaj Singh Sugara

Author Pankaj Singh Sugara

More posts by Pankaj Singh Sugara