作者:Eddy  历史版本:1  最后编辑:龚清  更新时间:2024-05-28 11:17

编写版本:v3.5.2
适用版本:v3.5.2+

脚本如何调用RESTFUL API

  1. com.lc.ibps.platform.script.script.ThridServiceScript
    /**
          * 示例:
     * <pre>
     * java.util.Map<String, Object> data = com.lc.ibps.base.framework.helper.MapBuilder.create()
     * .a("name", "3")
     * .a("type", "org")
     * .a("level", 3)
     * .p();
     * String url = "http://192.168.3.190:15100/ibps/platform/v3/level/save";
     * thridServiceScript.doPostBodyOfRestFull(url, null, data);
     * </pre>
     * @param url
     * @param headers
     * @param body
     * @return
     */
    public Object doPostBodyOfRestFull(String url, Map<String, String> headers, Object body) {
        ApacheHttpClient.doPost(url, body, (Integer)null, (Integer)null,
            ApacheHttpClient.HearderBuilder.create(headers)
                    .a(ParameterKey.HEADER_AUTHORIZATION, ContextUtil.getCurrentAccessToken())
                    .a(ParameterKey.HEADER_AUTHORIZATION_NORMAL, ContextUtil.getCurrentAccessToken())
                    .a(TenantConstant.TENANT_HEADER_KEY, TenantContext.getCurrentTenantId())
                    .a(ParameterKey.HEADER_INNER, secrectConfig.getInnerSecretValue())
                    .build());
        return null;
    }

流程中如何使用该脚本调用RESTFUL API

此处以节点后置脚本为例

脚本内容:

java.util.Map data = com.lc.ibps.base.framework.helper.MapBuilder.create()// 接口参数,body类型
 .a("name", "3")
 .a("type", "org")
 .a("level", 3)
 .p();
 String url = "http://192.168.3.190:15100/ibps/platform/v3/level/save";// restfull api地址
 java.util.Map headers = new java.util.HashMap<>();// 请求头
 headers.put(com.lc.ibps.cloud.constants.ParameterKey.HEADER_AUTHORIZATION, com.lc.ibps.base.web.context.ContextUtil.getCurrentAccessToken());
 thridServiceScript.doPostBodyOfRestFull(url, headers, data);