Foxtable(狐表)用户栏目专家坐堂 → [求助]企业微信网页取邮箱


  共有1724人关注过本帖树形打印复制链接

主题:[求助]企业微信网页取邮箱

帅哥哟,离线,有人找我吗?
ajie5211
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:815 积分:5616 威望:0 精华:1 注册:2015/11/28 14:00:00
[求助]企业微信网页取邮箱  发帖心情 Post By: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编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
ajie5211
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:四尾狐 帖子:815 积分:5616 威望:0 精华:1 注册:2015/11/28 14:00:00
  发帖心情 Post By:2018/9/12 14:36:00 [只看该作者]

企业微信帮助里有这么一段:

使用user_ticket获取成员详情

请求方式:POST(HTTPS)
请求地址:https://qyapi.weixin.qq.com/cgi-bin/user/getuserdetail?access_token=ACCESS_TOKEN

请求包体:

{
   "user_ticket": "USER_TICKET"
}

 

这个是怎么用的?啥子意思?


 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/9/12 14:48:00 [只看该作者]

1、加入msgbox调试一下哪句代码出问题

 

http://www.foxtable.com/webhelp/scr/1485.htm

 

2、比如下面这样调用,把参数传递进去即可

 

http://www.foxtable.com/mobilehelp/scr/0224.htm

 


 回到顶部