@sanjay 我将尝试向您概述我当时在按照此处的说明通过 PHP 试验 Flowgear 时所做的事情。
我不确定您是否还通过 PHP 或任何其他语言调用 Flowgear REST API,但无论如何我认为逻辑应该保持不变。
我所做的是将 PHP CURL 示例代码包装在一个类中,以便能够重用它。下面是我为一个简单的选择查询编写的代码:
<?php
//Require the FlowgearConnect class
require_once '/path/to/flowgear_class_with_api_call.php';
try{
$workflow = new FlowgearConnect(return include 'endpoints.php');
$serial = $_POST['serial'];
$clientId = $_POST['client_id'];
//Get the results
$sql = '';
if(empty($serial)){
$conditions = sprintf(' `a`.`client_id` = %s AND `a`.`serial` > -1 ORDER BY `a`.`serial` ASC', $clientId);
}else{
$conditions = ' `a`.`serial` = ' . $serial;
}
/**
In your workflow you will most probably have a VARIABLE BAR that holds your request parameters which is what $conditions speaks to.
*/
$conditions = array('conditions' => $conditions);
$results = $workflow->getResults('orders', 'orders', $conditions);
}catch(catch any exceptions thrown by the API here){
//Log the exceptions here or do whatever
}
上面的列表应该是不言自明的。下面我将向您展示我在 FlowgearConnect 类中使用的功能。这不是标准方式,因为您可以根据需要以不同方式配置代码。
//FlowgearConnect constructor
class FlowgearConnect
{
protetced $endpoints = [];
protected $domain = "https://your-domain.flowgear.io";
public function __construct(array $endpoints)
{
$this->endpoints = $endpoints;
}
public function getResults($model, $workflow, $options= array())
{
$endpoint = $this->getEndpoint($model, $workflow);
$results = array();
if(!empty($endpoint)){
$results = FlowgearInvoke::run($authOpts, $endpoint, $options, array('timeout' => 30));
}
return $results;
}
....
}
如前所述,enpoints.php 文件仅从 flowgear 控制台中返回一组配置的端点和/或工作流名称。下面是我的样子的摘录:
return array(
'orders' => array(
'shipped_orders' => '/shipped_orders',
//etc
),
'items' => array(
'your_model' => '/workflow_name_from_flowgear_console',
),
);
这只是一个使用 PHP 的 Flowgear REST API 的基本选择查询。如果幸运的话,您应该按照为工作流程配置响应正文的方式获取记录。
下面是一个典型的工作流测试以及你应该在你的 API 中得到什么。
我建议您首先在您的 flowgear 控制台上创建您的工作流程,并确保生成所需的输出并提取您想要更改的部分,而不是您的查询,将它们移动到您的请求的变量栏并在运行时将它们注入 -时间取决于您希望实现的目标。这种解释可以替代其他操作,例如更新和/或删除。最好的办法是先了解 flowgear,并确保在尝试创建一个安静的交互式应用程序之前,你可以在那里完成所有工作。
![在此处输入图像描述](https://i.stack.imgur.com/OHf4V.jpg)
警告:我使用这个平台已经一年多了,所以你可能会发现其中的错误,但我希望它会引导你找到解决问题的方法。如果没有,那么也许您可以创建一个 repo 并让我检查一下,看看您是如何配置所有内容的。