wlzboy
2025-07-09 ab0742bf945b5de8554761de6fa4ecda29f640e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%Session.CodePage=65001%>
<!--#include virtual="/inc/odbc.asp"-->
<%weixinID = Request("weixinAPPid")
scene_id = Request("QR_ID")
QR_Name=Request("QR_Name")
QR_type=Request("QR_type")
QR_Key=Request("QR_Key")
QRNew=Request("QRNew")
If weixinID="" Then weixinID=1
If scene_id="" And (QR_type="" Or QR_Key="") Then response.End%>
<!--#include virtual="/inc/JsonPost.asp"-->
<%
'Response.end
    'ID验证
    If scene_id<>"" Then
        sql="select * from weixinQR where QR_ID="&scene_id
    Else
        sql="select * from weixinQR where QR_type="&QR_type&" and QR_Key='"&QR_Key&"'"
    End If
    rs.open sql,objConn,1,1
    If rs.eof Then
        QR_ticket=""
        If scene_id="" Then
            rs.close()
            sql="select top 1 QR_ID from weixinQR where QR_ID<100000 order by QR_ID desc"
            rs.open sql,objConn,1,1
            If not rs.eof Then
                scene_id=CSng(rs(0))+1
            Else
                scene_id=1
            End If
        End If
        If QR_type=1 Then        '车牌
            
        ElseIf QR_type=2 Then    '人员
        
        ElseIf QR_type=4 Then    '个人用户
            QR_Name="个人二维码"
        Else
            QR_type=0
        End If
        sql="Insert into weixinQR (QR_ID,QR_Name,QR_type,QR_Key) values ("&scene_id&",'"&QR_Name&"',"&QR_type&",'"&QR_Key&"')"
        objConn.Execute sql
        QR_Time=DateAdd("s",2592000,Now) 
    Else
        scene_id=CSng(rs("QR_ID"))
        QR_Name=rs("QR_Name")
        QR_type=rs("QR_type")
        QR_ticket=rs("QR_ticket")
        QR_url=rs("QR_url")
        QR_Time=DateAdd("s",2592000,rs("QR_Time"))
        If InStr(QR_url,"errmsg")>0 Then QR_url=null
    End If
 
    rs.close()
 
    '二维码生成
    If (QR_ticket="" Or isnull(QR_ticket)) Or QRNew=1 Or QR_Time<Now()  Or isnull(QR_url) then
        appUrl="https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token="&access_token
 
        If scene_id>100000 Then
            '微信临时二维码请求
            QR_type=0
            args1="{"
            args1=args1&"""expire_seconds"": 2592000,"    '该二维码有效时间,以秒为单位。 最大不超过604800(即7天)。
            args1=args1&"""action_name"": ""QR_SCENE"","    '二维码类型,QR_SCENE为临时,QR_LIMIT_SCENE为永久,QR_LIMIT_STR_SCENE为永久的字符串参数值
            args1=args1&"""action_info"": {""scene"": {"    '二维码详细信息
            args1=args1&"""scene_id"": "&scene_id&""    '场景值ID,临时二维码时为32位非0整型,永久二维码时最大值为100000(目前参数只支持1--100000)
            args1=args1&"}}"
            'args1=args1&"""scene_str"": """&touser&""","    '场景值ID(字符串形式的ID),字符串类型,长度限制为1到64,仅永久二维码支持此字段
            args1=args1&"}"
            'Response.Write appUrl&"<br>"&args1 &"<br><br><br>"
 
        Else
            '微信永久二维码请求
            QR_type=1
            args1="{""action_name"": ""QR_LIMIT_SCENE"", ""action_info"": {""scene"": {""scene_id"": "&scene_id&"}}}"
 
        End If 
        'Response.Write appUrl&"<br><br>"
        HTMLCODE= PostBody(appUrl,args1)
        'Response.Write HTMLCODE &"<br><br>"
        QR_ticket=replace(HTMLCODE,"{""ticket"":""","")
        QR_ticket=Left(QR_ticket,InStr(QR_ticket,"""")-1)
        QR_url=Mid(HTMLCODE,InStr(HTMLCODE,"""url"":""")+7)
        QR_url=Mid(QR_url,1,InStr(QR_url,"""}")-1)
        QR_url=replace(QR_url,"\/","/")
        If InStr(QR_url,"40001")=0 Then
            sql="update weixinQR set QR_ticket='"&QR_ticket&"',QR_url='"&QR_url&"',QR_Time=getdate() where QR_ID="&scene_id
            objConn.Execute sql
        End If
 
    End If
QR_ticket=Replace(QR_ticket,"\/","/")
Response.Write "{""result"":1,""QR_URL"":""https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket="&QR_ticket&"""}"
 
 
 
 
%>