Ignore:
Timestamp:
Feb 10, 2015 5:17:08 PM (10 years ago)
Author:
dungnv
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pro-violet-viettel/sourcecode/application/modules/services/controllers/viettel.php

    r716 r758  
    1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
     1<?php
     2
     3if (! defined ( 'BASEPATH' ))
     4        exit ( 'No direct script access allowed' );
    25/**
    36 * Viettel Class
    4  * 
     7 *
    58 * @author dzungnv02
    6  *
     9 *       
    710 */
    8 
    9 class Viettel extends MX_Controller
    10 {
    11        
     11class Viettel extends MX_Controller {
    1212        private $_server = null;
    1313       
    1414        function __construct() {
    1515                parent::__construct ();
    16                 ini_set("soap.wsdl_cache_enabled","1");
    17                 $this->_server = new SoapServer(NULL,
    18                                 array('soap_version' => SOAP_1_2, 'encoding' => 'UTF-8', 'uri' => 'http://tempuri.org/')
    19                 );
    20         }
    21 
    22         public function index ()
    23         {
    24                 if($this->uri->segment(4) == "wsdl") {
    25                         header('Content-Type: text/xml; charset: utf-8');
    26                         $this->load->view('mowsdl');
    27                 } else {
    28                         header('Content-Type: text/html; charset: utf-8');
    29                         echo 'See service <a href="'.base_url().'violetservice/soanbai/mo/wsdl">WSDL page</a>';
    30                 }                       
     16                ini_set ( "soap.wsdl_cache_enabled", "1" );
     17                $this->_server = new SoapServer ( NULL, array (
     18                                'soap_version' => SOAP_1_2,
     19                                'encoding' => 'UTF-8',
     20                                'uri' => 'http://tempuri.org/'
     21                ) );
    3122        }
    3223       
    33         public function mo()
    34         {       
    35                 function messageReceiver(){
    36                         $aryArgs = func_get_args();
    37                         $aryExport = array('Username' => $aryArgs[0], 'Password' => $aryArgs[1], 'RequestID' => $aryArgs[2],'UserID' => $aryArgs[3],'ReceiverID' => $aryArgs[4],'ServiceID' => $aryArgs[5],'CommandCode' => $aryArgs[6], 'Info' => $aryArgs[7], 'ReceiveTime' => $aryArgs[8]);
    38 
    39                         error_log(date('Y-m-d H:i:s').' -- VARIABLES: '. var_export($aryExport, TRUE). "\n", 3, '/srv/www/sbg/log/sms.log');
    40                         list($username, $password, $requestID, $userID, $receiverID, $serviceID, $commandCode, $info, $receiveTime) = $aryArgs;
     24        function __destruct() {
     25                ini_set ( "soap.wsdl_cache_enabled", "0" );
     26        }
     27       
     28        public function index() {
     29                if ($this->uri->segment ( 4 ) == "wsdl") {
     30                        header ( 'Content-Type: text/xml; charset: utf-8' );
     31                        $this->load->view ( 'mowsdl' );
     32                } else {
     33                        header ( 'Content-Type: text/html; charset: utf-8' );
     34                        echo 'See service <a href="' . base_url () . 'violetservice/soanbai/mo/wsdl">WSDL page</a>';
     35                }
     36        }
     37       
     38        public function mo() {
     39                function messageReceiver() {
     40                        $aryArgs = func_get_args ();
     41                        $aryExport = array (
     42                                        'Username' => $aryArgs [0],
     43                                        'Password' => $aryArgs [1],
     44                                        'RequestID' => $aryArgs [2],
     45                                        'UserID' => $aryArgs [3],
     46                                        'ReceiverID' => $aryArgs [4],
     47                                        'ServiceID' => $aryArgs [5],
     48                                        'CommandCode' => $aryArgs [6],
     49                                        'Info' => $aryArgs [7],
     50                                        'ReceiveTime' => $aryArgs [8]
     51                        );
    4152                       
    42                         $msgType = '0'; //text message
    43                         $errCode = '1'; //#1:error; 1:Success;
     53                        error_log ( date ( 'Y-m-d H:i:s' ) . ' -- VARIABLES: ' . var_export ( $aryExport, TRUE ) . "\n", 3, '/srv/www/sbg/log/sms.log' );
     54                        list ( $username, $password, $requestID, $userID, $receiverID, $serviceID, $commandCode, $info, $receiveTime ) = $aryArgs;
    4455                       
    45                         $CI =& get_instance();                 
    46                         $mo_username = $CI->config->item('mo_username');
    47                         $mo_password = $CI->config->item('mo_password');
    48 
    49                         if (!$username) return '0|0|Username is required!';
    50                         if (!$password) return '0|0|Password is required!';
    51                         if ($username != $mo_username) return '0|0|Username is not corrected!';
    52                         if ($password != $mo_password) return '0|0|Password is not corrected!';
    53                         if (!$requestID) return '0|0|requestID is required!';                   
    54                         if (!$userID) return '0|0|UserID is required!';
    55                         if (!$serviceID) return '0|0|serviceID is required!';
    56                         if ($serviceID != '8062') return '0|0|serviceID is not corrected!';
    57 
    58                         $CI->load->model('Services_model');
    59                         $CI->load->model('frontend/User_model', 'objUserModel');
    60                         $result = $CI->Services_model->processMORequest($userID, $info);
    61                         error_log(date('Y-m-d H:i:s').' -- INFO VAR: '. var_export($info, TRUE). "\n\n", 3, '/srv/www/sbg/log/sms.log');
    62                         $CI->objUserModel->insertSmslog($receiverID, $serviceID, $commandCode, $info, $receiveTime);
     56                        $msgType = '0'; // text message
     57                        $errCode = '1'; // #1:error; 1:Success;
    6358                       
    64                         $aryResult = explode ('|', $result);
    65                         return $aryResult[0].'|'.$msgType.'|'.$aryResult[1];
     59                        $CI = & get_instance ();
     60                        $mo_username = $CI->config->item ( 'mo_username' );
     61                        $mo_password = $CI->config->item ( 'mo_password' );
     62                       
     63                        if (! $username)
     64                                return '0|0|Username is required!';
     65                        if (! $password)
     66                                return '0|0|Password is required!';
     67                        if ($username != $mo_username)
     68                                return '0|0|Username is not corrected!';
     69                        if ($password != $mo_password)
     70                                return '0|0|Password is not corrected!';
     71                        if (! $requestID)
     72                                return '0|0|requestID is required!';
     73                        if (! $userID)
     74                                return '0|0|UserID is required!';
     75                        if (! $serviceID)
     76                                return '0|0|serviceID is required!';
     77                        if ($serviceID != '8062')
     78                                return '0|0|serviceID is not corrected!';
     79                       
     80                        $CI->load->model ( 'Services_model' );
     81                        $CI->load->model ( 'frontend/User_model', 'objUserModel' );
     82                        $result = $CI->Services_model->processMORequest ( $userID, $info );
     83                        error_log ( date ( 'Y-m-d H:i:s' ) . ' -- INFO VAR: ' . var_export ( $info, TRUE ) . "\n\n", 3, '/srv/www/sbg/log/sms.log' );
     84                        $CI->objUserModel->insertSmslog ( $receiverID, $serviceID, $commandCode, $info, $receiveTime );
     85                       
     86                        $aryResult = explode ( '|', $result );
     87                        return $aryResult [0] . '|' . $msgType . '|' . $aryResult [1];
    6688                }
    6789               
    68                 $this->_server->addFunction('messageReceiver');
     90                $this->_server->addFunction ( 'messageReceiver' );
    6991               
    7092                try {
    71                         ob_start();
     93                        ob_start ();
    7294                        $soapOutput = '';
    73                         $this->_server->handle();
    74                                
    75                         if (ob_get_length() > 0) {
    76                                 $soapOutput = ob_get_clean();
     95                        $this->_server->handle ();
     96                       
     97                        if (ob_get_length () > 0) {
     98                                $soapOutput = ob_get_clean ();
    7799                        }
    78                                
     100                       
    79101                        if ($soapOutput != '') {
    80102                                $pattern = '/<[^>]*[^\/]>/i';
    81                                 $aryOutput = preg_split ($pattern, $soapOutput, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
    82                                 $aryData = array();
    83                                 $aryData['message'] = $aryOutput[1];
    84                                 $xml = $this->load->view('mo', $aryData, TRUE);
    85                                 header('Content-Type: text/xml; charset: utf-8');
     103                                $aryOutput = preg_split ( $pattern, $soapOutput, - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
     104                                $aryData = array ();
     105                                $aryData ['message'] = $aryOutput [1];
     106                                $xml = $this->load->view ( 'mo', $aryData, TRUE );
     107                                header ( 'Content-Type: text/xml; charset: utf-8' );
    86108                                echo $xml;
     109                        } else {
     110                                header ( 'Content-Type: text/html; charset: utf-8' );
     111                                echo 'See service <a href="' . base_url () . 'violetservice/soanbai/mo/wsdl">WSDL page</a>';
    87112                        }
    88                         else {
    89                                 header('Content-Type: text/html; charset: utf-8');
    90                                 echo 'See service <a href="'.base_url().'violetservice/soanbai/mo/wsdl">WSDL page</a>';
    91                         }
    92                 }
    93                 catch (Exception $e) {
    94                         $this->_server->fault('Sender', $e->getMessage());
     113                } catch ( Exception $e ) {
     114                        $this->_server->fault ( 'Sender', $e->getMessage () );
    95115                }
    96116        }
Note: See TracChangeset for help on using the changeset viewer.