1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
2 | /**
|
---|
3 | * Viettel Class
|
---|
4 | *
|
---|
5 | * @author dzungnv02
|
---|
6 | *
|
---|
7 | */
|
---|
8 |
|
---|
9 | class Viettel extends MX_Controller
|
---|
10 | {
|
---|
11 |
|
---|
12 | private $_server = null;
|
---|
13 |
|
---|
14 | function __construct() {
|
---|
15 | 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 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | public function mo()
|
---|
34 | {
|
---|
35 | function messageReceiver(){
|
---|
36 | $aryArgs = func_get_args();
|
---|
37 | list($username, $password, $requestID, $userID, $receiverID, $serviceID, $commandCode, $contentType ,$info, $receiveTime) = $aryArgs;
|
---|
38 |
|
---|
39 | $msgType = '0'; //text message
|
---|
40 | $errCode = '1'; //#1:error; 1:Success;
|
---|
41 |
|
---|
42 | $CI =& get_instance();
|
---|
43 | $mo_username = $CI->config->item('mo_username');
|
---|
44 | $mo_password = $CI->config->item('mo_password');
|
---|
45 |
|
---|
46 | if (!$username) return '0|0|Username is required!';
|
---|
47 | if (!$password) return '0|0|Password is required!';
|
---|
48 | if ($username != $mo_username) return '0|0|Username is not corrected!';
|
---|
49 | if ($password != $mo_password) return '0|0|Password is not corrected!';
|
---|
50 | if (!$requestID) return '0|0|requestID is required!';
|
---|
51 | if ((int)$requestID != 4) return '0|0|requestID is not corrected!';
|
---|
52 | if (!$userID) return '0|0|UserID is required!';
|
---|
53 | if (!$serviceID) return '0|0|serviceID is required!';
|
---|
54 | if ($serviceID != '8062') return '0|0|serviceID is not corrected!';
|
---|
55 |
|
---|
56 | $status = 0;
|
---|
57 | $sentNumber = $userID;
|
---|
58 | $username = !$receiverID ? $sentNumber : $receiverID;
|
---|
59 |
|
---|
60 | $CI->load->model('frontend/user_model', 'userModel');
|
---|
61 | $password = $CI->userModel->create_random_password();
|
---|
62 |
|
---|
63 | $result = $CI->userModel->register ($sentNumber, $receiverID, $serviceID, $commandCode, $info, $receiveTime, $status);
|
---|
64 |
|
---|
65 | $aryResult = explode ('|', $result);
|
---|
66 |
|
---|
67 | return $aryResult[0].'|'.$msgType.'|'.$aryResult[1];
|
---|
68 | }
|
---|
69 |
|
---|
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 | }
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | /* End of file viettel.php */
|
---|
107 | /* Location: ./application/modules/service/controllers/viettel.php */ |
---|