Foxtable(狐表)用户栏目专家坐堂 → cookies 没有起效果


  共有2204人关注过本帖平板打印复制链接

主题:cookies 没有起效果

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


加好友 发短信
等级:九尾狐 帖子:2355 积分:16187 威望:0 精华:0 注册:2013/9/1 8:09:00
  发帖心情 Post By:2017/10/26 22:07:00 [只看该作者]

恩恩,甜老师,我单独做了网页,还是不正常。说明添加cookies代码有问题。以下是全部代码。。。你帮我看下。看到底哪里错。。。。
If e.host = "www.soft.net" Then '
    Dim UserNamewx As String
    Dim openid As String
    
    Dim appid As String
    Dim secret As String
    Dim zhangtao As String
    
    
    If  e.GetValues.ContainsKey("code") And e.GetValues("state") = "quanzhou" Then '如果是通过授权链接跳转而来,就从链接重提取code来获取openid
        appid = "wx99..."
        secret = "d7df..."
    End If
    
    If  e.GetValues.ContainsKey("code") And e.GetValues("state") = "shandong" Then '如果是通过授权链接跳转而来,就从链接重提取code来获取openid
        appid = "wx89"
        secret = "bd8ca"
    End If
    If  e.GetValues.ContainsKey("code") And e.GetValues("state") = "sichuan" Then '如果是通过授权链接跳转而来,就从链接重提取code来获取openid
        appid = "wx005d"
        secret = "3c1b8b"
    End If
    
    If  e.GetValues.ContainsKey("code") And e.GetValues("state") = "shanxi" Then '如果是通过授权链接跳转而来,就从链接重提取code来获取openid
        appid = "wx686ef"
        secret = "07b"
    End If
    
    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
            '    UserNamewx = drwx("nickname")
        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
                UserNamewx = jo("nickname")
                drwx = DataTables("WXUsers").AddNew()
                Dim nms() As String = {"openid","nickname","sex","city","country","province","headimgurl"} '""
                For Each nm As String In nms
                    drwx(nm) = jo(nm)
                Next
                drwx("addtime") = Date.now
                drwx.Save
                DataTables("WXUsers").loadfilter = "openid = ''"
                DataTables("WXUsers").load
            Else
                e.WriteString(jo.ToString) '在用户浏览器显示错误信息
                Return
            End If
        End If
        '   e.AppendCookie("usernamewx",UserNamewx) '用户名和openid存储在Cookie中
        wb.AppendCookie("openid",openid)
        e.AppendCookie("openid",openid)
        e.Cookies.add("openid",openid)
        messagebox.show(Date.now & openid)
    Else
        e.WriteString(jo.ToString) '在用户浏览器显示错误信息
        Return
    End If
e.WriteString(wb.Build) '生成网页    
End If
[此贴子已经被作者于2017/10/26 22:07:52编辑过]

 回到顶部
总数 15 1 2 下一页