Skip to content

集成指南

本节介绍流程引擎+表单引擎与其他系统的集成方式。

与第三方系统集成

Webhook 集成

配置 Webhook 接收表单和流程事件:

bash
curl -X POST http://localhost:8080/api/v1/webhooks \
  -H "Content-Type: application/json" \
  -d '{
    "name": "订单系统集成",
    "url": "https://your-system.com/webhook",
    "events": ["form.submitted", "flow.completed"],
    "headers": {"X-Secret": "your-secret"},
    "enabled": true
  }'

Webhook 事件格式:

json
{
  "event": "form.submitted",
  "timestamp": "2024-01-15T10:30:00Z",
  "data": {
    "formId": "form001",
    "dataId": "data001",
    "formData": {"applicant": "张三"}
  }
}

REST API 集成

调用第三方系统 API:

javascript
async function syncToExternalSystem(formData) {
  const response = await fetch('https://external-system.com/api/sync', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer token'
    },
    body: JSON.stringify(formData)
  });
  return response.json();
}

单点登录 (SSO) 集成

OAuth2.0 配置

yaml
spring:
  security:
    oauth2:
      client:
        registration:
          sso:
            client-id: your-client-id
            client-secret: your-client-secret
            authorization-grant-type: authorization_code
            redirect-uri: http://localhost:8080/login/oauth2/code/sso
        provider:
          sso:
            authorization-uri: https://sso.example.com/oauth/authorize
            token-uri: https://sso.example.com/oauth/token
            user-info-uri: https://sso.example.com/oauth/userinfo

SAML 集成

xml
<bean id="samlConfig" class="com.example.SAMLConfig">
  <property name="idpMetadataUrl" value="https://idp.example.com/metadata"/>
  <property name="entityId" value="http://localhost:8080/saml"/>
</bean>

LDAP 集成

配置示例

yaml
spring:
  ldap:
    urls: ldap://ldap.example.com:389
    base: dc=example,dc=com
    username: cn=admin,dc=example,dc=com
    password: password
    user-dn-pattern: uid={0},ou=users

消息队列集成

RabbitMQ 配置

yaml
spring:
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest

发送消息

java
@Autowired
private RabbitTemplate rabbitTemplate;

public void sendFormEvent(FormData formData) {
  rabbitTemplate.convertAndSend(
    "form-exchange", 
    "form.submitted", 
    formData
  );
}

文件存储集成

阿里云 OSS

yaml
storage:
  type: oss
  oss:
    endpoint: oss-cn-hangzhou.aliyuncs.com
    accessKeyId: your-access-key
    accessKeySecret: your-secret
    bucketName: your-bucket

AWS S3

yaml
storage:
  type: s3
  s3:
    endpoint: s3.amazonaws.com
    accessKeyId: your-access-key
    secretAccessKey: your-secret
    bucketName: your-bucket

集成最佳实践

  1. 异步处理:使用消息队列处理异步事件
  2. 容错机制:添加重试和熔断处理
  3. 幂等性:确保操作的幂等性
  4. 日志追踪:使用分布式追踪工具
  5. 监控告警:设置集成状态监控