以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 公众号主动消息求助 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=175334) |
-- 作者:夜点蚊香 -- 发布时间:2022/3/1 15:01:00 -- 公众号主动消息求助 订阅号权限如下 报错代码如下 Dim jo As New JObject jo("touser") = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" Dim str22 As String str22 = jo("touser") Dim PR1 As DataRow = DataTables("学员管理_学员信息表").Find("微信号 = \'" & str22 & "\' ") Dim str23 As String str23 = PR1("姓名") MessageBox.Show(str23) jo("msgtype") = "text" jo("text") = New JObject jo("text")("content") = "您好," & str23 & " ,快点去学习." Dim URL As String = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={0}" Dim hc As New HttpClient(CExp(URL, Functions.Execute("GetAccessToken"))) hc.Content = jo.ToString() jo = JObject.Parse(hc.GetData()) If jo("errcode") = "0" Then MessageBox.Show("消息发送成功") Else MessageBox.show("消息发送失败,原因:" & vbcrlf & jo("errmsg").ToString) End If [此贴子已经被作者于2022/3/1 15:02:45编辑过]
|
-- 作者:SbFox -- 发布时间:2022/3/1 15:06:00 -- 提示的很明显 你的IP地址没有加入到白名单中 |
-- 作者:夜点蚊香 -- 发布时间:2022/3/1 15:16:00 -- ip 白名单加上了 现在报错如下 |
-- 作者:有点蓝 -- 发布时间:2022/3/1 15:36:00 -- 获取accesstoken失败,检查函数里appid和appscrect是否正确 |
-- 作者:夜点蚊香 -- 发布时间:2022/3/1 16:17:00 -- 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=" & appid & "&secret=" & AppSecret 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 AccessTocken 都获取最新的了,还是报错.
|
-- 作者:夜点蚊香 -- 发布时间:2022/3/1 16:28:00 -- 搞定了,多谢 搞定了,多谢 |
-- 作者:有点蓝 -- 发布时间:2022/3/1 16:30:00 -- msgbox(Functions.Execute("GetAccessToken"))显示什么内容? 另外确定开发者ID,开发者密匙填写正确 Dim AppId As String= tr("appid") \'开发者ID、 Dim AppSecret As String = tr("AppSecret") 不能使用A公众号的AccessToken给B公众号发消息的
|