使用项目标识访问processmaker中的数据库连接列表

时间:2016-05-16 12:27:01

标签: postgresql processmaker

我正在processmaker 3.0中开发REST api。我想在其中使用位于远程服务器中的外部数据库。在创建连接时,给我的错误是未经授权的错误。 用于创建数据库连接我引用此链接: http://wiki.processmaker.com/3.0/REST_API_Designer#Get_Database_Conections_List

我的代码是

echo "in php script";
    $pmServer = "http://127.0.0.1"; //set to your ProcessMaker address

    $accessToken = isset($_COOKIE['access_token']) ? $_COOKIE['access_token'] : getAccessToken();
    $accessToken = $_COOKIE['access_token'];

    function getAccessToken()
    {
        echo "in getAccessToken function";
    }       

    check_cookie($accessToken);
    check_header($pmServer,$accessToken);


    function check_cookie($accessToken)
    {
        echo "in checkcokkie function";
            /*check cookie expired or not*/
            try{

                if (empty($accessToken) and isset($_COOKIE['access_token']))
                throw new Exception("Internal Server Error 500");   
                }   
            catch(Exception $e) {
                echo 'Message: ' .$e->getMessage();

                }

            try{

                if (empty($accessToken)) { //if the access token has expired
                //To check if the PM login session has expired: !isset($_COOKIE['PHPSESSID'])
                /*header("Location: formLogin.php"); //change to match your login method
                die();*/
                throw new Exception("Internal Server Error 500");

                }
            }
            catch(Exception $e) {
                echo 'Message: ' .$e->getMessage();
                //header('location: formLogin.php');
                }
    }   
/***************************/

    function check_header($pmServer,$accessToken)
    {

        echo "in check header";
        $ch = curl_init($pmServer . "/api/1.0/workflow/project");
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer " . $accessToken));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $aUsers = json_decode(curl_exec($ch));
        $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

    try{
        if ($statusCode != 200) {
        if (isset ($aUsers) and isset($aUsers->error))
        echo "Error code:{$aUsers->error->code}\n Message: {$aUsers->error->message}\n";
        else
        echo "Error: HTTP status code: $statusCode\n";
        //header("Location: formLogin.php"); //change to match your login method
        //die();
        throw new Exception("Internal Server Error 500");

            }
        else {
        foreach ($aUsers as $oUser) {

        echo "{$oUser->prj_uid} {$oUser->prj_name}  {$oUser->prj_description} \n";


                    /*displying database connections*//////

                    $aVars = array(
                    "dbs_type" => "PostgreSQL", 
                    "dbs_server" => "192.168.190.79",
                    "dbs_database_name"=> "adani",
                    "dbs_username"=> "postgres",
                    "dbs_password"=> "stp2015",
                    "dbs_port"=> 5434,
                    "dbs_encode"=> "utf8",
                    "dbs_description"=> "Gas project"
                    );

                    /*prj_id="2146606445739a4aba0fc12089436797";  dbs_id="8728332515739af251ccf86002880169"*/ 


                            echo "<br/>";
                            $prj_id = $aUsers->prj_uid;
                            $ch = curl_init($pmServer . "/api/1.0/workflow/project/$prj_id/database-connection");


                            curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer". $accessToken)); 
                            curl_setopt($ch, CURLOPT_POST, 1); 
                            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($aVars));
                            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                            $aUsers = json_decode(curl_exec($ch)); 
                            $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
                            curl_close($ch);

                            try{

                            if ($statusCode != 201) {
                            if (isset ($aUsers) and isset($aUsers->error))
                            echo "Error code:{$aUsers->error->code}\n Message: {$aUsers->error->message}\n";
                            else
                            echo "Error: HTTP status code: $statusCode\n";
                            //header("Location: formLogin.php"); //change to match your login method
                            //die();
                            throw new Exception("Internal Server Error 500");

                            }
                            else {
                            foreach ($aUsers as $oUser) {

                            echo "{$oUser->dbs_uid} {$oUser->dbs_type} \n";

                                    }
                                }
                            }
                            catch(Exception $e) {
                            echo 'Message: ' .$e->getMessage();
                            //header('location: formLogin.php');
                            }                   

                    /************************************/      
                }
            }
    }
    catch(Exception $e) {
        echo 'Message: ' .$e->getMessage();
        header('location: formLogin.php');
        }

    }   ?>      

它会让我出现以下错误,如图enter image description here

所示

我正在添加此REST api进程并创建数据库函数,但它不显示任何连接列表。 如何显示连接列表以及如何创建与外部数据库的数据库连接。

0 个答案:

没有答案