以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  调用GET接口,传同样的参数,apipost能正常返回,狐表报错  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=193918)

--  作者:wudishaoshuai
--  发布时间:2024/10/25 11:59:00
--  调用GET接口,传同样的参数,apipost能正常返回,狐表报错
Dim st As New Date(1970, 1, 1, 8, 0, 0)
Dim timestamp As Long = (Date.Now - st).Totalseconds() * 1000
Dim Secret As String
Dim appSecret As String
Dim xyz As String

Dim myEncoder1 As New System.Text.UTF8Encoding
Dim myHMACSHA2561 As New System.Security.Cryptography.HMACSHA256(myEncoder1.getBytes("fe1dc7cc04f71a67656eb1cf7c64e10a87660a10"))
Dim hashSign1() As Byte = myHMACSHA2561.ComputeHash(myEncoder1.getBytes("xZh4CZ8o"))
Dim b1 As Byte() = System.Text.Encoding.UTF8.GetBytes(BitConverter.ToString(hashSign1).replace("-", "").ToLower())
Secret = Convert.ToBase64String(b1)
appSecret = PercentEncode(Secret)
appSecret = PercentEncode(appSecret)

Dim secretKey As String = "4d6fead97c45340dcf37ef98a6341c8e" \'\'\'私钥
Dim signStr As String = "GET" & Chr(10) & "%2Fjdyconnector%2Fapp_management%2Fkingdee_auth_token" & Chr(10) & "app_key=xZh4CZ8o&" & "app_signature=" & appSecret & Chr(10) & "x-api-nonce:" & timestamp & Chr(10) & "x-api-timestamp:" & timestamp & Chr(10)
Dim myEncoder As New System.Text.UTF8Encoding
Dim myHMACSHA256 As New System.Security.Cryptography.HMACSHA256(myEncoder.getBytes(secretKey))
Dim hashSign() As Byte = myHMACSHA256.ComputeHash(myEncoder.getBytes(signStr))
Dim b As Byte() = System.Text.Encoding.UTF8.GetBytes(BitConverter.ToString(hashSign).replace("-", "").ToLower())
Dim base64 = Convert.ToBase64String(b)

Dim hc As New HttpClient("https://api.kingdee.com/jdyconnector/app_management/kingdee_auth_token?app_key=xZh4CZ8o&app_signature=MGU1ZGQzZjFjYWU5NDg4Nzg1Y2RmYmViMjUyYjhjNDZjNTk3ZTEyNWM1NGE1N2M3MzAxZjI2MmQ0ZGUyOGQzYg==")
\'hc.Method = "GET"
hc.Headers.Add("X-Api-ClientID", "***")
hc.Headers.Add("X-Api-Auth-Version", "2.0")
hc.Headers.Add("X-Api-TimeStamp", timestamp)
hc.Headers.Add("X-Api-SignHeaders", "X-Api-TimeStamp,X-Api-Nonce")
hc.Headers.Add("X-Api-Nonce", timestamp)
hc.Headers.Add("X-Api-Signature", base64)

Output.Show("timestamp=" & timestamp)
Output.Show("Secret=" & Secret)
Output.Show("base64=" & base64)

Output.Show(hc.GetData)

--  作者:有点蓝
--  发布时间:2024/10/25 12:03:00
--  
报什么错?接口文档发上来看看
--  作者:wudishaoshuai
--  发布时间:2024/10/25 13:40:00
--  
小微生态门户-文档详情接口文档是这个,报519错,但是狐表只能看到200返回的提示,所以具体报什么错不清楚
--  作者:wudishaoshuai
--  发布时间:2024/10/25 14:03:00
--  
或者狐表考虑升级一下这个地方吗,可以接收除200以外的提示
--  作者:有点蓝
--  发布时间:2024/10/25 14:06:00
--  
app_signature里的内容要进行urlencode处理

Dim hc As New HttpClient("https://api.kingdee.com/jdyconnector/app_management/kingdee_auth_token?app_key=xZh4CZ8o&app_signature=MGU1ZGQzZjFjYWU5NDg4Nzg1Y2RmYmViMjUyYjhjNDZjNTk3ZTEyNWM1NGE1N2M3MzAxZjI2MmQ0ZGUyOGQzYg%3D%3D")
\'hc.Method = "GET"
hc.ContentType = "application/json"
hc.Headers.Add("Content-Type", "application/json")
hc.Headers.Add("X-Api-ClientID", "***")

--  作者:wudishaoshuai
--  发布时间:2024/10/25 14:21:00
--  
咦,我用apipost的时候没报错,看来是直接帮我转义了,感谢蓝版