钉钉开发之根据流程码processCode获取流程表单schema
一、环境:
1、钉钉oa审批流程中,已有“出差审批”流程,流程码为:PROC-48E207E5-EB8B-457C-BC3D-86CD5E5A50B3
2、开发环境:IDEA
二、代码
1、获取token
package sfccl.api; import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenResponse; import com.aliyun.tea.TeaException; public class Mytoken { // public static String accessToken; String AppKey = "ding**********kkq5"; String AppSecret = "ZM1iVltcUHlS_***********************_plbobp"; String accessToken = ""; public static com.aliyun.dingtalkoauth2_1_0.Client createClient() throws Exception { com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config(); config.protocol = "https"; config.regionId = "central"; return new com.aliyun.dingtalkoauth2_1_0.Client(config); } public String accessToken() throws Exception { //java.util.List<String> args = java.util.Arrays.asList(args_); com.aliyun.dingtalkoauth2_1_0.Client client = Mytoken.createClient(); com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest getAccessTokenRequest = new com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest() .setAppKey(AppKey) .setAppSecret(AppSecret); try { GetAccessTokenResponse tokenResponse = client.getAccessToken(getAccessTokenRequest); // System.out.println(tokenResponse.body); // System.out.println(tokenResponse.getHeaders()); // System.out.println(tokenResponse.getBody()); System.out.println(tokenResponse.getBody().accessToken); System.out.println(tokenResponse.getBody().expireIn); accessToken = tokenResponse.getBody().accessToken; } catch (TeaException err) { if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { // err 中含有 code 和 message 属性,可帮助开发定位问题 System.out.println("TeaException:"+err.message); } } catch (Exception _err) { TeaException err = new TeaException(_err.getMessage(), _err); if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { // err 中含有 code 和 message 属性,可帮助开发定位问题 System.out.println("TeaException:" + err.message); } } return accessToken; } }
2、获取表单schema
package sfccl.api; import com.aliyun.tea.*; import com.aliyun.teautil.*; import com.aliyun.teautil.models.*; import com.aliyun.dingtalkworkflow_1_0.*; import com.aliyun.dingtalkworkflow_1_0.models.*; import com.aliyun.teaopenapi.*; import com.aliyun.teaopenapi.models.*; import java.util.List; public class GetSchema { /** * 使用 Token 初始化账号Client * @return Client * @throws Exception */ public static com.aliyun.dingtalkworkflow_1_0.Client createClient() throws Exception { Config config = new Config(); config.protocol = "https"; config.regionId = "central"; return new com.aliyun.dingtalkworkflow_1_0.Client(config); } public static void main(String[] args_) throws Exception{ java.util.List<String> args = java.util.Arrays.asList(args_); Mytoken mytoken = new Mytoken(); String token = mytoken.accessToken(); com.aliyun.dingtalkworkflow_1_0.Client client = GetSchema.createClient(); QuerySchemaByProcessCodeHeaders querySchemaByProcessCodeHeaders = new QuerySchemaByProcessCodeHeaders(); querySchemaByProcessCodeHeaders.xAcsDingtalkAccessToken = token; QuerySchemaByProcessCodeRequest querySchemaByProcessCodeRequest = new QuerySchemaByProcessCodeRequest() .setProcessCode("PROC-48E207E5-EB8B-457C-BC3D-86CD5E5A50B3"); try { QuerySchemaByProcessCodeResponse userResponse = client.querySchemaByProcessCodeWithOptions(querySchemaByProcessCodeRequest, querySchemaByProcessCodeHeaders, new RuntimeOptions()); System.out.println(userResponse.getBody().toMap()); //注意:这里使用toMap()才能看到具体表单模板,若使用toString()只能看到类地址 } catch (TeaException err) { if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { // err 中含有 code 和 message 属性,可帮助开发定位问题 System.out.println(err.message); } } catch (Exception _err) { TeaException err = new TeaException(_err.getMessage(), _err); if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) { // err 中含有 code 和 message 属性,可帮助开发定位问题 System.out.println(err.message); } } } }
三、结果
1f997da77f873b49b2c3fa2653656762 7200 {result={creatorUserId=081944650937626047, gmtModified=2022-11-22T11:04Z, bizType=, formUuid=FORM-E4579C3A-30FA-41F4-9953-321259F1F23B, ownerIdType=orgId, formCode=PROC-48E207E5-EB8B-457C-BC3D-86CD5E5A50B3, icon=null, engineType=0, memo=测试001——api流程表单开发测试, gmtCreate=2022-11-22T10:44Z, schemaContent={icon=common, title=出差申请, items=[{children=[{componentName=TextField, props={bizAlias=, id=TextField-K2AD4O5B, label=出差地点(单行输入框, required=null}}, {componentName=DDPhotoField, props={bizAlias=null, id=DDPhotoField_1AWJR59S5BTS0, label=图片, required=false}}, {componentName=DDDateRangeField, props={bizAlias=null, id=DDDateRangeField_19TP9POJBE800, label=["开始时间","结束时间"], required=false}}, {componentName=NumberField, props={bizAlias=, id=NumberField_1WOIL8PMYE5C0, label=出差人数, required=false}}, {componentName=MoneyField, props={bizAlias=, id=MoneyField_KUPX9HK115O0, label=出差金额(元), required=false}}, {componentName=DDSelectField, props={bizAlias=, id=DDSelectField_21GQV9G2U9Z40, label=出差同伴(单选框), required=false}}, {componentName=TextField, props={bizAlias=, id=TextField_9RF2CYB4B380, label=出差工具, required=false}}, {componentName=TextareaField, props={bizAlias=, id=TextareaField_1WFOQXQCVGLC0, label=出差事由, required=false}}], componentName=TableField, props={staffStatusEnabled=false, bizType=null, hidden=null, payEnable=null, statField=null, link=null, align=null, durationLabel=null, pushToCalendar=null, required=null, duration=null, holidayOptions=[], appId=null, options=null, hiddenInApprovalDetail=null, useCalendar=null, disabled=null, id=TableField_16SENC2STKG00, placeholder=null, asyncCondition=null, behaviorLinkage=null, hideLabel=null, showAttendOptions=null, objOptions=null, notUpper=null, format=null, bizAlias=, label=行程明细, labelEditableFreeze=null, pushToAttendance=null, commonBizType=null, push={attendanceRule=null, pushSwitch=null, pushTag=null}, fieldsInfo=null, requiredEditableFreeze=null, unit=null, extract=null, verticalPrint=null, eSign=null, mainTitle=null, formula=null, notPrint=null, choice=null, childFieldVisible=null, actionName=添加, attendTypeLabel=null}}]}, appUuid=dingc2e467f9e6ed39aaf5bf40eda33b7ba0, appType=0, visibleRange=PRIVATE, listOrder=51, name=出差申请, customSetting=null, procType=, status=PUBLISHED}} Process finished with exit code 0