Source: noor-sms.phps - download
<?php
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* noor-sms.phps 0.1
* by daif alotaibi (http://daif.net)
* daif@daif.net
*
* Link:
* http://daif.net/script/noor-sms.phps
*
* # Add this to .htaccess
* RewriteEngine On
* RewriteCond %{REQUEST_FILENAME} !-f
* RewriteCond %{REQUEST_FILENAME} !-d
* RewriteRule ^ index.php [QSA,L]
*
*/
$method_arr = [
'GetBalance' =>['sUserName', 'sPassword'],
'GetSenderNames' =>['sUserName', 'sPassword'],
'SendBulkSMS' =>['sUserName', 'sPassword', 'sSender', 'sNumbers', 'sMessage'],
];
$method = str_replace(['/index.php','/noor.php','/noor-sms.php','/', $_SERVER['QUERY_STRING'],'?','v1'], '', $_SERVER['REQUEST_URI']);
$xmldata = file_get_contents("php://input");
$inputs = $_POST + $_GET;
// parsing XML data manually, it is Faster than PHP soap client
if($xmldata){
foreach ($method_arr[$method] as $key => $param) {
preg_match('#<'.$param.'>(.+)</'.$param.'>#i', $xmldata, $match);
if(isset($match[1])) {
$inputs[$param] = $match[1];
}
}
}
if(!isset($method_arr[$method])) {
echo "method is missing";
exit;
}
foreach ($method_arr[$method] as $key => $param) {
if(!isset($inputs[$param])) {
echo "$param is required for /$method method";
exit;
}
}
if($method == 'GetBalance') {
// Fetch your SMS balance from your SMS provider
/*
example:
$url = 'http://SMS-PROVIDER-DOMAIN/GetBalance.php?sUserName='.$inputs['sUserName'].'&sPassword='.$inputs['sPassword'];
$Result = file_get_contents($url);
*/
$Result = 100;
PrintXMLRessponse('GetBalance', $Result);
}
if($method == 'GetSenderNames') {
// Set your sender names
/*
example:
$url = 'http://SMS-PROVIDER-DOMAIN/GetSenderNames.php?sUserName='.$inputs['sUserName'].'&sPassword='.$inputs['sPassword'];
$Result = file_get_contents($url);
*/
// first array element must be 1, and add your sender name
$Result = ['1', 'Sender1', 'Sender2'];
PrintXMLRessponse('GetSenderNames', $Result);
}
if($method == 'SendBulkSMS') {
// Send the message to your SMS provider
/*
example:
$url = 'http://SMS-PROVIDER-DOMAIN/SendBulkSMS.php?sUserName='.$inputs['sUserName'].'&sPassword='.$inputs['sPassword'].'&sMessage='.$inputs['sMessage'].'&sNumbers='.$inputs['sNumbers'].'&sSender='.$inputs['sSender'];
$Result = file_get_contents($url);
*/
$Result = 1;
echo $Result;
}
// Send XML response as soap Envelope
function PrintXMLRessponse($Method, $Result) {
// send XML header and print xml opening tag
header('Content-Type: text/xml; charset: utf-8');
$return = '<?xml version="1.0" encoding="utf-8"?>'."\n";
$return .= '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'."\n";
$return .= '<soap:Body>'."\n";
$return .= '<'.$Method.'Response xmlns="http://tempuri.org/">'."\n";
$return .= '<'.$Method.'Result>';
if(is_array($Result)){
$return .= "\n";
foreach ($Result as $key => $val) {
$return .= '<string>'.$val.'</string>'."\n";
}
} else {
$return .= $Result;
}
$return .= '</'.$Method.'Result>'."\n";
$return .= '</'.$Method.'Response>'."\n";
$return .= '</soap:Body>'."\n";
$return .= '</soap:Envelope>'."\n";
echo $return;
//file_put_contents('debug.log', $return ."\n----------------------------------------------\n", FILE_APPEND);
}
?>