以文本方式查看主题 - 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=159780) |
-- 作者:zto001 -- 发布时间:2021/1/8 13:44:00 -- 【已解决】[求助]请问下这个中通api怎么写? https://op.zto.cn/#/document?menuId=29 using System; namespace ConsoleApp1 var js; public static String GetSign(String content,String appKey, String appSec) byte[] buytes = Encoding.GetEncoding("UTF-8").GetBytes(fullContent); 还是一样,先用转换代码的转换是吧 [此贴子已经被作者于2021/1/11 15:29:02编辑过]
|
-- 作者:zto001 -- 发布时间:2021/1/8 13:46:00 -- 转换后 Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Net Imports System.Net.Http Imports System.Security.Cryptography Imports System.Text Imports System.Threading.Tasks Namespace ConsoleApp1 Class Program Private Shared Async Function Main(ByVal args As String()) As Task Dim appKey = "d577e7b5024ad20446e10" Dim appSec = "0e8e9457d493666ee2f5adb783e69abb" Dim js"type"":0,""orderCode"":""210107000003719103"",""billCode"":""""}" Using client As HttpClient = New HttpClient() Using content = New StringContent(jsonStr, Encoding.UTF8, "application/json") content.Headers.Add("x-appKey", appKey) Dim digest = GetSign(jsonStr, appKey, appSec) content.Headers.Add("x-datadigest", digest) Dim response As HttpResponseMessage = Await client.PostAsync("https://japi-test.zto.com/zto.open.getOrderInfo", content) response.EnsureSuccessStatusCode() Dim responseBody As String = Await response.Content.ReadAsStringAsync() Console.WriteLine(responseBody) End Using End Using Console.ReadLine() End Function Public Shared Function GetSign(ByVal content As String, ByVal appKey As String, ByVal appSec As String) As String Dim fullContent As String = content & appSec Dim buytes As Byte() = Encoding.GetEncoding("UTF-8").GetBytes(fullContent) Using md5 As MD5 = New MD5CryptoServiceProvider() Dim outBytes = md5.ComputeHash(buytes) Return Convert.ToBase64String(outBytes) End Using End Function End Class End Namespace 放到全局代码里面提示 - 编译错误:"Imports"语句前面必须是声明。 错误代码: Imports System 怎么改? |
-- 作者:有点蓝 -- 发布时间:2021/1/8 13:56:00 -- 一样的处理方法 http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=159152&skin=0
|
-- 作者:zto001 -- 发布时间:2021/1/8 14:18:00 -- Private Async Function Main(ByVal args As String()) As Task Dim appKey = "d577e7b5024ad20446e10" Dim appSec = "0e8e9457d493666ee2f5adb783e69abb" Dim js"type"":0,""orderCode"":""210107000003719103"",""billCode"":""""}" Using client As System.Net.Http.HttpClient= New System.Net.Http.HttpClient() Using content = New StringContent(jsonStr, Encoding.UTF8, "application/json") content.Headers.Add("x-appKey", appKey) Dim digest = GetSign(jsonStr, appKey, appSec) content.Headers.Add("x-datadigest", digest) Dim response As HttpResponseMessage = Await client.PostAsync("https://japi-test.zto.com/zto.open.getOrderInfo", content) response.EnsureSuccessStatusCode() Dim responseBody As String = Await response.Content.ReadAsStringAsync() Console.WriteLine(responseBody) End Using End Using Console.ReadLine() End Function Public Function GetSign(ByVal content As String, ByVal appKey As String, ByVal appSec As String) As String Dim fullContent As String = content & appSec Dim buytes As Byte() = Encoding.GetEncoding("UTF-8").GetBytes(fullContent) Using md5 As MD5 = New MD5CryptoServiceProvider() Dim outBytes = md5.ComputeHash(buytes) Return Convert.ToBase64String(outBytes) End Using End Function 是这样吗?去掉Shared 这个单词 命名空间HttpClient 改成System.Net.Http.HttpClient 提示 错误 x 编译错误:未定义类型"Task"。 错误代码:Private Function Main(Byval args As String0) As Task 确定 |
-- 作者:有点蓝 -- 发布时间:2021/1/8 14:44:00 -- 这些是.net5.0的语法,foxtable用不了,咨询官方要支持.net 4.0的用法,或者试试 全局代码 Public Function GetSign(ByVal content As String, ByVal appKey As String, ByVal appSec As String) As String Dim fullContent As String = content & appSec Dim buytes As Byte() = Encoding.GetEncoding("UTF-8").GetBytes(fullContent) Using md5 As MD5 = New MD5CryptoServiceProvider() Dim outBytes = md5.ComputeHash(buytes) Return Convert.ToBase64String(outBytes) End Using End Function 调用 Dim htc As new HttpClient("https://japi-test.zto.com/zto.open.getOrderInfo") Dim appKey = "d577e7b5024ad20446e10" Dim appSec = "0e8e9457d493666ee2f5adb783e69abb" htc.Headers.Add("x-appKey", appKey) dim digest = GetSign(jsonStr, appKey, appSec) htc.Headers.Add("x-datadigest", digest) htc.Content = "提交的json字符串" htc.ContentType = "application/json" dim res = htc.GetData() msgbox(res)
|
-- 作者:zto001 -- 发布时间:2021/1/8 16:20:00 -- 错误 x 编译错误:未定义类型"MD5". 错误代码: Using md5 As MD5 = New MD5CryptoServiceProviderO 确定 全局代码 Public Function GetSign(ByVal content As String, ByVal appKey As String, ByVal appSec As String) As String Dim fullContent As String = content & appSec Dim buytes As Byte() = Encoding.GetEncoding("UTF-8").GetBytes(fullContent) Using md5 As MD5 = New MD5CryptoServiceProvider() 这段错误 Dim outBytes = md5.ComputeHash(buytes) Return Convert.ToBase64String(outBytes) End Using End Function |
-- 作者:有点蓝 -- 发布时间:2021/1/8 16:32:00 -- 加上命名空间 |
-- 作者:zto001 -- 发布时间:2021/1/11 10:54:00 -- MD5好像没找到有命名空间 |
-- 作者:有点蓝 -- 发布时间:2021/1/11 11:09:00 -- 肯定有。如果经常开发接口,建议安装一个vs,在vs项目里输入代码会有详细提示的。 转换后
Imports System Imports System.Collections.Generic Imports System.Linq Imports System.Net Imports System.Net.Http Imports System.Security.Cryptography Imports System.Text Imports System.Threading.Tasks Using md5 As System.Security.Cryptography.MD5CryptoServiceProvider= New System.Security.Cryptography.MD5CryptoServiceProvider() 这段错误 |
-- 作者:zto001 -- 发布时间:2021/1/11 13:08:00 -- jsonStr请教下这个值是什么值?json字符串吗? |