哪位大神做过delphi7 通过api 连接亚马逊MWS?

abc331540751 2020-08-11 03:20:55
请问有哪位大神做过delphi7 通过api 连接亚马逊MWS,能否提供一下对接思路和实例,小弟感激不尽。
...全文
413 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
david_jielin 2021-05-01
  • 打赏
  • 举报
回复
我也想了解用DELPHI 7 来开发,现在做的怎么样了, 可以交流一下吗
tanqth 2020-08-12
  • 打赏
  • 举报
回复
实例是没有,这些接口重点基本都是先要做好签名处理的功能,这个必须正确,做成统一的方法(类)什么的,方便使用。 其次,网络接口就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
abc331540751 2020-08-12
  • 打赏
  • 举报
回复
感谢回复,好像代码上好像没有看到ID、密钥、 商家提供授权和卖家Id等相关信息,代码没有注释,有点看不懂。
大肚肥肥 2020-08-11
  • 打赏
  • 举报
回复
delphi xe10.1下开发的
大肚肥肥 2020-08-11
  • 打赏
  • 举报
回复
给你一个上传阿里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.

2,496

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧