以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  网页授权域名 失败  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=101505)

--  作者:qwz405
--  发布时间:2017/6/1 19:22:00
--  网页授权域名 失败
微信 服务号

是否我HttpRequet要响应它的授权?


图片点击可在新窗口打开查看此主题相关图片如下:123.jpg
图片点击可在新窗口打开查看


--  作者:有点色
--  发布时间:2017/6/1 20:39:00
--  

 你测试哪一个有问题?这个?

 

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

 


--  作者:qwz405
--  发布时间:2017/6/1 20:56:00
--  
网页简单授权,用测试号,测试正常的。

这是认证的服务号,和测试号不一样,要下载个文件放置到web服务器目录中。

论坛里面没有提问过,郁闷,难到就我一个人碰到需要这样授权的~

应该是服务器要设置下,能让微信访问到就可以了,但不知道怎么设置~




--  作者:有点色
--  发布时间:2017/6/1 22:51:00
--  
 把那个txt文件,放在你服务器web文件夹下即可。
--  作者:qwz405
--  发布时间:2017/6/2 10:25:00
--  
老师,您好。
已经将文件放到了web服务器文件夹下:e:\\baidu\\web\\
应该是微信访问不到这个文件,或者访问前被阻止,或者被重定向了。

下面是我的HttpRequet代码,是否哪里有设置,或者我服务器要开端口。



Dim fl As String = "e:\\baidu\\web\\" & e.path     \'设置网页根目录
If filesys.FileExists(fl)
    Dim idx As Integer = fl.LastIndexOf(".")
    Dim ext As String  = fl.SubString(idx)
    Select Case ext
        Case ".jpg",".gif",".png",".bmp",".wmf",".js",".css" ,".html",".htm",".zip",".rar"
            e.WriteFile(fl)
            Return   \'这里必须返回
    End Select
End If


Select Case e.path
    
    Case "abc","abc1"        \'接口配置...接入验证,以及接入后进行收发消息.
        If e.Request.HttpMethod.ToUpper = "GET"
            If Functions.Execute("VerifySignature",e) Then        \'使用自定义函数Verifysignature,后续修改函数的Token即可
                e.WriteString(e.GetValues("echostr"))
            End If
        End If
End Select



Select Case e.path      \'下面是一些不需要授权就能访问的链接
    
    Case "***.htm"             
        Functions.Execute("***",e)
        
    ....
        
End Select


\'------需要授权才能访问....直接拷贝的帮助文件,还没有修改
If e.host = "abc.dddd.cn" Then \'需要授权才能访问的域名
    Dim OpenID As String
    Dim sb As New StringBuilder
    sb.AppendLine("<meta name=\'viewport\' c>")
    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,"wxd0106a49b1e546b4","541e1c7d389240ae705b8eb40c05ca22 ",e.GetValues("code"))
        Dim hc As new HttpClient(ul)
        Dim jo As JObject = JObject.Parse(hc.GetData)
        If jo("openid") IsNot Nothing Then
            OpenID = jo("openid")
            e.AppendCookie("openid",OpenID) \'将openid存储在Cookie中
        End If
    Else
        OpenId =  e.Cookies("openid") \'否则从cookie中提取openid
    End If
    Dim Verified As Boolean
    Dim dr As DataRow = DataTables("WXUsers").Find("openid  =\'" & OpenID & "\'") \'根据openid找出对应的行
    If OpenId > "" AndAlso dr IsNot Nothing AndAlso dr("permit") = True \'授权成功
        Verified  = True
    ElseIf e.GetValues.ContainsKey("code") = False Then \'如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接
        Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd0106a49b1e546b4&redirect_uri=http%3a%2f%2flitz.litzchina.cn&response_type=code&scope=snsapi_base&state=123#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("Foxtable欢迎您, <a href=\'http://wexin.foxtable.com\'>刷新页面</a>")
    End If
    e.WriteString(sb.ToString)
End If



Select Case e.path      \'下面是一些需要授权就能访问的链接
    
    Case "***.htm"             
        Functions.Execute("***",e)
        
    ....
        
End Select

[此贴子已经被作者于2017/6/2 11:51:10编辑过]

--  作者:有点蓝
--  发布时间:2017/6/2 10:39:00
--  
Case ".jpg",".gif",".png",".bmp",".wmf",".js",".css" ,".html",".htm",".zip",".rar",".txt"
--  作者:qwz405
--  发布时间:2017/6/2 18:19:00
--  
老师,授权通过后,怎么跳转到指定的网页?
下面的代码网页会一直在跑,出不来画面。

    Dim wb As New weui
    If Verified = False Then
        sb.AppendLine("你无权访问本系统")
        e.WriteString(sb.ToString)
    Else
        \'sb.AppendLine("Foxtable欢迎您, <a href=\'http://wexin.foxtable.com\'>刷新页面</a>")
        \'e.WriteString(sb.ToString)
        wb.InsertHTML("<meta http-equiv=\'Refresh\' c>")     \'直接跳转到首页
    End If
    e.WriteString(wb.Build)     \'生成网页


--  作者:有点蓝
--  发布时间:2017/6/2 20:08:00
--  
首页代码贴出来看看
--  作者:qwz405
--  发布时间:2017/6/2 21:12:00
--  
老师,您好。
使用的是移动开发指南《简单网页授权》中的代码

If e.host = "abc.dddd.cn" Then \'需要授权才能访问的域名
    Dim OpenID As String
    Dim sb As New StringBuilder
    sb.AppendLine("<meta name=\'viewport\' c>")
    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,"wxd0106a49b1e546b4","541e1c7d389240ae705b8eb40c05ca22 ",e.GetValues("code"))
        Dim hc As new HttpClient(ul)
        Dim jo As JObject = JObject.Parse(hc.GetData)
        If jo("openid") IsNot Nothing Then
            OpenID = jo("openid")
            e.AppendCookie("openid",OpenID) \'将openid存储在Cookie中
        End If
    Else
        OpenId =  e.Cookies("openid") \'否则从cookie中提取openid
    End If
    Dim Verified As Boolean
    Dim dr As DataRow = DataTables("WXUsers").Find("openid  =\'" & OpenID & "\'") \'根据openid找出对应的行
    If OpenId > "" AndAlso dr IsNot Nothing AndAlso dr("permit") = True \'授权成功
        Verified  = True
    ElseIf e.GetValues.ContainsKey("code") = False Then \'如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接
        Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd0106a49b1e546b4&redirect_uri=http%3a%2f%2flitz.litzchina.cn&response_type=code&scope=snsapi_base&state=123#wechat_redirect"    
        sb.Append("<meta http-equiv=\'Refresh\' c o n t ent=\'0; url=" & ul & "\'>") \'跳转到授权链接
        e.WriteString(sb.ToString)
        Return
    End If

    Dim wb As New weui
    If Verified = False Then
        sb.AppendLine("你无权访问本系统")
        e.WriteString(sb.ToString)
    Else
        \'sb.AppendLine("Foxtable欢迎您, <a href=\'http://wexin.foxtable.com\'>刷新页面</a>")
        \'e.WriteString(sb.ToString)
        wb.InsertHTML("<meta http-equiv=\'Refresh\' c o n t ent=\'0; url=/default.htm\'>")     \'直接跳转到首页
    End If
    e.WriteString(wb.Build)     \'生成网页
End If



Select Case e.path      \'下面是一些需要授权就能访问的链接
    
    Case "default.htm"             
        Functions.Execute("default",e)
        
    Case "***.htm"             
        Functions.Execute("***",e)
    ....
        
End Select


--  作者:有点蓝
--  发布时间:2017/6/2 21:48:00
--  
Dim wb As New weui
If Verified = False Then
    sb.AppendLine("你无权访问本系统")
    e.WriteString(sb.ToString)
    Return
ElseIf e.path = ""
    \'sb.AppendLine("Foxtable欢迎您, <a href=\'http://wexin.foxtable.com\'>刷新页面</a>")
    \'e.WriteString(sb.ToString)
    wb.InsertHTML("<meta http-equiv=\'Refresh\' c o n t ent=\'0; url=/default.htm\'>")     \'直接跳转到首页
    e.WriteString(wb.Build)     \'生成网页
    Return
End If