Home > Back-end >  What a great god had done delphi7 amazon MWS via API connection?
What a great god had done delphi7 amazon MWS via API connection?

Time:09-15

Excuse me, what a great god had done delphi7 amazon MWS via API connection, can you provide the docking ideas and examples, the younger brother grateful,

CodePudding user response:

Give you an upload ali oss code, similar to the
 
The unit duAliYun_OSS;

Interface

USES the
REST. The Client system. JSON, system. SysUtils, Vcl. Dialogs;

The function invokeAliOSS (objName, fileName, method: PChar; AHost, Bucket, AccessKey, AccessSecret: PChar) : Boolean; Stdcall;

Implementation

USES the
REST. Types, DateUtils, Soap. EncdDecd cHash, system. Classes, system.Net Encoding,
Dulogclass IPPeerCommon, idhttp fmclient;

The function DateTimeToGMT (const ADate: TDateTime) : string;
Const
WEEK: array [7] 1.. of PChar=(' Sun ', 'Mon, Tue, Wed, Thu, Fri, "Sat");
MonthDig: array=[12] 1.. of PChar (' Jan, Feb, Mar, Apr, 'May' and 'Jun, Jul, Aug, Sep, Oct, Nov, Dec');
Var
WWeek wYear, wMonth wDay, wHour, wMin, wSec, wMilliSec: Word;
SWeek, sMonth: string;
The begin
DecodeDateTime (ADate wYear, wMonth wDay, wHour, wMin, wSec, wMilliSec);
WWeek: DayOfWeek=(ADate);
SWeek:=WEEK [wWeek];
SMonth:=MonthDig [wMonth];
Result:=Format (' % s, %, 2 % d % d % s. 2 d: %. The 2 d: %. The 2 d GMT ', [sWeek wDay, sMonth, wYear, wHour, wMin, wSec]);
The end;

//encryption algorithm from http://fundementals.sourceforge.net
The function signString (source, secret: AnsiString) : string;
Var
D: T160BitDigest;
The begin
D:=CalcHMAC_SHA1 (secret, source);
The Result: string=(EncodeBase64 (@ db ytes, Length (db ytes)));
The end;

The function composeStringToSign (method, contentMD5, contentType, date, signHeaders, resource: string) : string;
The begin
Result:=method + # 10 + contentMD5 + # 10 + contentType + # 10 + date + # 10 + signHeaders + resource;
The end;

The function invokeAliOSS (objName, fileName, method: PChar; AHost, Bucket, AccessKey, AccessSecret: PChar) : Boolean; Stdcall;
Var
VItem: TRESTRequestParameter;
StringToSign, signature, sDate, resource, accessKeyId accessKeySecret: string;
BucketID, path, host, sContentType contentMD5: string;
ContentType: TRESTContentType;
D: T128BitDigest;
AStream: TMemoryStream;
LBytes: TBytes;
The req: TRESTRequest;
The begin

Result:=False;
If not FileExists (fileName) then
The Exit;
Try

If not Assigned (Form1) then
Form1:=TForm1. Create (nil);

The req:=Form1. RESTRequest1;

BucketID:=Bucket;//
Path:='/' + objName;
Host:=AHost;
Host:=LowerCase (host);
Host:=StringReplace (host 'http://', ' ', [rfReplaceAll rfIgnoreCase]);
If Length (the host) & gt; 0 then
If the host [Length (the host)]='/' then
Delete (host, Length (the host), 1);
Host:=bucketID + '+ host;
ContentType:=TRESTContentType. CtIMAGE_JPEG;//TRESTContentType. CtAPPLICATION_OCTET_STREAM;//TRESTContentType. CtIMAGE_JPEG;//
SContentType:=ContentTypeToString (TRESTContentType. CtIMAGE_JPEG);//'application/octet - stream;//'application/json;
AccessKeyId:=the AccessKey;
AccessKeySecret:=AccessSecret;
AStream:=TMemoryStream. Create;
Try
//sDate='Tue, 13 Mar 2018 03:11:33 GMT;
SDate=DateTimeToGMT (TTimeZone. Local. ToUniversalTime (Now ()));
Resource:='/' + + objName bucketID + '/';
The req. ClearBody ();
The req. Params. The Clear ();

//the req. Client. BaseURL:='http://localhost:8080' + path;
The req. Client. BaseURL:='https://' + host + path;

AStream. LoadFromFile (fileName);
SetLength (LBytes, AStream. Size);
AStream. Seek (0, TSeekOrigin. SoBeginning);
AStream. Read (LBytes, 0, AStream. Size);
The req. AddBody (AStream);

D:=CalcMD5 (LBytes [0], AStream. Size);
ContentMD5: string=(EncodeBase64 (@ db ytes, Length (db ytes)));
The finally
AStream. Free;
The end;

StringToSign:=composeStringToSign (method, contentMD5 sContentType, sDate, ' ', the resource).
Signature:=signString (AnsiString (stringToSign), AnsiString (accessKeySecret));

VItem:=the req. Params. AddItem;
VItem. Kind:=TRESTRequestParameterKind. PkHTTPHEADER;
VItem. ContentType:=contentType;
VItem. Options:=[TRESTRequestParameterOption poDoNotEncode];
VItem. Name:='authorization';
VItem. Value:='OSS + accessKeyId +', '+ signature;

VItem:=the req. Params. AddItem;
VItem. Kind:=TRESTRequestParameterKind. PkHTTPHEADER;
VItem. ContentType:=contentType;
VItem. Options:=[TRESTRequestParameterOption poDoNotEncode];
VItem. Name:='host';
VItem. Value:=host;

VItem:=the req. Params. AddItem;
VItem. Kind:=TRESTRequestParameterKind. PkHTTPHEADER;
VItem. ContentType:=contentType;
VItem. Options:=[TRESTRequestParameterOption poDoNotEncode];
VItem. Name:='date';
VItem. Value:=sDate;

VItem:=the req. Params. AddItem;
VItem. Kind:=TRESTRequestParameterKind. PkHTTPHEADER;
VItem. ContentType:=contentType;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related