蓝老师,你帮忙看下。。。
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编辑过]