以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- GetAccessToken 获取access_token 报错,帮忙看一下代码 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=172543) |
-- 作者:夜点蚊香 -- 发布时间:2021/10/18 17:32:00 -- GetAccessToken 获取access_token 报错,帮忙看一下代码 Dim tR As DataRow = DataTables("系统设置").Find("序号 = \'1\'") Static CreateTime As Date \'记录最近一次生成access_token的时间 Static AccessTocken As String \'记录最近一次生成的access_token Dim AppId As String= tr("appid") \'开发者ID Dim AppSecret As String = tr("AppSecret") \'开发者密匙 Dim tp As TimeSpan = Date.Now - CreateTime Dim url As String = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}" If tp.TotalSeconds > 3600 Then Dim hc As New HttpClient(CExp(url,AppId,AppSecret)) Dim ret As String = hc.GetData() If ret = "" Then \'如果失败,再尝试一次 hc.GetData() End If CreateTime = Date.Now() Dim jo As JObject = JObject.Parse(ret) If jo("errcode") Is Nothing Then AccessTocken = jo("access_token") Else MessageBox.show("获取access_token失败,原因:" & vbcrlf & jo("errmsg").ToString) End If End If Return Nothing 使用的是正式公众号 在命令窗口运行 Dim access_token As
String = Functions.Execute("GetAccessToken") Output.Show(access_token) 报错代码 获取accecc_token失败,原因: invalid ip 27.211.118.55 ipv6 :ffff:27.211.118.55,not in whitelist rid: 616d3e77-704b8e3b-229f0765
[此贴子已经被作者于2021/10/18 17:32:48编辑过]
|
-- 作者:有点蓝 -- 发布时间:2021/10/18 17:35:00 -- 把外网IP添加到公众号的白名单中 |
-- 作者:夜点蚊香 -- 发布时间:2021/10/18 17:40:00 -- 我用的花生壳,ip地址添加进去了,还是不行。测试版没有问题。 |
-- 作者:夜点蚊香 -- 发布时间:2021/10/18 18:09:00 -- 加了一个 127.0.0.1 报错内容如下图
|
-- 作者:有点蓝 -- 发布时间:2021/10/18 20:38:00 -- 只能添加外网IP地址。 使用了花生壳说明外网IP不是固定的,这种就麻烦了。公众号白名单仅支持IP,不支持域名,建议使用云服务器 |
-- 作者:夜点蚊香 -- 发布时间:2021/10/18 22:06:00 -- 搞定了,谢谢指教 [此贴子已经被作者于2021/10/18 22:13:43编辑过]
|