以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 百度接口在狐表怎么写? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=186295) |
-- 作者:lxhmax -- 发布时间:2023/4/19 22:31:00 -- 百度接口在狐表怎么写? 请问老师,这个百度智能外呼的接口获取token在狐表里要怎么写? https://cloud.baidu.com/doc/CCC/s/ikt3q5j2y
|
-- 作者:lxhmax -- 发布时间:2023/4/20 11:48:00 -- 请问老师,这个接口在狐表可以写出来吗? |
-- 作者:有点蓝 -- 发布时间:2023/4/20 12:07:00 -- 没时间研究。加密算法有点像这个:http://www.foxtable.com/webhelp/topics/3389.htm |
-- 作者:lxhmax -- 发布时间:2023/4/20 13:41:00 -- 老师,下面这个是GPT翻译过来的,有很多报错,我调整不过来,麻烦老师看下能不能调试出来,万分感谢! \' 1.AK/SK?host?method?URL绝对路径?querystring Dim AK As String: AK = "07b2391cee0f40bd806c6318a572b3ef" Dim SK As String: SK = "83195d93149b4692821cfb424482b961" Dim host As String: host = "localhost:8080" Dim method As String: method = "POST" Dim query As String: query = "" Dim URI As String: URI = "/api/test" \' 2.x-bce-date Dim x_bce_date As String: x_bce_date = Format(Now(), "yyyy-mm-ddThh:nn:ssZ") \' 3.header和signedHeaders Dim header As New Dictionary header("Host") = host Dim signedHeaders As String: signedHeaders = "host" \' 4.认证字符串前缀 Dim authStringPrefix As String: authStringPrefix = "cc-api-auth-v1" + "/" + AK + "/" + x_bce_date + "/" + "1800" Debug.Print "authStringPrefix=" & authStringPrefix \' 5.生成CanonicalRequest \' 5.1生成CanonicalURI Dim CanonicalURI As String: CanonicalURI = EncodeUrl(URI) \' 5.2生成CanonicalQueryString Dim CanonicalQueryString As String: CanonicalQueryString = query \' 5.3生成CanonicalHeaders Dim CanonicalHeaders As String Dim keys As Variant: keys = header.Keys Dim i As Long For i = 0 To header.Count - 1 CanonicalHeaders = CanonicalHeaders & EncodeUrl(LCase(keys(i))) & ":" & EncodeUrl(header(keys(i))) & vbCrLf Next CanonicalHeaders = Left(CanonicalHeaders, Len(CanonicalHeaders) - 2) \' 5.4拼接得到CanonicalRequest Dim CanonicalRequest As String: CanonicalRequest = method & vbCrLf & CanonicalURI & vbCrLf & CanonicalQueryString & vbCrLf & CanonicalHeaders Debug.Print "Can"> \' 6.生成signingKey Dim signingKey As Object Set signingKey = CreateObject("System.Security.Cryptography.HMACSHA256") signingKey.Key = StrConv(SK, vbFromUnicode) Dim authStringPrefixBytes As Variant authStringPrefixBytes = StrConv(authStringPrefix, vbFromUnicode) signingKey.ComputeHash authStringPrefixBytes Dim signingKeyHash As String signingKeyHash = HexToString(signingKey.Hash) Debug.Print "signingKey=" & signingKeyHash \' 7.生成Signature Dim Signature As Object Set Signature = CreateObject("System.Security.Cryptography.HMACSHA256") Signature.Key = StrConv(signingKeyHash, vbFromUnicode) Dim CanonicalRequestBytes As Variant CanonicalRequestBytes = StrConv(CanonicalRequest, vbFromUnicode) Signature.ComputeHash CanonicalRequestBytes Dim SignatureHash As String SignatureHash = HexToString(Signature.Hash) Debug.Print "Signature=" & SignatureHash \' 8.生成Authorization并放到header里 Debug.Print "token=" & authStringPrefix & "/" & signedHeaders & "/" & SignatureHash |
-- 作者:lxhmax -- 发布时间:2023/4/20 16:02:00 -- 老师,我改到下面这样子了,一直提示"远程服务器返回错误: (401) 未经授权。", 麻烦老师帮我看下是哪里出错了可以吗?谢谢啦 AK,SK,robotId都是真实的 Dim AK As String: AK = "1111" Dim SK As String: SK = "222" Dim host As String : host = "localhost:8080" Dim method As String : method = "POST" Dim URI As String : URI = "/api/test" \' 计算x_bce_date和authStringPrefix Dim x_bce_date As String: x_bce_date = Format(Date.Now, "yyyy-MM-ddTHH:mm:ssZ") Output.Show(x_bce_date) Dim authStringPrefix As String: authStringPrefix = "cc-api-auth-v1/" & AK & "/" & x_bce_date & "/1800" \' 计算CanonicalRequest \'Dim CanonicalRequest As String: CanonicalRequest = method & vbCrLf & URI & vbCrLf & "" & vbCrLf & "host:" & host & vbCrLf & "host" & vbCrLf & "UNSIGNED-PAYLOAD" Dim CanonicalRequest As String: CanonicalRequest = method & "\\n" & URI & "\\n" & "" & "\\n" & "host:" & host & "\\n" & "host" & "\\n" & "UNSIGNED-PAYLOAD" \' 计算signingKey和Signature Dim signingKey As Object signingKey = CreateObject("System.Security.Cryptography.HMACSHA256") signingKey.Key = System.Text.Encoding.Unicode.GetBytes(SK) Dim authStringPrefixBytes As Object authStringPrefixBytes = System.Text.Encoding.Unicode.GetBytes(authStringPrefix) signingKey.ComputeHash( authStringPrefixBytes) Dim signingKeyHash As Byte(): signingKeyHash = signingKey.Hash Dim Signature As Object Signature = CreateObject("System.Security.Cryptography.HMACSHA256") Signature.Key = signingKeyHash Dim CanonicalRequestBytes As Byte(): CanonicalRequestBytes = System.Text.Encoding.Unicode.GetBytes(CanonicalRequest) Signature.ComputeHash (CanonicalRequestBytes) Dim SignatureHash As Byte(): SignatureHash = Signature.Hash \' 生成Authorization并放到header里 Dim Authorization As String: Authorization = authStringPrefix & "/host/" For i As Integer = 0 To UBound(SignatureHash) Authorization = Authorization & Right("0" & Hex(SignatureHash(i)), 2) Next output.show("token=" & Authorization) Dim hc As New HttpClient("https://aicc.bce.baidu.com/api/v3/console/realtime/status/create") hc.Conte ntType = "application/json" \' hc.FormData.Add("Authorization",Authorization) Dim jo As New JObject jo("robotId") = CStr("333") jo("mobile") = CStr("12345678901") jo("secretType") = CStr("2") Dim ja As New JArray jo("dialogVar") = ja ja.Add(New JObject) \'给数组添加两个对象成员 ja(0)("xqmc") = CStr("小区") ja(0)("khmc") = CStr("张先生") ja(0)("rwsj") = CStr("下午三点") ja(0)("rwnr") = CStr("带看") hc.Content = jo.ToString Dim ret As String = hc.GetData Output.Show( "识别结果JSON: " & vbcrlf & ret) [此贴子已经被作者于2023/4/21 13:27:26编辑过]
|
-- 作者:lxhmax -- 发布时间:2023/4/20 17:40:00 -- 老师,可以帮忙看下吗? |
-- 作者:有点蓝 -- 发布时间:2023/4/20 20:21:00 -- 提示权限问题一般是加密的数据不符合规定 1、合成的字符串格式不符合要求,比如使用的符号、大小写、编码....... 2、合成的字符串参数的顺序不一致 3、加密算法不正确 没有时间研究。建议理解一下3楼帮助的用法,这个帮助仅仅去理解阿里云签名算法我都花了整整2天时间
|
-- 作者:lxhmax -- 发布时间:2023/4/21 14:59:00 -- 老师,下面这个能在狐表实现获取到token吗?麻烦老师指教下,没其他语言的基础,看不懂,谢谢啦java SDK使用示例平台提供Token认证的java sdk,支持开发者直接调用获取Token。 Maven POM文件 引入SDK jar包
SDK 示例代码
|
-- 作者:有点蓝 -- 发布时间:2023/4/21 15:08:00 -- java我也不懂,找对方要.net的例子 |