以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  帮助文件代码运行报错 求解  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=155801)

--  作者:xa139
--  发布时间:2020/9/27 11:25:00
--  帮助文件代码运行报错 求解

DataTables("WXUsers").DataRows.Clear()
Dim ul As String = "https://api.weixin.qq.com/cgi-bin/user/get?access_token={0}&next_openid={1}"  \'获取用户OpenID列表接口
Dim
il = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token={0}" \'批量获取用户信息接口
Dim
nms() As String = {"openid","nickname","sex","city","country","province","headimgurl","groupid","remark","language"} \'列名
Dim
hc As New HttpClient(CExp(ul, Functions.Execute("GetAccessToken"),""))
Dim
ids As New List(of String) \'OpenId集合,每次获取10000
Dim
ba As New Jarray \'准备用来获取用户信息的OpenId列表,一次不能超过100
Dim
jo As JObject = JObject.Parse(hc.GetData)
Do
\'循环获取,一次只能获取10000OpenID
    If jo("errcode") Is Nothing Then
        Dim cnt As Integer = jo("count")
        If cnt = 0 Then
\'
如果已经获取完所有用户\'
            Exit Do
        End If
        For Each jk As JToken  In jo("data")("openid")
            ids.Add(jk)
        Next
        For i As Integer = 0 To ids.Count - 1 
\'
循环获取用户详情,一次不能超过100个用户
            Dim uo As New JObject
            uo("openid") = ids(i)
           
ba.Add(uo)
            If ba.Count = 100 OrElse i = ids.Count - 1 Then \'每满100个就获取一次
                Dim bo As New Jobject
               
bo("user_list") = ba
                hc = New HttpClient(CExp(il, Functions.Execute("GetAccessToken")))
                hc.Content = bo.ToString()
                Dim ro As JObject = JObject.Parse(hc.GetData)
                If ro("errcode") Is  Nothing Then
                    Dim ia As JArray = ro("user_info_list")
\'
获取的用户信息列表
                    For Each jt As JToken In ia
                        Dim dr As DataRow = DataTables("WXUsers").Find("openid = \'" & jt("openid").ToString() & "\'")
                        If dr Is Nothing Then
                            dr = DataTables("WXUsers").AddNew()
                        End If
                        For Each nm As String In nms
                            dr(nm) = jt(nm)
                        Next
                        dr("tagid_list") = CompressJSON(jt("tagid_list"))
                    Next
                Else
                    MessageBox.Show(ro.ToString)
                    Exit For
                End If
                ba.Clear()
\'
清除集合,准备获取下一批用户详情,每批只能100.
            End If
        Next
        ids.Clear
\'
清除已经获取的OpenID.,准备接收下一批OpenID
        hc =  New HttpClient(CExp(ul, Functions.Execute("GetAccessToken"),jo("next_openid").Tostring)) 
\'
获取下一批OpenID
        jo = JObject.Parse(hc.GetData)
    Else
        MessageBox.Show(jo.ToString)
        Exit Do
    End
If

Loop
DataTables
("WXUsers").Save() 
帮助文件内 微信get用户信息
执行报错 
图片点击可在新窗口打开查看此主题相关图片如下:1601176781(1).png
图片点击可在新窗口打开查看
求解

--  作者:有点蓝
--  发布时间:2020/9/27 11:53:00
--  
提示是没有权限使用api。确认客户端外网ip已经加入公众号的白名单?