asp的api获取数据接口
gyx521lw 发布于2019-03 浏览:26542 回复:4
0
收藏
<%
dim client_id:client_id="" ' 应用的API Key;
dim client_secret:client_secret="" ' 应用的Secret Key;

dim post_data:post_data="{""text"": ""2019诺思星快手电商班精华浓缩版VIP教程(5)""}"

response.write access_token
response.write post_content

' 获取返回数据
function post_content()
	dim api_url:api_url = "https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer"
	dim json:json = post_https(api_url&"?charset=UTF-8&access_token="&access_token,post_data)
	dim obj
	set obj = parseJSON(json)

	post_content = json
	' 遍历解析JSON不会了 哈哈

	set obj = Nothing
end function

' 获取access_token
function access_token()
	dim access_token_url:access_token_url = "https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id="&client_id&"&client_secret="&client_secret&"" ' 组合获取access_token网址
	dim obj
	set obj = parseJSON(post_https(access_token_url,""))
	access_token = obj.access_token
	set obj = Nothing
end function

' 解析json
Dim scriptCtrl
Function parseJSON(str)
	If Not IsObject(scriptCtrl) Then
			Set scriptCtrl = Server.CreateObject("MSScriptControl.ScriptControl")
			scriptCtrl.Language = "JScript"
			scriptCtrl.AddCode "Array.prototype.get = function(x) { return this[x]; }; var result = null;"
	End If
	scriptCtrl.ExecuteStatement "result = " & str & ";"
	Set parseJSON = scriptCtrl.CodeObject.result
End Function

' post获取数据函数
public function post_https(post_url,post_data)
	dim https
	set https = server.createobject("msxml2.xmlhttp")
	with https
	.open "post", post_url, false
	.setrequestheader "content-type","application/json"
	.send post_data
	post_https = .responsebody
	end with
	post_https = bytestobstr(post_https,"UTF-8")
	set https = nothing
end function

' 转换编码
function bytestobstr(body,cset)
	dim objstream
	set objstream = server.createobject("adodb.stream")
		objstream.type = 1
		objstream.mode =3
		objstream.open
		objstream.write body
		objstream.position = 0
		objstream.type = 2
		objstream.charset = cset
		bytestobstr = objstream.readtext
		objstream.close
	set objstream = nothing
end function
%>
收藏
点赞
0
个赞
共4条回复 最后由Swigheart回复于2021-12
#5Swigheart回复于2021-12

这个编译器是怎么识别汉字的?

0
#4asdsadd4回复于2020-04

http://parkv21-clota.galasystrip.com

0
#3xjzlmy回复于2019-12

用这个代码,调试文字识别的接口,"https://aip.baidubce.com/rest/2.0/ocr/v1/general

图片用url,结果显示错误信息:"error_code": 216101, "error_msg": "param image not exist"

url肯定是没错的,直接测试都是可以的。

什么原因?

0
#2低调的男人666回复于2019-08

1

0
TOP
切换版块