DELPHI7下实在难以测试出来,最后在DELPHI XE10 下经过两天测试出来了,能正常下载。
特别注意的是标红处的一些登录参数,要从钉钉氚云专业版系统处获得,然后替换红色处的代号,才能登录下载.先将测试出来的代码上传,逐步完善说明。
unit TESTINDY;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdIOHandler, Web.UTF8ContentParser,
IdMultipartFormData, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL,
//
IdGlobalProtocols, util_uft8,
//
IdBaseComponent, System.JSON, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, Vcl.StdCtrls;
const
sContentTransferPlaceHolder = 'Content-Transfer-Encoding: %s';
sContentTransferQuotedPrintable = 'quoted-printable';
sContentTransferBinary = 'binary';
type
TForm1 = class(TForm)
Button1: TButton;
IdHTTP1: TIdHTTP;
IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
Memo1: TMemo;
Button2: TButton;
procedure Button1Click(Sender: TObject);
function UnicodeToChinese(inputstr: string): string;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Url: string;
streanResponse: TStringStream;
response: string;
ResponseStr: string;
SSLopen: tIdSSLIOHandlerSocketOpenSSL;
StreamRequest: TStringStream;
jsonData, tempstr, tempstr2, sjc: string;
vres, STR: string;
requeststr: UTF8String;
AJSON: TJSONObject;
bytes: SYSTEM.TArray<SYSTEM.BYTE>;
begin
try
streanResponse := TStringStream.Create('',tencoding.utf8);
//要注意返回值是UTF8格式的流
StreamRequest := TStringStream.Create('');
SSLopen := tIdSSLIOHandlerSocketOpenSSL.Create(IdHTTP1);
IdHTTP1.IOHandler := SSLopen;
IdHTTP1.ReadTimeout := 50000;
IdHTTP1.Request.ContentType := 'application/json';
IdHTTP1.Request.CustomHeaders.Values['EngineCode'] := 'EngineCode';
IdHTTP1.Request.CustomHeaders.Values['EngineSecret'] :=
'EngineSecret';
STR := ' { ' + ' "ActionName":"LoadBizObjects",' +
' "SchemaCode":"SchemaCode", ' +
' "Filter":"{\"FromRowNum\": 0,\"RequireCount\": false,\"ReturnItems\": [], \"SortByCollection\": [],\"ToRowNum\": 3, \"Matcher\": { \"Type\": \"And\", \"Matchers\": []}}"' +
' }';
Url := 'https://www.h3yun.com/OpenApi/Invoke';
StreamRequest := TStringStream.Create;
AJSON := TJSONObject.Create;
AJSON := TJSONObject.ParseJSONValue(Trim(STR)) as TJSONObject;
requeststr := AJSON.ToString;
bytes := TEncoding.UTF8.GetBytes(requeststr);
IdHTTP1.Request.ContentLength := Length(bytes);
StreamRequest.Write(bytes, IdHTTP1.Request.ContentLength);
//以UTF-8编码写入相应的JSON字符流。
IdHTTP1.Post('https://www.h3yun.com/OpenApi/Invoke', StreamRequest, streanResponse); //
vres := streanResponse.DataString; // Post返回值Utf8码
Memo1.Text :=UnicodeToChinese(vres); // 显示反馈信息Utf8To
finally
// IdHTTP1.Free;
StreamRequest.Free;
streanResponse.Free;
end;
end;
function TForm1.UnicodeToChinese(inputstr: string): string;
var
i: Integer;
index: Integer;
temp, top, last: string;
begin
index := 1;
while index >= 0 do
begin
index := Pos('U', inputstr) - 1;
if index < 0 then
begin
last := inputstr;
Result := Result + last;
Exit;
end;
top := Copy(inputstr, 1, index); // 取出 编码字符前的 非 unic 编码的字符,如数字
temp := Copy(inputstr, index + 1, 6); // 取出编码,包括 u,如u4e3f
Delete(temp, 1, 2);
Delete(inputstr, 1, index + 6);
Result := Result + top + WideChar(StrToInt('$' + temp));
end;
end;
end.
参考帮助如下