Windows live api get email contact vs email hash - php

I am trying to get email contact from hotmail with php or javascript.
I have read that windows live api return only hash of the email contact, and it is proved by the code example:
http://isdk.dev.live.com/ISDK.aspx
But some web site like facebook can retrieve the plaintext of email contact from hotmail. How it is possible?
Thanks a lot.

Simply change the scope to:
wl.basic,wl.contacts_emails

You can test this code (dont forget to [SECRET API KEY] with your api key) :
<?php
function isEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
function unfucked_base_convert ($numstring, $frombase, $tobase) {
$chars = "0123456789abcdefghijklmnopqrstuvwxyz";
$tostring = substr($chars, 0, $tobase);
$length = strlen($numstring);
$result = '';
for ($i = 0; $i < $length; $i++) {
$number[$i] = strpos($chars, $numstring{$i});
}
do {
$divide = 0;
$newlen = 0;
for ($i = 0; $i < $length; $i++) {
$divide = $divide * $frombase + $number[$i];
if ($divide >= $tobase) {
$number[$newlen++] = (int)($divide / $tobase);
$divide = $divide % $tobase;
} elseif ($newlen > 0) {
$number[$newlen++] = 0;
}
}
$length = $newlen;
$result = $tostring{$divide} . $result;
}
while ($newlen != 0);
return $result;
}
function hexaTo64SignedDecimal($hexa) {
$bin = unfucked_base_convert($hexa, 16, 2);
if(64 === strlen($bin) and 1 == $bin[0]) {
$inv_bin = strtr($bin, '01', '10');
$i = 63;
while (0 !== $i) {
if(0 == $inv_bin[$i]) {
$inv_bin[$i] = 1;
$i = 0;
}
else {
$inv_bin[$i] = 0;
$i–;
}
}
return '-'.unfucked_base_convert($inv_bin, 2, 10);
}
else {
return unfucked_base_convert($hexa, 16, 10);
}
}
function email2nickname($email) {
$output = str_replace(array('.', '-', '_', ',', ':'), ' ', substr($email, 0, strpos($email, '#')));
$output = str_replace(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), '', $output);
$output = ucwords($output);
return $output;
}
function grabLiveContacts($token) {
if(!empty($token)) {
$HOTMAIL_CLIENT_SECRET='[SECRET API KEY]';
parse_str(urldecode($token), $parsedToken);
$token = base64_decode($parsedToken['delt']);
$cryptkey = substr( hash('sha256', 'ENCRYPTION' . $HOTMAIL_CLIENT_SECRET, true), 0, 16);
parse_str(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $cryptkey, substr($token, 16), MCRYPT_MODE_CBC, substr($token, 0, 16)),$result);
$intlid = hexaTo64SignedDecimal($parsedToken['lid']);
$url = 'https://livecontacts.services.live.com/users/#C#'.$intlid.'/rest/livecontacts';
$headers = array(
'Authorization: DelegatedToken dt="'.$parsedToken['delt'].'"'
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
$xml = new SimpleXMLElement($data);
$grab = array();
$grab['user'] = array(
'name'=>trim(strval($xml->Owner->Profiles->Personal->DisplayName)),
'email'=>trim(strval($xml->Owner->WindowsLiveID)), 'token'=>$token
);
$grab['contacts'] = array();
foreach ($xml->Contacts->Contact as $entry) {
$name = trim(strval($entry->Profiles->Personal->DisplayName));
if (isset($entry->Emails->Email->Address)){
$email = trim(strval($entry->Emails->Email->Address));
if(!empty($email)) {
if(empty($name)) {
$name = trim(strval($entry->Profiles->Personal->FirstName));
$name .= ' '.trim(strval($entry->Profiles->Personal->LastName));
$name = trim($name);
}
if(empty($name)) {
$name = trim(strval($entry->Profiles->Personal->NickName));
}
if(empty($name) or isEmail($name)) {
$name = email2nickname($email);
}
$grab['contacts'][] = array('name'=>$name, 'email'=>$email);
}
}
}
return $grab;
}
else return false;
}
if(isset($_POST['ConsentToken'])) {
$grab = grabLiveContacts($_POST['ConsentToken']);
foreach ($grab['contacts'] as $contact){
if (isset($contact['email'])){
echo($contact['email']."</br>");
}
}
}
?>

Related

PHP Script stopping without any error

For some reason i do not know why my script is stopping. It runs for about 20mins and then it stops without retrieving all the records. Im sure something is causing it to stop, but i don't know what. if it were out of memory then i suppose that error message would be thrown, but its not. This project is due next week. We are running this script by a cron job. Please help!
<?php
set_time_limit(0);
ini_set('max_execution_time', 0);
ini_set('memory_limit','4G');
$Num = $_GET['Num'];
$Token = $_GET['Token'];
if(strlen($Num) > 0){
$j = $Num;
$j = 1;
}
else{
$j = 0;
}
$e = 0;
$k = 0;
$g = 1;
$x=0;
$json = '';
$EmailIDs = array();
$leads = new bList();
$leads->listId = 2867;
$AllLeads = array();
$AllLeads = $leads->fields;
if(strlen($Token) > 0){
$NextPage = $Token;
$leads->nextPageToken = $NextPage;
}
RUN();
function RUN(){
global $leads;
global $k;
global $json;
global $Next;
if($k == 0){
AreUnsubscribed($leads->getData());
$k = 1;
$Next = $json[nextPageToken];
$NextPage = $Next;
}
else{
AreUnsubscribed($leads->getData());
$Next = $json[nextPageToken];
if($Next != null){
$NextPage = $Next;
unset($Next);
}
else{
$msg = 'Status = no NextPage' ;
$msg = wordwrap($msg,70);
mail("email#domain.com",'Status = no NextPage - Done',$msg);
}
}
unset($leads,$json,$Next);
}
class bList {
private $host = "Some URL";//CHANGE ME
private $clientId = "###############";//CHANGE ME
private $clientSecret = "###############";//CHANGE ME
public $listId;//id of list to retrieve leads from
public $fields = array("Time","SignUp","createdDate", etc....)
public $batchSize; //max 300 default 300
public $NextPage;
public $nextPageToken; //token returned from previous call for paging
public function getData(){
$url = $this->host . "/rest/v1/list/" . $this->listId . "/leads.json?access_token=" . $this->getToken();
if (isset($this->fields)){
$url = $url . "&fields=" . $this::csvString($this->fields);
}
if (isset($this->batchSize)){
$url = $url . "&batchSize=" . $this->batchSize;
}
if (isset($this->nextPageToken)){
$url = $url . "&nextPageToken=" . $this->nextPageToken;
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept: application/json',));
$response = curl_exec($ch);
return $response;
}
private function getToken(){
$ch = curl_init($this->host . "/identity/oauth/token?grant_type=client_credentials&client_id=" . $this->clientId . "&client_secret=" . $this->clientSecret);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept: application/json',));
$response = json_decode(curl_exec($ch));
curl_close($ch);
$token = $response->access_token;
return $token;
}
private static function csvString($fields){
$csvString = "";
$rr= implode(",",$fields);
$FF = str_replace(' ', '', $rr);
$csvString = $FF;
$csvString = rtrim($csvString,',');
return $csvString;
}
}
function AreUnsubscribed($G){
global $k;
global $AllLeads;
global $EmailIDs;
global $j;
global $e;
global $json;
global $Next;
$json = json_decode($G, true);
if($j == 0){
$EmailIDs[0] = $AllLeads;
$j=1;
}
if($e == 0){
for($n = 0; $n<=300; $n++){
$SORTING = $json['result'][$n];
if($SORTING == null){
break;
}
else{
array_push($EmailIDs, jj($SORTING));
}
unset($SORTING);
}
$e = 1;
$k =1;
RUN();
}
if($k == 1){
Part2($json);
}
unset($EmailIDs, $json, $AllLeads);
}
function Part2($json){
global $EmailIDs;
global $g;
for($n = 0; $n<=300; $n++, $g++){ // 300 records
$SORTING = $json['result'][$n];
if($SORTING == null){
break;
} else{
$EmailIDs[$g] = array_merge((array)$EmailIDs[$g], jj($SORTING));// position
}
unset($SORTING);
}
GG($EmailIDs);
unset($EmailIDs, $json);
}
function jj($kk){
$NewArray = array();
global $AllLeads;
global $e;
if($e == 0){
for($b = 0; $b<270; $b++){
if($kk[$AllLeads[$b]] == null){
array_push($NewArray, $kk[$AllLeads[$b]]);
}
else{
array_push($NewArray, '"'.$kk[$AllLeads[$b]].'"');
}
}
$kk = null;
} else{
for($b = 270; $b<540; $b++){
if($kk[$AllLeads[$b]] == null){
array_push($NewArray, $kk[$AllLeads[$b]]);
}else{
array_push($NewArray, '"'.$kk[$AllLeads[$b]].'"');
}
}
$kk = null;
}
unset($EmailIDs, $json, $kk);
return $NewArray;
unset($NewArray);
}
function GG($val){
$datetime = date('Y-m-d');
global $EmailIDs;
global $x;
global $e;
global $g;
global $Next;
global $j;
global $json;
$handle = fopen("New" . "-Export-" . $datetime . ".csv", "a");
foreach($val as $value){
fputcsv($handle, (array)$value);
}
fclose($handle);
unset($val);
//echo '<pre>';
//$vars = get_defined_vars();
//foreach($vars as $name=>$var)
//{
// echo '<strong>' . $name . '</strong>: ' . strlen(serialize($var)) . '<br/>';
//}
$EmailIDs = array();
$Next = $json[nextPageToken];
if($Next != null){
print_r('{"Number":"'. $j . '", "Token":"' . $Next .'"}');
unset($EmailIDs, $json);
unset($GLOBALS['leads']);
exit;
}else{
print_r('Finished');
}
}
?>

How to use class in php

I have this php class and I don't know how to use it. I know a little bit php but I don't know how to use/call a class.
<?php
Class Checkserver {
static function getString(&$packet){
$str = "";
$n = strlen($packet);
for($i=0;($packet[$i]!=chr(0)) && ($i < $n);++$i)
$str .= $packet[$i];
$packet = substr($packet, strlen($str));
return trim($str);
}
static function getChar(&$packet){
$char = $packet[0];
$packet = substr($packet, 1);
return $char;
}
function serverInfo($server) {
list($ip,$port) = explode(":", $server);
$fp = #fsockopen('udp://'.$ip, $port);
if($fp) {
stream_set_timeout($fp, 2);
fwrite($fp,"\xFF\xFF\xFF\xFFTSource Engine Query\0\r");
$temp = fread($fp, 4);
$status = socket_get_status($fp);
if($status['unread_bytes']>0) {
$temp = fread($fp, $status['unread_bytes']);
$version = ord(self::getChar($temp));
$array = array();
$array['status'] = "1";
if($version == 109) {
$array['ip'] = self::getString($temp);
$temp = substr($temp, 1);
$array['hostname'] = self::getString($temp);
$temp = substr($temp, 1);
$array['mapname'] = self::getString($temp);
$temp = substr($temp, 1);
self::getString($temp);
$temp = substr($temp, 1);
self::getString($temp);
$temp = substr($temp, 1);
$array['players'] = ord(self::getChar($temp));
$array['maxplayers'] = ord(self::getChar($temp));
} elseif($version == 73) {
self::getChar($temp);
$array['hostname'] = self::getString($temp);
$temp = substr($temp, 1);
$array['mapname'] = self::getString($temp);
$temp = substr($temp, 1);
self::getString($temp);
$temp = substr($temp, 1);
self::getString($temp);
$temp = substr($temp, 3);
$array['players'] = ord(self::getChar($temp));
$array['maxplayers'] = ord(self::getChar($temp));
}
} else {
$array['hostname'] = 'Server offline';
$array['mapname'] = '-';
$array['players'] = '0';
$array['maxplayers'] = '0';
$array['status'] = '0';
}
}
return $array;
}
}
?>
I have tried to query a server by writing this in the same file where the class is:
<?php
$newServer = serverInfo();
$date = $newServer->serverInfo("127.0.0.1:27015");
?>
But I can't get it to work. How can I query a server with udp, with this class and print the output ?
serverInfo belongs to the class, so you need to create a new instance of the class before you can use it.
$newServer = new Checkserver();
$date = $newServer->serverInfo("127.0.0.1:27015");

PHP Link Shortener

Zack here.. I've recently run into a spot of trouble with my URL Shortener.. Can you check the below code for errors? Thanks so much!
<?php
$db = new mysqli("localhost","pretzel_main","00WXE5fMWtaVd6Dd","pretzel");
function code($string_length = 3) {
$permissible_characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$char_length = strlen($permissible_characters);
$random = '';
for ($i = 0; $i < $string_length; $i++) {
$random .= $permissible_characters[rand(0, $char_length - 1)];
}
return $random;
}
if (substr($_POST['long'], 0, 7) == http://) {
$url = $_POST['long'];
} elseif (substr($_POST['long'], 0, 8) == https://) {
$url = $_POST['long'];
} else {
$url = "http://".$_POST['long'];
}
$result = $db->prepare("INSERT INTO links VALUES('',?,?)");
$result->bind_param("ss",$url, $title);
$result->execute();
$title = $code();
?>
Good luck, and Thanks in advance!
- Zack
Try this :
<?php
$db = new mysqli("localhost","pretzel_main","00WXE5fMWtaVd6Dd","pretzel");
function code($string_length = 3) {
$permissible_characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$char_length = strlen($permissible_characters);
$random = '';
for ($i = 0; $i < $string_length; $i++) {
$random .= $permissible_characters[rand(0, $char_length - 1)];
}
return $random;
}
if (substr($_POST['long'], 0, 7) == "http://") {
$url = $_POST['long'];
} elseif (substr($_POST['long'], 0, 8) == "https://") {
$url = $_POST['long'];
} else {
$url = "http://".$_POST['long'];
}
$result = $db->prepare("INSERT INTO links VALUES('ss','$url','$title')");
$result->execute();
$title = code(); // no need of $ sign here
?>

PHP - ID generator//not working on linux

I have made an "ID generator" for a website known as xat now this fully works on any up to date windows machine. But I do not understand why when I run it on a linux Debian server I get:
root#vps:/idgen# php get.php
[3:45:42 PM] Connected to MySQL server
[3:45:42 PM] Starting ID Generator With 0 IDs to begin with.
PHP Fatal Error: Call to undefined function curl_init() in /idgen/get.php on line 70
root#vps:/idgen#
(I am new to linux machines. I did some research but till don't understand it :L my code is very long. Its
<?php
set_time_limit(0);
ini_set('display_error', 1);
error_reporting(E_ALL);
date_default_timezone_set('America/New_York');
$idGen = new IDGenerator;
$loop = 1;
while(true)
{
switch(#$argv[1]) {
case '0':
default:
$list = fopen('proxies.txt', 'r');
while(!feof($list))
{
$proxy = fgets($list);
$idGen->generate($proxy);
}
fclose($list);
break;
}
$loop++;
usleep(50000);
$idGen->report('Starting loop #'.$loop);
}
class IDGenerator
{
public $sql = NULL;
public $one = array('1','2','3','4','5','6','7','8','9','0');
public $two = array('11','22','33','44','55','66','77','88','99','00');
public $three = array('111','222','333','444','555','666','777','888','999','000');
public $four = array('0000','1010','1111','1212','1313','1414','1515','1616','1717','1818','1919','2020','2121','2222','2323','2424','2525','2626','2727','2828','2929','3030','3131','3232','3333','3434','3535','3636','3737','3838','3939','4040','4141','4242','4343','4444','4545','4646','4747','4848','4949','5050','5151','5252','5353','5454','5555','5656','5757','5858','5959','6060','6161','6262','6363','6464','6565','6666','6767','6868','6969','7070','7171','7272','7373','7474','7575','7676','7777','7878','7979','8080','8181','8282','8383','8484','8585','8686','8787','8888','8989','9090','9191','9292','9393','9494','9595','9696','9797','9898','9999');
public $five = array('00000','10101','11111','12121','13131','14141','15151','16161','17171','18181','19191','20202','21212','22222','23232','24242','25252','26262','27272','28282','29292','30303','31313','32323','33333','34343','35353','36363','37373','38383','39393','40404','41414','42424','43434','44444','45454','46464','47474','48484','49494','50505','51515','52525','53535','54545','55555','56565','57575','58585','59595','60606','61616','62626','63636','64646','65656','66666','67676','68686','69696','70707','71717','72727','73737','74747','75757','76767','77777','78787','79797','80808','81818','82828','83838','84848','85858','86868','87878','88888','89898','90909','91919','92929','93939','94949','95959','96969','97979','98989','99999');
public $six = array('000000','101010','111111','121212','131313','141414','151515','161616','171717','181818','191919','202020','212121','222222','232323','242424','252525','262626','272727','282828','292929','303030','313131','323232','333333','343434','353535','363636','373737','383838','393939','404040','414141','424242','434343','444444','454545','464646','474747','484848','494949','505050','515151','525252','535353','545454','555555','565656','575757','585858','595959','606060','616161','626262','636363','646464','656565','666666','676767','686868','696969','707070','717171','727272','737373','747474','757575','767676','777777','787878','797979','808080','818181','828282','838383','848484','858585','868686','878787','888888','898989','909090','919191','929292','939393','949494','959595','969696','979797','989898','999999');
public $seven = array('0000000','1010101','1111111','1212121','1313131','1414141','1515151','1616161','1717171','1818181','1919191','2020202','2121212','2222222','2323232','2424242','2525252','2626262','2727272','2828282','2929292','3030303','3131313','3232323','3333333','3434343','3535353','3636363','3737373','3838383','3939393','4040404','4141414','4242424','4343434','4444444','4545454','4646464','4747474','4848484','4949494','5050505','5151515','5252525','5353535','5454545','5555555','5656565','5757575','5858585','5959595','6060606','6161616','6262626','6363636','6464646','6565656','6666666','6767676','6868686','6969696','7070707','7171717','7272727','7373737','7474747','7575757','7676767','7777777','7878787','7979797','8080808','8181818','8282828','8383838','8484848','8585858','8686868','8787878','8888888','8989898','9090909','9191919','9292929','9393939','9494949','9595959','9696969','9797979','9898989','9999999');
public $eight = array('00000000','10101010','11111111','12121212','13131313','14141414','15151515','16161616','17171717','18181818','19191919','20202020','21212121','22222222','23232323','24242424','25252525','26262626','27272727','28282828','29292929','30303030','31313131','32323232','33333333','34343434','35353535','36363636','37373737','38383838','39393939','40404040','41414141','42424242','43434343','44444444','45454545','46464646','47474747','48484848','49494949','50505050','51515151','52525252','53535353','54545454','55555555','56565656','57575757','58585858','59595959','60606060','61616161','62626262','63636363','64646464','65656565','66666666','67676767','68686868','69696969','70707070','71717171','72727272','73737373','74747474','75757575','76767676','77777777','78787878','79797979','80808080','81818181','82828282','83838383','84848484','85858585','86868686','87878787','88888888','89898989','90909090','91919191','92929292','93939393','94949494','95959595','96969696','97979797','98989898','99999999');
public $nine = array('000000000','101010101','111111111','121212121','131313131','141414141','151515151','161616161','171717171','181818181','191919191','202020202','212121212','222222222','232323232','242424242','252525252','262626262','272727272','282828282','292929292','303030303','313131313','323232323','333333333','343434343','353535353','363636363','373737373','383838383','393939393','404040404','414141414','424242424','434343434','444444444','454545454','464646464','474747474','484848484','494949494','505050505','515151515','525252525','535353535','545454545','555555555','565656565','575757575','585858585','595959595','606060606','616161616','626262626','636363636','646464646','656565656','666666666','676767676','686868686','696969696','707070707','717171717','727272727','737373737','747474747','757575757','767676767','777777777','787878787','797979797','808080808','818181818','828282828','838383838','848484848','858585858','868686868','878787878','888888888','898989898','909090909','919191919','929292929','939393939','949494949','959595959','969696969','979797979','989898989','999999999');
public $proxy;
public $cp = array();
public function __construct()
{
include('database.class.php');
$this->sql = new Database($this);
$this->report('Connected to MySQL Server');
$nc = number_format( $this->sql->countRows('ids WHERE sold=0') );
$this->report('Starting ID Generator With '.$nc.' IDs to begin with.');
}
public function generate($ip='111.111.111.111',$port=1, $elapsed=0) {
if( ( $elapsed - time() ) >= 0 && $elapsed != 0) {
//This causes MAJOR terminal/CMD flood.
// $this->report('Proxy: '.$ip.':'.$port.' will be trying again in '.$this->sec2hms($elapsed-time()));
return;
}
$this->cp = array(
'ip' => $ip,
'port' => $port
);
$proxy = $ip.':'.$port;
$tries = 0;
$xData = '';
$timeout = 3;
// echo "Tries -> ";
while($xData=='' && $tries < 3) {
$ch = curl_init(); //curl init :D
curl_setopt($ch, CURLOPT_URL, 'http://xat.com/web_gear/chat/auser3.php?t='.rand(100000000000,1000000000000000000000000000000000)); //url
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
$rdata = $data;
if(#$data{0} == '<') {
return;//Bad Proxy Detected.
}
if(strpos($data, 'Not Found') != FALSE) {
$data = '&UserId=0&k1=0&k2=0';
}
if($data != '&UserId=0&k1=0&k2=0') {
if(strpos($data, '&k2=0') != FALSE) {
$data = '&UserId=0&k1=0&k2=0';
} else {
$xData = $data;
}
} else {
echo $data."\n";
}
$tries++;
}
if($xData=='') {
return;//Dead Proxy
}
if (strlen($data) < 50 && $data) {
$this->check($data);
}
}
public function sec2hms($sec, $padHours = false) {
#$hms = "";
#$days = intval($sec/86400);
if($days > 0 ) {
if($days == 1) {
#$hms .= (($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':#$days.' Day');
} else {
#$hms .= (($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':#$days.' Days');
}
}
#$sec-= ($days*86400);
#$hours = intval(intval($sec) / 3600);
if($hours > 0) {
if($days > 0) { #$s = ', '; }
if($hours == 1) {
#$hms .= #$s.(($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':#$hours.' Hour');
} else {
#$hms .= #$s.(($padHours)?str_pad($hours, 2, "0", STR_PAD_LEFT).':':#$hours.' Hours');
}
}
#$minutes = intval(($sec / 60) % 60);
if($minutes > 0) {
if($hours > 0) { #$d = ', '; }
if($minutes == 1) {
#$hms .= #$d.str_pad($minutes, 2, "0", STR_PAD_LEFT) . ' Minute';
} else {
#$hms .= #$d.str_pad($minutes, 2, "0", STR_PAD_LEFT) . ' Minutes';
}
}
#$seconds = intval($sec % 60);
if($seconds > 0) {
if($minutes > 0) { #$p = ', '; }
if($seconds == 1) {
#$hms .= #$p.str_pad($seconds, 2, "0", STR_PAD_LEFT) . ' Second';
} else {
#$hms .= #$p.str_pad($seconds, 2, "0", STR_PAD_LEFT) . ' Seconds';
}
}
return #$hms;
}
public function report($data) {
$time = date('g:i:s A', time());
echo "[$time] $data\n";
}
public function rwrite($data) {
$auser = $this->idFix($data);
$check = $this->CheckForID($auser['UserId']);
if($check) {
if(str_replace(' ', '', $auser['UserId'])!='') {
$this->report($auser['UserId'].' already exists in the database.');
}
return;
}
$auser['rare'] = true;
$auser['price'] = $this->determinePrice($auser['UserId']);
$auser['reglink'] = 'http://xat.com/web_gear/chat/register.php?UserId='.$auser['UserId'].'&k2='.$auser['k2'].'&mode=1';
$auser['added'] = date('l, F jS Y g:i:s A');
$this->sql->insert('ids', $auser);
$nc = number_format( $this->sql->countRows('ids WHERE sold=0') );
$this->report($auser['UserId'].' added as a rare id, we have '.$nc.' ids now.');
}
public function write($data) {
$auser = $this->idFix($data);
$check = $this->CheckForID($auser['UserId']);
if($check) {
if(str_replace(' ', '', $auser['UserId'])!='') {
$this->report($auser['UserId'].' already exists in the database.');
}
return;
}
$auser['rare'] = false;
$auser['added'] = date('l, F jS Y g:i:s A');
$auser['price'] = $this->determinePrice($auser['UserId']);
$auser['reglink'] = 'http://xat.com/web_gear/chat/register.php?UserId='.$auser['UserId'].'&k2='.$auser['k2'].'&mode=1';
$this->sql->insert('ids', $auser);
$nc = number_format( $this->sql->countRows('ids WHERE sold=0') );
$this->report($auser['UserId'].' added as a normal id, we have '.$nc.' ids now.');
}
public function determinePrice($id='0') {
if($id=='0' || !is_numeric($id)) {
return '0';//0 xats cuz of no id.
}
$price = 100;//Start the bid off at 100 xats, NO FREE IDS.
if ( $this->strposa($id, $this->nine) ) {
$price = $price + 900;// never mind that, make it 1k
} else
if ( $this->strposa($id, $this->eight) ) {
$price = $price + 800;
} else
if ( $this->strposa($id, $this->seven) ) {
$price = $price + 700;
} else
if ( $this->strposa($id, $this->six) ) {
$price = $price + 600;
} else
if ( $this->strposa($id, $this->five) ) {
$price = $price + 500;
} else
if ( $this->strposa($id, $this->four) ) {
$price = $price + 150;
} else
if ( $this->strposa($id, $this->three) ) {
$price = $price + 20;
}
return $price;
}
public function idFix($data='&UserId=0&k1=0&k2=0')
{
if($data=='') { $data = '&UserId=0&k1=0&k2=0'; }
$user = explode('&', $data);
return array(
'UserId'=> str_replace('UserId=', '', #$user[1]),
'k1' => str_replace('k1=', '', #$user[2]),
'k2'=> str_replace('k2=', '', #$user[3])
);
}
public function randomString($chars=32) {
$letters = range('a','z');
$caps = range('A', 'Z');
$numbers = range(0, 9);
$array = array_merge(range('a','z'), array_merge(range('A', 'Z'), range(0,9)));
for($x=0;$x<=100;$x++) {
shuffle($array);//shuffle it up really good =D
}
$i = 0;
$ch = '';
for($index=0; $index<$chars; $index++) {
$ch .= $array[ array_rand($array) ];
}
return $ch;
}
public function CheckForID($id=0)
{
if($id==0) return true;
$check = $this->sql->select('*', 'ids', 'UserId='.$id);
if(!$check)
{
return false;
}
return true;
}
public function check($data='&UserId=0&k1=0&k2=0') {
if($data=='') { $data = '&UserId=0&k1=0&k2=0'; }
$auser = $this->idFix($data);
$this->storage($auser['UserId'], $data);
}
public function storage($id, $data) {
if ($this->strposa($id,$this->nine) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->eight) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->seven) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->six) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->five) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->four) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else
if ($this->strposa($id,$this->three) && strlen($data) < 50 && $data) {
$this->rwrite($data);
return true;
} else {
$this->write($data);
return true;
}
return false;
}
public function reset() {
die('restart me!');
}
public function strposa($haystack, $needles=array(), $offset=1) {
$chr = array();
foreach($needles as $needle) {
$res = strpos($haystack, $needle);
if ($res !== false)
{
$chr[$needle] = $res;
}
}
if(empty($chr))
{
return false;
}
return min($chr);
}
}
?>
The PHP fatal error actually has nothing whatsoever to do with Linux itself, it's the cURL extension that's missing from PHP.
To get back to the Debian side of things, to install the extension, run this in a command line / terminal:
sudo apt-get install php5-curl
Note: Don't EVER copy-paste stuff from the internet into your console. You could be copying hidden text as well and potentially compromise your system. Go ahead and type it.

PHP SMPP delivery report deliver_sm_resp not receiving?

<?php
/*
File : smppclass.php
Implements : SMPPClass()
Description : This class can send messages via the SMPP protocol. Also supports unicode and multi-part messages.
License : GNU Lesser Genercal Public License: http://www.gnu.org/licenses/lgpl.html
Commercial advertisement: Contact info#chimit.nl for SMS connectivity and more elaborate SMPP libraries in PHP and other languages.
*/
/*
The following are the SMPP PDU types that we are using in this class.
Apart from the following 5 PDU types, there are a lot of SMPP directives
that are not implemented in this version.
*/
/*
define(CM_BIND_TRANSMITTER, 0x00000002);
define(CM_SUBMIT_SM, 0x00000004);
define(CM_SUBMIT_MULTI, 0x00000021);
define(CM_UNBIND, 0x00000006);
define(CM_ENQUIRELINK, 0x00000015);
*/
define('generic_nack', 0x80000000);
define('bind_receiver', 0x00000001);
define('bind_receiver_resp', 0x80000001);
define('bind_transmitter', 0x00000002);
define('bind_transmitter_resp', 0x80000002);
define('query_sm', 0x00000003);
define('query_sm_resp', 0x80000003);
define('submit_sm', 0x00000004);
define('submit_sm_resp', 0x80000004);
define('deliver_sm', 0x00000005);
define('deliver_sm_resp', 0x80000005);
define('unbind', 0x00000006);
define('unbind_resp', 0x80000006);
define('replace_sm', 0x00000007);
define('replace_sm_resp', 0x80000007);
define('cancel_sm', 0x00000008);
define('cancel_sm_resp', 0x80000008);
define('bind_transceiver', 0x00000009);
define('bind_transceiver_resp', 0x80000009);
define('outbind', 0x0000000B);
define('enquire_link', 0x00000015);
define('enquire_link_resp', 0x80000015);
define('submit_multi', 0x00000021);
define('submit_multi_resp', 0x80000021);
define('alert_notification', 0x00000102);
define('data_sm', 0x00000103);
define('data_sm_resp', 0x80000103);
class SMPPClass
{
// public members:
/*
Constructor.
Parameters:
none.
Example:
$smpp = new SMPPClass();
*/
function SMPPClass()
{
/* seed random generator */
list($usec, $sec) = explode(' ', microtime());
$seed = (float)$sec + ((float)$usec * 100000);
srand($seed);
/* initialize member variables */
$this->_debug = true;
/* set this to false if you want to suppress debug output. */
$this->_socket = null;
$this->_command_status = 0;
$this->_sequence_number = 1;
$this->_source_address = "";
$this->_message_sequence = rand(1, 255);
$this->_message_id = 0;
$this->interface_version = 0x34;
$this->addr_ton = 1;
$this->addr_npi = 1;
$this->address_range = '';
$this->dlvrSms = array();
}
/*
For SMS gateways that support sender-ID branding, the method
can be used to set the originating address.
Parameters:
$from : Originating address
Example:
$smpp->SetSender("31495595392");
*/
function SetSender($from)
{
if (strlen($from) > 20) {
$this->debug("Error: sender id too long.\n");
return;
}
$this->_source_address = $from;
}
/*
This method initiates an SMPP session.
It is to be called BEFORE using the Send() method.
Parameters:
$host : SMPP ip to connect to.
$port : port # to connect to.
$username : SMPP system ID
$password : SMPP passord.
$system_type : SMPP System type
Returns:
true if successful, otherwise false
Example:
$smpp->Start("smpp.chimit.nl", 2345, "chimit", "my_password", "client01");
*/
function getMessageId(){
return $this->_message_id;
}
function Start($host, $port, $username, $password, $system_type, $type)
{
/*
$testarr = stream_get_transports();
$have_tcp = false;
reset($testarr);
while (list(, $transport) = each($testarr)) {
if ($transport == "tcpp") {
$have_tcp = true;
}
}
if (!$have_tcp) {
$this->debug("No TCP support in this version of PHP.\n");
return false;
}
*/
$this->_socket = #fsockopen($host, $port, $errno, $errstr, 120);
// todo: sanity check on input parameters
if (!$this->_socket) {
$this->debug("Error opening SMPP session.\n");
$this->debug("Error was: $errstr.\n");
return;
}
socket_set_timeout($this->_socket, 120);
//$status = $this->SendBindTransmitter($username, $password, $system_type);
if ($type == 'transmitter') {
$status = $this->SendBindTransmitter($username, $password, $system_type);
} elseif ($type == 'receiver') {
$status = $this->SendBindReceiver($username, $password, $system_type);
}
if ($status != 0) {
$this->debug("Error binding to SMPP server. Invalid credentials?\n");
}
return($status == 0);
}
/*
This method sends out one SMS message.
Parameters:
$to : destination address.
$text : text of message to send.
$unicode: Optional. Indicates if input string is html encoded unicode.
Returns:
true if messages sent successfull, otherwise false.
Example:
$smpp->Send("31649072766", "This is an SMPP Test message.");
$smpp->Send("31648072766", "صباحالخير", true);
*/
function Send($to, $text, $unicode = false)
{
if (strlen($to) > 20) {
$this->debug("to-address too long.\n");
return;
}
if (!$this->_socket) {
$this->debug("Not connected, while trying to send SUBMIT_SM.\n");
// return;
}
$service_type = "";
//default source TON and NPI for international sender
$source_addr_ton = 1;
$source_addr_npi = 1;
$source_addr = $this->_source_address;
if (preg_match('/\D/', $source_addr)) {
//alphanumeric sender
$source_addr_ton = 5;
$source_addr_npi = 0;
} elseif (strlen($source_addr) < 11) {
//national or shortcode sender
$source_addr_ton = 2;
$source_addr_npi = 1;
}
$dest_addr_ton = 1;
$dest_addr_npi = 1;
$destination_addr = $to;
$esm_class = 3;
$protocol_id = 0;
$priority_flag = 0;
$schedule_delivery_time = "";
$validity_period = "";
$registered_delivery_flag = 1;
$replace_if_present_flag = 0;
$data_coding = 241;
$sm_default_msg_id = 0;
if ($unicode) {
$text = mb_convert_encoding($text, "UCS-2BE", "HTML-ENTITIES");
/* UCS-2BE */
$data_coding = 8;
/* UCS2 */
$multi = $this->split_message_unicode($text);
} else {
$multi = $this->split_message($text);
}
$multiple = (count($multi) > 1);
if ($multiple) {
$esm_class += 0x00000040;
}
$result = true;
reset($multi);
while (list(, $part) = each($multi)) {
$short_message = $part;
$sm_length = strlen($short_message);
$status = $this->SendSubmitSM($service_type, $source_addr_ton, $source_addr_npi, $source_addr, $dest_addr_ton, $dest_addr_npi, $destination_addr, $esm_class, $protocol_id, $priority_flag, $schedule_delivery_time, $validity_period, $registered_delivery_flag, $replace_if_present_flag, $data_coding, $sm_default_msg_id, $sm_length, $short_message);
if ($status != 0) {
$this->debug("SMPP server returned error $status.\n");
$result = false;
}
}
return $result;
}
/*
This method ends a SMPP session.
Parameters:
none
Returns:
true if successful, otherwise false
Example: $smpp->End();
*/
function end()
{
if (!$this->_socket) {
// not connected
return;
}
$status = $this->SendUnbind();
if ($status != 0) {
$this->debug("SMPP Server returned error $status.\n");
}
fclose($this->_socket);
$this->_socket = null;
return($status == 0);
}
/*
This method sends an enquire_link PDU to the server and waits for a response.
Parameters:
none
Returns:
true if successfull, otherwise false.
Example: $smpp->TestLink()
*/
function TestLink()
{
$pdu = "";
$status = $this->SendPDU(enquire_link, $pdu);
return($status == 0);
}
function ReadSms()
{
$pdu = "";
$status = true;
$m = 0;
echo date('H:i:s') . "\n";
$status = $this->SendPDU(deliver_sm_resp, $pdu);
return $this->dlvrSms;
}
function QuerySms($message_id, $gsm)
{
$this->dlvrSms = array();
socket_set_timeout($this->_socket, 120);
$pdu = "";
$message_id = $message_id;
$source_addr_ton = 1;
$source_addr_npi = 1;
$source_addr = $gsm;
////$pdu = pack($message_id . chr(0), $source_addr_ton . chr(0), $source_addr_npi . chr(0), $source_addr);
$status = $this->SendPDU(deliver_sm, $pdu);
////$this->ExpectPDU(0);
return $this->dlvrSms;
}
/*
This method sends a single message to a comma separated list of phone numbers.
There is no limit to the number of messages to send.
Parameters:
$tolist : comma seperated list of phone numbers
$text : text of message to send
$unicode: Optional. Indicates if input string is html encoded unicode string.
Returns:
true if messages received by smpp server, otherwise false.
Example:
$smpp->SendMulti("31777110204,31649072766,...,...", "This is an SMPP Test message.");
*/
function SendMulti($tolist, $text, $unicode = false)
{
if (!$this->_socket) {
$this->debug("Not connected, while trying to send SUBMIT_MULTI.\n");
// return;
}
$service_type = '';
//default source TON and NPI for international sender
$source_addr_ton = 1;
$source_addr_npi = 1;
$source_addr = $this->_source_address;
if (preg_match('/\D/', $source_addr)) {
//alphanumeric sender
$source_addr_ton = 5;
$source_addr_npi = 0;
} elseif (strlen($source_addr) < 11) {
//national or shortcode sender
$source_addr_ton = 2;
$source_addr_npi = 1;
}
$dest_addr_ton = 1;
$dest_addr_npi = 1;
$destination_arr = explode(",", $tolist);
$esm_class = 3;
$protocol_id = 0;
$priority_flag = 0;
$schedule_delivery_time = "";
$validity_period = "";
$registered_delivery_flag = 1;
$replace_if_present_flag = 0;
$data_coding = 241;
$sm_default_msg_id = 0;
if ($unicode) {
$text = mb_convert_encoding($text, "UCS-2BE", "HTML-ENTITIES");
$data_coding = 8;
/* UCS2 */
$multi = $this->split_message_unicode($text);
} else {
$multi = $this->split_message($text);
}
$multiple = (count($multi) > 1);
if ($multiple) {
$esm_class += 0x00000040;
}
$result = true;
reset($multi);
while (list(, $part) = each($multi)) {
$short_message = $part;
$sm_length = strlen($short_message);
$status = $this->SendSubmitMulti($service_type, $source_addr_ton, $source_addr_npi, $source_addr, $dest_addr_ton, $dest_addr_npi, $destination_arr, $esm_class, $protocol_id, $priority_flag, $schedule_delivery_time, $validity_period, $registered_delivery_flag, $replace_if_present_flag, $data_coding, $sm_default_msg_id, $sm_length, $short_message);
if ($status != 0) {
$this->debug("SMPP server returned error $status.\n");
$result = false;
}
}
return $result;
}
// private members (not documented):
function ExpectPDU($our_sequence_number)
{
do {
$this->debug("\n\nTrying to read PDU.\n");
if (feof($this->_socket)) {
$this->debug("Socket was closed.!!\n");
return false;
}
$elength = fread($this->_socket, 4);
if (empty($elength)) {
$this->debug("Connection lost.\n");
return false;
}
extract(unpack("Nlength", $elength));
$this->debug("Reading PDU : $length bytes.\n");
$stream = fread($this->_socket, $length - 4);
//$stream = fread($this->_socket, 12);
if (!$stream)
return false;
$this->debug("Stream len : " . strlen($stream) . "\n");
$this->debug("Stream Hex : " . $this->printHex($stream) . "\n");
extract(unpack("Ncommand_id/Ncommand_status/Nsequence_number", $stream));
//$info = stream_get_meta_data($this->_socket);
//$this->debug("stream_get_meta_data id : ".var_export($info,true)."\n");
$command_id &= 0x0fffffff;
$this->debug("Command id : $command_id.\n");
$this->debug("Command status : $command_status.\n");
$this->debug("sequence_number : $sequence_number.\n");
$pdu = substr($stream, 12);
//$pdu=$stream;
switch ($command_id) {
case bind_transmitter:
$this->debug("Got bind_transmitter_RESP.\n");
$spec = "asystem_id";
//extract($this->unpack2($spec, $pdu));
$this->debug("system id : $system_id.\n");
break;
case bind_receiver:
$this->debug("Got bind_receiver_RESP.\n");
$spec = "asystem_id";
extract($this->unpack2($spec, $pdu));
$this->debug("system id : $system_id.\n");
break;
case unbind:
$this->debug("Got unbind_RESP.\n");
break;
case submit_sm:
$this->debug("Got submit_sm_RESP.\n");
if ($command_status == 0) {
$spec = "amessage_id";
extract($this->unpack2($spec, $pdu));
$this->debug("message id : $message_id.\n");
$this->_message_id = $message_id;
}
break;
case submit_multi:
$this->debug("Got submit_multi_RESP.\n");
$spec = "amessage_id/cno_unsuccess/";
extract($this->unpack2($spec, $pdu));
$this->debug("message id : $message_id.\n");
$this->debug("no_unsuccess : $no_unsuccess.\n");
break;
case enquire_link:
$this->debug("GOT enquire_link_RESP.\n");
break;
case deliver_sm;
$this->debug("GOT deliver_sm.\n");
$body = substr($stream, 8, $length);
$this->dlvrSms[] = $this->parseSMS($body, $sequence_number);
$this->SendPDU(deliver_sm_resp, "",$sequence_number);
break;
case deliver_sm_resp;
$this->debug("GOT deliver_sm_resp.\n");
//$body = substr($stream,8, $length);
//$this->dlvrSms[]= $this->parseSMS($body);
break;
case query_sm;
$this->debug("GOT deliver_sm.\n");
$body = substr($stream, 8, $length);
$this->dlvrSms[] = $this->parseSMS($body, $sequence_number);
break;
case generic_nack:
$this->debug("Got generic_nack SMPP pdu.\n");
$spec = "ccommand_length/ccommand_id/ccommand_status/csequence_number";
extract($this->unpack2($spec, $pdu));
$this->debug("command_length generic_nack == " . $command_length . "\n");
$this->debug("command_id generic_nack == " . $command_id . "\n");
$this->debug("command_status generic_nack == " . $command_status . "\n");
$this->debug("command_status generic_nack == " . $command_status . "\n");
break;
default:
$this->debug("Got unknow $command_id SMPP pdu.\n");
}
$this->debug("\nReceived PDU: \n");
for ($i = 0; $i < strlen($stream); $i++) {
if (ord($stream[$i]) < 32)
$this->debug("(" . ord($stream[$i]) . ")");
else
$this->debug($stream[$i]);
}
$this->debug("\n");
} while ($sequence_number != $our_sequence_number);
return $command_status;
}
/**
* #private function
* Parse deliver PDU from SMSC.
* #param $pdu - deliver PDU from SMSC.
* #return parsed PDU as array.
*/
function parseSMS($body, $sequence_number)
{
//check command id
//unpack PDU
$ar = unpack("C*", $body);
//$ar=unpack("C*",$pdu['body']);
$sms = array('service_type' => $this->getString($ar, 6), 'source_addr_ton' => array_shift($ar), 'source_addr_npi' => array_shift($ar), 'source_addr' => $this->getString($ar, 21), 'dest_addr_ton' => array_shift($ar), 'dest_addr_npi' => array_shift($ar), 'destination_addr' => $this->getString($ar, 21), 'esm_class' => array_shift($ar), 'protocol_id' => array_shift($ar), 'priority_flag' => array_shift($ar), 'schedule_delivery_time' => array_shift($ar), 'validity_period' => array_shift($ar), 'registered_delivery' => array_shift($ar), 'replace_if_present_flag' => array_shift($ar), 'data_coding' => array_shift($ar), 'sm_default_msg_id' => array_shift($ar), 'sm_length' => array_shift($ar), 'short_message' => $this->getString($ar, 255));
// $this->_sequence_number=$sequence_number;
//send responce of recieving sms
return $sms;
}
function SendPDU($command_id, $pdu, $sequence_number = null)
{
if ($sequence_number == null) {
$sequence_number = $this->_sequence_number;
}
$length = strlen($pdu) + 16;
$header = pack("NNNN", $length, $command_id, $this->_command_status, $sequence_number);
$this->debug("Sending PDU, len == $length\n");
$this->debug("Sending PDU, header-len == " . strlen($header) . "\n");
$this->debug("Sending PDU, command_id == " . $command_id . "\n");
$this->debug("Sending PDU, sequence number == " . $sequence_number . "\n");
$this->debug("Sending PDU, command status == " . $this->_command_status . "\n");
fwrite($this->_socket, $header . $pdu, $length);
$status = $this->ExpectPDU($sequence_number);
$this->_sequence_number = $this->_sequence_number + 1;
return $status;
}
function SendBindTransmitter($system_id, $smpppassword, $system_type)
{
$system_id = $system_id . chr(0);
$system_id_len = strlen($system_id);
$smpppassword = $smpppassword . chr(0);
$smpppassword_len = strlen($smpppassword);
$system_type = $system_type . chr(0);
$system_type_len = strlen($system_type);
$pdu = pack("a{$system_id_len}a{$smpppassword_len}a{$system_type_len}CCCa1", $system_id, $smpppassword, $system_type, $this->interface_version, $this->addr_ton, $this->addr_npi, $this->address_range);
$this->debug("Bind Transmitter PDU: ");
for ($i = 0; $i < strlen($pdu); $i++) {
$this->debug(ord($pdu[$i]) . " ");
}
$this->debug("\n");
$status = $this->SendPDU(bind_transmitter, $pdu);
return $status;
}
function SendBindReceiver($system_id, $smpppassword, $system_type)
{
$system_id = $system_id . chr(0);
$system_id_len = strlen($system_id);
$smpppassword = $smpppassword . chr(0);
$smpppassword_len = strlen($smpppassword);
$system_type = $system_type . chr(0);
$system_type_len = strlen($system_type);
$pdu = pack("a{$system_id_len}a{$smpppassword_len}a{$system_type_len}CCCa1" . (strlen($this->address_range) + 1), $system_id, $smpppassword, $system_type, $this->interface_version, $this->addr_ton, $this->addr_npi, $this->address_range);
$this->debug("Bind Receiver PDU: ");
for ($i = 0; $i < strlen($pdu); $i++) {
$this->debug(ord($pdu[$i]) . " ");
}
$this->debug("\n");
$status = $this->SendPDU(bind_transceiver, $pdu);
return $status;
}
function SendUnbind()
{
$pdu = "";
$status = $this->SendPDU(unbind, $pdu);
return $status;
}
function SendSubmitSM($service_type, $source_addr_ton, $source_addr_npi, $source_addr, $dest_addr_ton, $dest_addr_npi, $destination_addr, $esm_class, $protocol_id, $priority_flag, $schedule_delivery_time, $validity_period, $registered_delivery_flag, $replace_if_present_flag, $data_coding, $sm_default_msg_id, $sm_length, $short_message)
{
$service_type = $service_type . chr(0);
$service_type_len = strlen($service_type);
$source_addr = $source_addr . chr(0);
$source_addr_len = strlen($source_addr);
$destination_addr = $destination_addr . chr(0);
$destination_addr_len = strlen($destination_addr);
$schedule_delivery_time = $schedule_delivery_time . chr(0);
$schedule_delivery_time_len = strlen($schedule_delivery_time);
$validity_period = $validity_period . chr(0);
$validity_period_len = strlen($validity_period);
// $short_message = $short_message . chr(0);
$message_len = $sm_length;
$spec = "a{$service_type_len}cca{$source_addr_len}cca{$destination_addr_len}ccca{$schedule_delivery_time_len}a{$validity_period_len}ccccca{$message_len}";
$this->debug("PDU spec: $spec.\n");
$pdu = pack($spec, $service_type, $source_addr_ton, $source_addr_npi, $source_addr, $dest_addr_ton, $dest_addr_npi, $destination_addr, $esm_class, $protocol_id, $priority_flag, $schedule_delivery_time, $validity_period, $registered_delivery_flag, $replace_if_present_flag, $data_coding, $sm_default_msg_id, $sm_length, $short_message);
$status = $this->SendPDU(submit_sm, $pdu);
return $status;
}
function SendSubmitMulti($service_type, $source_addr_ton, $source_addr_npi, $source_addr, $dest_addr_ton, $dest_addr_npi, $destination_arr, $esm_class, $protocol_id, $priority_flag, $schedule_delivery_time, $validity_period, $registered_delivery_flag, $replace_if_present_flag, $data_coding, $sm_default_msg_id, $sm_length, $short_message)
{
$service_type = $service_type . chr(0);
$service_type_len = strlen($service_type);
$source_addr = $source_addr . chr(0);
$source_addr_len = strlen($source_addr);
$number_destinations = count($destination_arr);
$dest_flag = 1;
$spec = "a{$service_type_len}cca{$source_addr_len}c";
$pdu = pack($spec, $service_type, $source_addr_ton, $source_addr_npi, $source_addr, $number_destinations);
$dest_flag = 1;
reset($destination_arr);
while (list(, $destination_addr) = each($destination_arr)) {
$destination_addr .= chr(0);
$dest_len = strlen($destination_addr);
$spec = "ccca{$dest_len}";
$pdu .= pack($spec, $dest_flag, $dest_addr_ton, $dest_addr_npi, $destination_addr);
}
$schedule_delivery_time = $schedule_delivery_time . chr(0);
$schedule_delivery_time_len = strlen($schedule_delivery_time);
$validity_period = $validity_period . chr(0);
$validity_period_len = strlen($validity_period);
$message_len = $sm_length;
$spec = "ccca{$schedule_delivery_time_len}a{$validity_period_len}ccccca{$message_len}";
$pdu .= pack($spec, $esm_class, $protocol_id, $priority_flag, $schedule_delivery_time, $validity_period, $registered_delivery_flag, $replace_if_present_flag, $data_coding, $sm_default_msg_id, $sm_length, $short_message);
$this->debug("\nMulti PDU: ");
for ($i = 0; $i < strlen($pdu); $i++) {
if (ord($pdu[$i]) < 32)
$this->debug(".");
else
$this->debug($pdu[$i]);
}
$this->debug("\n");
//$this->_command_status='';
$status = $this->SendPDU(submit_multi, $pdu);
return $status;
}
function split_message($text)
{
$this->debug("\n\nIn split_message.\n");
$max_len = 153;
$res = array();
if (strlen($text) <= 160) {
$this->debug("One message: " . strlen($text) . "\n");
$res[] = $text;
return $res;
}
$pos = 0;
$msg_sequence = $this->_message_sequence++;
$num_messages = ceil(strlen($text) / $max_len);
$part_no = 1;
while ($pos < strlen($text)) {
$ttext = substr($text, $pos, $max_len);
$pos += strlen($ttext);
$udh = pack("cccccc", 5, 0, 3, $msg_sequence, $num_messages, $part_no);
$part_no++;
$res[] = $udh . $ttext;
$this->debug("Split: UDH = ");
for ($i = 0; $i < strlen($udh); $i++) {
$this->debug(ord($udh[$i]) . " ");
}
$this->debug("\n");
$this->debug("Split: $ttext.\n");
}
return $res;
}
function split_message_unicode($text)
{
$this->debug("\n\nIn split_message.\n");
$max_len = 134;
$res = array();
if (mb_strlen($text) <= 140) {
$this->debug("One message: " . mb_strlen($text) . "\n");
$res[] = $text;
return $res;
}
$pos = 0;
$msg_sequence = $this->_message_sequence++;
$num_messages = ceil(mb_strlen($text) / $max_len);
$part_no = 1;
while ($pos < mb_strlen($text)) {
$ttext = mb_substr($text, $pos, $max_len);
$pos += mb_strlen($ttext);
$udh = pack("cccccc", 5, 0, 3, $msg_sequence, $num_messages, $part_no);
$part_no++;
$res[] = $udh . $ttext;
$this->debug("Split: UDH = ");
for ($i = 0; $i < strlen($udh); $i++) {
$this->debug(ord($udh[$i]) . " ");
}
$this->debug("\n");
$this->debug("Split: $ttext.\n");
}
return $res;
}
function unpack2($spec, $data)
{
$res = array();
$specs = explode("/", $spec);
$pos = 0;
reset($specs);
while (list(, $sp) = each($specs)) {
$subject = substr($data, $pos);
$type = substr($sp, 0, 1);
$var = substr($sp, 1);
switch ($type) {
case "N":
$temp = unpack("Ntemp2", $subject);
$res[$var] = $temp["temp2"];
$pos += 4;
break;
case "c":
$temp = unpack("ctemp2", $subject);
$res[$var] = $temp["temp2"];
$pos += 1;
break;
case "a":
$pos2 = strpos($subject, chr(0)) + 1;
$temp = unpack("a{$pos2}temp2", $subject);
$res[$var] = $temp["temp2"];
$pos += $pos2;
break;
}
}
return $res;
}
/**
* #private function
* Reads C style zero padded string from the char array.
* #param $ar - input array
* #param $maxlen - maximum length to read.
* #return readed string.
*/
function getString(&$ar, $maxlen = 255)
{
$s = "";
$i = 0;
do {
$c = array_shift($ar);
if ($c != 0)
$s .= chr($c);
$i++;
} while ($i < $maxlen && $c != 0);
return $s;
}
/**
* #private function
* Prints the binary string as hex bytes.
* #param $maxlen - maximum length to read.
*/
function printHex($pdu)
{
$a = "";
$ar = unpack("C*", $pdu);
foreach ($ar as $v) {
$s = dechex($v);
if (strlen($s) < 2)
$s = "0$s";
$a .= "$s ";
}
return $a . "\n";
}
function debug($str)
{
if ($this->_debug) {
echo $str;
}
}
}
?>
Deliver_sm and Deliver_sm_resp is not working, When i request for delivery report the server is sending me deliver_sm but deliver_sm_resp is not working.
Any body know how to receive delivery report of specific sms, although i have message id of every sms.

Categories