以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 每100行执行一次。。。 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=108310) |
-- 作者:fubblyc -- 发布时间:2017/10/19 23:52:00 -- 每100行执行一次。。。 导入券号一次 只能到100个,我索性就一次一行(也就是一个券号)导入, 然后库存 +1 但是感觉这样效率很低,每一行都要去调用微信的接口,而不是100行100行地调用 但是这个一次100行的遍历的低级问题却不知道怎么写。。。 以下是我之前的代码 For Each r As Row In Tables("导入券").Rows Dim qh As String = r("券号") Dim url As String = "https://api.weixin.qq.com/card/code/deposit?access_token={0}" Dim hc As New HttpClient(CExp(url,Functions.Execute("GetAccessToken"))) Dim jo As New JObject jo("card_id") = kaid jo("code") = qh hc.Content = jo.ToString() jo = JObject.Parse(hc.GetData) r("是否已导入") = "1" \'以上是导入券的代码 \'以下是让券的库存+1的代码 Dim url1 As String = "https://api.weixin.qq.com/card/modifystock?access_token={0}" Dim hc1 As New HttpClient(CExp(url1,Functions.Execute("GetAccessToken"))) Dim jo1 As New JObject jo1("card_id") = kaid jo1("increase_stock_value") = 1 hc1.Content = jo1.ToString() jo1 = JObject.Parse(hc1.GetData) Next [此贴子已经被作者于2017/10/19 23:51:53编辑过]
|
-- 作者:有点蓝 -- 发布时间:2017/10/20 9:05:00 -- 一次导入100个卡卷可以这样 Dim maxCount As Integer = 100 Dim ja As Jarray Dim count As Integer = Tables("导入券").Rows.Count Dim url As String = "https://api.weixin.qq.com/card/code/deposit?access_token={0}" Dim hc As New HttpClient(CExp(url,Functions.Execute("GetAccessToken"))) Dim jo As New JObject jo("card_id") = kaid For i As Integer = 0 To count Step maxCount \'按maxCount的数据进行分组 ja = new Jarray Dim n = Math.Min(i + maxCount - 1,count ) For j As Integer = i To n \'添加当前组的项目到集合 ja.Add(Tables("导入券").Rows(j)("券号")) Tables("导入券").Rows(j)("是否已导入") = 1 Next jo("code") = ja hc.Content = jo.ToString() hc.GetData Next 至于修改库存接口只能一个个来,只能分开处理,投放完成后再重新循环之前投放的卡卷进行修改了
|
-- 作者:有点甜 -- 发布时间:2017/10/20 9:09:00 -- Dim tb As Table = Tables("表A") Dim prs As Integer = 20 \'每页20行 For p As Integer = 0 To math.Ceiling(tb.Rows.Count / prs) - 1 For r As Integer = p * prs To math.min(tb.Rows.Count - 1,( p + 1) * prs - 1) output.show(r) Next output.show("--------------") Next |
-- 作者:fubblyc -- 发布时间:2017/10/20 10:24:00 -- 谢谢甜老师!! 我试一下!!
|
-- 作者:fubblyc -- 发布时间:2017/10/22 15:59:00 -- 甜老师,这样可以批量导入,但是有个问题: 每导10个(我是设成10个导一次),第一个10个会成功导入,第二个就会出现这个问题: 第一个弹出错误: 请求被中止: 连接被意外关闭。 第二个弹出错误 Error reading JObject from JsonReader. Path \'\', line 0, position 0. [此贴子已经被作者于2017/10/22 16:09:15编辑过]
|
-- 作者:有点甜 -- 发布时间:2017/10/22 16:36:00 -- msgbox弹出返回的内容,看报什么错? |
-- 作者:fubblyc -- 发布时间:2017/10/22 17:18:00 -- 第一次的10行弹出的是导入成功的内容。 接下去就是依次弹出那两个错误。 第一个弹出错误: 请求被中止: 连接被意外关闭。 第二个弹出错误 Error reading JObject from JsonReader. Path \'\', line 0, position 0. |
-- 作者:fubblyc -- 发布时间:2017/10/22 17:50:00 -- 甜老师,我换种方法,可以成功! Dim ja As Jarray Dim url As String = "https://api.weixin.qq.com/card/code/deposit?access_token={0}" Dim hc As New HttpClient(CExp(url,Functions.Execute("GetAccessToken"))) Dim jo As New JObject jo("card_id") = kaid ja = new Jarray Dim count As Integer = Tables("不定向卡券导入券号").Rows.Count If Count >= 10 Then For j As Integer = 0 To 9 \'添加当前组的项目到集合 ja.Add(Tables("不定向卡券导入券号").Rows(j)("券号")) Next jo("code") = ja hc.Content = jo.ToString() jo = JObject.Parse(hc.GetData) output.Show(jo.ToString) For j As Integer = 0 To 9 \'添加当前组的项目到集合 Tables("不定向卡券导入券号").Rows(j)("是否已导入") = "1" Next Dim drs As List(Of DataRow) drs = DataTables("不定向卡券导入券号").Select("是否已导入 = \'1\'") For Each dr As DataRow In drs dr.Delete Next Dim btn As WinForm.Button = e.Form.Controls("Button2") btn.PerformClick() \'模拟单击 Else For j As Integer = 0 To count-1 \'添加当前组的项目到集合 ja.Add(Tables("不定向卡券导入券号").Rows(j)("券号")) Next jo("code") = ja hc.Content = jo.ToString() jo = JObject.Parse(hc.GetData) output.Show(jo.ToString) For j As Integer = 0 To count-1 \'添加当前组的项目到集合 Tables("不定向卡券导入券号").Rows(j)("是否已导入") = "1" Next Dim drs As List(Of DataRow) drs = DataTables("不定向卡券导入券号").Select("是否已导入 = \'1\'") For Each dr As DataRow In drs dr.Delete Next End If 305条用了16\'
[此贴子已经被作者于2017/10/22 17:55:25编辑过]
|
-- 作者:有点甜 -- 发布时间:2017/10/22 19:52:00 -- 贴出你本来写的代码。你每次都要重新 New HttpClient 的。 |
-- 作者:fubblyc -- 发布时间:2017/10/22 22:32:00 -- 哦,甜老师,那意思是这样: Dim maxCount As Integer = 100 Dim ja As Jarray Dim count As Integer = Tables("导入券").Rows.Count Dim url As String = "https://api.weixin.qq.com/card/code/deposit?access_token={0}" Dim jo As New JObject jo("card_id") = kaid For i As Integer = 0 To count Step maxCount \'按maxCount的数据进行分组 Dim hc As New HttpClient(CExp(url,Functions.Execute("GetAccessToken"))) \'这句放在循环里哈 ja = new Jarray Dim n = Math.Min(i + maxCount - 1,count ) For j As Integer = i To n \'添加当前组的项目到集合 ja.Add(Tables("导入券").Rows(j)("券号")) Tables("导入券").Rows(j)("是否已导入") = 1 Next jo("code") = ja hc.Content = jo.ToString() hc.GetData Next |