×
Namespaces

Variants
Actions

Using PHP and cURL to send a notification using Notification Service API

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: isalento (17 Jan 2011)
Last edited: hamishwillee (21 Nov 2013)

Introduction

With the Notifications API you can enable Push messages for Qt applications. Notifications API consists of two major parts Client API and Service API. Client API is to be used on a device with Qt. It handles registration and message passing between device and Notifications Server. Notifications Service API is REST API that handles the communication between your service and Notifications Server.

See more information on http://developer.nokia.com/Resources/Library/Java/#!developers-guides/nokia-notifications.html

You can include the code below to your Web Page or run it directly from console, by saving the file as notification.php and running it “php notification.php”.


notification.php

<?php
 
$serviceId = "<service id>";
$serviceSecret = "<service secret>";
 
$nid = urlencode("<notification id of the application>");
 
$url = "https://alpha.one.ovi.com/nnapi/1.0/nid/".$nid."/";
 
$args = '&payload=hello&ctype='.urlencode("text/plain");
 
$session = curl_init($url);
 
//HTTP POST
curl_setopt ($session, CURLOPT_POST, true);
 
//POST Body
curl_setopt ($session, CURLOPT_POSTFIELDS, $args);
 
//http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
 
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_RETURNTRANSFER, false);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
 
curl_setopt($session, CURLOPT_VERBOSE, true); //verbose
curl_setopt($session, CURLOPT_HEADER, true); //display headers
 
curl_setopt($session, CURLOPT_USERPWD, $serviceId.':'.$serviceSecret);
 
 
curl_exec($session);
 
curl_close($session);
 
?>
This page was last modified on 21 November 2013, at 10:20.
135 page views in the last 30 days.