Ignore:
Timestamp:
Nov 12, 2014 10:52:13 PM (11 years ago)
Author:
dungnv
Message:
 
File:
1 edited

Legend:

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

    r470 r483  
    99class Viettel extends MX_Controller
    1010{
     11       
     12        private $_server = null;
     13       
    1114        function __construct() {
    1215                parent::__construct ();
    13                
    14                 $this->nusoap_server = new soap_server ();
    15                 $this->nusoap_server->configureWSDL('messageReceiverWSDL','urn:messageReceiverWSDL');
    16 
    17                 $this->nusoap_server->soap_defencoding = 'UTF-8';               
    18                 $this->nusoap_server->methodreturnisliteral=TRUE;
    19                
    20                 $this->nusoap_server->wsdl->addComplexType(
    21                                 'messageReceiver',
    22                                 'simpleType',
    23                                 'struct',
    24                                 '',
    25                                 'SOAP-ENC:Array',
    26                                 array(
    27                                                 'username'=>array('name'=>'username', 'type'=>'xsd:string'),
    28                                                 'password'=>array('name'=>'password', 'type'=>'xsd:string'),
    29                                                 'requestID'=>array('name'=>'requestID', 'type'=>'xsd:string'),
    30                                                 'userID'=>array('name'=>'userID', 'type'=>'xsd:string'),
    31                                                 'receiverID'=>array('name'=>'receiverID', 'type'=>'xsd:string'),
    32                                                 'serviceID'=>array('name'=>'serviceID', 'type'=>'xsd:string'),
    33                                                 'commandCode'=>array('name'=>'commandCode', 'type'=>'xsd:string'),
    34                                                 'contentType'=>array('name'=>'contentType', 'type'=>'xsd:string'),
    35                                                 'info'=>array('name'=>'info', 'type'=>'xsd:string'),
    36                                                 'receiveTime'=>array('name'=>'receiveTime', 'type'=>'xsd:string')
    37                                 )
     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/')
    3819                );
    39                
    40                 $this->nusoap_server->register ( 'MOReceiver',
    41                                 array( 'username' => 'xsd:string',
    42                                                 'password' => 'xsd:string',
    43                                                 'requestID' => 'xsd:string',
    44                                                 'userID' => 'xsd:string',
    45                                                 'receiverID' => 'xsd:string',
    46                                                 'serviceID' => 'xsd:string',
    47                                                 'commandCode' => 'xsd:string',
    48                                                 'contentType' => 'xsd:string',
    49                                                 'info' => 'xsd:string',
    50                                                 'receiveTime' => 'xsd:string')
    51                                 , array ('return' => 'xsd:string'),
    52                                 'urn:messageReceiverWSDL',"urn:messageReceiverWSDL#MOReceiver","rpc","encoded");
    5320        }
    5421
     
    5623        {
    5724                if($this->uri->segment(4) == "wsdl") {
    58                         $_SERVER['QUERY_STRING'] = "wsdl";
     25                        header('Content-Type: text/xml; charset: utf-8');
     26                        $this->load->view('mowsdl');
    5927                } else {
    60                         $_SERVER['QUERY_STRING'] = "";
    61                 }
    62                 $this->nusoap_server->service(file_get_contents("php://input"));
     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                }                       
    6331        }
    6432       
    6533        public function mo()
    6634        {       
    67                 function MOReceiver($username, $password, $requestID, $userID, $receiverID, $serviceID, $commandCode, $contentType ,$info, $receiveTime){
     35                function messageReceiver(){
     36                        $aryArgs = func_get_args();
     37                        list($username, $password, $requestID, $userID, $receiverID, $serviceID, $commandCode, $contentType ,$info, $receiveTime) = $aryArgs;
     38                       
    6839                        $msgType = '0'; //text message
    6940                        $errCode = '1'; //#1:error; 1:Success;
     
    7849                        if ($password != $mo_password) return '0|0|Password is not corrected!';
    7950                        if (!$requestID) return '0|0|requestID is required!';
     51                        if ((int)$requestID != 4) return '0|0|requestID is not corrected!';
    8052                        if (!$userID) return '0|0|UserID is required!';
    8153                        if (!$serviceID) return '0|0|serviceID is required!';
     
    9668                }
    9769               
    98                 $this->nusoap_server->service(file_get_contents("php://input"));
     70                $this->_server->addFunction('messageReceiver');
     71                try {
     72                        ob_start();
     73                        $soapOutput = '';
     74                        $this->_server->handle();
     75                               
     76                        if (ob_get_length() > 0) {
     77                                $soapOutput = ob_get_clean();
     78                        }
     79                               
     80                        if ($soapOutput != '') {
     81                                $pattern = '/<[^>]*[^\/]>/i';
     82                                $aryOutput = preg_split ($pattern, $soapOutput, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
     83               
     84                                $xml = '<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
     85                                                   <S:Body>
     86                                                      <messageReceiverResponse xmlns="http://tempuri.org/">
     87                                                         <return>'.$aryOutput[1].'</return>
     88                                                      </messageReceiverResponse>
     89                                                   </S:Body>
     90                                                </S:Envelope>';
     91               
     92                                header('Content-Type: text/xml; charset: utf-8');
     93                                echo $xml;
     94                        }
     95                        else {
     96                                header('Content-Type: text/html; charset: utf-8');
     97                                echo 'See service <a href="'.base_url().'violetservice/soanbai/mo/wsdl">WSDL page</a>';
     98                        }
     99                }
     100                catch (Exception $e) {
     101                        $this->_server->fault('Sender', $e->getMessage());
     102                }
    99103        }
    100104}
Note: See TracChangeset for help on using the changeset viewer.