source: pro-violet-viettel/www/deploy/20150304/application/libraries/vservices.php @ 780

Last change on this file since 780 was 780, checked in by dungnv, 10 years ago
File size: 1.9 KB
Line 
1<?php
2
3Class VServices {
4       
5        private $_apiUrl;
6        private $_curlObj;
7        private $_userId;
8        private $_password;
9       
10        private $_httpUser;
11        private $_httpPasswd;
12       
13        public function __construct() {
14        }
15        public function setApiUrl($url) {
16                $this->_apiUrl = $url;
17        }
18       
19        public function setConnection($curl) {
20                $this->_curlObj = $curl;
21        }
22       
23        public function setUserId ($userId) {
24                $this->_userId = $userId;
25        }
26       
27        public function setPassword ($password) {
28                $this->_password = $password;
29        }
30       
31        public function getPrivateTree () {
32                $this->_curlObj->create($this->_apiUrl. 'space/dir/isgetall/1');
33                $this->_curlObj->option(CURLOPT_BUFFERSIZE, 10);
34                $this->_curlObj->options(array(CURLOPT_BUFFERSIZE => 10));
35                $post =  $this->_userId ? array('userid' => $this->_userId) : array();
36                $this->_curlObj->post($post);
37                return $this->_curlObj->execute();
38        }
39       
40        /**
41         * $aryParams
42         *
43         * @param unknown $action
44         * @param unknown $aryParams
45         */
46
47        public function actionExecute ($action, $aryParams = array(), $module = 'space') {
48                $url = $this->_apiUrl. $module .'/'.$action;
49               
50                $this->_curlObj->create($url);
51                $this->_curlObj->option(CURLOPT_BUFFERSIZE, 10);
52                $this->_curlObj->option(CURLOPT_HEADER, 0);
53                $this->_curlObj->option(CURLOPT_FAILONERROR, FALSE);
54               
55                if ($this->_httpUser && $this->_httpPasswd) {
56                        $this->_curlObj->http_login($this->_httpUser, $this->_httpPasswd);
57                }
58               
59                if ($this->_userId) $aryParams['userid'] = $this->_userId;
60                if (count($aryParams) > 0) $this->_curlObj->post($aryParams);
61               
62                $result = $this->_curlObj->execute();
63               
64                $logMsg = date('Y-m-d H:i:s') .' - File: '. __FILE__ . ' - line:'. __LINE__ .' - API Result: '. var_export($result, true). ' - Action: '. var_export($url, true) .' - PARAMS: '. var_export($aryParams, true)."\n";
65                write_file('./log/apicalling.log', $logMsg, FOPEN_WRITE_CREATE);
66               
67                return $result;
68        }
69
70       
71       
72        public function __destruct() {
73               
74        }
75}
Note: See TracBrowser for help on using the repository browser.