請問有哪位大神做過delphi7 通過api 連接亞馬遜MWS,能否提供一下對接思路和實體,小弟感激不盡。
uj5u.com熱心網友回復:
給你一個上傳阿里oss的代碼,類似
unit duAliYun_OSS;
interface
uses
REST.Client, system.JSON, system.SysUtils, Vcl.Dialogs;
function invokeAliOSS(objName, fileName, method: PChar; AHost, Bucket, AccessKey, AccessSecret: PChar): Boolean; stdcall;
implementation
uses
REST.Types, DateUtils, Soap.EncdDecd, cHash, system.Classes, system.NetEncoding,
dulogclass, IPPeerCommon, idhttp, fmclient;
function DateTimeToGMT(const ADate: TDateTime): string;
const
WEEK: array[1..7] of PChar = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
MonthDig: array[1..12] of PChar = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
var
wWeek, wYear, wMonth, wDay, wHour, wMin, wSec, wMilliSec: Word;
sWeek, sMonth: string;
begin
DecodeDateTime(ADate, wYear, wMonth, wDay, wHour, wMin, wSec, wMilliSec);
wWeek := DayOfWeek(ADate);
sWeek := WEEK[wWeek];
sMonth := MonthDig[wMonth];
Result := Format('%s, %.2d %s %d %.2d:%.2d:%.2d GMT', [sWeek, wDay, sMonth, wYear, wHour, wMin, wSec]);
end;
// 加密演算法來自http://fundementals.sourceforge.net
function signString(source, secret: AnsiString): string;
var
d: T160BitDigest;
begin
d := CalcHMAC_SHA1(secret, source);
Result := string(EncodeBase64(@d.Bytes, Length(d.Bytes)));
end;
function composeStringToSign(method, contentMD5, contentType, date, signHeaders, resource: string): string;
begin
Result := method + #10 + contentMD5 + #10 + contentType + #10 + date + #10 + signHeaders + resource;
end;
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;
req: TRESTRequest;
begin
Result := False;
if not FileExists(fileName) then
Exit;
try
if not Assigned(Form1) then
Form1 := TForm1.Create(nil);
req := Form1.RESTRequest1;
bucketID := Bucket; //
path := '/' + objName;
host := AHost;
host := LowerCase(host);
host := StringReplace(host, 'http://', '', [rfReplaceAll, rfIgnoreCase]);
if Length(host) > 0 then
if host[Length(host)] = '/' then
Delete(host, Length(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 := AccessKey;
accessKeySecret := AccessSecret;
AStream := TMemoryStream.Create;
try
// sDate:='Tue, 13 Mar 2018 03:11:33 GMT';
sDate := DateTimeToGMT(TTimeZone.local.ToUniversalTime(Now()));
resource := '/' + bucketID + '/' + objName;
req.ClearBody();
req.Params.Clear();
// req.Client.BaseURL:='http://localhost:8080'+path;
req.Client.BaseURL := 'https://' + host + path;
AStream.LoadFromFile(fileName);
SetLength(LBytes, AStream.Size);
AStream.Seek(0, TSeekOrigin.soBeginning);
AStream.Read(LBytes, 0, AStream.Size);
req.AddBody(AStream);
d := CalcMD5(LBytes[0], AStream.Size);
contentMD5 := string(EncodeBase64(@d.Bytes, Length(d.Bytes)));
finally
AStream.Free;
end;
stringToSign := composeStringToSign(method, contentMD5, sContentType, sDate, '', resource);
signature := signString(AnsiString(stringToSign), AnsiString(accessKeySecret));
vItem := req.Params.AddItem;
vItem.Kind := TRESTRequestParameterKind.pkHTTPHEADER;
vItem.contentType := contentType;
vItem.Options := [TRESTRequestParameterOption.poDoNotEncode];
vItem.Name := 'authorization';
vItem.Value := 'OSS ' + accessKeyId + ':' + signature;
vItem := req.Params.AddItem;
vItem.Kind := TRESTRequestParameterKind.pkHTTPHEADER;
vItem.contentType := contentType;
vItem.Options := [TRESTRequestParameterOption.poDoNotEncode];
vItem.Name := 'host';
vItem.Value := host;
vItem := req.Params.AddItem;
vItem.Kind := TRESTRequestParameterKind.pkHTTPHEADER;
vItem.contentType := contentType;
vItem.Options := [TRESTRequestParameterOption.poDoNotEncode];
vItem.Name := 'date';
vItem.Value := sDate;
vItem := req.Params.AddItem;
vItem.Kind := TRESTRequestParameterKind.pkHTTPHEADER;
vItem.contentType := contentType;
vItem.Options := [TRESTRequestParameterOption.poDoNotEncode];
vItem.Name := 'content-md5';
vItem.Value := contentMD5;
req.Accept := sContentType;
req.Client.contentType := sContentType;
//G_Log.WriteLogFile(req.Client.BaseURL);
if (method = 'PUT') then
req.method := TRESTRequestMethod.rmPUT
else if (method = 'GET') then
req.method := TRESTRequestMethod.rmGET;
req.Execute();
Result := req.Response.StatusCode = 200;
if Result = False then
G_Log.WriteLogFile(AnsiString(req.Response.Content));
except
on e: Exception do
begin
G_Log.WriteLogFile(AnsiString(e.Message));
G_Log.WriteLogFile(AnsiString(req.Response.Content));
end;
end;
end;
end.
uj5u.com熱心網友回復:
delphi xe10.1下開發的uj5u.com熱心網友回復:
感謝回復,好像代碼上好像沒有看到ID、密鑰、 商家提供授權和賣家Id等相關資訊,代碼沒有注釋,有點看不懂。uj5u.com熱心網友回復:
實體是沒有,這些介面重點基本都是先要做好簽名處理的功能,這個必須正確,做成統一的方法(類)什么的,方便使用。其次,網路介面就http/https協議,都一樣,主要是介面資料的處理不同。
最后要注意一點是介面處理流程,一定要詳細看說明檔案,理解透徹,別進了誤區。
還有一點,做介面,先做好作業難度大的思想準備作業。
亞馬遜國內區開發API的相關地址:
在線除錯器
https://mws.amazonservices.com.cn/scratchpad/index.html
亞馬遜商城網路服務(亞馬遜 MWS)中心
https://developer.amazonservices.com.cn/index.html
Amazon MWS 開發者指南 (HTML)
http://docs.developer.amazonservices.com/zh_CN/dev_guide/index.html
針對 FBA 賣家的亞馬遜 MWS (HTML)
http://docs.developer.amazonservices.com/zh_CN/fba_guide/index.html
API 參考 (HTML)
http://docs.developer.amazonservices.com/zh_CN/fba_inventory/index.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/8192.html
標籤:數據庫相關
上一篇:如何用matlab寫WGCNA?
