-- 作者:ajie5211
-- 发布时间:2018/9/12 13:07:00
-- [求助]企业微信网页取邮箱
如下代码,我需要用到企业微信中的邮箱,但总提示出错,把用户ID复制出来单独查询邮箱是可以,写到一块就不行了。
Dim e As RequestEventArgs = args(0) If e.host = "www.china-wj.net" Then \'需要授权才能访问的域名 Dim UserId As String Dim UserName As String Dim UserEmail As String Dim sb As New StringBuilder sb.AppendLine("<meta name=\'viewport\' c>") If e.GetValues.ContainsKey("code") Then \'如果通过授权链接跳转而来,就根据传递过来的code参数调用接口,获取用户的UserId Dim ul As String ul = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token={0}&code={1}" ul = CExp(ul,Functions.Execute("getcardbookAccessToken"),e.GetValues("code")) Dim hc As new HttpClient(ul) Dim jo As JObject = JObject.Parse(hc.GetData) If jo("UserId") IsNot Nothing Then UserId = jo("UserId") End If Dim ul1 As String ul1 = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token={0}&userid={1}" ul1 = CExp(ul1,Functions.Execute("getcardbookAccessToken"),UserId) Dim hc1 As new HttpClient(ul1) Dim jo1 As JObject = JObject.Parse(hc1.GetData) If jo1("email") IsNot Nothing Then UserEmail = jo1("email") End If Else UserId = e.Cookies("userid") \'否则从cookie中提取userid和username UserEmail = e.Cookies("useremail") End If Dim Verified As Boolean If UserId > "" Then \'授权成功 Verified = True e.AppendCookie("userid",UserId) \'将userid和username存储在Cookie中 e.AppendCookie("useremail",UserEmail) ElseIf e.GetValues.ContainsKey("code") = False Then \'如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接 Dim ul As String ul = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=ww9b694751da4a96a6&redirect_uri=http%3a%2f%2fwww.china-wj.net&response_type=code&scope=snsapi_base&state=wjexcel#wechat_redirect" sb.Append("<meta http-equiv=\'Refresh\' c>") \'跳转到授权链接 e.WriteString(sb.ToString) Return "" End If If Verified = False Then sb.AppendLine("你无权访问本系统") Else sb.AppendLine("欢迎" & UserId & ":" & UserEmail & " , <a href=\'http://www.china-wj.net\'>刷新页面</a>") End If e.WriteString(sb.ToString) End If
此主题相关图片如下:qq图片20180912130036.png

[此贴子已经被作者于2018/9/12 13:07:55编辑过]
|