以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  微信如何从接收到的模板信息,直达目标页面。  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=132076)

--  作者:qwz405
--  发布时间:2019/3/13 12:19:00
--  微信如何从接收到的模板信息,直达目标页面。
老师,您好。

1、员工接收到模板信息,点击“详情”登录,"详情"链接如下所示:
 jo("url") = "http://abc.cn/abc.htm?key=" & PrimaryKey &  "&page=" & PageNumber &  "&from=2"       \'数据详细页面


2、员工若当天第1次登录,需要先获取openid,会登录到首页:http://abc.cn
    需要关闭次页面,再点击“详情”,才能到达目标页面(即要登录2次):http://abc.cn/abc.htm
    当天后续的登录,因为openid已经存在,所以都会到达目标页面。

咨询:授权登录页面要如何修改?

If e.host = "abc.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,"wxd123***","333***",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中,后续使用此openid
        End If
    Else
        OpenId =  e.Cookies("openid")   \'否则从cookie中提取openid
    End If
    Dim Verified As Boolean
    Dim dr As DataRow = DataTables("Users").SQLFind("openid  =\'" & OpenID & "\'")     \'从登录用户表中,根据openid找出对应的行
    If OpenId > "" AndAlso dr IsNot Nothing AndAlso dr("离职") = 0 Then      \'存在需要访问者的openid,而且未离职.
        Verified  = True
    ElseIf e.GetValues.ContainsKey("code") = False Then       \'如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接
        Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd***&redirect_uri=http%3a%2f%2fabc.cn&response_type=code&scope=snsapi_base&state=123#wechat_redirect"
        sb.Append("<meta h t t p-equiv=\'Refresh\' c o ntent=\'0; u r l=" & ul & "\'>")         \'跳转到授权链接
        e.WriteString(sb.ToString)
        Return      \'必须的
    End If
    Dim wb As New weui
    If Verified = False Then
        wb.InsertHTML("<meta h t t p-equiv=\'Refresh\' c o ntent=\'0; url=/***.htm\'>")        \'直接跳转到登录页,显示无登录权限.
        e.WriteString(wb.Build)     \'生成网页
        Return  \'必须的
    ElseIf e.path = "" Then     \'从登录页访问
        wb.InsertHTML("<meta h t t p-equiv=\'Refresh\' c o ntent=\'0; url=/d efault.htm\'>")    \'直接跳转到首页
        e.WriteString(wb.Build)     \'生成网页
        Return  \'必须的
    End If
End If


Select Case e.path     
    
    Case "abc.htm"    
        Functions.Execute("abc",e)

End Select
[此贴子已经被作者于2019/3/13 17:18:39编辑过]

--  作者:有点甜
--  发布时间:2019/3/13 12:32:00
--  

你这个合成的地址,跳转到对应的e.path路径去,也就是合成如 http://abc.cn/abc.htm?key=123 这样的地址 

 

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"


--  作者:qwz405
--  发布时间:2019/3/13 14:58:00
--  
老师,按您的提示,我在推送信息中插入了OpenID。
因为我在给员工推送信息的时候,首先要获取要推送对象的OpenID,所以在推送模板的链接中加入OpenID,只是顺带的事
 jo("url") = "http://abc.cn/abc.htm?key=" & PrimaryKey &  "&page=" & PageNumber &  "&id=OpenID"       \'数据详细页面


然后员工打开“详情”链接,就可以直接获得OpenID直达需要的页面。

现在的问题是:我在推送链接中插入OpenID,这样目的是达到了,但OpenID直接暴露,只要有人用此OpenID合成一段链接代码,就可以登录到系统内部了。
是否有别的好办法可以处理?或者说我这个问题是多余的,这样操作是安全的?

If e.host = "abc.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,"wxd123***","333***",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中,后续使用此openid
        End If
    Else

        Dim OpenId  As String = e.GetValues("id")
        If OpenId > "" Then
            
            OpenId = OpenId  

        Else
            
            OpenId =  e.Cookies("openid")   \'否则从cookie中提取openid
        End If
    End If
    Dim Verified As Boolean
    Dim dr As DataRow = DataTables("Users").SQLFind("openid  =\'" & OpenID & "\'")     \'从登录用户表中,根据openid找出对应的行
    If OpenId > "" AndAlso dr IsNot Nothing AndAlso dr("离职") = 0 Then      \'存在需要访问者的openid,而且未离职.
        Verified  = True
    ElseIf e.GetValues.ContainsKey("code") = False Then       \'如果授权失败,且不是通过授权链接跳转而来,那么就跳转到授权链接
        .....****....
End If


Select Case e.path     
    
    Case "abc.htm"    
        Functions.Execute("abc",e)

End Select
[此贴子已经被作者于2019/3/13 14:59:53编辑过]

--  作者:有点甜
--  发布时间:2019/3/13 15:27:00
--  

1、openid暴露没问题,别人无法通过你的openid获取微信的信息;

 

2、但是,你这里编写的代码逻辑有问题,openid,请从微信那里获取,或者从cookie里面获取。

 

3、请认认真真看看 2楼啊,授权后,跳转回来的地址,改成你e.path的路径啊。


--  作者:qwz405
--  发布时间:2019/3/13 17:06:00
--  
老师,您好。
推送的信息有几十种,url是不相同的(每次目标地址e.path是不确定的),我是否可以获得登录者的访问链接,就可以合成地址

jo("url") = "http://abc.cn/***.htm?key=" & PrimaryKey &  "&page=" & PageNumber &  "&from=***"        \'数据详细页面


--  作者:有点甜
--  发布时间:2019/3/13 18:00:00
--  

改成这样,动态合成

 

msgbox(UrlEncode(e.Request.URL.ToString))

 

Dim ul As String = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxd0106a49b1e546b4&redirect_uri=" & UrlEncode(e.Request.URL.ToString) & "&response_type=code&scope=snsapi_base&state=123#wechat_redirect"

[此贴子已经被作者于2019/3/13 18:00:16编辑过]