Foxtable(狐表)用户栏目专家坐堂 → [求助]API接口狐表改造,请老师指教


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

主题:[求助]API接口狐表改造,请老师指教

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


加好友 发短信
等级:一尾狐 帖子:402 积分:4154 威望:0 精华:0 注册:2017/3/24 15:10:00
[求助]API接口狐表改造,请老师指教  发帖心情 Post By:2024/1/4 22:02:00 [只看该作者]

‘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
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:162 积分:1089 威望:0 精华:0 注册:2020/1/16 11:58:00
  发帖心情 Post By:2024/1/4 22:27:00 [只看该作者]

代码前面加Net.ServicePointManager.SecurityProtocol = Net.SecurityProtocolType.Tls12

 回到顶部