Sending Push notification through pushwoosh from php

PHP Pushwoosh notification using Pushwoosh API

Pushwoosh is real time cross-platfrom service to send push notification on android and IOS mobile application.

To send and push notification fro PHP pannel 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 mobile application or other web.

Example : pushwoosh notification code in php:

 
    $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

Experienced Software Engineer with a demonstrated history of working in the marketing and advertising industry. Skilled in SQL, Web Applications, PHP, WordPress, and Joomla. Strong engineering professional with a B-TECH focused in Information Technology from JCDM College of Engineering Sirsa, Haryana.

More posts by Pankaj Singh Sugara