以文本方式查看主题 - 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=189924) |
-- 作者:fczhaobo -- 发布时间:2024/1/4 22:02:00 -- [求助]API接口狐表改造,请老师指教 ‘VB.net调用的参考代码: \'Private Sub SurroundingSub() \' Dim client = New RestClient("/tool/open_api/api/goods/cat-detail?id=<id>") \' client.Timeout = -1 \'无限超时为-1 \' Dim request = New RestRequest(Method.[GET]) ‘GET请求 \' request.AddHeader("X-Signature", "{{signature}}") \' request.AddHeader("X-Timestamps", "{{timestamps}}") \' request.AddHeader("X-Nonce", "{{nonce}}") \' request.AddHeader("X-Apikey", "{{api_key}}") \' client.UserAgent = "Apifox/1.0.0 (https://apifox.com)" ’标头 \' Dim response As IRestResponse = client.Execute(request) \' Console.WriteLine(response.Content) \'End Sub 下面是改造的代码,报错 \'\'\'所需参数 Dim hj_url As String = "https://mp.gswhcm.cn" \'服务器域名 Dim api_key As String = "open_sl7QZrwNPlHi_lOXz1CHyssz2NN" \'开放平台api_key Dim api_secret As String = "qmiRDg9pcv8_Sxb6N0Z_J08nmU12K9AC" \'api_secret Dim st As New Date(1970, 1, 1, 8, 0, 0) Dim timestamps As Integer = (Date.Now - st).TotalSeconds() \'X - Timestamps int 10 接口请求时间戳 Dim nonce As String = rand.NextString(32) \'X - Nonce String 32 随机字符串 \'\'\'生成签名步骤 Dim Strings As String = "id=1" Dim base64_temp As String = UrlEncode(api_secret & Strings & timestamps) \'进行base64_encode转义下得到数据base64_temp Dim temp As String = md5(Strings & base64_temp & api_secret & nonce) \'MD5加密 Dim dev_msg_signature As String = Ucase(temp) \'字符串转换成大写,生成签名 \'\'\'正式调用 Dim htc As New HttpClient(hj_url & "/tool/open_api/api/goods/cat-detail?id=1") htc.TimeOut = -1 htc.Headers.Add("X-Signature", dev_msg_signature) \'32位接口请求签名 htc.Headers.Add("X-Timestamps", timestamps) \'10位接口请求时间戳 htc.Headers.Add("X-Nonce", nonce) \'32位随机字符串 htc.Headers.Add("X-Apikey", api_key) \'32位API_Key htc.UserAgent = "Apifox/1.0.0 (https://mp.gswhcm.cn)" ’设置标头 Dim s As String = htc.GetData() Output.Show(s) [此贴子已经被作者于2024/1/4 22:02:57编辑过]
|
-- 作者:linyunu1 -- 发布时间:2024/1/4 22:27:00 -- 代码前面加Net.ServicePointManager.SecurityProtocol = Net.SecurityProtocolType.Tls12 |