請教一下,怎么寫拼多多的代碼?我老是出錯
介面地址:
https://open.pinduoduo.com/#/apidocument/port?portId=pdd.order.number.list.increment.get
我寫的代碼是這樣的
Dim 網址 As String="http://*****&state=1212"
Dim code() As String = 網址 .split("=")
Output.Show(code(1) )
Dim 開發者ID As String ="7dd1dd0e6*****336f5689afbabf"
Dim 開發者秘鑰 As String="4571a199*****c1f8bd2030e9db2c"
Dim hcat As new HttpClient("http://open-api.pinduoduo.com/oauth/token")
hcat.ContentType = "application/json"
Dim jo As New JObject
jo("grant_type") = "authorization_code"
jo("code") = code(1).Replace("&state","")
jo("client_id" )= 開發者ID
jo("client_secret")=開發者秘鑰
hcat.Content = jo.tostring
'output.Show(hcat.GetData)
Dim jo1 As JObject = JObject.Parse(hcat.GetData)
If jo1("error_response") IsNot Nothing Then
Output.Show(jo1("error_response")("error_msg").Tostring) '錯誤
End If
If jo1("access_token") IsNot Nothing Then
Output.Show(jo1("access_token").Tostring) 'access_token獲取
Dim access_token As String = jo1("access_token").Tostring
Dim 時間戳 As String=CInt((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000)
Dim 介面名稱 As String = "pdd.order.number.List.increment.get"
Dim sign As String= 開發者秘鑰 & "access_token" & access_token & "client_id " & 開發者ID & "data_typeJSONorder_status5page1page_size100timestamp" & 時間戳 & "Type" & 介面名稱 & 開發者秘鑰
Dim hc訂單 As new HttpClient("https://gw-api.pinduoduo.com/api/router")
hc訂單 .ContentType = "application/x-www-form-urlencoded;charset=utf-8" '
hc訂單.FormData.Add("refund_status", "1")
hc訂單 .FormData.Add("type",介面名稱)
hc訂單 .FormData.Add("sign",sign)
hc訂單 .FormData.Add("client_id",開發者ID)
hc訂單 .FormData.Add("page","1")
hc訂單 .FormData.Add("page_size","100")
hc訂單 .FormData.Add("data_type","JSON")
hc訂單 .FormData.Add("timestamp" , 時間戳 )
hc訂單 .FormData.Add("order_status","5")
hc訂單 .FormData.Add("access_token",access_token )
hc訂單.FormData.Add("is_lucky_flag","0")
hc訂單.FormData.Add("start_updated_at","1571187628")
hc訂單.FormData.Add("end_updated_at","1571189427")
output.Show(hc訂單.GetData)
End If
錯誤是這樣的
{"error_response":{"error_msg":"用戶沒有授權訪問此介面","sub_msg":"用戶沒有授權訪問此介面","sub_code":"20031","error_code":20031,"request_id":"15719671278709720"}}
我看了有介面訪問的權限,測驗里面以及其他語言出的結果是對的。別人告訴我這樣寫又沒錯。有大神可以幫我看看是哪里有問題不?
uj5u.com熱心網友回復:
Dim str As String= 開發者秘鑰 & "access_token" & access_token & "client_id " & 開發者ID & "data_typeJSONorder_status5page1page_size100timestamp" & 時間戳 & "Type" & 介面名稱 & 開發者秘鑰Output.Show("加密:"&sign)
Dim sign= System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5")
Output.Show(sign)
上面的代碼忘記加MD5加密進去了。這段是加密的。幫忙看下哪里寫錯了
uj5u.com熱心網友回復:
沒寫過拼多多,不過類似的寫過不少,建議抓個包看下你發的資料到底有沒有問題,也可以用postman測驗一下介面是否有效轉載請註明出處,本文鏈接:https://www.uj5u.com/net/103394.html
標籤:VB.NET
