接收二维码扫描事件

用户扫描带场景ID的二维码,会向Foxtable端的HTTP服务推送事件,事件推送分两种情况:

接收处理二维码扫描事件,可以参考以下HttpRequest事件代码:

Select Case e.path
    Case "wefox"
        If e.Request.HttpMethod.ToUpper = "GET"
            If Functions.Execute("VerifySignature",e) Then
                e.WriteString(e.GetValues("echostr"))
           
End If
        ElseIf e.Request.HttpMethod.ToUpper = "Post"
            Dim xo As Foxtable.XObject = Foxtable.XObject.Parse(e.PlainText)
            Dim st As New
Date(1970,1,1,8,0,0)
            Select Case xo("MsgType")
                Case "text","image"
                   
'保存和回复文本和图片消息的代码
               
Case "event"
                    Select Case xo("Event")
                        Case "subscribe"
'
关注事件
                           
'
处理用户关注事件的代码
                            Dim eKey As String = xo("EventKey")
                            If eKey  IsNot Nothing AndAlso eKey.StartsWith("qrscene_")Then
'
判断是否是通过扫描二维码关注
                                Dim openid As String = xo("FromUserName")
'
获取用户OpenID
                                Dim ticket As String = xo("Ticket")
'
获取二维码的ticket
                                Dim sceneid As String = eKey.SubString(8
'
获取二维码的情景ID,排除前缀qrscene_
                               
'
被动回复消息
                                Dim so As New Foxtable.XObject()
                                so("ToUserName") = xo("FromUserName")
                                so("FromUserName") = xo("ToUserName")
                                so("CreateTime") = (Date.Now - st).TotalSeconds()
                                so("MsgType") = "text"
                                so("Content") = "
您好,谢谢关注,您扫描的二维码的情景ID" & sceneid
                                e.WriteString(so.ToXML)
                            End If
                        Case "unsubscribe"
'
取消关注事件
                           
'
处理用户取消关注事件的代码'
                        Case "LOCATION"
'
上报地理位置事件
                           
'处理用户上报地理位置的代码
                        Case "TEMPLATESENDJOBFINISH"
                            '处理模板消息发送事件的代码
                        Case "SCAN"
                            Dim openid As String = xo("FromUserName") '获取用户OpenID
                            Dim ticket As String = xo("Ticket") '获取二维码的ticket
                            Dim sceneid As String = xo("EventKey") '获取二维码的情景ID
                            '被动回复消息
                            Dim so As New Foxtable.XObject()
                            so("ToUserName") = xo("FromUserName")
                            so("FromUserName") = xo("ToUserName")
                            so("CreateTime") = (Date.Now - st).TotalSeconds()
                            so("MsgType") = "text"
                            so("Content") = "您好,您扫描的二维码的情景ID为" & sceneid
                            e.WriteString(so.ToXML)
                   
End Select
            End Select
        End
If

End
Select

为避免代码冗余,也为了精简HttpRequest事件代码,建议将相关代码做成自定义函数。


本页地址:http://www.foxtable.com/mobilehelp/topics/0197.htm