Foxtable(狐表)用户栏目专家坐堂 → [求助]这个api怎么写?空包api


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

主题:[求助]这个api怎么写?空包api

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


加好友 发短信
等级:六尾狐 帖子:1490 积分:10607 威望:0 精华:0 注册:2018/10/16 11:42:00
[求助]这个api怎么写?空包api  发帖心情 Post By:2019/11/7 10:39:00 [只看该作者]


[此贴子已经被作者于2020/3/19 23:10:45编辑过]

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


加好友 发短信
等级:超级版主 帖子:111422 积分:567186 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/11/7 13:54:00 [只看该作者]

全局代码
public Function generateSign(ByVal dict As Dictionary(Of String, String)) As String
        Dim str As String = ""

        For Each key As String In dict.Keys
            str = str & key & dict(key)
        Next

        Dim md5psw As String = MD5Encrypt2(appSecret, 16).ToLower()
        str = md5psw & str & md5psw
        Return MD5Encrypt2(str, 32).ToUpper()
    End Function

    public Function MD5Encrypt2(ByVal password As String, ByVal bit As Integer) As String
        Dim md5Hasher As New System.Security.Cryptography.MD5CryptoServiceProvider()
        Dim hashedDataBytes As Byte()
        hashedDataBytes = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(password))
        Dim tmp As StringBuilder = New StringBuilder()

        For Each i As Byte In hashedDataBytes
            tmp.Append(i.ToString("x2"))
        Next

        If bit = 16 Then
            Return tmp.ToString().Substring(8, 16)
        ElseIf bit = 32 Then
            Return tmp.ToString()
        Else
            Return String.Empty
        End If
    End Function

调用
Dim postedJObject As JObject = New JObject()
postedJObject.Add("Platform", "拼多多申通")
postedJObject.Add("SendContact", "sir张")
postedJObject.Add("SendOfficePhone", "18225405356")
postedJObject.Add("UserId", "8989")
postedJObject.Add("SendCellPhone", "18225405356")
postedJObject.Add("SendState", "浙江省")
postedJObject.Add("SendCity", "金华市")
postedJObject.Add("SendDistrict", "义乌市")
postedJObject.Add("SendAddress", "柳青(五区)66栋")
postedJObject.Add("ProductTitle", "衣服")
postedJObject.Add("Weight", "2")
Dim jArray As JArray = New JArray()
Dim rOrder As JObject = New JObject()
rOrder.Add("OrderNo", "3112e2e2e111e")
rOrder.Add("Contact", "唐淑莲")
rOrder.Add("OfficePhone", "15672618101")
rOrder.Add("CellPhone", "15672618101")
rOrder.Add("State", "湖北省")
rOrder.Add("City", "黄冈市")
rOrder.Add("District", "英山县")
rOrder.Add("Address", "温泉镇西汤河民政局斜对面一修家电服务中心")
jArray.Add(rOrder)
Dim rOrder1 As JObject = New JObject()
rOrder1.Add("OrderNo", "3112e2e2e111e22")
rOrder1.Add("Contact", "唐淑莲")
rOrder1.Add("OfficePhone", "15672618101")
rOrder1.Add("CellPhone", "15672618101")
rOrder1.Add("State", "湖北省")
rOrder1.Add("City", "黄冈市")
rOrder1.Add("District", "英山县")
rOrder1.Add("Address", "温泉镇西汤河民政局斜对面一修家电服务中心")
jArray.Add(rOrder1)
postedJObject.Add("Raddress", jArray)

Dim 订单详情 As String = CompressJson(postedJObject)

Dim hc As new HttpClient("http://kongbao100.cn/OrderSubmit/index.asp")
hc.C
hc.FormData.Add("appKey","zto001")
hc.FormData.Add("logiType","buykongbao")
hc.FormData.Add("orders",订单详情 )
hc.FormData.Add("timestamp",Date.Now.ToString("yyyy-MM-dd HH:mm:ss"))

Dim dict As new Dictionary(of String, String)
dict.Add("appKey", "zto001")
dict.Add("logiType", "buykongbao")
dict.Add("orders", 订单详情)
dict.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
Dim 签名 As String = generateSign(dict)
hc.FormData.Add("sign",签名 )
dim ret = hc.GetData
msgbox(ret)

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:c# demo.zip



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


加好友 发短信
等级:六尾狐 帖子:1490 积分:10607 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2019/11/9 9:46:00 [只看该作者]

你这样写是不是有点复杂,我的好像比较简单点

Dim 时间 As Date = Date.Now
Dim 订单详情 As String="{""Platform"":""电子百世"",""SendContact"":""发件人"",""SendOfficePhone"":""15888888888"",""SendCellPhone"":""15888888888"",""SendState"":""广东省"",""SendCity"":""广州市"",""SendDistrict"":""番禺区"",""SendAddress"":""岭南大道321号"",""ProductTitle"":""物品类别如化妆品"",""Weight"":""2"",""Raddress"":[{""OrderNo"":""T100001111"",""Contact"":""收货人1"",""OfficePhone"":""15888888888"",""CellPhone"":""15888888888"",""State"":""广东省"",""City"":""广州市"",""District"":""番禺区"",""Address"":""岭南大道321号""}]}"
Dim 签名0 As String="13f4a636545c424eappKeyzto001logiTypebuykongbaoorders" & 订单详情 & "timestamp" & 时间 & "13f4a636545c424e"


Dim 被加密= 签名0
Dim 签名 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(被加密 , "MD5")

Dim hc As new HttpClient("http://kongbao100.cn/OrderSubmit/index.asp")
hc.FormData.Add("appKey","zto001")
hc.FormData.Add("logiType","buykongbao")
hc.FormData.Add("orders",订单详情 )
hc.FormData.Add("timestamp", 时间 )
hc.FormData.Add("sign",签名 )
'Output.Show(hc.GetData)
'{"code":"0","msg":"下单成功","Data":[{"OrderNo":"T100001111","WaybillSn":"","Trackingno":"73120393412531"},{"OrderNo":"T100002","WaybillSn":"","Trackingno":"73120393412529"}]}
'{"code":"1010","msg":"对不起,该商品暂停出售","Data":""}

Dim jo As JObject = JObject.Parse(hc.GetData)
If jo("msg")="下单成功" Then

For Each jt As JToken In jo("Data")
    Output.Show("快递单号:" & jt("Trackingno").ToString )
Next

Else
output.Show("错误提醒:"jo("age"))
End If

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


加好友 发短信
等级:六尾狐 帖子:1490 积分:10607 威望:0 精华:0 注册:2018/10/16 11:42:00
  发帖心情 Post By:2019/11/9 9:49:00 [只看该作者]

MD5 16位小写这样获取 (里面不是动态的就直接写出MD5小写16的值了)
Dim str As String = "1233312"
Dim md5 As new System.Security.Cryptography.MD5CryptoServiceProvider()
Dim byData() As Byte = Encoding.Default.GetBytes(str)
Dim result() As Byte = md5.ComputeHash(byData)
Dim md5Str As String = BitConverter.ToString(result, 4, 8)
md5Str = md5Str.Replace("-", "").ToLower
Output.Show(md5Str)

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


加好友 发短信
等级:超级版主 帖子:111422 积分:567186 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2019/11/9 9:58:00 [只看该作者]

我是直接从官方示例转换过来的。有能力的自己优化当然就更好

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


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

哦,懂了,MD5你是做在全局代码里面,然后写JObject 然后在放进去

 回到顶部