source: pro-violet-viettel/sourcecode/application/modules/services/controllers/moservice.php @ 698

Last change on this file since 698 was 483, checked in by dungnv, 11 years ago
File size: 1.9 KB
Line 
1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * Moservice Class
4 *
5 * @author dzungnv02
6 *
7 */
8
9class Moservice extends MX_Controller
10{
11        private $_wsdl = 'http://210.211.97.53/mo.wsdl';
12        private $_server = null;
13               
14        public function __construct()
15        {
16                parent::__construct();
17                ini_set("soap.wsdl_cache_enabled","1");         
18                $this->_server = new SoapServer(NULL,
19                                        array('soap_version' => SOAP_1_2, 'encoding' => 'UTF-8', 'uri' => 'http://tempuri.org/')
20                                );
21               
22        }
23       
24        public function index ()
25        {
26                function messageReceiver()
27                {
28                        $aryArgs = func_get_args();
29                        list($username, $password, $requestID, $userID, $receiverID, $serviceID, $commandCode, $contentType ,$info, $receiveTime) = $aryArgs;
30                        return '1|0|'.$commandCode.$serviceID;
31                }
32               
33                $this->_server->addFunction('messageReceiver');         
34
35                try {
36                        ob_start();
37                        $soapOutput = '';
38                        $this->_server->handle();
39                       
40                        if (ob_get_length() > 0) {
41                                $soapOutput = ob_get_clean();
42                        }                       
43                       
44                        if ($soapOutput != '') {
45                                $pattern = '/<[^>]*[^\/]>/i';
46                                $aryOutput = preg_split ($pattern, $soapOutput, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
47                               
48                                $xml = '<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
49                                                   <S:Body>
50                                                      <messageReceiverResponse xmlns="http://tempuri.org/">
51                                                         <return>'.$aryOutput[1].'</return>
52                                                      </messageReceiverResponse>
53                                                   </S:Body>
54                                                </S:Envelope>';
55                               
56                                header('Content-Type: text/xml; charset: utf-8');
57                                echo $xml;
58                        }
59                        else {
60                                header('Content-Type: text/html; charset: utf-8');
61                                echo 'See service <a href="'.base_url().'services/moservice/wsdl">WSDL page</a>';
62                        }
63                }
64                catch (Exception $e) {
65                    $this->_server->fault('Sender', $e->getMessage());
66                }               
67        }
68       
69        public function wsdl ()
70        {
71                header('Content-Type: text/xml; charset: utf-8');
72                echo file_get_contents($this->_wsdl);
73        }
74}
Note: See TracBrowser for help on using the repository browser.