Created
May 3, 2012 20:59
-
-
Save t2-support-gists/2589421 to your computer and use it in GitHub Desktop.
MMS PHP app3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AT&T API Samples - MMS app3 | |
----------------------------- | |
This file describes how to set up, configure and run the php versions of the AT&T HTML5 Program sample applications. | |
It covers all steps required to register the application on DevConnect and, based on the generated API keys and secrets, | |
create and run one's own full-fledged sample applications. | |
1. Configuration | |
2. Installation | |
3. Parameters | |
1. Configuration | |
Configuration consists of a few steps necessary to get an application registered on DevConnect with the proper services and | |
endpoints, depending on the type of client-side application (autonomous/non-autonomous). | |
To register an application, go to https://devconnect-api.att.com/ and login with your valid username and password. | |
Next, choose "My Page" from the bar at the top of the page and click the "Setup a New Application" button. | |
Fill in the form, in particular all fields marked as "required". | |
Be careful while filling in the "OAuth Redirect URL" field. It should contain the URL that the oAuth provider will redirect | |
users to when he/she successfully authenticates and authorizes your application. | |
Having your application registered, you will get back an important pair of data: an API key and Secret key. They are | |
necessary to get your applications working with the AT&T HTML5 APIs. See 'Adjusting parameters' below to learn how to use | |
these keys. | |
Initially your newly registered application is restricted to the "Sandbox" environment only. To move it to production, | |
you may promote it by clicking the "Promote to production" button. Notice that you will get a different API key and secret, | |
so these values in your application should be adjusted accordingly. | |
Depending on the kind of authentication used, an application may be based on either the Autonomous Client or the Web-Server | |
Client OAuth flow (see https://devconnect-api.att.com/docs/oauth20/autonomous-client-application-oauth-flow or | |
https://devconnect-api.att.com/docs/oauth20/web-server-client-application-oauth-flow respectively). | |
2. Installation | |
Requirements: | |
Apache web server | |
PHP 5.2+ | |
Apache and PHP configured, on most Linux systems if installed using packages this will be done automatically. | |
Installation: | |
Copy the sample application folder to Apache web root folder, for example /var/www/html. | |
Allow for apache user to read/write to MoMessages subfolder. | |
3. Parameters | |
Each application contains a config.php file. It holds the following configurable parameters and defaults | |
$short_code : Short code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Licensed by AT&T under 'Software Development Kit Tools Agreement.' September 2011 | |
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION: http://developer.att.com/sdk_agreement/ | |
Copyright 2011 AT&T Intellectual Property. All rights reserved. http://developer.att.com | |
For more information contact [email protected] | |
--> | |
<?php | |
$short_code = ""; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file_cont = file_get_contents( "/tmp/sample MMS delivery.txt"); | |
//echo $file_cont; | |
$boundaries_parts = explode("--Nokia-mm-messageHandler-BoUnDaRy",$file_cont); | |
echo "-------------------------------------------------\n\n\n"; | |
print_r( $boundaries_parts ); | |
echo "##################################################\n\n\n"; | |
foreach ( $boundaries_parts as $part ){ | |
echo "##################################################\n\n\n"; | |
$mm_part = explode("\n\n", $part ); | |
// print_r($mm_part); | |
preg_match("@Filename=([^;^\n]+)@i",$mm_part[0],$matches); | |
$filename = $matches[1]; | |
preg_match("@Content-Type:([^;^\n]+)@i",$mm_part[0],$matches); | |
$content_type = $matches[1]; | |
if ( $filename == null ){ | |
preg_match("@Content-ID: ([^;^\n]+)@i",$mm_part[0],$matches); | |
$filename = $matches[1]; | |
} | |
echo " #########".$filename." ##########".$content_type." \n\n"; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Licensed by AT&T under 'Software Development Kit Tools Agreement.' September 2011 | |
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION: http://developer.att.com/sdk_agreement/ | |
Copyright 2011 AT&T Intellectual Property. All rights reserved. http://developer.att.com | |
For more information contact [email protected] | |
--> | |
<?php | |
header("Content-Type: text/html; charset=ISO-8859-1"); | |
include("config.php"); | |
?> | |
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head> | |
<title>AT&T Sample MMS Application 3 - MMS Gallery Application</title> | |
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type"> | |
<link rel="stylesheet" type="text/css" href="common.css"/ > | |
<body> | |
<div id="container"> | |
<!-- open HEADER --><div id="header"> | |
<div> | |
<div id="hcRight"> | |
<?php echo date("D M j G:i:s T Y"); ?> | |
</div> | |
<div id="hcLeft">Server Time:</div> | |
</div> | |
<div> | |
<div id="hcRight"><script language="JavaScript" type="text/javascript"> | |
var myDate = new Date(); | |
document.write(myDate); | |
</script></div> | |
<div id="hcLeft">Client Time:</div> | |
</div> | |
<div> | |
<div id="hcRight"><script language="JavaScript" type="text/javascript"> | |
document.write("" + navigator.userAgent); | |
</script></div> | |
<div id="hcLeft">User Agent:</div> | |
</div> | |
<br clear="all" /> | |
</div><!-- close HEADER --> | |
<div id="wrapper"> | |
<div id="content"> | |
<h1>AT&T Sample MMS Application 3 - MMS Gallery Application</h1> | |
<h2>Feature 1: Web gallery of MMS photos sent to short code</h2> | |
</div> | |
</div> | |
<br /> | |
<br /> | |
<p>Photos sent to short code <?php echo $short_code; ?>:</p> | |
<div id="gallerywrapper"> | |
<?php | |
$path_is = __FILE__; | |
$folder = dirname($path_is); | |
$folder = $folder. "/MoMessages"; | |
if(!is_dir($folder)) | |
{ | |
echo "MoMessages folder is missing ( $folder )"; | |
exit(); | |
} | |
$db_filename = $folder . "/". "mmslistner.db"; | |
$messages = unserialize(file_get_contents($db_filename)); | |
foreach ( $messages as $message ){ | |
$message_txt = file_get_contents( $folder.'/'.$message["text"]); | |
$message_image = "MoMessages/".$message['image']; | |
$address = $message['address']; | |
?> | |
<div id="gallery"><img src="<?php echo $message_image ; ?>" width="150" border="0" /><br /><strong>Sent from:</strong> <?php echo $address; ?> <br /><strong>On:</strong> <?php echo $message['date']; ?><div><?php echo $message_txt; ?></div></div> | |
<?php | |
} | |
?> | |
</div> | |
<br clear="all" /> | |
<div id="footer"> | |
<div style="float: right; width: 20%; font-size: 9px; text-align: right">Powered by AT&T Virtual Mobile</div> | |
<p>© 2011 AT&T Intellectual Property. All rights reserved. <a href="http://developer.att.com/" target="_blank">http://developer.att.com</a> | |
<br> | |
The Application hosted on this site are working examples intended to be used for reference in creating products to consume AT&T Services and not meant to be used as part of your product. The data in these pages is for test purposes only and intended only for use as a reference in how the services perform. | |
<br> | |
For download of tools and documentation, please go to <a href="https://devconnect-api.att.com/" target="_blank">https://devconnect-api.att.com</a> | |
<br> | |
For more information contact <a href="mailto:[email protected]">[email protected]</a> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Licensed by AT&T under 'Software Development Kit Tools Agreement.' September 2011 | |
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION: http://developer.att.com/sdk_agreement/ | |
Copyright 2011 AT&T Intellectual Property. All rights reserved. http://developer.att.com | |
For more information contact [email protected] | |
--> | |
<?php | |
$path_is = __FILE__; | |
$folder = dirname($path_is); | |
$folder = $folder. "/MoMessages"; | |
if(!is_dir($folder)) | |
{ | |
echo "MoMessages folder is missing"; | |
exit(); | |
} | |
$db_filename = $folder . "/". "mmslistner.db"; | |
$post_body = file_get_contents('php://input'); | |
//$post_body = file_get_contents( "full_message3.mm"); | |
if ( file_exists( $db_filename) ){ | |
$messages = unserialize(file_get_contents($db_filename)); | |
}else{ | |
$messages = null; | |
} | |
$local_post_body = $post_body; | |
$ini = strpos($local_post_body,"<SenderAddress>tel:+"); | |
if ($ini == 0 ) | |
{ | |
exit(); | |
}else{ | |
preg_match("@<SenderAddress>tel:(.*)</SenderAddress>@i",$local_post_body,$matches); | |
$message["address"] = $matches[1]; | |
preg_match("@<subject>(.*)</subject>@i",$local_post_body,$matches); | |
$message["subject"] = $matches[1]; | |
$message["date"]= date("D M j G:i:s T Y"); | |
} | |
if( $messages !=null ){ | |
$last=end($messages); | |
$message['id']=$last['id']+1; | |
}else{ | |
$message['id'] = 0; | |
} | |
mkdir($folder.'/'.$message['id']); | |
$boundaries_parts = explode("--Nokia-mm-messageHandler-BoUnDaRy",$local_post_body); | |
foreach ( $boundaries_parts as $mime_part ){ | |
if ( preg_match( "@BASE64@",$mime_part )){ | |
$mm_part = explode("BASE64", $mime_part ); | |
$filename = null; | |
$content_type =null; | |
if ( preg_match("@Filename=([^;^\n]+)@i",$mm_part[0],$matches)){ | |
$filename = trim($matches[1]); | |
} | |
if ( preg_match("@Content-Type:([^;^\n]+)@i",$mm_part[0],$matches)){ | |
$content_type = trim($matches[1]); | |
} | |
if ( $content_type != null ){ | |
if ( $filename == null ){ | |
preg_match("@Content-ID: ([^;^\n]+)@i",$mm_part[0],$matches); | |
$filename = trim($matches[1]); | |
} | |
if ( $filename != null ){ | |
//Save file | |
$base64_data = base64_decode($mm_part[1]); | |
$full_filename = $folder.'/'.$message['id'].'/'.$filename; | |
if (!$file_handle = fopen($full_filename, 'w')) { | |
echo "Cannot open file ($full_filename)"; | |
exit; | |
} | |
fwrite($file_handle, $base64_data); | |
fclose($file_handle); | |
if ( preg_match( "@image@",$content_type ) && ( !isset($message["image"]))){ | |
$message["image"]=$message['id'].'/'.$filename; | |
} | |
if ( preg_match( "@text@",$content_type ) && ( !isset($message["text"]))){ | |
$message["text"]=$message['id'].'/'.$filename; | |
} | |
} | |
} | |
} | |
} | |
if( $messages !=null ){ | |
$messages_stored=array_push($messages,$message); | |
if ( $messages_stored > 10 ){ | |
$old_message = array_shift($messages); | |
// remove old message folder | |
} | |
}else{ | |
$messages = array($message); | |
} | |
$fp = fopen($db_filename, 'w+') or die("I could not open $filename."); | |
fwrite($fp, serialize($messages)); | |
fclose($fp); | |
//print_r($messages); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment