以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  快递鸟怎么目前的代码只能单个查询,请问怎么改成批量查询  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=106305)

--  作者:zoudezhao
--  发布时间:2017/9/6 14:38:00
--  快递鸟怎么目前的代码只能单个查询,请问怎么改成批量查询
窗口AfterLoad
Dim Asv As new KdApiSearchDemo
Dim jtb As String = Asv.getOrderTracesByJson
ClipBoard.SetText(jtb)
Dim jo As JObject = Jobject.Parse(ClipBoard.GetText) 
Dim kdzt As String = (jo("State") ) 
Dim kdlx As String = (jo("ShipperCode") )
Dim ydh As String = (jo("LogisticCode") )
Dim sfcg As String = (jo("Success") )
Dim sbyy As String = (jo("Reason") )
If kdzt = "0" Then
kdzt = "无轨迹"
Else If kdzt = "2" Then
kdzt = "在途中"
Else If kdzt = "3" Then
kdzt = "已签收"
Else If kdzt = "4" Then
kdzt = "问题件"
End If 
If kdlx = "YTO" Then
kdlx = "圆通快递"
Else If kdlx = "ZTO" Then
kdlx = "中通快递"
Else If kdlx = "SF" Then
kdlx = "顺丰快递"
Else If kdlx = "EMS" Then
kdlx =  "邮局"
End If
If sfcg = "True" Then
sfcg = "成功"
Else If sfcg = "False" Then
sfcg = " 失败"
End If
e.Form.Controls("Textbox1").text = vbcrlf & "物流状态:" & kdzt & " | 快递类型: " & kdlx & " | 运单号: " & ydh & vbcrlf & vbcrlf & " 查询是否成功: " & sfcg & " | 失败原因: " & sbyy
If jo IsNot Nothing Then
For Each jt As JToken In jo("Traces")
    e.Form.Controls("Textbox1").text &= vbcrlf & vbcrlf & jt("AcceptTime").ToString & " | " & jt("AcceptStation").ToString 
Next
End If 

图片点击可在新窗口打开查看此主题相关图片如下:1234.bmp
图片点击可在新窗口打开查看

全局代码
Public Class KdApiSearchDemo
\'电商ID
Private EBusinessID As String = Vars("dsID")
\'电商加密私钥,快递鸟提供,注意保管,不要泄漏
Private AppKey As String = Vars("dsKey")
\'请求url
Private ReqURL As String = Vars("dsURL")

\'\'\' <summary>
\'\'\' Json方式 查询订单物流轨迹
\'\'\' </summary>
\'\'\' <returns></returns>
Public Function getOrderTracesByJson() As String
Dim ddbkd As Row = Tables(Vars("DD")).current
Dim danhao As String =ddbkd("快递单号")
Dim daima As String =ddbkd("快递")
Dim kt As String ="{\'OrderCode\':\'\',\'ShipperCode\':\'"
Dim zj As String = "\' ,\'LogisticCode\': \'"
Dim jw As String = "\' }"
Dim requestData As String = kt & daima & zj & danhao & jw
\'"{\'OrderCode\':\'\',\'ShipperCode\':\'YTO\' ,\'LogisticCode\': \'DD1523944605\' }"
Dim param As New System.Collections.Generic.Dictionary(Of String, String)()
param.Add("RequestData", System.Web.HttpUtility.UrlEncode(requestData, System.Text.Encoding.UTF8))
param.Add("EBusinessID", EBusinessID)
param.Add("RequestType", "1002")
Dim dataSign As String = encrypt(requestData, AppKey, "UTF-8")
param.Add("DataSign", System.Web.HttpUtility.UrlEncode(dataSign, System.Text.Encoding.UTF8))
param.Add("DataType", "2")

Dim result As String = sendPost(ReqURL, param)


目前这个快递的查询放在双击单号所在的行打开一个窗口来更新一个新的快递信息,但是这样效率太慢了,有没有方法改成每天定时会批量自动更新快递单号。。。

--  作者:有点甜
--  发布时间:2017/9/6 14:48:00
--  

 批量查询的话,你写成循环,不就好了?

 

 循环所有的快递单号,一个一个的查。


--  作者:zoudezhao
--  发布时间:2017/9/6 15:45:00
--  
Dim Result As DialogResult
Result = MessageBox.Show("刷新是否开始,确定刷新?.", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
    For Each r As Row In Tables("自动查询_Table1").Rows
Dim Asv As new KdApiSearchDemo
Dim jtb As String = Asv.getOrderTracesByJson
ClipBoard.SetText(jtb)
Dim jo As JObject = Jobject.Parse(ClipBoard.GetText) 
Dim kdzt As String = (jo("State") ) 
Dim kdlx As String = (jo("ShipperCode") )
Dim ydh As String = (jo("LogisticCode") )
Dim sfcg As String = (jo("Success") )
Dim sbyy As String = (jo("Reason") )
If kdzt = "0" Then
kdzt = "无轨迹"
r("订单状态") = "无轨迹"
Else If kdzt = "2" Then
kdzt = "在途中"
r("订单状态") = "在途中"
Else If kdzt = "3" Then
kdzt = "已签收"
r("订单状态") = "已签收"
Else If kdzt = "4" Then
kdzt = "问题件"
r("订单状态") = "问题件"
End If 
If kdlx = "YTO" Then
kdlx = "圆通快递"
Else If kdlx = "ZTO" Then
kdlx = "中通快递"
Else If kdlx = "SF" Then
kdlx = "顺丰快递"
Else If kdlx = "EMS" Then
kdlx =  "邮局"
End If
If sfcg = "True" Then
sfcg = "成功"
Else If sfcg = "False" Then
sfcg = " 失败"
End If
r("物流信息") = vbcrlf & "物流状态:" & kdzt & " | 快递类型: " & kdlx & " | 运单号: " & ydh & vbcrlf & vbcrlf & " 查询是否成功: " & sfcg & " | 失败原因: " & sbyy
If jo IsNot Nothing Then
For Each jt As JToken In jo("Traces")
    r("物流信息") &= vbcrlf & vbcrlf & jt("AcceptTime").ToString & " | " & jt("AcceptStation").ToString 
Next
End If
Next
End If

DataColChanged
If e.DataCol.Name = "物流信息" Then \'如果是否签收列的内容变动
e.DataRow("快递查询日期")= Date.Today
End If


快递的查询日期是更新了,,但是物流信息跟订单状态都没更新,我哪里写错了么甜老师。。

图片点击可在新窗口打开查看此主题相关图片如下:5678.bmp
图片点击可在新窗口打开查看

[此贴子已经被作者于2017/9/6 15:46:06编辑过]

--  作者:zoudezhao
--  发布时间:2017/9/6 15:45:00
--  
图附不上了。。
[此贴子已经被作者于2017/9/6 15:45:44编辑过]

--  作者:有点甜
--  发布时间:2017/9/6 15:52:00
--  

全局代码修改

 

Public Function getOrderTracesByJson() As String
Dim ddbkd As Row = Tables(Vars("DD")).current
Dim danhao As String =ddbkd("快递单号")
Dim daima As String =ddbkd("快递")
 
改成
 
Public Function getOrderTracesByJson(danhao As String, daima As String) As String
 
 
然后,调用代码也要修改
 
Dim Asv As new KdApiSearchDemo
For Each r As Row In Tables("自动查询_Table1").Rows
    Dim danhao As String = r("快递单号")
    Dim daima As String = r("快递")
    Dim jtb As String = Asv.getOrderTracesByJson(danhao, daima)

--  作者:zoudezhao
--  发布时间:2017/9/6 16:15:00
--  
感谢甜老师完成了
--  作者:zoudezhao
--  发布时间:2017/9/8 13:47:00
--  
甜老师,远程服务器返回错误: (404) 未找到。Unexpected character encountered while parsing value: 远. Path \'\', line 0, position 0.他经常会出现这个问题然后查询就中断了有没有办法解决呀。。。
--  作者:有点甜
--  发布时间:2017/9/8 14:25:00
--  

404错误,是你合成的访问的路径有问题。找不到对应的地址。

 

你看看你 Vars("dsURL") 的值是否正确


--  作者:zoudezhao
--  发布时间:2017/9/8 14:31:00
--  
没问题的甜老师,这个路径好用但是每隔 2  3  个就一个弹错。。。有的时候批量查200个到150左右就报错。。
--  作者:zoudezhao
--  发布时间:2017/9/8 14:32:00
--  
昨天扫1800个弹了一次,今天上午查700个弹了一次,然后到了下午几乎扫两三个就一次。。