开发钉钉审批流时,需要用到钉钉表单的Processcode,有两种方法 :
一、手动获取:
管理员后台——审批——找到对应的表单:如图:
ProcessCode后面就是了!
二、接口获取:今天的重点,不说了,直接上代码。
function TDingtalkNew.GetProcessCode(ProcessName: string): string;
constProcessCodeAPI: string = 'https://oapi.dingtalk.com/topapi/process/get_by_name';
varHttpClient: TNetHTTPClient;Params: TStringList;Response: TStringStream;
varJO: TJSONObject;errcode: string; //返回代码
beginHttpClient := TNetHTTPClient.Create(nil);Params := TStringList.Create();Response := TStringStream.Create('', 65001);tryParams.Add('access_token=' + Token);Params.Add('name=' + ProcessName);HttpClient.post(ProcessCodeAPI, Params, Response);JO := TJSONObject.ParseJSONValue(Response.DataString) as TJSONObject;tryif JO <> nil thenbeginJO.TryGetValue<string>('errcode', errcode);if errcode.ToInteger = 0 thenbegin
// Result := Response.DataString;JO.TryGetValue<string>('process_code', Result);endelsebeginJO.TryGetValue<string>('errmsg', Result);//这里最好做日志记录错误信息end;end;finallyJO.Free;end;finallyHttpClient.Free;Params.Free;Response.Free;end;end;
下面就是调用了:
procedure TMainForm.ToolButton6Click(Sender: TObject); vardk: TDingtalkNew; begindk := TDingtalkNew.Create;trydk.Getappid := '你企业钉钉的APPID';dk.Getappsecret := '你企业钉钉的Appsecret';Log.Debug(dk.GetProcessCode('ERP客户订单'),'debug');finallydk.Free;end; end;
中年大叔学Delphi