Art of Mobile
Home GeneralHardwareJavaMMSPerlPHPSMSWAP

Archive for the ‘WAP’ Category

How to create a WAP push service in Perl

Posted in Perl, WAP by artofmobile

To push a service (or commonly a URL) to a mobile phone from a Push Initiator (PI), normally a web server, WAP defines a protocol to do so in Push Access Protocol (PAP).

This Push Message can be sent either as Service Indication (SI) or Service Loading (SL) kind of service push.

SI signals an event on which the client should get informed when a message is pushed to the mobile device. The user can base of the text message to decide whether to retrieve it or not. SL push service was specified so that a PI can push a URL to the mobile device which is automatically loaded and executed.

The following covers Perl code to do both SI and SL service. The Perl code is the same, you just need to load different raw file to achieve the different kind of Push Message.

#!/usr/local/bin/perl

use LWP::UserAgent;

my $ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");

my $req = HTTP::Request->new(
   POST => 'http://127.0.0.1:9004/pushservice');

$req->content_type('multipart/related; type="application/xml"; '.
   'boundary="boundary0123456789"');

open(FILE, "raw") or die "$!";
my $content=<FILE>;
close FILE;

$req->content($content);
print "----Header-----\\n";
$hash=$req->headers;
# print $hash->as_string;
print "\\n----Body-------\\n";
print $req->content;

my $res = $ua->request($req);
if ($res) {
   # Check the outcome of the response
   if ($res->is_success) {
      my $ret= $res->content;
      print "$ret\\n";
   } else {
      print "\\n".$res->status_line, "\\n";
      print $res->content;
      print "\\n";
   }
} else {
   print "No pointer assigned\\n";
}

print "\\n\\n";

Input file for SI push (raw_si):

--boundary0123456789
Content-Type: application/xml

<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 1.0//EN"
   "http://www.wapforum.org/DTD/pap_1.0.dtd">
<pap>
<push-message push-id="ABC_1092049461_push">
<address address-value="WAPPUSH=6591234567/TYPE=user@mytelco.artofmobile.com"/>
<quality-of-service delivery-method="unconfirmed" priority="medium" network="gsm"
   network-required="false" bearer="sms" bearer-required="false"/>
</push-message>
</pap>

--boundary0123456789
Content-Type: text/vnd.wap.si

<?xml version="1.0"?>
<!DOCTYPE si PUBLIC "-//WAPFORUM//DTD SI 1.0//EN"
   "http://www.wapforum.org/DTD/si.dtd">
<si>
<indication si-id="61412077449" href="http://www.artofmobile.com/">
Welcome to Art of Mobile!
</indication>
</si>
--boundary0123456789--

Input file for SL push (raw_sl):

--boundary0123456789
Content-Type: application/xml

<?xml version="1.0"?>
<!DOCTYPE pap PUBLIC "-//WAPFORUM//DTD PAP 1.0//EN"
   "http://www.wapforum.org/DTD/pap_1.0.dtd">
<pap>
<push-message push-id="ABC_1092049461_push">
<address address-value="WAPPUSH=6591234567/TYPE=user@mytelco.artofmobile.com"/>
<quality-of-service delivery-method="unconfirmed" priority="medium" network="gsm"
    network-required="false" bearer="sms" bearer-required="false"/>
</push-message>
</pap>

--boundary0123456789
Content-Type: text/vnd.wap.sl

<?xml version="1.0"?>
<!DOCTYPE sl PUBLIC "-//WAPFORUM//DTD SL 1.0//EN"
   "http://www.wapforum.org/DTD/sl.dtd">
<sl href="http://www.artofmobile.com/" action="execute-high" />
--boundary0123456789--

Detect WAP browser and redirect to different url in PHP

Posted in PHP, WAP by artofmobile

Do you want to have the same url for your Web and Wap broswer? The following is the code to do so in PHP:

<?php

$htmlredirect = "http://www.artofmobile.com/index.html";
$wmlredirect = "http://www.artofmobile.com/index.wml";

$br='html';

if(preg_match("/wap/i",$HTTP_ACCEPT)) {

   $br = "wml";
}

if($br == "wml") {
   header("302 Moved Temporarily");
   header("Location: ".$wmlredirect);
   exit;
}

header("302 Moved Temporarily");
header("Location: ".$htmlredirect);

?>
Powered by WordPress. Theme created by Art Of Mobile