delphi7调用EasyDL
xcc67841782 发布于2019-01-23 22:07 浏览:1150 回复:5
1
收藏
快速回复

fssl := TIdSSLIOHandlerSocket.Create(nil);
FTxtFileName :=ExtractFilePath(paramstr(0))+'base2.txt';
AssignFile(txtFile,FTxtFileName);
rewrite(txtFile);
write(txtFile,'{"top_num":5,"image":"');

fssl.SSLOptions.Method :=sslvSSLv3;
fssl.SSLOptions.Mode :=sslmClient;

IdHTTP1 :=TIdHTTP.Create(nil);

with IdHTTP1 do
begin
HandleRedirects :=true;
ProtocolVersion:=pv1_1;
Request.Connection:='Keep-Alive';
Request.Accept := 'text/javascript';
Request.ContentType := 'application/json';
Request.ContentEncoding := 'utf-8';
IOHandler :=fssl;
end;

jsonToSendMem :=TMemoryStream.Create;
BitmapBase64ToStr(AImageFile,FBase64Str);
write(txtFile,FBase64Str);
write(txtFile,'"}');
closefile(txtFile);

jsontosendmem.LoadFromFile(FTxtFileName);
jsonToSendMem.Position :=0;

try
FStrTemp := IdHTTP1.Post(BAIDU_URL,jsonToSendMem);

 

一个80后老大叔写的delphi7调用baidu EasyDL API的部分代码。直接用摄像头拍照,把bmp转换成jpg格式,通过CnVCL转换成base64(delphi自带的转换太慢)。

收藏
点赞
1
个赞
共5条回复 最后由ei柯步e回复于2020-03-07 16:52
#6ei柯步e回复于2020-03-07 16:52:15

https://www.jianshu.com/p/efb231a4669a

0
#5ei柯步e回复于2020-03-07 16:51:52

https://www.jianshu.com/p/173019d6e13f

0
#4136*****767回复于2019-06-29 23:06:53

这是VB 调用 easyDL api 

Private Function getToken()

Dim xmlhttp
Dim url

Set xmlhttp = CreateObject("msxml2.xmlhttp")
With xmlhttp
url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=xxxxxx&client_secret=xxxxx"

.Open "POST", url, False '////填网址
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.send "MENU=200&code=1540&JOB=VOTE" '////填写所需send的内容
Dim p As Object, key As Variant
Set p = JSON.parse(.responseText)
getToken = p.Item("access_token")
'Text2.Text = .responseText
'MsgBox .responseText '显示POST之后网页返回的结果

End With
Set xmlhttp = Nothing

End Function

Private Function sendPic(Token As String)'发送base64 图像文件 解析反馈结果
Dim xmlhttp
Dim url
Dim p As Object

Set xmlhttp = CreateObject("msxml2.xmlhttp")
With xmlhttp

url = "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/classification/xxxx?access_token=" & Token

.Open "POST", url, False '////填网址
.setRequestHeader "Content-Type", "application/json"
.send TXTImg.Text '////填写所需send的内容
Respone.Text = .responseText
Set p = JSON.parse(.responseText)

nook.Text = JSONParse("results[0].score", toString(p)) * 100  '解析Json 结果
ok.Text = JSONParse("results[1].score", toString(p)) * 100
End With
Set xmlhttp = Nothing

End Function

Public Function JSONParse(ByVal JSONPath As String, ByVal JSONString As String) As Variant
Dim JSON As Object
Set JSON = CreateObject("MSScriptControl.ScriptControl")
JSON.Language = "JScript"
JSONParse = JSON.Eval("JSON=" & JSONString & ";JSON." & JSONPath & ";")
Set JSON = Nothing
End Function

0
#3czrjcn回复于2019-05-14 21:02:07

把代码搞全一下,我也80后DELPHI7的,想用

0
#2付洋洋carrie回复于2019-01-24 22:07:56

厉害了

0
TOP
切换版块