以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]这个api怎么写? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=158360) |
||||||
-- 作者:zto001 -- 发布时间:2020/11/17 16:44:00 -- [求助]这个api怎么写? [求助]这个api怎么写? Dim hc As New HttpClient("http://api.map.baidu.com/place/v2/search?") hc.c hc.Timeout = 5 \'设置超时为5秒 Dim jo As new JObject jo("query") = "关键词" jo("region") = "行政区划" jo("ak") = "ak" jo("sn") = "sn" jo("timestamp") = "时间戳" hc.Content = jo.ToString Dim ret As String = hc.GetData() MessageBox.Show(ret) 是这样吗? [此贴子已经被作者于2020/11/17 16:56:20编辑过]
|
||||||
-- 作者:zto001 -- 发布时间:2020/11/17 16:57:00 -- 编码说明
sn计算算法 |
||||||
-- 作者:zto001 -- 发布时间:2020/11/17 16:58:00 -- 这一步不是太懂 |
||||||
-- 作者:有点蓝 -- 发布时间:2020/11/17 17:38:00 -- 这种是get模式,直接拼字符串 Dim hc As New HttpClient("http://api.map.baidu.com/place/v2/search?query=天安门®ion=北京&city_limit=true&output=json&ak=你的ak") Dim ret As String = hc.GetData() MessageBox.Show(ret) |
||||||
-- 作者:zto001 -- 发布时间:2020/11/18 21:55:00 -- sn的计算方法 是要哪种方法转成狐表能写的代码
|
||||||
-- 作者:有点蓝 -- 发布时间:2020/11/19 8:44:00 -- 看c#的代码。转换为vb.net参考:http://converter.telerik.com/ |
||||||
-- 作者:zto001 -- 发布时间:2020/11/19 14:02:00 -- Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Text Public Class AKSNCaculater Private Shared Function MD5(ByVal password As String) As String Dim textBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(password) Try Dim cryptHandler As System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler = New System.Security.Cryptography.MD5CryptoServiceProvider() Dim hash As Byte() = cryptHandler.ComputeHash(textBytes) Dim ret As String = "" For Each a As Byte In hash ret += a.ToString("x") Next Return ret Catch Throw End Try End Function Private Shared Function UrlEncode(ByVal str As String) As String str = System.Web.HttpUtility.UrlEncode(str) Dim buf As Byte() = Encoding.ASCII.GetBytes(str) For i As Integer = 0 To buf.Length - 1 If buf(i) = "%"c Then If buf(i + 1) >= "a"c Then buf(i + 1) -= 32 If buf(i + 2) >= "a"c Then buf(i + 2) -= 32 i += 2 End If Next Return Encoding.ASCII.GetString(buf) End Function Private Shared Function HttpBuildQuery(ByVal querystring_arrays As IDictionary(Of String, String)) As String Dim sb As StringBuilder = New StringBuilder() For Each item In querystring_arrays sb.Append(UrlEncode(item.Key)) sb.Append("=") sb.Append(UrlEncode(item.Value)) sb.Append("&") Next sb.Remove(sb.Length - 1, 1) Return sb.ToString() End Function Public Shared Function CaculateAKSN(ByVal ak As String, ByVal sk As String, ByVal url As String, ByVal querystring_arrays As IDictionary(Of String, String)) As String Dim queryString = HttpBuildQuery(querystring_arrays) Dim str = UrlEncode(url & "?" & queryString & sk) Return MD5(str) End Function End Class 转换过来了,是放全局代码还是? 哪里需要修改下 [此贴子已经被作者于2020/11/19 14:02:28编辑过]
|
||||||
-- 作者:有点蓝 -- 发布时间:2020/11/19 14:11:00 -- 去掉前面4句Imports语句,放到全局代码 调用比如:msgbox(AKSNCaculater.MD5("123456"))
|
||||||
-- 作者:zto001 -- 发布时间:2020/11/19 15:55:00 -- 编译错误:没有为类型"Byte"和Char"定义运算符”=”。 错误代码:lf buf(0= "%"c Then 放到全局代码提示这样
|
||||||
-- 作者:有点蓝 -- 发布时间:2020/11/19 16:04:00 -- If buf(i) = "%"c Then 改为 If buf(i) = Asc("%") Then
|