Tencent Cloud API 3.0 (signature V3) common interface Delphi version

        

Table of contents

1. Introduction to Tencent Cloud API 3.0:

2. Delphi interface function description:

1. Units included in the Delphi interface:

2. The difference between synchronous call and asynchronous call:

3. Example of program call:

3. Delphi version Tencent Cloud API version 3.0 interface function download

4. Demo program recording and broadcasting


Download the source code and Demo ( for a fee )

1. Introduction to Tencent Cloud API 3.0:

        Tencent Cloud API has been fully upgraded to API 3.0, realizing multi-regional deployment, supporting nearby access, significantly reducing access latency, standard interface design, detailed and comprehensive interface documents, rich and easy-to-use developer tools, allowing you to use it conveniently and quickly Tencent Cloud products.

        From January 1, 2023, the old version API 2.0 interface service has been stopped for new users, and the service is expected to be stopped on March 31, 2023 for existing users.

        Based on the above reasons, we have simultaneously updated and upgraded Delphi's original API 2.0 interface to API version 3.0. The upgraded version 3.0 has unified standards. The entire Tencent Cloud API uses a unified signature rule, but different interfaces call domain names, actions, and versions There is a difference.

Shortcut links to some documents in Communication Cloud:

serial number Function Link to Tencent Cloud Documentation
1 API Center General Entrance Cloud Product API Center_Cloud API Interface Center-Tencent Cloud
2 API 3.0 V3 signature method Text Recognition Signature Method v3-Call Method-API Center-Tencent Cloud
3 AI Conversation 3.0 Intelligent Wensheng Diagram AI Painting Intelligent Vincent Graph-Vensen Graph Related Interfaces-API Center-Tencent Cloud
4 AI Conversation 3.0 Smart Map Generation AI painting intelligent map generation-Graphic generation related interface-API Center-Tencent Cloud
5 ID card OCR recognition Text Recognition ID Card Recognition-Card Text Recognition Related Interface-API Center-Tencent Cloud

2. Delphi interface function description:

        Fully realize the V3 signature, and realize the HTTP-POST request function. Calling the Tencent API does not need to consider any details such as the signature. It only needs to construct the entry parameters of each function. It is very simple and does not require boring and time-consuming debugging! All Tencent Cloud API 3.0 calls can be realized.

1. Units included in the Delphi interface:
serial number unit illustrate
1 uTencent_V3_Core.Pas Complete the V3 signature and implement the HTTP-POST general request. Specifically, there is no need to call this unit function.
2 uTencent_V3_Interface.Pas Realized the synchronous and asynchronous call interface of intelligent Wenshengtu, smart map-generated diagram and ID card OCR recognition synchronous call interface, the actual call is this unit, which in turn calls uTencent_V3_Core.Pas unit.
2. The difference between synchronous call and asynchronous call:

        Since all APIs need to communicate with Tencent's background, due to network and other reasons, there may be a certain delay in receiving the results. In this way, if it is synchronous, it means that the function must receive the result before exiting. This will cause the UI to not move before the program receives the result, and the program seems to be stuck. If it is asynchronous, the program can still operate smoothly after calling, and the UI will not be locked. After the result comes back, it will be processed through the callback function.

Examples of specific functions are as follows (defined in the Tencent_V3_Interface.Pas unit):

//1. AI 文生图函数
//1.1 异步调用
procedure Asyn_Text2Image(const requestStr : string; ResultCallBack : TResultCallBack1); overload;
procedure Asyn_Text2Image(const requestStr : string; ResultCallBack : TResultCallBack2); overload;
//1.2 同步调用
function Sync_Text2Image(const requestStr : string; var responseStr : string ) : Boolean;

//2. AI 图生图函数
//2.1 异步调用
procedure Asyn_Image2Image(const requestStr : string; ResultCallBack : TResultCallBack1); overload;
procedure Asyn_Image2Image(const requestStr : string; ResultCallBack : TResultCallBack2); overload;
//2.2 同步调用
function Sync_Image2Image(const requestStr : string; var responseStr : string ) : Boolean;


//3. 身份证识别,同步
function Sync_IDCardOCR(const requestStr : string; var responseStr : string ) : Boolean;
3. Example of program call:

Example of synchronously calling a Vincent diagram:

procedure TForm1.SpeedButton1Click(Sender: TObject);
var
  requestStr : string;
  responseStr: string;
  jo : TJSONObject;
  T  : TDateTime;
begin
  T := Now;
  //生成请求的JSON字符串,具体需要根据腾讯API文档实现,不同API,请求参数不一样
  requestStr := Build_Text2Picture_RequesteJSONStr;
  //同步发送请求到腾讯后台,签名等已经实现,无需考虑
  if not Sync_Text2Image(requestStr, responseStr) then
     begin
       ShowMessage(responseStr);
       Exit;
     end;
  //等待结果,结果返回后转换成图片显示出来
  Base64toImage(responseStr,'A1.jpg');
  Image1.Picture.LoadFromFile('A1.jpg');

  //花费时间
  Label_Time.Caption := SecondsBetween(Now,T).ToString + ' S';
end;

Example of asynchronously calling a Vincent graph:

procedure TForm1.SpeedButton5Click(Sender: TObject);
var
  requestStr : string;
  responseStr: string;
  jo : TJSONObject;
begin
  ActivityIndicator1.Animate := True;
  T2 := Now;
  requestStr := Build_Image2Image_RequesteJSONStr;
  //注意 ResultCallBackA 是一个回调函数,回调函数支持对象的方法,也支持独立的函数,通过重载实现
  Asyn_Image2Image(requestStr,ResultCallBackA);
end;

Pay attention to the ResultCallBackA callback function. This callback function is a method of an object, specifically a method of the main From.

procedure TForm1.ResultCallBackA(ResultOK: Boolean; responseStr: string);
begin
  ActivityIndicator1.Animate := False;
  if not ResultOK then
     begin
       ShowMessage(responseStr);
       Exit;
     end;

  Base64toImage(responseStr,'A1.jpg');
  Image1.Picture.LoadFromFile('A1.jpg');
  //花费时间
  Label_Time.Caption := SecondsBetween(Now,T2).ToString + ' S';

end;

3. Delphi version Tencent Cloud API version 3.0 interface function download

Download link (paid)

The source code includes: all interface source programs, demonstration programs, and detailed documentation.

4. Demo program recording and broadcasting

 

Guess you like

Origin blog.csdn.net/sensor_WU/article/details/131719758