Example #1
0
 private function resolveJsonStream($message, $addresses)
 {
     $messageDetails = array("message" => $message, "destinationAddresses" => $addresses);
     // Comment from this if app is not working
     //        if (isset($this->sourceAddress)) {
     //            $messageDetails = array_merge($messageDetails, array("sourceAddress" => $this->sourceAddress));
     //        }
     //
     //        if (isset($this->deliveryStatusRequest)) {
     //            $messageDetails = array_merge($messageDetails, array("deliveryStatusRequest" => $this->deliveryStatusRequest));
     //        }
     //
     //        if (isset($this->binaryHeader)) {
     //            $messageDetails = array_merge($messageDetails, array("binaryHeader" => $this->binaryHeader));
     //        }
     //
     //        if (isset($this->version)) {
     //            $messageDetails = array_merge($messageDetails, array("version" => $this->version));
     //        }
     //
     //        if (isset($this->encoding)) {
     //            $messageDetails = array_merge($messageDetails, array("encoding" => $this->encoding));
     //        }
     // Comment End
     $applicationDetails = array('applicationId' => $this->applicationId, 'password' => $this->password);
     $jsonStream = json_encode($applicationDetails + $messageDetails);
     $log = new Logger();
     $log->WriteLog($jsonStream);
     return $jsonStream;
 }
Example #2
0
        $subsret = subcribe($SUBSCRIPTION_SERVER_URL, $APP_ID, $PASSWORD, $address);
        //$log->WriteLog($subsret);
        // subscribe end
        // Code for LBS
        $lbsClient = new LbsClient();
        $lbsResponse = new LbsResponse($lbsClient->getResponse($request));
        $lbsResponse->setTimeStamp(getModifiedTimeStamp($lbsResponse->getTimeStamp()));
        //Changing the timestamp format. Ex: from '2013-03-15T17:25:51+05:30' to '2013-03-15 17:25:51'
        // LBS end
        $sessionArrary = array("sessionid" => $sessionId, "tel" => $address, "menu" => "main", "pg" => "", "others" => "", "longitude" => $lbsResponse->getLongitude(), "latitude" => $lbsResponse->getLatitude());
        //  longitude   latitude
        $operations->setSessions($sessionArrary);
        $sender->ussd($sessionId, $responseMsg, $address);
        //        $sender->ussd($sessionId, $resp, $address);
    } catch (Exception $e) {
        $log->WriteLog($e->getMessage());
        $sender->ussd($sessionId, 'Sorry error occured try again', $address);
    }
} else {
    $flag = 0;
    $sessiondetails = $operations->getSession($sessionId);
    $cuch_menu = $sessiondetails['menu'];
    $operations->session_id = $sessiondetails['sessionsid'];
    switch ($cuch_menu) {
        case "main":
            // Following is the main menu
            if ($receiver->getMessage() == "99") {
                $sender->ussd($sessionId, 'Thank you using our service !', $address, 'mt-fin');
            } elseif ($receiver->getMessage() == "") {
                $operations->session_menu = "main";
                $operations->saveSesssion();
Example #3
0
// Licence : MIT License
// http://opensource.org/licenses/MIT
// ==========================================
ini_set('error_log', 'sms-app-error.log');
require_once 'lib/Log.php';
require_once 'lib/SMSReceiver.php';
require_once 'lib/SMSSender.php';
define('SERVER_URL', 'http://localhost:7000/sms/send');
define('APP_ID', 'APPID');
define('APP_PASSWORD', 'password');
$logger = new Logger();
try {
    // Creating a receiver and intialze it with the incomming data
    $receiver = new SMSReceiver(file_get_contents('php://input'));
    //Creating a sender
    $sender = new SMSSender(SERVER_URL, APP_ID, APP_PASSWORD);
    $message = $receiver->getMessage();
    // Get the message sent to the app
    $address = $receiver->getAddress();
    // Get the phone no from which the message was sent
    $logger->WriteLog($receiver->getAddress());
    if ($message == 'broadcast') {
        // Send a broadcast message to all the subcribed users
        $response = $sender->broadcast("This is a broadcast message to all the subcribers of the application");
    } else {
        // Send a SMS to a particular user
        $response = $sender->sms('This message is sent only to one user', $address);
    }
} catch (SMSServiceException $e) {
    $logger->WriteLog($e->getErrorCode() . ' ' . $e->getErrorMessage());
}
Example #4
0
$production = false;
if ($production == false) {
    $CASS_SERVER_URL = "http://localhost:7000/caas/direct/debit";
    $SMS_SERVER_URL = "http://localhost:7000/sms/send";
} else {
    $CASS_SERVER_URL = 'https://api.dialog.lk/caas/direct/debit';
    $SMS_SERVER_URL = "https://api.dialog.lk/sms/send";
}
$logger = new Logger();
try {
    $receiver = new SMSReceiver();
    $message = $receiver->getMessage();
    // Get the message sent to the app
    $address = $receiver->getAddress();
    // Get the phone no from which the message was sent
    list($keyword, $amount) = explode(" ", $message);
    // Setting up CAAS
    $cass = new DirectDebitSender($CASS_SERVER_URL, $APP_ID, $PASSWORD);
    $sender = new SmsSender($SMS_SERVER_URL, $APP_ID, $PASSWORD);
    try {
        if (isset($amount)) {
            $cass->cass($EXTERNAL_TRX_ID, $address, $amount);
            $sender->sms("Thank you for your generosity, You Have made a donation for " . $amount . " Rupees", $address);
        }
    } catch (CassException $ex) {
        $logger->WriteLog($ex);
        $sender->sms("You do not have sufficient credit to make this donation", $address);
    }
} catch (Exception $e) {
    $logger->WriteLog($e);
}
Example #5
0
    $logger->WriteLog($receiver->getAddress());
    // Code for LBS
    $request = new LbsRequest($LBS_SERVER_URL);
    $request->setAppId(APP_ID);
    $request->setAppPassword(APP_PASSWORD);
    $request->setSubscriberId($address);
    $request->setServiceType($SERVICE_TYPE);
    $request->setFreshness($FRESHNESS);
    $request->setHorizontalAccuracy($HORIZONTAL_ACCURACY);
    $request->setResponseTime($RESPONSE_TIME);
    // LBS end
    list($keyword, $id) = explode(" ", $message);
    if (isset($id)) {
        // Code for subscribe
        subcribe($SUBSCRIPTION_SERVER_URL, APP_ID, APP_PASSWORD, $address);
        // subscribe end
        //
        // Code for LBS
        $lbsClient = new LbsClient();
        $lbsResponse = new LbsResponse($lbsClient->getResponse($request));
        $lbsResponse->setTimeStamp(getModifiedTimeStamp($lbsResponse->getTimeStamp()));
        //Changing the timestamp format. Ex: from '2013-03-15T17:25:51+05:30' to '2013-03-15 17:25:51'
        // LBS end
        //DB save
        $saveBin = "INSERT INTO red_firediv(div_id,tel_no,type,latitude,longitude,alt_time) VALUES('" . $id . "','" . $address . "','fire','" . $lbsResponse->getLatitude() . "','" . $lbsResponse->getLongitude() . "','" . $lbsResponse->getTimeStamp() . "')";
        $ccc = mysqli_query($connection, $saveBin);
        if (mysqli_error($connection)) {
            $logger->WriteLog(mysqli_error($connection));
        }
        //http post request
    } else {
    }
} catch (SMSServiceException $e) {
    $logger->WriteLog($e->getErrorCode() . ' ' . $e->getErrorMessage());