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


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

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

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


加好友 发短信
等级:六尾狐 帖子:1490 积分:10607 威望:0 精华:0 注册:2018/10/16 11:42:00
[求助]申通接口写法Base64怎么写?  发帖心情 Post By:2020/12/15 19:01:00 [显示全部帖子]

Dim hc As new HttpClient("http://cloudinter-linkgatewaytest.sto.cn/gateway/link.do")

hc.ContentType = "application/x-www-form-urlencoded charset=UTF-8"

hc.FormData.Add("content",报文)

hc.FormData.Add("data_digest",报文签名)

hc.FormData.Add("api_name",API)

hc.FormData.Add("from_appkey",应用key)

hc.FormData.Add("from_code",资源code)

hc.FormData.Add("to_appkey",注册方appkey)

hc.FormData.Add("to_code",注册方资源code)

hc.FormData.Add("content",业务)


Output.Show(hc.GetData)


签名怎么写?
MD5会写
APPSign=System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sign , "MD5")

Base64怎么写?

https://open.sto.cn/#/help/tz5gl0

[此贴子已经被作者于2020/12/18 19:13:52编辑过]

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


加好友 发短信
等级:六尾狐 帖子:1490 积分:10607 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2020/12/15 20:26:00 [显示全部帖子]

这个东西也要吧
下载地址sdk.rar
这个文件怎么没有dll可以调用
2..NET


调用示例:



using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Web;

namespace LinkRequest
{
    class Program
    {
        public static void Main(string[] args)
        {
            string response = LinkTest();
            Console.WriteLine(response);
            Console.ReadLine();
        }

        public static string LinkTest()
        {
            byte[] responseArray = null;
            string url = "http://cloudinter-linkgatewaytest.sto.cn/gateway/link.do";
            using (WebClient webClient = new WebClient())
            {
                NameValueCollection postValues = new NameValueCollection();
                string secretKey = "123abc";
                string c;
               
                string dataDigest = 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);
            }
            string response = Encoding.UTF8.GetString(responseArray);
            return response;
        }

        //加密
    public static string CalculateDigest(string content, string secretKey)
        {
            string toSignContent = content + secretKey;
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = System.Text.Encoding.GetEncoding("utf-8").GetBytes(toSignContent);
            byte[] hash = md5.ComputeHash(inputBytes);
            return Convert.ToBase64String(hash);
        }
    }
}
[此贴子已经被作者于2020/12/15 20:30:38编辑过]

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


加好友 发短信
等级:六尾狐 帖子:1490 积分:10607 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2020/12/15 20:30:00 [显示全部帖子]

转后

Imports System
Imports System.Collections.Generic
Imports System.Collections.Specialized
Imports System.Linq
Imports System.Net
Imports System.Security.Cryptography
Imports System.Text
Imports System.Web

Namespace LinkRequest
    Class Program
        Public Shared Sub Main(ByVal args As String())
            Dim response As String = LinkTest()
            Console.WriteLine(response)
            Console.ReadLine()
        End Sub

        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 WebClient = New 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
    End Class
End Namespace


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


加好友 发短信
等级:六尾狐 帖子:1490 积分:10607 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2020/12/15 20:45:00 [显示全部帖子]

编译错误:模块中的方法不能声明为”Shared".。
错误代码:Public Shared Function LinkTest0 As String


还有那个SDK我怎么引用,他不是dll后缀

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


加好友 发短信
等级:六尾狐 帖子:1490 积分:10607 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2020/12/15 22:18:00 [显示全部帖子]

那意思是上面这个.ne转换过来的东西用不了?

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


加好友 发短信
等级:六尾狐 帖子:1490 积分:10607 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2020/12/15 23:14:00 [显示全部帖子]

去掉Shared 字符
怎么去掉?删掉这个,还是删掉这段代码(试了都出错)

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


加好友 发短信
等级:六尾狐 帖子:1490 积分:10607 威望: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类型的命名空间都补齐了吗?
是什么意思?


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


加好友 发短信
等级:六尾狐 帖子:1490 积分:10607 威望: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(


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


加好友 发短信
等级:六尾狐 帖子:1490 积分:10607 威望: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


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


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


加好友 发短信
等级:六尾狐 帖子:1490 积分:10607 威望: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编辑过]

 回到顶部
总数 13 1 2 下一页