当前位置: 首页 > 工具软件 > ProcessMaker > 使用案例 >

ProcessMaker REST API 定制开发

樊桐
2023-12-01

开发一个获取登录用户ID的REST API

ProcessMaker没有提供获取登录用户ID的REST API,需要我们自己定制开发。

1 、运行环境

  • ProcessMaker 版本 :3.2.2 社区版
  • workspace:workflow
  • 操作系统:Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linu

2、操作步骤

2-1 、切换到Api目录

cd /opt/processmaker-3.2.2-0/apps/processmaker/htdocs/workflow/engine/src/ProcessMaker/Services/Api

2-2 、创建类文件LoggedUserId.php

sudo vi LoggedUserId.php

2-3、输入代码

<?php
namespace ProcessMaker\Services\Api;

use \ProcessMaker\Services\Api;
use \Luracast\Restler\RestException;

/**
 * LoggedUserId Api Controller
 *
 * @protected
 */
class LoggedUserId extends Api
{
    /**
     * Return the ID of the logged-in user
     * 
     * @url GET  
     * @access protected
     * @class  AccessControl {@permission PM_USERS,PM_FACTORY}      
     * 
     * @author genwise <1207831141@qq.com>
     * @copyright Public Domain
     */
    public function getLoggedUserId()
    {
                $response['id'] = $this->getUserId();
                return $response;
    }
}

2-4 、切换到Services目录

cd ..

2-5 、编辑api.ini

sudo vi api.ini

2-6 、在api.ini 最后添加以下代码


[alias: loggeduserid]
    loggeduserid = "ProcessMaker\Services\Api\LoggedUserId"

2-7、删除文件routes.php

cd /opt/processmaker-3.2.2-0/apps/processmaker/htdocs/shared/sites/workflow
sudo rm routes.php

3、获取登录用户ID的REST API开发完成

访问方法是:GET

访问端点是:/api/1.0/workflow/loggeduserid

参考资料:

 类似资料: