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)
小微生态门户-文档详情接口文档是这个,报519错,但是狐表只能看到200返回的提示,所以具体报什么错不清楚
或者狐表考虑升级一下这个地方吗,可以接收除200以外的提示
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", "***")
咦,我用apipost的时候没报错,看来是直接帮我转义了,感谢蓝版