Foxtable(狐表)用户栏目专家坐堂 → [求助]申通接口写法Base64怎么写?


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

主题:[求助]申通接口写法Base64怎么写?

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


加好友 发短信
等级:六尾狐 帖子:1465 积分:10397 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2020/12/16 17:53:00 [只看该作者]

'Public Shared Function LinkTest() As String
Dim responseArray As Byte() = Nothing
Dim url As String = "http://cloudinter-linkgatewaytest.sto.cn/gateway/link.do"

Using webClient As System.Web.WebClient = New System.Web.WebClient()
Dim postValues As NameValueCollection = New NameValueCollection()
Dim secretKey As String = "123abc"
Dim content As String = "{""orderNo"":""8885452262"",""orderSource"":""VIPEO""}"
Dim dataDigest As String = CalculateDigest(content, secretKey)
postValues.Add("content", content)
postValues.Add("data_digest", dataDigest)
postValues.Add("api_name", "OMS_EXPRESS_ORDER_CREATE")
postValues.Add("from_appkey", "sto_test")
postValues.Add("from_code", "sto_test_code")
postValues.Add("to_appkey", "sto_oms")
postValues.Add("to_code", "sto_oms")
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
responseArray = webClient.UploadValues(url, "POST", postValues)
End Using

Dim response As String = Encoding.UTF8.GetString(responseArray)
Return response
End Function

Public Shared Function CalculateDigest(ByVal content As String, ByVal secretKey As String) As String
Dim toSignContent As String = content & secretKey
Dim md5 As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create()
Dim inputBytes As Byte() = System.Text.Encoding.GetEncoding("utf-8").GetBytes(toSignContent)
Dim hash As Byte() = md5.ComputeHash(inputBytes)
Return Convert.ToBase64String(hash)
End Function


我去掉第一行,提示
编译错误:语句不能出现在方法体/多行lambda外。
错误代码: Using webClient As System.Web.WebClient = NewSystem.Web.WebCliento

还有 其它.net类型的命名空间都补齐了吗?
是什么意思?


 回到顶部
帅哥,在线噢!
有点蓝
  12楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:105943 积分:538784 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/12/17 8:37:00 [只看该作者]

去掉Shared 这个单词,不是去掉整行

2楼using/3楼import后面的内容就是命名空间,如果不懂,百度一下什么是“命名空间”,由于foxtable不支持using、import用法,只能是把命名空间放到代码中,比如

Using webClient As WebClient = New WebClient()
改为
Using webClient As System.Web.WebClient = New System.Web.WebClient()

WebClient 是属于命名空间System.Web.的,NameValueCollection 是属于其它命名空间的,至于是哪个,自行网上搜索一下。代码中如果还有其他的.net类型都一样处理

 回到顶部
帅哥哟,离线,有人找我吗?
zto001
  13楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1465 积分:10397 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2020/12/17 18:06:00 [只看该作者]


Public Function LinkTest() As String
Dim responseArray As Byte() = Nothing
Dim url As String = "http://cloudinter-linkgatewaytest.sto.cn/gateway/link.do"

Using webClient As System.Web.WebClient = New System.Web.WebClient()
Dim postValues As NameValueCollection = New NameValueCollection()
Dim secretKey As String = "123abc"
Dim content As String = "{""orderNo"":""8885452262"",""orderSource"":""VIPEO""}"
Dim dataDigest As String = CalculateDigest(content, secretKey)
postValues.Add("content", content)
postValues.Add("data_digest", dataDigest)
postValues.Add("api_name", "OMS_EXPRESS_ORDER_CREATE")
postValues.Add("from_appkey", "sto_test")
postValues.Add("from_code", "sto_test_code")
postValues.Add("to_appkey", "sto_oms")
postValues.Add("to_code", "sto_oms")
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
responseArray = webClient.UploadValues(url, "POST", postValues)
End Using

Dim response As String = Encoding.UTF8.GetString(responseArray)
Return response
End Function

Public Function CalculateDigest(ByVal content As String, ByVal secretKey As String) As String
Dim toSignContent As String = content & secretKey
Dim md5 As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create()
Dim inputBytes As Byte() = System.Text.Encoding.GetEncoding("utf-8").GetBytes(toSignContent)
Dim hash As Byte() = md5.ComputeHash(inputBytes)
Return Convert.ToBase64String(hash)
End Function


是这样吗?去掉了两个Shared ,改为
Using webClient As System.Web.WebClient = New System.Web.WebClient()
还是提示错误
Dim postValues As NameValueCollection = New NameValueCollection()
这样要改成这个?
Dim postValues As System.Collections.Specialized.NameValueCollection = New System.Collections.Specialized.NameValueCollection()


编译错误:未定义类型"System.Web.WebClient".
错误代码: Using webClient As System.Web.webclient = Newsystem.Web.WebClient(


 回到顶部
帅哥,在线噢!
有点蓝
  14楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:105943 积分:538784 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/12/17 20:16:00 [只看该作者]

命名空间不对:System.Net.WebClient

 回到顶部
帅哥哟,离线,有人找我吗?
zto001
  15楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1465 积分:10397 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2020/12/18 13:13:00 [只看该作者]

Public Function LinkTest() As String
Dim responseArray As Byte() = Nothing
Dim url As String = "http://cloudinter-linkgatewaytest.sto.cn/gateway/link.do"

Using webClient As System.Net.WebClient= New System.Net.WebClient()
Dim postValues As System.Collections.Specialized.NameValueCollection = New System.Collections.Specialized.NameValueCollection()
Dim secretKey As String = "123abc"
Dim content As String = "{""orderNo"":""8885452262"",""orderSource"":""VIPEO""}"
Dim dataDigest As String = CalculateDigest(content, secretKey)
postValues.Add("content", content)
postValues.Add("data_digest", dataDigest)
postValues.Add("api_name", "OMS_EXPRESS_ORDER_CREATE")
postValues.Add("from_appkey", "sto_test")
postValues.Add("from_code", "sto_test_code")
postValues.Add("to_appkey", "sto_oms")
postValues.Add("to_code", "sto_oms")
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
responseArray = webClient.UploadValues(url, "POST", postValues)
End Using

Dim response As String = Encoding.UTF8.GetString(responseArray)
Return response
End Function

Public Function CalculateDigest(ByVal content As String, ByVal secretKey As String) As String
Dim toSignContent As String = content & secretKey
Dim md5 As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create()
Dim inputBytes As Byte() = System.Text.Encoding.GetEncoding("utf-8").GetBytes(toSignContent)
Dim hash As Byte() = md5.ComputeHash(inputBytes)
Return Convert.ToBase64String(hash)
End Function


全局代码可以。怎么调用?


 回到顶部
帅哥,在线噢!
有点蓝
  16楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:105943 积分:538784 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/12/18 13:55:00 [只看该作者]

命令窗口:msgbox(LinkTest())

 回到顶部
帅哥哟,离线,有人找我吗?
zto001
  17楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1465 积分:10397 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2020/12/18 15:16:00 [只看该作者]


Public Function LinkTest() As String
Dim responseArray As Byte() = Nothing
Dim url As String = "http://cloudinter-linkgatewaytest.sto.cn/gateway/link.do"

Using webClient As System.Net.WebClient= New System.Net.WebClient()
Dim postValues As System.Collections.Specialized.NameValueCollection = New System.Collections.Specialized.NameValueCollection()
Dim secretKey As String = "123abc"
Dim content As String = "{""orderNo"":""8885452262"",""orderSource"":""VIPEO""}"
Dim dataDigest As String = CalculateDigest(content, secretKey)
postValues.Add("content", content)
postValues.Add("data_digest", dataDigest)
postValues.Add("api_name", "OMS_EXPRESS_ORDER_CREATE")
postValues.Add("from_appkey", "sto_test")
postValues.Add("from_code", "sto_test_code")
postValues.Add("to_appkey", "sto_oms")
postValues.Add("to_code", "sto_oms")
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
responseArray = webClient.UploadValues(url, "POST", postValues)
End Using

Dim response As String = Encoding.UTF8.GetString(responseArray)
Return response
End Function

Public Function CalculateDigest(ByVal content As String, ByVal secretKey As String) As String
Dim toSignContent As String = content & secretKey
Dim md5 As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create()
Dim inputBytes As Byte() = System.Text.Encoding.GetEncoding("utf-8").GetBytes(toSignContent)
Dim hash As Byte() = md5.ComputeHash(inputBytes)
Return Convert.ToBase64String(hash)
End Function



红色区域是变量,我要怎样才能在外部执行代码传递给他呢 精英频道

[此贴子已经被作者于2020/12/19 21:40:11编辑过]

 回到顶部
帅哥,在线噢!
有点蓝
  18楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:105943 积分:538784 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/12/18 15:23:00 [只看该作者]

Public Function LinkTest(url as string,xxx1 as srting,...........) As String
Dim responseArray As Byte() = Nothing
Dim url As String = url 

 回到顶部
帅哥哟,离线,有人找我吗?
zto001
  19楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1465 积分:10397 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2020/12/18 15:39:00 [只看该作者]

调用的话就这样写

msgbox(LinkTest(第一个参数,第二个参数....)
我知道了


 回到顶部
帅哥哟,离线,有人找我吗?
zto001
  20楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1465 积分:10397 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2020/12/18 19:16:00 [只看该作者]

有一个新问题,我要一次行传递20个单号过去,有什么写法比较好组合成一个字符串?我下面这个写法第21个不会传递过去,有什么好写的方法?


Dim 传递 As String
Dim 数 As Integer
For Each r As Row In Tables("订单").Rows
    
    If 数<20 Then
        数=数+1
        传递=传递 & "," & r("变量")
    Else
        
       解析LinkTest(传递)

        传递=""
        数=0
    End If
    
Next


 回到顶部
总数 22 上一页 1 2 3 下一页