following program written send push-notifications using php-pushwoosh library:
<?php ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(-1); use gomoob\pushwoosh\client\pushwoosh; use gomoob\pushwoosh\model\request\createmessagerequest; use gomoob\pushwoosh\model\notification\notification; use gomoob\pushwoosh\exception; require __dir__.'/vendor/autoload.php'; /*require('../config.php'); require('../common.php');*/ $data = json_decode(file_get_contents('php://input'), true); $auth_token = $data['auth_token']; $app_code = $data['app_code']; $page_no = $data['page_no']; $page_total = $data['page_total']; define('pw_auth', $auth_token); define('pw_application', $app_code); // create pushwoosh client $pushwoosh = pushwoosh::create() ->setapplication(pw_auth) ->setauth(pw_application); if(!empty($page_no) && !empty($page_total)) { if (!phpfox::isuser()) { $flag = false; $response["error"] = "error"; $response["message"] = "please login"; echorespnse(401, $response); } else { $notificaions = phpfox::getservice('notification')->getallnotifications($page_no,$page_total); if(!empty($notificaions)) { $notificaions = walk_recursive_remove($notificaions, 'unset_null_children'); for($i=0;$i<count($notificaions);$i++) { $notificaions[$i]['message'] = stripslashes(strip_tags($notificaions[$i]['message'])); $notificaions[$i]['profile_image'] = image_creator($notificaions[$i]['user_image']); } $notifications_data = json_encode($notifications); } } } else { $notifications_data = "error in request"; } // create request '/createmessage' web service $request = createmessagerequest::create() ->addnotification(notification::create()->setcontent($notifications_data)); // call rest web service $response = $pushwoosh->createmessage($request); // check if ok if($response->isok()) { print 'great, message has been sent !'; } else { print 'oops, sent failed :-( '; print 'status code : ' . $response->getstatuscode()." "; print 'status message : ' . $response->getstatusmessage(); } ?>
after executing on server got following fatal error :
fatal error: uncaught exception 'gomoob\pushwoosh\exception`\pushwooshexception' message 'none of 'application' or 'applicationsgroup' properties set !' in /var/www/api/gomoob-php-pushwoosh/vendor/gomoob/php-pushwoosh/src/main/php/gomoob/pushwoosh/client/pushwoosh.php:106 stack trace: #0 /var/www/api/gomoob-php-pushwoosh/push_notifications.php(61): gomoob\pushwoosh\client\pushwoosh->createmessage(object(gomoob\pushwoosh\model\request\createmessagerequest)) #1 {main} thrown in /var/www/api/gomoob-php-pushwoosh/vendor/gomoob/php-pushwoosh/src/main/php/gomoob/pushwoosh/client/pushwoosh.php on line 106`
if want check hierarchy of name spaces included can check @ php-pushwoosh namespace hierarchy
thanks in advance.
you problem in lines, because pw_auth & pw_application not defined.
// create pushwoosh client $pushwoosh = pushwoosh::create() ->setapplication(pw_auth) ->setauth(pw_application);
you must define pw_auth & pw_application constants, must swap , setauth use pw_application
Comments
Post a Comment