以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 判断是否有关注公众号 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=111309) |
-- 作者:fubblyc -- 发布时间:2017/12/19 22:27:00 -- 判断是否有关注公众号 蓝老师,你帮忙看下。。。 If e.GetValues.ContainsKey("code") Then \'如果是通过授权链接跳转而来,就从链接重提取code来获取openid Dim ul As String = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code" ul = CExp(ul,appid,secret,e.GetValues("code")) Dim hc As new HttpClient(ul) Dim jo As JObject = JObject.Parse(hc.GetData) If jo("openid") IsNot Nothing Then \'如果获取openid成功(成功的话,还会同时返回一个accesstiken,用于获取用户详情) OpenID = jo("openid") If e.GetValues("state") = "gugisrq" Then popmessage(openid) \'正常执行 Dim url As String = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN" url = CExp(url, Functions.Execute("GetAccessToken12","变量A"), openid) \'oI4erjj48vvEdVxFzbAj6fZ8SSLw Dim hc1 As New HttpClient(url) Dim jo1 As JObject = Jobject.Parse(hc1.GetDaTa) popmessage(jo1("subscribe")) If jo1("openid") IsNot Nothing Then If jo1("subscribe") = "0" Then e.WriteString("请先关注公众号") Return ElseIf jo1("subscribe") = "1" Then e.writestring("可以访问网页") Return End If Else e.WriteString(jo.ToString) \'在用户浏览器显示错误信息 Return End If 以上黄色这段单独测试没问题(用固定的openid),整段去掉黄色的也没问题。就是这样放在一起,一访问这个页面就死掉。不知道什么原因。。。 End If Dim drwx As DataRow = DataTables("WXUsers").sqlFind("openid =\'" & Openid & "\'") If drwx IsNot Nothing Then Else ul = "https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN " \'根据openid和accesstoken获取用户详情,注意这里这个accesstoken不是普通accesston,只能用于网页授权 hc = New HttpClient(CExp(ul, jo("access_token"), OpenId)) jo = jo.Parse(hc.GetData) If jo("openid") IsNot Nothing Then drwx = DataTables("WXUsers").sqlAddNew() Dim nms() As String = {"openid","nickname","sex","city","country","province","headimgurl"} \'"" For Each nm As String In nms drwx(nm) = jo(nm) Next drwx("账套") = zhangtao drwx("addtime") = Date.now drwx.Save Else e.WriteString(jo.ToString) \'在用户浏览器显示错误信息 Return End If End If e.AppendCookie("openid",OpenID) sb.Append("<meta http-equiv=\'refresh\' c>") e.WriteString(sb.ToString) Else e.WriteString(jo.ToString) \'在用户浏览器显示错误信息 Return End If End If [此贴子已经被作者于2017/12/19 22:31:19编辑过]
|
-- 作者:有点蓝 -- 发布时间:2017/12/19 22:47:00 -- 测试一下提示框是否能够出现 …… If jo("openid") IsNot Nothing Then \'如果获取openid成功(成功的话,还会同时返回一个accesstiken,用于获取用户详情) OpenID = jo("openid") If e.GetValues("state") = "gugisrq" Then popmessage(openid) \'正常执行 Dim url As String = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN" url = CExp(url, Functions.Execute("GetAccessToken12","变量A"), openid) \'oI4erjj48vvEdVxFzbAj6fZ8SSLw Dim hc1 As New HttpClient(url) Dim jo1 As JObject = Jobject.Parse(hc1.GetDaTa) popmessage(jo1("subscribe")) ‘能够弹出来吗 If jo1("openid") IsNot Nothing Then If jo1("subscribe") = "0" Then msgbox(0) e.WriteString("请先关注公众号") Return ElseIf jo1("subscribe") = "1" Then e.writestring("可以访问网页") msgbox(1) Return End If Else e.WriteString(jo.ToString) \'在用户浏览器显示错误信息 msgbox(2) Return End If msgbox(3) 以上黄色这段单独测试没问题(用固定的openid),整段去掉黄色的也没问题。就是这样放在一起,一访问这个页面就死掉。不知道什么原因。。。 End If ……
|
-- 作者:fubblyc -- 发布时间:2017/12/19 22:49:00 -- 蓝老师, 就到这里: If e.GetValues("state") = "gugisrq" Then popmessage(openid) \'正常执行 下面的就死了。 但是单独测试黄色整段的都没有问题。
[此贴子已经被作者于2017/12/19 22:49:35编辑过]
|
-- 作者:有点蓝 -- 发布时间:2017/12/19 22:52:00 -- If e.GetValues("state") = "gugisrq" Then popmessage(openid) \'正常执行 Dim url As String = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN" dim acc as string = Functions.Execute("GetAccessToken12","变量A") msgbox(acc) url = CExp(url, acc, openid) \'oI4erjj48vvEdVxFzbAj6fZ8SSLw Dim hc1 As New HttpClient(url) dim ret as strng = hc1.GetDaTa msgbox(ret) Dim jo1 As JObject = Jobject.Parse(ret) popmessage(jo1("subscribe")) ‘能够弹出来吗 If jo1("openid") IsNot Nothing Then If jo1("subscribe") = "0" Then msgbox(0) e.WriteString("请先关注公众号")
|
-- 作者:fubblyc -- 发布时间:2017/12/19 22:55:00 -- [此贴子已经被作者于2017/12/19 22:56:20编辑过]
|
-- 作者:fubblyc -- 发布时间:2017/12/19 23:06:00 -- 蓝老师,就到第一个弹窗: If e.GetValues.ContainsKey("code") And e.GetValues("state") = "arq" Then \'如果是通过授权链接跳转而来,就从链接重提取code来获取openid Dim ul As String = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code" ul = CExp(ul,appid,secret,e.GetValues("code")) Dim hc As new HttpClient(ul) Dim jo As JObject = JObject.Parse(hc.GetData) If jo("openid") IsNot Nothing Then \'如果获取openid成功(成功的话,还会同时返回一个accesstiken,用于获取用户详情) OpenID = jo("openid") messagebox.show(openid) \'就到这里。下面就死了 Dim url As String = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN" \' url = CExp(url, Functions.Execute("GetAccessToken12","变量A"), openid) \'oI4erjj48vvEdVxFzbAj6fZ8SSLw Dim acc As String = Functions.Execute("GetAccessToken12","变量A") messagebox.show(acc) url = CExp(url, acc, openid) \'oI4erjj48vvEdVxFzbAj6fZ8SSLw Dim hc1 As New HttpClient(url) Dim ret As String = hc1.GetDaTa messagebox.show(ret) Dim jo1 As JObject = Jobject.Parse(ret) messagebox.show(jo1("subscribe")) If jo1("subscribe") = "0" Then e.WriteString("请先关注公众号") messagebox.show("0") Return ElseIf jo1("subscribe") = "1" Then sb.Append("<meta http-equiv=\'refresh\' c>") e.WriteString(sb.ToString) Return End If Else e.WriteString(jo.ToString) \'在用户浏览器显示错误信息 Return End If End If [此贴子已经被作者于2017/12/19 23:06:36编辑过]
|
-- 作者:fubblyc -- 发布时间:2017/12/19 23:23:00 -- 我Functions.Execute("GetAccessToken12","变量A") 函数的代码是这样: Dim _zhangtao As String= Args(0) Dim hc As New HttpClient("http://www.yft.net/GetAccessToken/") \'请改为中控服务器的实际IP hc.FormData.Add("name","yonghuming") \'添加用户名和密码 hc.FormData.Add("password","mima") hc.FormData.Add("zhangtao",_zhangtao) Dim AccessTocken = hc.GetData \'获取AccessToken output.Show(AccessTocken) Return AccessTocken 这个在 命令窗口执行没有问题 [此贴子已经被作者于2017/12/19 23:24:25编辑过]
|
-- 作者:有点蓝 -- 发布时间:2017/12/20 8:49:00 -- 中控服务是如何处理的,写了什么代码?Dim hc As New HttpClient("http://www.yft.net/GetAccessToken/") www.yft.net是否是和微信服务是同一台电脑的?是云服务器还是本地服务器? 如果中控服务和微信服务是在同一个项目的,直接调用获取AccessToken的函数;如果不是同一个项目但是在同一台服务器的,通过本地ip访问,如"http://127.0.0.1/GetAccessToken/"
|
-- 作者:fubblyc -- 发布时间:2017/12/21 -- 对,就是这个问题。 谢谢蓝老师,解决了
|