- 积分
- 50
- 阅读权限
- 100
- 鲜花
- 0
- 猫粮
- 184
- 在线时间
- 82 小时
- 精华
- 0
- 注册时间
- 2018-5-1
- 性别
- 保密
- 最后登录
- 2024-2-10
易语言游戏编程班学员
- 鲜花
- 0
- 猫粮
- 184
|
发表于 2020-3-13 18:47:31
|
显示全部楼层
Dim bs64
Dim tokenid
Dim path
path= "C:\Users\Administrator\Desktop\1.PNG" //图片路径自选
tokenid = gettokenid()
bs64 = BToBase64(path)
bs64 = URLEncode(bs64)
TracePrint postret
Import "C:\vbsjson.vbs"
Set json = New vbsJson
Set o = json.Decode(postret)
//返回 = o("words_result")(0)("words")
//If 返回 > "" Then
//TracePrint 返回
//End If
Function Postret()
Dim BodyTXT
Set WinHttp = CreateObject("Microsoft.XMLHTTP")
WinHttp.Open "POST", "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token="&tokenid, False
WinHttp.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
WinHttp.SetRequestHeader "Content-Length", len(bs64)
WinHttp.Send("&image=" & bs64 )
// 超时设置 60秒 默认
j = 0
i = Now
Do
Delay 100
j = DateDiff("s", i, Now)
Loop Until (WinHttp.ReadyState = 4 Or j > 60)
BodyTXT = winhttp.responsetext
If Len(BodyTXT) = 0 Then
Postret = ""
Exit Function
End If
Postret = BodyTXT
End Function
Function BToBase64(path)
Dim ADS,MSD, node
Set ADS = CreateObject("ADODB.Stream")
ADS.Type = 1
ADS.Open
ADS.LoadFromFile path'加载图片,path为图片路径
Set MSD = CreateObject("Msxml2.DOMDocument")
Set node = MSD.CreateElement("Base64Data")
node.DataType = "bin.base64"
node.NodeTypedValue = ADS.Read()
BToBase64 = node.Text
Set node = Nothing
Set MSD = Nothing
Set ADS = Nothing
End Function
Function URLEncode(EncodeStr)
Dim i
Dim erg
erg = EncodeStr
' *** First replace '%' chr
erg = Replace(erg, "%", Chr(1))
' *** then '+' chr
erg = Replace(erg, "+", Chr(2))
For i = 0 To 255
If i=1 or i =37 or i = 43 or (i >=48 and i <= 57) or (i>=65 and i <=90 ) or (i>=97 and i <=122)
Delay 1
ElseIf i = 2
erg = Replace(erg, Chr(i), "%2B")
ElseIf i = 32
erg = Replace(erg, Chr(i), "+")
Elseif (i>=3 and i <=15 )
erg = Replace(erg, Chr(i), "%0" & Hex(i))
Else
erg = Replace(erg, Chr(i), "%" & Hex(i))
End If
Next
URLEncode = erg
End Function
Function gettokenid()
Dim sendstr
Dim Bodytext
dim tokedid
Dim arr, brr
//client_id与client_secret的值需替换成你自己百度ocr的
sendstr = "&grant_type=client_credentials&client_id=你的ID&client_secret=你的ID"
Set WinHttp = CreateObject("Microsoft.XMLHTTP")
WinHttp.Open "POST", "https://aip.baidubce.com/oauth/2.0/token", False
WinHttp.SetRequestHeader "Content-Type", "text/html"
WinHttp.SetRequestHeader "Content-Length", len(sendstr)
WinHttp.Send( sendstr )
// 超时设置 60秒 默认
j = 0
i = Now
Do
Delay 100
j = DateDiff("s", i, Now)
Loop Until (WinHttp.ReadyState = 4 Or j > 60)
// TracePrint winhttp.responsetext
arr = Split(winhttp.responsetext, "access_token")
brr = Split(arr(1), chr(34))
gettokenid = brr(2)
End Function |
评分
-
查看全部评分
|