0

I need to use the functions of this class,I wrote a code but the output was empty,need echo data from all functions. I correctly entered the connection requirements,script use Json-rpc for request,The port is open on the server

I don't know how to use this class

my class

<?php

require_once("jsonrpc.inc");

class IBSjsonrpcClient {

    function IBSjsonrpcClient($server_ip="127.0.0.1", $auth_name="user", $auth_pass="pass", $auth_type="ADMIN", $server_port="1237", $timeout=1800){
        $this->client = new jsonrpc_client($server_ip. ':' . $server_port);

        $this->auth_name = $auth_name;
        $this->auth_pass = $auth_pass;
        $this->auth_type = $auth_type;

        $this->timeout = $timeout;
    }

    function sendRequest($server_method, $params_arr){
        /*
            Send request to $server_method, with parameters $params_arr
            $server_method: method to call ex admin.addNewAdmin
            $params_arr: an array of parameters
        */
        $params_arr["auth_name"] = $this->auth_name;
        $params_arr["auth_pass"] = $this->auth_pass;
        $params_arr["auth_type"] = $this->auth_type;
        $response = $this->client->send($server_method, $params_arr, $this->timeout);
        $result = $this->__returnResponse($response);
        unset($response);
        return $result;
    }
    function __returnResponse($response){
        if ($response == FALSE)
            return $this->__returnError("Error occured while connecting to server");
        else if ($response->faultCode() != 0)
            return $this->__returnError($response->faultString());
        else
            return $this->__returnSuccess($response->value());
    }
    function __returnError($err_str){
        return array(FALSE, $err_str);
    }

    function __returnSuccess($value){
        return array(TRUE, $value);
    }

    function getUserInfoByUserID($user_id){
        return $this->sendRequest("user.getUserInfo", array("user_id"=>(string)$user_id));
    }

    function getUserInfoByNormalUserName($normal_username){
        return $this->sendRequest("user.getUserInfo", array("normal_username"=>$normal_username));
    }

    function getBasicUserInfoByNormalUserName($normal_username){### for Zahedan Telecom, ticket 34083
        $result = $this->sendRequest("user.getUserInfo", array("normal_username"=>$normal_username));
        if(!$result[0]){
            return $result;
        }
        $info = $result[1];
        return array(
            "user_id" => $info["basic_info"]["user_id"],
            "normal_username" => $info["attrs"]["normal_username"],
            "remaining_days" => $info["remaining_days"],
            "remaining_mega_bytes" => $info["remaining_mega_bytes"],
            "credit" => $info["basic_info"]["credit"],
            "group_name" => $info["basic_info"]["group_name"]
        );
    }

    function getUserInfoBySerial($serial){
        return $this->sendRequest("user.getUserInfo", array("serial"=>$serial));
    }

    function addNewUser($count, $credit, $isp_name, $group_name, $credit_comment=""){
        return $this->sendRequest("user.addNewUsers", array(
            "count" => $count,
            "credit" => $credit,
            "isp_name" => $isp_name,
            "group_name" => $group_name,
            "credit_comment" => $credit_comment
        ));
    }

    function setNormalUserAuth($user_id, $username, $password){
        return $this->setUserAttributes($user_id, array(
            "normal_user_spec" => array(
                "normal_username"=>$username,
                "normal_password"=>$password,
            )
        ));
    }






}


?>

example code for use function in class but empty array

<?php
    require "ibs-jsonrpc-client.php";
$ibs = new IBSjsonrpcClient();
$a =  $ibs->getBasicUserInfoByNormalUserName("user1");
print_r($a);
?>
cmaxxx
  • 45
  • 3
  • Use the constructor parameters to connect to the _real_ server? Btw, the constructor is in PHP4 style - probably reconsider to use this class – Honk der Hase Dec 07 '19 at 17:29
  • Yes use real server – cmaxxx Dec 07 '19 at 18:11
  • localhost is the real server? So you have the API enpoint installed on the same machine... maybe you made a mistake with the setup? You'd also better contact the vendor of the Software you're using and ask them, if it doesn't work as you expect... – Honk der Hase Dec 07 '19 at 18:19
  • output is empty=> Array ( [user_id] => [normal_username] => [remaining_days] => [remaining_mega_bytes] => [credit] => [group_name] => ) – cmaxxx Dec 08 '19 at 08:38

0 Answers0