https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx8921022fc595bc93&redirect_uri=http%3a%2f%2fwww.yijiansoft.net&response_type=code&scope=snsapi_userinfo&state=antashandong#wechat_redirect
Dim AppId As String= dr("AppId")
Dim Secret As String = dr("AppSecret")
Dim zhangtao As String = dr("账套")
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")
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)
e.AppendCookie("zhangtaowxzc",dr("账套"))
sb.Append("<meta http-equiv='refresh' c o n t e n t = '0; u r l =/yhqshouye.htm'>")
'sb.Append("<meta http-equiv='refresh' c >")
e.WriteString(sb.ToString)
Else
e.WriteString(jo.ToString) '在用户浏览器显示错误信息
Return ""
End If
End If