Foxtable(狐表)用户栏目专家坐堂 → 百度接口在狐表怎么写?


  共有3862人关注过本帖树形打印复制链接

主题:百度接口在狐表怎么写?

帅哥哟,离线,有人找我吗?
lxhmax
  1楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:636 积分:5699 威望:0 精华:0 注册:2012/8/2 19:04:00
百度接口在狐表怎么写?  发帖心情 Post By:2023/4/19 22:31:00 [显示全部帖子]

请问老师,这个百度智能外呼的接口获取token在狐表里要怎么写?

https://cloud.baidu.com/doc/CCC/s/ikt3q5j2y

 回到顶部
帅哥哟,离线,有人找我吗?
lxhmax
  2楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:636 积分:5699 威望:0 精华:0 注册:2012/8/2 19:04:00
  发帖心情 Post By:2023/4/20 11:48:00 [显示全部帖子]

请问老师,这个接口在狐表可以写出来吗?

 回到顶部
帅哥哟,离线,有人找我吗?
lxhmax
  3楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:636 积分:5699 威望:0 精华:0 注册:2012/8/2 19:04:00
  发帖心情 Post By: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
  4楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:636 积分:5699 威望:0 精华:0 注册:2012/8/2 19:04:00
  发帖心情 Post By: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
  5楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:636 积分:5699 威望:0 精华:0 注册:2012/8/2 19:04:00
  发帖心情 Post By:2023/4/20 17:40:00 [显示全部帖子]

老师,可以帮忙看下吗?

 回到顶部
帅哥哟,离线,有人找我吗?
lxhmax
  6楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:636 积分:5699 威望:0 精华:0 注册:2012/8/2 19:04:00
  发帖心情 Post By:2023/4/21 14:59:00 [显示全部帖子]

老师,下面这个能在狐表实现获取到token吗?麻烦老师指教下,没其他语言的基础,看不懂,谢谢啦

java SDK使用示例

平台提供Token认证的java sdk,支持开发者直接调用获取Token。

sdk jar包地址:https://bce-doc-on.bj.bcebos.com/bce-documentation/CCC/cf-auth-api-token-5.1.5-SNAPSHOT-jar-with-dependencies.jar

Maven POM文件 引入SDK jar包

     <dependencies>
        <dependency>
            <groupId>com.baidu.contact-center</groupId>
            <artifactId>cf-auth-api-token</artifactId>
            <version>5.1.5-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>/Users/lihuiyao01/Desktop/cf-auth-api-token-5.1.5-SNAPSHOT-jar-with-dependencies.jar</systemPath>
        </dependency>
    </dependencies>

SDK 示例代码

    public class TokenGenerate {
    public static void main(String[] args) {
        ApiTokenV1.ApiAuthTokenV1Builder builder = new ApiTokenV1.ApiAuthTokenV1Builder();
        // 必填参数 ak,sk,uri,host,http method, 过期时间
        builder.ak("ac92a217bb4f43ebbfe31cda859f647e");   // ak
        builder.sk("c5432f291e2d472395348d399a8d8640");   // sk
        builder.uri("/api/v1/robot/list");                // 接口路径
        builder.host("aicc.bce.baidu.com");               // host
        builder.httpMethod("GET");                        // http method
        builder.expireInSeconds(1800);                    // 过期时间

        // 以下是非必须参数
        // 参与生成token的请求头, 此处若使用了x-bce-date,则调用外呼api接口时,请求头内必需带上x-bce-date
        HashMap<String, String> headerMap = new HashMap<String, String>();
        headerMap.put("x-bce-date", "2021-10-12T10:02:14Z");
        builder.httpHeaderMap(headerMap);
        // builder.httpHeader("Content-Type", "application/json");

        // url里?带的参数,如/api/v1/robot/list?robotName=test, 没有?参数可以不调用此方法
        builder.queryStr("robotName=test&pn=1");
        System.out.println(builder.build().getToken());
    }
    }

 回到顶部