示例#1
0
 function _api_request($service, $method, $params, $parname = false)
 {
     require_once _base_ . '/lib/lib.json.php';
     require_once _base_ . '/lib/lib.fsock_wrapper.php';
     $server = Get::sett('bbb_server', false);
     $output = false;
     $_parname = $parname ? $parname . "=" : "";
     if ($server && $service && $method) {
         $url = 'http://' . $server . '/api/' . $service . '/' . $method;
         $json = new Services_JSON();
         $fsock = new FSock();
         //check user login
         if ($service != 'auth') {
             $auth_code = $this->get_auth_code();
             if (!$auth_code) {
                 //make login
                 $auth_code = $this->api_login();
             } else {
                 //verify if login is valid
                 if (!$this->api_verify()) {
                     $auth_code = $this->api_login();
                 }
             }
             if ($auth_code) {
                 $other_header = array(_BBB_AUTH_CODE => $auth_code, "Content-type" => "application/x-www-form-urlencoded");
                 $post = $_parname . urlencode($json->encode($params));
                 $res_json = $fsock->post_request($url, Get::sett('bbb_port', '80'), $post, $other_header);
                 if ($res_json) {
                     $output = $json->decode($res_json);
                 }
             }
         } else {
             $post = $_parname . urlencode($json->encode($params));
             $other_header = array("Content-type" => "application/x-www-form-urlencoded");
             if ($method != 'login') {
                 $other_header[_BBB_AUTH_CODE] = $this->get_auth_code();
             }
             $res_json = $fsock->post_request($url, Get::sett('bbb_port', '80'), $post, $other_header);
             if ($res_json) {
                 $output = $json->decode($res_json);
             }
         }
     }
     return $output;
 }