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