【调度系统】广东民航医疗快线调度系统源代码
wlzboy
2025-09-06 2decf5219e3476e30095fd9dbf6e49c55e105563
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
<% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %> 
<% Session.CodePage=65001 %> 
<% Response.charset = "utf-8" %>
<!--#include virtual="/inc/odbc.asp"-->
<!--#include virtual="/inc/function.asp"-->
<!--#include virtual="/inc/core.asp"-->
<%
Set rs = Server.CreateObject("ADODB.Recordset")
Set rsDt = Server.CreateObject("ADODB.Recordset")
 
method=trim(Request("method"))
errcode=""
if method="" Then
    errcode=40001
    errmsg="invalid method"
end If
 
'时间戳验证----------
UnixTime=trim(Request("UnixTime"))
Call MD5_UnixTime(UnixTime)
'时间戳验证---end
 
'签名验证----------
ApiSign=trim(Request("Sign"))
if ApiSign="" Then
    errcode=40005
    errmsg="invalid Sign"
else
    '待签名字符串
    ReDim arr(Request.QueryString.Count+Request.Form.Count,2)
    Dim v                       '所有表单值
    Dim t                       '所有表单数量
    v=Request.QueryString
    If v<>"" And Request.Form<>"" Then
        v=v&"&"&Request.Form
    ElseIf Request.Form<>"" Then
        v=Request.Form
    End If
    t=Request.QueryString.Count+Request.Form.Count
    For i=0 To t-1
     arr(i,1)=Split(Split(v,"&")(i),"=")(0)
     arr(i,2)=Split(Split(v,"&")(i),"=")(1)
    Next
    For i = 0 To t-1
        For j = i + 1 To t-1
            If arr(i,1) > arr(j,1) Then
                tmp1 = arr(i,1)
                arr(i,1) = arr(j,1)
                arr(j,1) = tmp1
                tmp2 = arr(i,2)
                arr(i,2) = arr(j,2)
                arr(j,2) = tmp2
            End If
        Next
    Next
    For i = 0 To t-1
        'response.write arr(i,1) & "=" & arr(i,2) & "<br>"
        If arr(i,1)="Sign" Then
            reserve=arr(i,2)
        else
            If arr(i,2)="timestamp" Then arr(i,2)=Date() &" "& Time()
            sParaSort=sParaSort & arr(i,1) & arr(i,2)
            sParaRunning=sParaRunning &"&"& arr(i,1) &"="& arr(i,2)
        End if
    Next
    sign_type       = "MD5"
    input_charset="utf-8"
    stringA=sParaSort&key
    'response.write sParaSort & "<br>"
    Private Function BuildRequestMysign(sParaSort)
        '获得签名结果
         Select Case sign_type
            Case "MD5" BuildRequestMysign = Md5Sign(sParaSort,key,input_charset)
            Case Else BuildRequestMysign = ""
         End Select
    End Function
    sParaSort=BuildRequestMysign(sParaSort)
    If CStr(ApiSign)<>CStr(sParaSort) Then
        errcode=40006
        errmsg="invalid Sign"
        '签名调试
        If is_test="1" Or ApiSign="vicgame" Then errmsg="invalid stringA:"&stringA&",Sign:"&sParaSort
        errmsg="invalid stringA:"&stringA&",Sign:"&sParaSort
    End If
End If
'签名验证---end
 
Function saveCoupon(objConn,Money,UserID,Remarks,Name)
    CouponNO=DTimeID()&getIDnumbers(6)
    CouponMoney=Money
    CouponRemarks=Remarks
    CouponName=Name
    If UserID="" Then UserID=0
    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365*2,'"&CouponRemarks&"',0,"&UserID&")"
    objConn.Execute sql
End Function
 
objConn.BeginTrans
 
If errcode="" then
    select case method
    case "APITest"    '接口测试
        TestData=trim(Request("Test"))    '服务单状态
        webJson="{""method"":""APITest"",""result"":1,""Test"":"""&TestData&"""}"
    '接口测试 end    
 
    case "User_Login"    '用户登陆/信息查询/用户注册
        '必须
        LoginType    = trim(Request("LoginType"))    '登陆方式(0用户ID,1电话号,2手机号+短信验证码,4微信openid)
        '可选
        UserSource    = trim(Request("UserSource"))    '用户来源信息
        UserName    = trim(Request("UserName"))        '用户姓名
        More        = trim(Request("More"))            '更多会员信息
 
        errcode=1
        NewUser=0
        RecommendUserID=0
        beginning_title=""
        beginning_address=""
        ending_title=""
        ending_address=""
        If UserSource="undefined" Then UserSource=""
        If IsNumeric(UserSource) Then UserSource="Rid"&UserSource    '来源为纯数字时,默认个人推荐ID(2023.11.3)
        If LoginType="" Then LoginType="0"
        If UserSource<>"" Then        '分拆推荐人
            UserSource    = Replace(UserSource,"lid","Iid")
            UserSource    = Replace(UserSource,"/","|")
            UserSourceSP    = SPLIT(UserSource,"|")
            UserSource        = ""
            for i=0 to ubound(UserSourceSP)
                If InStr(UserSourceSP(i),"Rid")>=1 Then
                    '推荐人信息
                    Rid=Replace(UserSourceSP(i),"Rid","")
                    If IsNumeric(Rid) Then RecommendUserID=Rid
                ElseIf UserSourceSP(i)="UP" Then
                    '更新来源信息
                    UpdateSource="YES"
                ElseIf UserSourceSP(i)="QR" Then
                    '转运快线小程序扫码下单
                    UpdateSource="QR"
                ElseIf UserSourceSP(i)="Valet" Then
                    '转运快线小程序代客下单
                    UpdateSource="Valet"
                ElseIf InStr(UserSourceSP(i),"iuid")>=1 Then
                    '转运快线小程序介绍人id
                    iuid=Replace(UserSourceSP(i),"iuid","")
                ElseIf InStr(UserSourceSP(i),"uuid")>=1 Then
                    '转运快线小程序推广单uuid
                    uuid=Replace(UserSourceSP(i),"uuid","")
                Else
                    UserSource = UserSource &"|"&UserSourceSP(i)
                    If InStr(UserSourceSP(i),"Iid")>=1 Then
                        Iid=Replace(UserSourceSP(i),"Iid","")
                        sql="select UnitName,UnitAddress from IntroducerData,IntroducerUnitData where UnitID=IntroducerUnitID and UnitAddress<>'' and IntroducerID="&Iid
                        rs.open sql,objConn,1,1
                        if not rs.eof Then
                            ending_title    = rs("UnitName")
                            ending_address    = rs("UnitAddress")
                        End If
                        rs.close()
                    End If
                    If UserSourceSP(i)="Iid75" Then
                        UserBranch    = "ZA"
                    ElseIf UserSourceSP(i)="Iid85" Then
                        UserBranch    = "HA"
                    ElseIf UserSourceSP(i)="Iid88" Then
                        UserBranch    = "JI"
                    ElseIf UserSourceSP(i)="Iid148" Then
                        ADUser="148"
                    ElseIf UserSourceSP(i)="Iid153" Then
                        ADUser="153"
                    ElseIf UserSourceSP(i)="Iid155" Then
                        ADUser="155"
                    ElseIf UserSourceSP(i)="Iid166" Then
                        ADUser="166"
                    ElseIf  UserSourceSP(i)="Iid193" Then
                        ADUser="193"
                    End If
                End If
            Next
            If UserSource<>"" Then UserSource=Mid(UserSource,2)
        End If
        If LoginType="0" Then        '用户ID登陆
            '必须
            UserID        = trim(Request("UserID"))    '用户唯一ID
        
        ElseIf LoginType="1" Then    '电话号登陆
            '必须
            UserPhone        = trim(Request("UserPhone"))    '用户手机号
            '可选
            UserID        = trim(Request("UserID"))    '用户唯一ID
 
            If UserPhone="" Or Not IsNumeric(UserPhone) Then
                errcode=40602
                errmsg="empty UserPhone"
            else
                sql="select top 1 id,ToUserID from UserPhone where strPhone='"&UserPhone&"' order by LoginTime desc"
                rs.open sql,objConn,1,1
                if not rs.eof Then
                    PhoneID        = rs("id")
                    ToUserID    = rs("ToUserID")
                Else
                    PhoneID=0
                    ToUserID=0
                End If
                rs.close()
                If UserID<>"" And UserID<>"0" And IsNumeric(UserID) And PhoneID<>0 Then
                    '更新已有手机信息
                    sql="update UserPhone set ToUserID="&UserID&",LoginTime=getdate() where id="&PhoneID
                    objConn.Execute sql
                    If UserSource<>"" Then
                        sql="update UserData set UserPhone='"&UserPhone&"',UserSource='"&UserSource&"' where UserID="&UserID
                    Else
                        sql="update UserData set UserPhone='"&UserPhone&"' where UserID="&UserID
                    End If
                    objConn.Execute sql
                ElseIf UserID<>"" And UserID<>"0" And IsNumeric(UserID) And PhoneID=0 Then
                    '新增用户手机信息
                    sql="Insert into UserPhone (ToUserID,strPhone,strPhone_is) values ("&UserID&",'"&UserPhone&"',1)"
                    objConn.Execute sql
                    sql="update UserData set UserPhone='"&UserPhone&"' where UserID="&UserID
                    objConn.Execute sql
                    'NewUser=1
                ElseIf PhoneID=0 And ToUserID=0 Then
                    '新用户&手机注册
                    sql="Insert into UserData (UserUnitID,UserPhone,UserSource) values ("&UnitID&",'"&UserPhone&"','"&UserSource&"')"
                    objConn.Execute sql
                    sql="select top 1 UserID from UserData where UserPhone='"&UserPhone&"' order by UserID desc"
                    rs.open sql,objConn,1,1
                    if not rs.eof Then
                        UserID=rs("UserID")
                        sql="Insert into UserPhone (ToUserID,strPhone) values ("&UserID&",'"&UserPhone&"')"
                        objConn.Execute sql
                    End If
                    rs.close()
                    NewUser=1
                Else
                    '正常手机登陆
                    UserID=ToUserID
                    sql="update UserPhone set LoginTime=getdate() where id="&PhoneID
                    objConn.Execute sql
                End If
                sql="update ServiceOrder set ServiceOrdUserID="&UserID&" where ServiceOrdUserID<>"&UserID&" and ServiceOrdCoPhone='"&UserPhone&"'"
                objConn.Execute sql
            End If
 
            sql="select top 1 ToUserID from UserPhone where strPhone='"&UserPhone&"' order by LoginTime desc"
            rs.open sql,objConn,1,1
            if not rs.eof Then
                UserID    = rs("ToUserID")
            Else
                errcode=40603
                errmsg="invalid UserPhone"
            End if
            rs.close()
 
        ElseIf LoginType="2" Then    '手机号+短信验证码登陆
            '必须
            UserPhone        = trim(Request("UserPhone"))        '用户手机号
            UserPhoneVerify    = trim(Request("UserPhoneVerify"))    '短信验证码
            '可选
            UserID        = trim(Request("UserID"))    '用户唯一ID
            
            If UserPhone="" Or UserPhoneVerify="" Or Not IsNumeric(UserPhone)  Then
                errcode=40603
                errmsg="empty UserPhone/UserPhoneVerify"
            else
                sql="select top 1 ID from UserPhoneVerify where Phone='"&UserPhone&"' and PhoneVerify='"&UserPhoneVerify&"' and datediff(Mi,SendTime,getdate())<=30 order by SendTime desc"
                rs.open sql,objConn,1,1
                if not rs.eof Then
                    rs.close()
                    PhoneID=0
                    ToUserID=0
                    sql="select top 1 id,ToUserID from UserPhone where strPhone='"&UserPhone&"' order by LoginTime desc"
                    rs.open sql,objConn,1,1
                    if not rs.eof Then
                        PhoneID        = rs("id")
                        ToUserID    = rs("ToUserID")
                    End If
                    If UserID<>"" And UserID<>"0" And IsNumeric(UserID) And PhoneID<>0 Then
                        '更新已有手机信息
                        sql="update UserPhone set strPhone_is=1,ToUserID="&UserID&",LoginTime=getdate() where id="&PhoneID
                        objConn.Execute sql
                        sql="update UserData set UserPhone='"&UserPhone&"' where UserID="&UserID
                        objConn.Execute sql
                    ElseIf UserID<>"" And UserID<>"0" And IsNumeric(UserID) And PhoneID=0 Then
                        '新增用户手机信息
                        sql="Insert into UserPhone (ToUserID,strPhone,strPhone_is) values ("&UserID&",'"&UserPhone&"',1)"
                        objConn.Execute sql
                        sql="update UserData set UserPhone='"&UserPhone&"' where UserID="&UserID
                        objConn.Execute sql
                    ElseIf PhoneID=0 And ToUserID=0 Then
                        '新用户&手机注册
                        rs.close()
                        sql="Insert into UserData (UserUnitID,UserPhone,UserSource) values ("&UnitID&",'"&UserPhone&"','"&UserSource&"')"
                        objConn.Execute sql
                        sql="select top 1 UserID from UserData where UserPhone='"&UserPhone&"' order by UserID desc"
                        rs.open sql,objConn,1,1
                        if not rs.eof Then
                            UserID=rs("UserID")
                            sql="Insert into UserPhone (ToUserID,strPhone,strPhone_is) values ("&UserID&",'"&UserPhone&"',1)"
                            objConn.Execute sql
                        End If
                        NewUser=1
                    Else
                        '正常手机登陆
                        UserID=ToUserID
                        sql="update UserPhone set strPhone_is=1,LoginTime=getdate() where id="&PhoneID
                        objConn.Execute sql
                    End If
                    sql="update ServiceOrder set ServiceOrdUserID="&UserID&" where ServiceOrdUserID<>"&UserID&" and ServiceOrdCoPhone='"&UserPhone&"'"
                    objConn.Execute sql
                Else
                    errcode=40603
                    errmsg="invalid UserPhoneVerify"
                End if
                rs.close()
            End If
 
        ElseIf LoginType="3" Then    '微信openid登陆
            '必须
            wxOpenid        = trim(Request("wxOpenid"))        '微信OpenID
            
            '可选
            UserID            = trim(Request("UserID"))    '用户唯一ID
            wxOriginalID    = trim(Request("wxOriginalID"))    '微信原始ID
            wxUnionID        = trim(Request("wxUnionID"))    '微信UnionID
            wxNickName        = trim(Request("wxNickName"))    '微信昵称
            wxAvatarUrl        = trim(Request("wxAvatarUrl"))    '微信头像链接
            
            If wxOpenid="" Or wxOpenid="undefined" Then
                errcode=40604
                errmsg="empty wxOpenid"
            else
                If wxUnionID="undefined" Then wxUnionID=""
                If wxOriginalID<>"" Then OriginalSql=" and OriginalID='"&wxOriginalID&"' "
                If wxUnionID<>"" Then UnionIDSql=",UnionID='"&wxUnionID&"'"
                sql="select top 1 id,ToUserID,UserPhone from weixinOpenID,UserData where UserID=ToUserID and OpenID='"&wxOpenid&"'"&OriginalSql&" order by LoginTime desc"
                rs.open sql,objConn,1,1
                if not rs.eof Then
                    weixinID    = rs("id")
                    ToUserID    = rs("ToUserID")
                    UserPhone    = rs("UserPhone")
                ElseIf wxUnionID<>"" Then
                    rs.close()
                    sql="select top 1 id,ToUserID from weixinOpenID where UnionID='"&wxUnionID&"' and ToUserID<>0 order by LoginTime desc"
                    rs.open sql,objConn,1,1
                    if not rs.eof Then
                        weixinID    = 0
                        ToUserID    = rs("ToUserID")
                        UserID        = ToUserID
                    Else
                        weixinID    = 0
                        ToUserID    = 0
                    End If
                Else
                    weixinID    = 0
                    ToUserID    = 0
                End If
                rs.close()
 
                If UserID<>"" And UserID<>"0" And IsNumeric(UserID) And weixinID<>0 Then
                    '更新已有微信信息
                    sql="update weixinOpenID set ToUserID="&UserID&",LoginTime=getdate()"&UnionIDSql&" where id="&weixinID
                    objConn.Execute sql
                ElseIf UserID<>"" And UserID<>"0" And IsNumeric(UserID) And weixinID=0 Then
                    '新增用户微信信息
                    sql="Insert into weixinOpenID (ToUserID,OriginalID,OpenID,UnionID) values ("&UserID&",'"&wxOriginalID&"','"&wxOpenid&"','"&wxUnionID&"')"
                    objConn.Execute sql
                ElseIf weixinID=0 And ToUserID=0 Then
                    '新用户&微信注册
                    sql="Insert into UserData (UserUnitID,UserSource) values ("&UnitID&",'"&UserSource&"')"
                    objConn.Execute sql
                    sql="select top 1 UserID from UserData order by UserID desc"
                    rs.open sql,objConn,1,1
                    if not rs.eof Then
                        UserID=rs("UserID")
                        sql="Insert into weixinOpenID (ToUserID,OriginalID,OpenID,UnionID) values ("&UserID&",'"&wxOriginalID&"','"&wxOpenid&"','"&wxUnionID&"')"
                        objConn.Execute sql
                    End If
                    rs.close()
                    NewUser=1
                Else
                    '正常微信登陆
                    UserID=ToUserID
                    sql="update weixinOpenID set LoginTime=getdate()"&UnionIDSql&" where id="&weixinID
                    objConn.Execute sql
                End If
                If wxNickName<>"" And UserID<>"" Then
                    '更新微信昵称
                    sql="update UserData set UserNickName='"&wxNickName&"' where UserID="&UserID
                    objConn.Execute sql
                End If
                If wxAvatarUrl<>"" And UserID<>"" Then
                    '更新微信头像
                    sql="update UserData set UserAvatarUrl='"&wxAvatarUrl&"' where UserID="&UserID
                    objConn.Execute sql
                End If
                If  UserID<>"" And UserID<>"0" And UserPhone<>"" And not isnull(UserPhone) Then
                    sql="update UserPhone set ToUserID="&UserID&" where ToUserID<>"&UserID&" and strPhone='"&UserPhone&"'"
                    objConn.Execute sql
                    sql="update ServiceOrder set ServiceOrdUserID="&UserID&" where ServiceOrdUserID<>"&UserID&" and ServiceOrdCoPhone='"&UserPhone&"'"
                    objConn.Execute sql
                End If
            End If
 
            '转运快线小程序介绍人处理
            If UpdateSource="Valet" Or UpdateSource="QR" Then
                If iuid<>"" Or uuid<>"" Then
                    sql="select top 1 id from UserUUID where ToUserID="&UserID&" And (iuid='"&iuid&"') order by LoginTime desc"
                    rs.open sql,objConn,1,1
                    if not rs.eof Then
                        sql="update UserUUID set iuid='"&iuid&"',LoginTime=getdate() where id="&rs(0)
                        objConn.Execute sql
                        UserUUID=rs(0)
                    Else
                        sql="Insert into UserUUID (ToUserID,iuid) values ("&UserID&",'"&iuid&"')"
                        objConn.Execute sql
                        rs.close()
                        sql="select top 1 id from UserUUID order by id desc"
                        rs.open sql,objConn,1,1
                        if not rs.eof Then
                            UserUUID=rs(0)
                        End If
                    End If
                    rs.close()
                    UserSource="UUID"&UserUUID
                    sql="update UserData set UserSource='"&UserSource&"' where UserID="&UserID
                    objConn.Execute sql
                End If
            End If
            
            'NewUser=1 新用户
            Randomize
            RndInt=CInt(Rnd*100)-DateDiff("d","2023-8-1",now())
            If RndInt>0 And NewUser=1 Then
                NewUserCoupon=1
            Else
                NewUserCoupon=0
            End If
            
            if (ADUser="193")  And DateDiff("d",now(),"2025-9-5")<=0 And DateDiff("d",now(),"2028-1-1")>=0 Then
                sql="select * from Coupon where CouponDate_Ent>=getdate() and CouponName like '城市服务 优惠%' and ToUserID="&UserID
                rs.open Sql,objConn,1,1
                If rs.Eof then            
                    '公交车广告优惠
                    '城市服务优惠 发优惠券: 市内50 省内200 省外500 高铁1000 航空3000                    
                    saveCoupon objConn,50,UserID,"","城市服务 优惠 50元代金券-(本市行政区域内救护车转运可使用)"
                    saveCoupon objConn,50,UserID,"","城市服务 优惠 50元代金券-(本市行政区域内救护车转运可使用)"
                    saveCoupon objConn,200,UserID,"","城市服务 优惠 200元代金券-(单程距离100公里以上救护车转运可使用)"
                    saveCoupon objConn,500,UserID,"","城市服务 优惠 500元代金券-(单程距离500公里以上救护车转运可使用)"
                    saveCoupon objConn,1000,UserID,"","城市服务 优惠 1000元代金券-(高铁医疗转运可使用)"
                    saveCoupon objConn,3000,UserID,"","城市服务 优惠 3000元代金券-(航空医疗转运可使用)"
                End if    
                rs.close()
            ElseIf (ADUser="153") And NewUser=1 And DateDiff("d",now(),"2023-9-15")<=0 And DateDiff("d",now(),"2024-6-30")>=0 Then
                sql="select * from Coupon where CouponDate_Ent>=getdate() and CouponName like '城市服务优惠%' and ToUserID="&UserID
                rs.open Sql,objConn,1,1
                If rs.Eof then
                    '城市服务优惠 发优惠券: 市内50 省内200 省外500 高铁1000 航空3000
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=50
                    CouponRemarks=""
                    CouponName="城市服务优惠 50元代金券-(本市行政区域内转运可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
                    CouponNO=DTimeID()&getIDnumbers(6)
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
 
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=200
                    CouponRemarks=""
                    CouponName="城市服务优惠 200元代金券-(广东内单程转运距离100公里以上可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
 
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=500
                    CouponRemarks=""
                    CouponName="城市服务优惠 500元代金券-(全国范围内单程转运距离500公里以上可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
 
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=1000
                    CouponRemarks=""
                    CouponName="城市服务优惠 1000元代金券-(全国范围内高铁医疗转运可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
 
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=3000
                    CouponRemarks=""
                    CouponName="城市服务优惠 3000元代金券-(全国范围内航空医疗转运可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
                End If
                rs.close()
 
            ElseIf (ADUser="166") And NewUser=1 And DateDiff("d",now(),"2024-3-22")<=0 And DateDiff("d",now(),"2024-10-31")>=0 Then
                sql="select * from Coupon where CouponDate_Ent>=getdate() and CouponName like '报刊亭促销活动%' and ToUserID="&UserID
                rs.open Sql,objConn,1,1
                If rs.Eof then
                    '报刊亭促销活动 发优惠券: 市内50 省内200 省外500 高铁1000 航空3000
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=50
                    CouponRemarks=""
                    CouponName="报刊亭促销活动 50元代金券-(本市行政区域内转运可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
                    CouponNO=DTimeID()&getIDnumbers(6)
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
 
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=200
                    CouponRemarks=""
                    CouponName="报刊亭促销活动 200元代金券-(广东内单程转运距离100公里以上可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
 
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=500
                    CouponRemarks=""
                    CouponName="报刊亭促销活动 500元代金券-(全国范围内单程转运距离500公里以上可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
 
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=1000
                    CouponRemarks=""
                    CouponName="报刊亭促销活动 1000元代金券-(全国范围内高铁医疗转运可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
 
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=3000
                    CouponRemarks=""
                    CouponName="报刊亭促销活动 3000元代金券-(全国范围内航空医疗转运可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
                End If
                rs.close()
 
            ElseIf (ADUser="167") And NewUser=1 And DateDiff("d",now(),"2024-4-1")<=0 And DateDiff("d",now(),"2024-12-31")>=0 Then
                sql="select * from Coupon where CouponDate_Ent>=getdate() and CouponName like '小葫芦圈促销活动%' and ToUserID="&UserID
                rs.open Sql,objConn,1,1
                If rs.Eof then
                    '小葫芦圈促销活动 发优惠券: 市内50 省内200 省外500 高铁1000 航空3000
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=50
                    CouponRemarks=""
                    CouponName="小葫芦圈促销活动 50元代金券-(本市行政区域内转运可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
                    CouponNO=DTimeID()&getIDnumbers(6)
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
 
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=200
                    CouponRemarks=""
                    CouponName="小葫芦圈促销活动 200元代金券-(广东内单程转运距离100公里以上可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
 
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=500
                    CouponRemarks=""
                    CouponName="小葫芦圈促销活动 500元代金券-(全国范围内单程转运距离500公里以上可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
 
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=1000
                    CouponRemarks=""
                    CouponName="小葫芦圈促销活动 1000元代金券-(全国范围内高铁医疗转运可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
 
                    CouponNO=DTimeID()&getIDnumbers(6)
                    CouponMoney=3000
                    CouponRemarks=""
                    CouponName="小葫芦圈促销活动 3000元代金券-(全国范围内航空医疗转运可使用)"
                    If UserID="" Then UserID=0
                    sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&UserID&")"
                    objConn.Execute sql
                End If
                rs.close()
 
            End If
        
        Else
            errcode=40601
            errmsg="empty LoginType"
        End If
        'If UserID="4" Then UserID=31982
        '数据不完整
        If errcode<>1 Then
 
        ElseIf UserID="" Then
                errcode=40610
                errmsg="empty Data"
        Else
            'If UnitState<>2 Then UnitSql=" and UserUnitID="&UnitID    '只显示指定商户
            sql="select * from UserData where UserID="&UserID & UnitSql
            rs.open sql,objConn,1,1
            if not rs.eof Then
                UserID        = rs("UserID")
                If UserName<>"" Then
                    UserNameSql=",UserName='"&UserName&"'"
                Else
                    UserName    = rs("UserName")
                End If
                
 
                UserPhone    = rs("UserPhone")
                UserNickName= rs("UserNickName")
                UserAvatarUrl=rs("UserAvatarUrl")
                UserLevel    = rs("UserLevel")
                UserRegisterTime= rs("UserRegisterTime")
                UserLoginTime= rs("UserLoginTime")
                UserUnitID    = rs("UserUnitID")
                Old_RecommendUserID    = rs("RecommendUserID")
                Old_UserSource    = rs("UserSource")
                Old_UserSourceTime=rs("UserSourceTime")
                Old_UserSourceTimeTerm=rs("UserSourceTimeTerm")
                If UserBranch="" Then    UserBranch    = "BF"
 
                '更新推荐人信息
                If RecommendUserID<>0 And CLng(RecommendUserID)<>CLng(UserID) Then    '只有用户是首次注册或之前没推荐人的,才会更新推荐人 And Old_RecommendUserID=0
                    RecommendSql=",RecommendUserID="&RecommendUserID&",RecommendTime=getdate(),RecommendTimeTerm=24"    '推荐人24小时内有效
                    rs.close()
                    sql="select RecommendUserID from UserData where RecommendUserIDs is not null and UserID="&RecommendUserID
                    rs.open sql,objConn,1,1
                    if not rs.eof Then
                        RecommendSql=RecommendSql&",RecommendUserIDs=',"&rs("RecommendUserID")&","&RecommendUserID&",'"    '上级推荐人
                    Else
                        RecommendSql=RecommendSql&",RecommendUserIDs=',"&RecommendUserID&",'"    '上级推荐人
                    End If
                    If 1=2 Then '2021.3.12停止
                        CouponNO=DTimeID()&getIDnumbers(6)
                        CouponMoney=10
                        CouponRemarks=""
                        CouponName="好友注册赠送10元优惠券"
                        sql="Insert into Coupon (CouponNO,CouponName,CouponMoney,CouponDate_Ent,CouponRemarks,ServiceOrdIDPK,ToUserID) values ('"&CouponNO&"','"&CouponName&"',"&CouponMoney&",getdate()+365,'"&CouponRemarks&"',0,"&RecommendUserID&")"
                        objConn.Execute sql
                    End If
                Else
                    If rs("RecommendUserID")<>0 Then
                        If datediff("s",Now(),DateAdd("h",rs("RecommendTimeTerm"),rs("RecommendTime")))>=0 Then
                            RecommendUserID=rs("RecommendUserID")
                        End If
                    End If
                End If
                '更新用户来源信息
                If UserSource<>"" Then
                    UserSourceSql=",UserSource='"&UserSource&"',UserSourceTime=getdate(),UserSourceTimeTerm=12"    '用户来源信息12小时内有效
                Else
                    If Old_UserSource<>"" And Old_UserSourceTime<>"" Then
                        If datediff("s",Now(),DateAdd("h",Old_UserSourceTimeTerm,Old_UserSourceTime))>=0 Then
                            UserSource=Old_UserSource
                        End If
                    End If
                End If
                sql="update UserData set UserLoginTime=getdate()"&UserNameSql&UserSourceSql&RecommendSql&" where UserID="&UserID
                objConn.Execute sql
 
                '用户昵称处理
                If UserNickName<>"" Then
                    UserNickName = Replace(UserNickName,"?","")
                    If UserNickName="" Then UserNickName="微信用户"
                End If
                '更多用户信息
                If More="1" Then
                    '订单金额/订单数量
                    rs.close()
                    sql="select count(ServiceOrdID),isnull(sum(ServiceOrdTraTxnPrice),0) from ServiceOrder where ServiceOrdState<>4 and ServiceOrdUserID="&UserID
                    rs.open sql,objConn,1,1
                    OrderInt = rs(0)
                    'PointsInt = rs(1)
                    
                    '用户积分
                    rs.close()
                    sql="select isnull(SUM(Points_Score),0) Points_Score from UserPoints where ToUserID="&UserID
                    rs.open sql,objConn,1,1
                    PointsInt    = rs("Points_Score")
                
 
                    '现金券金额
                    rs.close()
                    sql="select isnull(SUM(CouponMoney),0) from Coupon where getdate() BETWEEN CouponDate and CouponDate_Ent and CouponState=0 and ToUserID="&UserID
                    rs.open sql,objConn,1,1
                    CouponMoney = rs(0)
 
                    MoreJson=",""Points"":"""&PointsInt&""",""Coupon"":"""&CouponMoney&""",""OrderInt"":"""&OrderInt&""""
                End If
                webJson="{""method"":""User_Login"",""result"":1,""UserID"":"&UserID&",""UserName"":"""&UserName&""",""UserPhone"":"""&UserPhone&""",""UserNickName"":"""&UserNickName&""",""UserAvatarUrl"":"""&UserAvatarUrl&""",""UserLevel"":"&UserLevel&",""RegisterTime"":"""&UserRegisterTime&""",""LoginTime"":"""&UserLoginTime&""",""UserUnitID"":"""&UserUnitID&""",""UserBranch"":"""&UserBranch&""",""UserSource"":"""&UserSource&""",""RecommendUserID"":"""&RecommendUserID&""",""beginning"": {""title"":"""&beginning_title&""",""address"":"""&beginning_address&"""},""ending"": {""title"":"""&ending_title&""",""address"":"""&ending_address&"""}"&MoreJson&",""ADUser"":"""&ADUser&"""}"
            Else
                errcode=40611
                errmsg="invalid UserID"
            End if
            rs.close()
        End if
    '用户登陆/信息查询/用户注册 end
    
    case "Send_SMS"    '短信发送
        '必须
        SendPhone    = trim(Request("SendPhone"))    '发送手机
        SendType    = trim(Request("SendType"))        '发送信息类型(1 自定义信息,2 手机验证)
        
        '可选
        UserID        = trim(Request("UserID"))        '用户唯一ID
        SendText    = trim(request("SendText"))        '发送内容
        SendRemarks    = trim(request("SendRemarks"))    '发送备注
        
        errcode=1
 
        if SendPhone="" Or Len(SendPhone)<>11 Or Not IsNumeric(SendPhone) Then
            errcode=40621
            errmsg="invalid SendPhone"
        
        ElseIf SendType="1" Then
            '1 自定义信息
            If SendText<>"" Then
                SendText    = SendText&"【医疗快线】" 
                call Get_SMS(SendPhone,SendText,SendRemarks)
                webJson="{""APPID"":"""&APPID&""",""method"":"""&method&""",""result"":1}"
            Else
                errcode=40623
                errmsg="invalid SendText"
            End If
 
        ElseIf SendType="2" Then
            '2 手机验证
            randomize
            for i=1 to 4
            PhoneVerify = PhoneVerify&int(10*Rnd())
            Next
            PhoneVerify=Left(PhoneVerify,4)
            sql="Insert into UserPhoneVerify (Phone,PhoneVerify) values ('"&SendPhone&"','"&PhoneVerify&"')"
            objConn.Execute sql
            SendText    = "您的验证码是:"&PhoneVerify&",请您在15分钟内输入验证码,切勿泄露于他人"
            SendText    = SendText&"【医疗快线】" 
            lateCode="SMS_171940354"
            appUrl="https://api.966120.com.cn/v1/SendSms.php?Phone="&SendPhone&"&code="&PhoneVerify&"&lateCode="&lateCode
            call PostBody(appUrl,args1)
            'call Get_SMS(SendPhone,SendText,SendRemarks)
            webJson="{""APPID"":"""&APPID&""",""method"":"""&method&""",""result"":1}"
        Else
            errcode=40622
            errmsg="invalid SendType"
        End If
        
    '短信发送 end
 
    case "User_CouponsList"    '会员优惠券列表
            '必须
            UserID=trim(Request("UserID"))    '购物系统会员ID
 
            '可选
            CouponsListType=trim(Request("CouponsListType"))    '列表类型(1未使用,2已使用,3已过期)
 
            '写入默认值
            If UserID="undefined" Then UserID=""
            If CouponsListType="" Then CouponsListType=1
 
            '查找数据库
            If UserID="" Then
                errcode=40071
                errmsg="invalid UserID"
            ElseIf CouponsListType=2 Then
                '2已使用
                webJson = """UserID"":"""&UserID&""",""CouponsList"":["
                i=0
                    sql="select * from Coupon where CouponState=1 and ToUserID="&UserID&" order by CouponDate desc"
                    'Response.Write sql &"<br>"
                    rs.open sql,objConn,1,1
                    do while not rs.Eof
                      Did        = rs("id")
                      D_No        = rs("CouponNO")
                      D_Name    = rs("CouponName")            '优惠券名称
                      D_NameSP    = SPLIT(D_Name,"-")
                      If UBOUND(D_NameSP)>=1 Then
                        D_Name=D_NameSP(0)
                        LimitTXT=D_NameSP(1)
                      Else
                        D_Name=D_Name
                        LimitTXT=Mid(D_No,1,4)&" "&Mid(D_No,4,4)&" "&Mid(D_No,8,4)&" "&Mid(D_No,12,4)
                      End If
                      UserMoney    = Abs(rs("CouponMoney"))        '优惠券金额
                      time1        = rs("CouponDate")            '使用时间
                      time2        = FormatDateTime(rs("CouponDate_Ent"),2)        '有效时间
                      UseURL    = "pages/index/index"            '转跳连接
 
                      If i>0 Then webJson=webJson&","
                      webJson=webJson&"{""Did"":"""&Did&""",""D_Name"":"""&D_Name&""",""UserMoney"":"""&UserMoney&""",""time2"":"""&time2&""",""LimitTXT"":"""&LimitTXT&""",""UseURL"":"""&UseURL&"""}"
                      i=i+1
                      rs.movenext
                    loop
                    rs.close()
                    webJson = webJson&"]"
            ElseIf CouponsListType=3 Then
                '3已过期
                webJson = """UserID"":"""&UserID&""",""CouponsList"":["
                i=0
                    sql="select * from Coupon where CouponState=0 and datediff(ss,getdate(),CouponDate_Ent)<0 and ToUserID="&UserID&" order by CouponDate desc"
                    'Response.Write sql &"<br>"
                    rs.open sql,objConn,1,1
                    do while not rs.Eof
                      Did        = rs("id")
                      D_No        = rs("CouponNO")
                      D_Name    = rs("CouponName")            '优惠券名称
                      D_NameSP    = SPLIT(D_Name,"-")
                      If UBOUND(D_NameSP)>=1 Then
                        D_Name=D_NameSP(0)
                        LimitTXT=D_NameSP(1)
                      Else
                        D_Name=D_Name
                        LimitTXT=Mid(D_No,1,4)&" "&Mid(D_No,4,4)&" "&Mid(D_No,8,4)&" "&Mid(D_No,12,4)
                      End If
                      UserMoney    = Abs(rs("CouponMoney"))        '优惠券金额
                      time1        = rs("CouponDate")            '使用时间
                      time2        = FormatDateTime(rs("CouponDate_Ent"),2)        '有效时间
                      UseURL    = "pages/index/index"            '转跳连接
 
                      If i>0 Then webJson=webJson&","
                      webJson=webJson&"{""Did"":"""&Did&""",""D_Name"":"""&D_Name&""",""UserMoney"":"""&UserMoney&""",""time2"":"""&time2&""",""LimitTXT"":"""&LimitTXT&""",""UseURL"":"""&UseURL&"""}"
                      i=i+1
                      rs.movenext
                    loop
                    rs.close()
                    webJson = webJson&"]"
            Else
                '1未使用
                webJson = """UserID"":"""&UserID&""",""CouponsList"":["
                i=0
                    sql="select * from Coupon where CouponState=0 and datediff(ss,getdate(),CouponDate_Ent)>=0 and ToUserID="&UserID&" order by CouponDate desc"
                    'Response.Write sql &"<br>"
                    rs.open sql,objConn,1,1
                    do while not rs.Eof
                      Did        = rs("id")
                      D_No        = rs("CouponNO")
                      D_Name    = rs("CouponName")            '优惠券名称
                      D_NameSP    = SPLIT(D_Name,"-")
                      If UBOUND(D_NameSP)>=1 Then
                        D_Name=D_NameSP(0)
                        LimitTXT=D_NameSP(1)
                      Else
                        D_Name=D_Name
                        LimitTXT=Mid(D_No,1,4)&" "&Mid(D_No,4,4)&" "&Mid(D_No,8,4)&" "&Mid(D_No,12,4)
                      End If
                      UserMoney    = Abs(rs("CouponMoney"))        '优惠券金额
                      time1        = rs("CouponDate")            '使用时间
                      time2        = FormatDateTime(rs("CouponDate_Ent"),2)        '有效时间
                      UseURL    = "pages/h5/h5?src=https://api.966120.com.cn/user/UserCoupons.php@D_No#"&D_No&"$CouponName#"&rs("CouponName")            '转跳连接
 
                      If i>0 Then webJson=webJson&","
                      webJson=webJson&"{""Did"":"""&Did&""",""D_Name"":"""&D_Name&""",""UserMoney"":"""&UserMoney&""",""time2"":"""&time2&""",""LimitTXT"":"""&LimitTXT&""",""UseURL"":"""&UseURL&"""}"
                      i=i+1
                      rs.movenext
                    loop
                    rs.close()
                    webJson = webJson&"]"
            End If
 
            If webJson<>"" Then
                webJson="{""method"":""User_CouponsList"",""result"":1,"&webJson&",""total"":"""&i&"""}"
            End If
    '会员优惠券列表 end
 
    case "User_Information"    '用户公告
            '必须
            UserID        = trim(Request("UserID"))        '用户ID
            wxOpenid    = trim(Request("wxOpenid"))        '微信OpenID
            pages        = trim(Request("pages"))        '当前页面链接
 
            '可选
 
            '写入默认值
            If pages="" Then pages="index"
            If not IsNumeric(UserID) Then UserID=0
            If wxOpenid="undefined" Then wxOpenid=""
            If UserID="" Then UserID=0
 
            FormIDInt=0        '总用户已收到公告数量
            FormIDInt1=0    '最近一天用户已收到公告数量
            FormIDInt7=0    '最近一周用户已收到公告数量
 
            '页面转跳类型说明
            'OpenType switchTab 转跳底部主页面,navigateTo 转跳内容页面,reLaunch 关闭所有页面并转跳页面,redirectTo 关闭当前页面并转跳内页
 
            '查找数据库
            If wxOpenid<>"" Then
                '检查wxOpenid同期公告次数
                sql="select count(id) from UserInformation where datediff(Hour,InformationTime,GETDATE())<24 and ToWxOpenID='"&wxOpenid&"'"
                rs.open sql,objConn,1,1
                FormIDInt1=rs(0)
                rs.close()
                sql="select count(id) from UserInformation where datediff(Hour,InformationTime,GETDATE())<168 and ToWxOpenID='"&wxOpenid&"'"
                rs.open sql,objConn,1,1
                FormIDInt7=rs(0)
                rs.close()
                sql="select count(id) from UserInformation where ToWxOpenID='"&wxOpenid&"'"
                rs.open sql,objConn,1,1
                FormIDInt=rs(0)
                rs.close()
            ElseIf UserID<>0 Then 
                '检查UserID同期公告次数
                sql="select count(id) from UserInformation where datediff(Hour,InformationTime,GETDATE())<24 and ToUserID="&UserID
                rs.open sql,objConn,1,1
                FormIDInt1=rs(0)
                rs.close()
                sql="select count(id) from UserInformation where datediff(Hour,InformationTime,GETDATE())<168 and ToUserID="&UserID
                rs.open sql,objConn,1,1
                FormIDInt7=rs(0)
                rs.close()
                sql="select count(id) from UserInformation where ToUserID="&UserID
                rs.open sql,objConn,1,1
                FormIDInt=rs(0)
                rs.close()
            End If
            If UserID<>"0" Then
                '检查用户优惠券情况
                CouponNames=","
                sql="select CASE WHEN CHARINDEX('-',CouponName)>0 THEN left(CouponName,CHARINDEX('-',CouponName)-1) ELSE CouponName END as CouponName,SUM(CouponMoney) from Coupon where ToUserID="&UserID&" and CouponDate_Ent>=getdate() GROUP BY CouponName"
                rs.open sql,objConn,1,1
                do while not rs.Eof
                    CouponNames=CouponNames& rs("CouponName") &"|"
                rs.movenext
                loop
                rs.close()
                sql="select UserPhone from UserData where UserID="&UserID
                rs.open sql,objConn,1,1
                if not rs.Eof Then
                    UserPhone=rs("UserPhone")
                End If
                rs.close()
            End If
 
            'wxOpenid="okHIJ0Y3jT30pJJhVwCmdHgPu8Kk"  Or UserID="6129" Or userid="6237" Or userid="10"
            '20.01.14活动
            If UserID<>"0" And UserPhone="" And (InStr(pages,"148")>0 Or InStr(pages,"155")>0 Or InStr(CouponNames,"代金券")>0) Then
                'webJson="""UserInformation"":{""Title"":""用户优惠券"",""Content"":"""",""PicUrl"":""https://api.966120.com.cn/OA_img/ad_20230419.png"",""Url"":""/pages/my/coupon/coupon"",""OpenType"":""navigateTo""}"
                webJson="""UserInformation"":{""Title"":""用户优惠券"",""Content"":"""",""PicUrl"":""https://api.966120.com.cn/OA_img/20231013160503.png"",""Url"":""/pages/my/login/login"",""OpenType"":""navigateTo""}"
            ElseIf UserID<>"0" And FormIDInt=0 And (InStr(pages,"148")>0 Or InStr(pages,"155")>0 Or InStr(CouponNames,"代金券")>0) Then
                webJson="""UserInformation"":{""Title"":""用户优惠券"",""Content"":"""",""PicUrl"":""https://api.966120.com.cn/OA_img/ad_20230727.png"",""Url"":"""",""OpenType"":""""}"
            ElseIf wxOpenid<>"" and FormIDInt=0 and (InStr(pages,"193")>0 or InStr(CouponNames,"代金券")>0) then
                webJson="""UserInformation"":{""Title"":""用户优惠券"",""Content"":""&pages&"",""PicUrl"":""https://api.966120.com.cn/OA_img/ad_0904.png"",""Url"":"""",""OpenType"":""""}"
            Else
                webJson="""UserInformation"":0"
            End If
 
            If webJson<>"""UserInformation"":0" And UserPhone<>"" Then
                '记录公告次数
                sql="insert into UserInformation (ToUserID,ToWxOpenID,UserPages) values ("&UserID&",'"&wxOpenid&"','"&pages&"')"
                objConn.Execute sql
            End If
            
            'webJson="""UserInformation"":{""Title"":""首页公告"",""Content"":""公告内容测试"",""PicUrl"":""http://m.v.com.cn/images/2018091601.jpg"",""Url"":""""}"
            'webJson="""UserInformation"":{""Title"":""首页公告"",""Content"":""公告内容测试公告内容测试公告内容测试公告内容测试公告内容测试公告内容测试公告内容测试"",""PicUrl"":"""",""Url"":""""}"
            
            If webJson<>"" Then
                webJson="{""method"":""User_Information"",""result"":1,"&webJson&"}"
            End If
    '用户公告 end
    
    case "Points_UserList"    '用户推荐人员记录
            '必须
            UserID        = trim(Request("UserID"))        '用户ID
 
            '可选
            page_no        = trim(Request("page_no"))        '页码(默认1)
            page_size    = trim(Request("page_size"))    '每页显示数量(默认20,最大100)
            
            '写入默认值
            If UserID="undefined" Then UserID=""
            If CouponsListType="" Then CouponsListType=1
            If page_no="" Then page_no=1
            If page_size="" Then page_size=20
            If CInt(page_size)>100 Then page_size=100
            total=0
            totalMoney=0
            errcode=1
 
            '查找数据库
            If UserID="" Then
                errcode=40071
                errmsg="invalid UserID"
            Else
                '测试
                'UserID=53
                webJson=""
                sql="select UserID,UserName,UserLevel from UserData where UserID="&UserID
                rs.open sql,objConn,1,1
                if not rs.eof Then
                    UserID        = rs("UserID")
                    UserName    = rs("UserName")
                    UserLevel    = rs("UserLevel")
                Else
                    errcode=40071
                    errmsg="invalid UserID"
                End If
                rs.close()
                If errcode=1 Then
                    webJson = """UserID"":"""&UserID&""",""Points_UserList"":["
                    i=0
                    'sql="select UserID,UserName,UserLevel,NoteName,UserPhone,UserNickName,UserAvatarUrl,RecommendTime=CONVERT(varchar(20),RecommendTime,111),sumUser=(select COUNT(UserID) from UserData as b where b.RecommendUserID=a.UserID),RecommendUserID,sumOrdInt=(select COUNT(DispatchOrdID) from ServiceOrder,DispatchOrd where DispatchOrd.ServiceOrdIDDt=ServiceOrdID and ServiceOrdUserID=a.UserID and DispatchOrdState=8),sumPaidMoney=(select isnull(sum(PaidMoney),0) from ServiceOrder,DispatchOrd,PaidMoney where DispatchOrd.ServiceOrdIDDt=ServiceOrdID and PaidMoney.ServiceOrdIDDt=ServiceOrdID and PaidMoney<>0 and ServiceOrdUserID=a.UserID and DispatchOrdState=8) from UserData as a LEFT JOIN UserRecommendNote on ToUserID=UserID and ToRUserID=RecommendUserID where RecommendUserID="&UserID&" order by RecommendTime desc"
 
                    sql="select UserID,UserName,NoteName,UserPhone,UserNickName,UserAvatarUrl,RecommendTime,sumUser=(select COUNT(UserID) from UserData as b where b.RecommendUserID=a1.UserID),COUNT(ServiceOrdID) sumOrdInt,sum(isnull(sumPaidMoney,0)) sumPaidMoney from (select a.UserID,a.UserName,NoteName,a.UserPhone,a.UserNickName,a.UserAvatarUrl,a.RecommendTime,isnull(ServiceOrdID,0) ServiceOrdID,sum(isnull(PaidMoney,0)) sumPaidMoney from UserData a  LEFT JOIN UserRecommendNote on ToUserID=UserID and ToRUserID=RecommendUserID LEFT JOIN ServiceOrder on ServiceOrdUserID=a.UserID and ServiceOrdState=3 and (a.RecommendUserID=ServiceOrder.RecommendUserID or a.UserID=ServiceOrdUserID) LEFT JOIN DispatchOrd on DispatchOrd.ServiceOrdIDDt=ServiceOrdID and DispatchOrdState=8 LEFT JOIN PaidMoney on PaidMoney.ServiceOrdIDDt=DispatchOrd.ServiceOrdIDDt and PaidMoney<>0  where a.RecommendUserID="&UserID&"  GROUP BY a.UserID,a.UserName,NoteName,a.UserPhone,a.UserNickName,a.UserAvatarUrl,a.RecommendTime,ServiceOrdID) a1 GROUP BY UserID,UserName,NoteName,UserPhone,UserNickName,UserAvatarUrl,RecommendTime order by RecommendTime"
                    'Response.Write sql
                    rs.open sql,objConn,1,1
                    if not rs.eof then
                    rs.pagesize=page_size
                    rs.absolutepage=page_no
                    total=rs.recordcount
                    end If
                    do while not rs.Eof and i<CInt(page_size)
                        P_UserID        = rs("UserID")    
                        P_UserName        = rs("UserName")
                        P_NoteName        = rs("NoteName")
                        P_UserPhone        = rs("UserPhone")
                        P_UserNickName    = rs("UserNickName")
                        P_UserAvatarUrl    = rs("UserAvatarUrl")
                        P_RecommendTime    = rs("RecommendTime")
                        P_sumUser        = rs("sumUser")
                        P_sumOrdInt        = rs("sumOrdInt")
                        P_sumPaidMoney    = rs("sumPaidMoney")
                        totalMoney=totalMoney+P_sumPaidMoney
                        
                        If P_sumPaidMoney<=0 Then P_sumOrdInt=0
                        If P_NoteName="" Or Isnull(P_NoteName) Then P_NoteName=P_UserName
                        If P_NoteName="" Or Isnull(P_NoteName) Then P_NoteName=P_UserNickName
                        If P_NoteName="" Or Isnull(P_NoteName) Then P_NoteName="微信用户"
                        If P_NoteName="微信用户" Then P_NoteName=P_NoteName&Right(P_UserPhone,4)
                        
                        If i>0 Then webJson=webJson&","
                        webJson=webJson&"{""P_UserID"":"""&P_UserID&""",""P_NoteName"":"""&P_NoteName&""",""P_UserPhone"":"""&P_UserPhone&""",""P_UserAvatarUrl"":"""&P_UserAvatarUrl&""",""P_RecommendTime"":"""&P_RecommendTime&""",""P_sumOrdInt"":"""&P_sumOrdInt&""",""P_sumPaidMoney"":"""&P_sumPaidMoney&""""
                        If UserLevel>1 And P_sumUser>0 Then    '二级用户
                            j=0
                            P_UserListJson=",""P_UserList"":["
                            sql="select UserID,UserName,NoteName,UserPhone,UserNickName,UserAvatarUrl,RecommendTime,COUNT(ServiceOrdID) sumOrdInt,sum(isnull(sumPaidMoney,0)) sumPaidMoney from (select a.UserID,a.UserName,NoteName,a.UserPhone,a.UserNickName,a.UserAvatarUrl,a.RecommendTime,isnull(ServiceOrdID,0) ServiceOrdID,sum(isnull(PaidMoney,0)) sumPaidMoney from UserData a  LEFT JOIN UserRecommendNote on ToUserID=UserID and ToRUserID=RecommendUserID LEFT JOIN ServiceOrder on ServiceOrdUserID=a.UserID and ServiceOrdState=3 LEFT JOIN DispatchOrd on DispatchOrd.ServiceOrdIDDt=ServiceOrdID and DispatchOrdState=8 LEFT JOIN PaidMoney on PaidMoney.ServiceOrdIDDt=DispatchOrd.ServiceOrdIDDt and PaidMoney<>0  where a.RecommendUserID="&UserID&"  GROUP BY a.UserID,a.UserName,NoteName,a.UserPhone,a.UserNickName,a.UserAvatarUrl,a.RecommendTime,ServiceOrdID) a1 GROUP BY UserID,UserName,NoteName,UserPhone,UserNickName,UserAvatarUrl,RecommendTime order by RecommendTime"
                            rsDt.open sql,objConn,1,1
                            do while not rsDt.Eof
                                P_UserID        = rsDt("UserID")    
                                P_UserName        = rsDt("UserName")
                                P_NoteName        = rsDt("NoteName")
                                P_UserPhone        = rsDt("UserPhone")
                                P_UserNickName    = rsDt("UserNickName")
                                P_UserAvatarUrl    = rsDt("UserAvatarUrl")
                                P_RecommendTime    = rsDt("RecommendTime")
                                P_sumOrdInt        = rsDt("sumOrdInt")
                                P_sumPaidMoney    = rsDt("sumPaidMoney")
                                'total=total+1
                                totalMoney=totalMoney+P_sumPaidMoney
                                If P_sumPaidMoney<=0 Then P_sumOrdInt=0
                                If P_NoteName="" Or Isnull(P_NoteName) Then P_NoteName=P_UserName
                                If P_NoteName="" Or Isnull(P_NoteName) Then P_NoteName=P_UserNickName
                                If P_NoteName="" Or Isnull(P_NoteName) Then P_NoteName="微信用户"
                                If P_NoteName="微信用户" Then P_NoteName=P_NoteName&Right(P_UserPhone,4)
                                If j>0 Then P_UserListJson=P_UserListJson&","
                                P_UserListJson=P_UserListJson&"{""P_UserID"":"""&P_UserID&""",""P_NoteName"":"""&P_NoteName&""",""P_UserPhone"":"""&P_UserPhone&""",""P_UserAvatarUrl"":"""&P_UserAvatarUrl&""",""P_RecommendTime"":"""&P_RecommendTime&""",""P_sumOrdInt"":"""&P_sumOrdInt&""",""P_sumPaidMoney"":"""&P_sumPaidMoney&"""}"
                            j=j+1
                            rsDt.movenext
                            loop
                            rsDt.close()
                            P_UserListJson=P_UserListJson&"]"
                            webJson=webJson&P_UserListJson
                        Else
                            webJson=webJson&",""P_UserList"":[]"
                        End If
                        webJson=webJson&"}"
                        
                        i=i+1
                    rs.movenext
                    loop
                    rs.close()
                    webJson = webJson&"],""total"":"""&total&""",""totalMoney"":"""&totalMoney&""""
                End If
            End If
 
            If webJson<>"" Then
                webJson="{""method"":""Points_UserList"",""result"":1,"&webJson&"}"
            End If
            
    '用户推荐人员记录 end
 
    case "Points_NoteNameUpdate"    '用户推荐人员姓名修改
            '必须
            UserID        = trim(Request("UserID"))        '用户ID
            ToUserID    = trim(Request("ToUserID"))        '推荐用户ID
            ToNoteName    = trim(Request("ToNoteName"))    '推荐用户名称
 
            errcode=1
 
            '查找数据库
            If UserID="" Then
                errcode=40071
                errmsg="invalid UserID"
            ElseIf ToUserID="" Then
                errcode=40071
                errmsg="invalid ToUserID"
            ElseIf ToNoteName="" Then
                errcode=40071
                errmsg="invalid ToNoteName"
            Else
                '测试
                'UserID=53
                webJson=""
                sql="select id from UserRecommendNote where ToRUserID="&UserID&" and ToUserID="&ToUserID
                rs.open sql,objConn,1,1
                if not rs.eof Then
                    id        = rs("id")
                End If
 
                If errcode=1 Then
                    If id<>"" Then
                        sql="update UserRecommendNote set NoteName='"&ToNoteName&"',UpdateTime=getdate() where id="&id
                        objConn.Execute sql
                    Else
                        sql="insert into UserRecommendNote (ToUserID,ToRUserID,NoteName) values ("&ToUserID&","&UserID&",'"&ToNoteName&"')"
                        objConn.Execute sql
                    End If
                    webJson="{""method"":""Points_NoteNameUpdate"",""result"":1}"
                End If
            End If
    '用户推荐人员姓名修改 end
 
    case "Points_List"    '用户积分记录
            '必须
            UserID        = trim(Request("UserID"))        '用户ID
            Points_Type    = trim(Request("Points_Type"))    '查询类型
 
            '可选
            page_no        = trim(Request("page_no"))        '页码(默认1)
            page_size    = trim(Request("page_size"))    '每页显示数量(默认20,最大100)
 
            '写入默认值
            If UserID="undefined" Then UserID=""
            If Points_Type="undefined" Then Points_Type=""
            If page_no="" Then page_no=1
            If page_size="" Then page_size=20
            If CInt(page_size)>100 Then page_size=100
            total=0
            errcode=1
            '查找数据库
            If UserID="" Then
                errcode=40071
                errmsg="invalid UserID"
            Else
                '测试
                'UserID=53
                webJson=""
                sql="select UserID,UserName,UserLevel from UserData where UserID="&UserID
                rs.open sql,objConn,1,1
                if not rs.eof Then
                    UserID        = rs("UserID")
                    UserName    = rs("UserName")
                    UserLevel    = rs("UserLevel")
                Else
                    errcode=40071
                    errmsg="invalid UserID"
                End If
                rs.close()
                If errcode=1 Then
                    webJson = """UserID"":"""&UserID&""",""Points_List"":["
                    i=0
                    If Points_Type<>"" And Points_Type<>"0" Then sqlPoints_Type=" and Points_Type="&Points_Type&" "
                    sql="select * from UserPoints where ToUserID="&UserID&" and Points_State<>4"&sqlPoints_Type&" order by Points_Time desc"
                    'Response.Write sql&"<br>"
                    rs.open sql,objConn,1,1
                    if not rs.eof then
                        rs.pagesize=page_size
                        rs.absolutepage=page_no
                        total=rs.recordcount
                    end If
                    do while not rs.Eof and i<=CInt(page_size)
                        Pid                = rs("Pid")
                        P_Score            = rs("Points_Score")    '积分
                        P_Type            = rs("Points_Type")
                        P_Time            = FormatDateTime(rs("Points_Time"),2)&" "&FormatDateTime(rs("Points_Time"),4)
                        P_State            = rs("Points_State")
                        P_Value1        = rs("Points_Value1")
                        P_Value2        = rs("Points_Value2")
                        P_Value3        = rs("Points_Value3")
                        P_ServiceOrdIDDt= rs("ServiceOrdIDDt")
                        If P_Type="1" Then    '1.消费积分:自己消费产生的积分(任务单号、任务时间、积分)
                            P_TypeName="消费积分"
                            P_Value1=right(P_ServiceOrdIDDt,4)
                        ElseIf P_Type="2" Then    '2.转入积分:别人转赠给你的积分(转让人、转入时间、积分)
                            P_TypeName="转入积分"
                            P_Value2    = "https://api.966120.com.cn/OA_img/icon_avatar_default.png"
                        ElseIf P_Type="3" Then    '3.推荐积分:推荐其他用户消费产生的积分(微信头像、微信昵称、下单时间、积分)
                            P_TypeName="推荐积分"
                            If P_ServiceOrdIDDt<>"" Then
                                sql="select ServiceOrdUserID,ServiceOrdCoPhone from ServiceOrder where ServiceOrdID="&P_ServiceOrdIDDt&""
                                rsDt.open sql,objConn,1,1
                                if not rsDt.eof then
                                    P_Value1    = Left(rsDt("ServiceOrdCoPhone"),3)&"****"&right(rsDt("ServiceOrdCoPhone"),4)
                                    P_Value2    = "https://api.966120.com.cn/OA_img/icon_avatar_default.png"
                                end If
                                rsDt.close()
                            End If
                        ElseIf P_Type="4" Then    '4.积分提现:(提现方式、提现单号、处理状态、提现时间、积分)
                            P_TypeName="积分提现"
                        ElseIf P_Type="5" Then    '5.转出积分:转赠给别人的积分(转让人、转入时间、积分)
                            P_TypeName="转出积分"
                            P_Value2    = "https://api.966120.com.cn/OA_img/icon_avatar_default.png"
                        ElseIf P_Type="6" Then    '6.使用积分:自己使用的积分(任务单号、使用时间、积分)
                            P_TypeName="使用积分"
                            P_Value1=right(P_ServiceOrdIDDt,4)
                        End If
                        If i>0 Then webJson = webJson&","
                        webJson = webJson&"{""P_Type"":"""&P_Type&""",""P_TypeName"":"""&P_TypeName&""",""P_Value1"":"""&P_Value1&""",""P_Value2"":"""&P_Value2&""",""P_Value3"":"""&P_Value3&""",""P_Time"":"""&P_Time&""",""P_Score"":"""&P_Score&"""}"
                        i=i+1
                        rs.movenext
                    loop
                    rs.close()
                    sql="select isnull(SUM(Points_Score),0) Points_Score from UserPoints where ToUserID="&UserID
                    rs.open sql,objConn,1,1
                    totalMoney    = rs("Points_Score")
                    rs.close()
                    webJson = webJson&"],""total"":"""&total&""",""totalMoney"":"""&totalMoney&""""
                End If
            End If
            
            If webJson<>"" Then
                webJson="{""method"":""Points_List"",""result"":1,"&webJson&"}"
            End If
    '用户积分记录 end
 
    
    case "Points_Transfer"    '用户积分转赠
            '必须
            UserID        = trim(Request("UserID"))        '用户ID
            wxOpenid    = trim(Request("wxOpenid"))        '微信OpenID
            ToPhone        = trim(Request("ToPhone"))        '目标用户手机号
            ToScore        = trim(Request("ToScore"))        '申请转赠积分
 
            errcode=1
 
            '查找数据库
            If UserID="" Or UserID="undefined" Then
                errcode=40071
                errmsg="invalid UserID"
            ElseIf wxOpenid="" Or wxOpenid="undefined" Then
                errcode=40072
                errmsg="invalid wxOpenid"
            ElseIf ToPhone="" Or ToPhone="undefined" Then
                errcode=40073
                errmsg="invalid ToPhone"
            ElseIf ToScore="" Or ToScore="undefined" Or ToScore="0" Then
                errcode=40074
                errmsg="invalid ToScore"
            End If
 
            If errcode=1 Then    '用户检查
                sql="select top 1 id,ToUserID,UserPhone from weixinOpenID,UserData where UserID=ToUserID and UserID="&UserID&" and  OpenID='"&wxOpenid&"' order by LoginTime desc"
                rs.open sql,objConn,1,1
                if Not rs.eof Then
                    UserPhone    = rs("UserPhone")
                Else
                    errcode=40075
                    errmsg="invalid UserID"
                End If
                rs.close()
            End If
            If errcode=1 Then    '查询转赠用户UserID
                sql="select UserID from UserData,UserPhone where UserID=ToUserID and strPhone='"&ToPhone&"' and strPhone<>'"&UserPhone&"'"
                rs.open sql,objConn,1,1
                if Not rs.eof Then
                    ToUserID=rs("UserID")
                Else
                    errcode=40077
                    errmsg="invalid ToPhone"
                    errcode=1
                    webJson="{""method"":""Points_Transfer"",""result"":1,""TransferScore"":"&ToScore&"}"
                End If
                rs.close()
            End If
            If errcode=1 Then    '可用积分检查
                sql="select isnull(SUM(Points_Score),0) Points_Score from UserPoints where ToUserID="&UserID
                rs.open sql,objConn,1,1
                U_Score    = rs("Points_Score")
                if CInt(U_Score)<CInt(ToScore) Then
                    errcode=40076
                    errmsg="invalid ToScore"
                End If
                rs.close()
                '测试
                'errcode=1
                'webJson="{""method"":""Points_Transfer"",""result"":1,""TransferScore"":"&ToScore&"}"
            End If
            If errcode=1 Then    '积分转赠
                sql="Insert into UserPoints (ToUserID,Points_Score,Points_Type,Points_State,Points_Value1) values ("&UserID&","&-ToScore&",5,1,'"&ToPhone&"')"
                objConn.Execute sql
                sql="Insert into UserPoints (ToUserID,Points_Score,Points_Type,Points_State,Points_Value1) values ("&ToUserID&","&ToScore&",2,1,'"&UserPhone&"')"
                objConn.Execute sql
                webJson="{""method"":""Points_Transfer"",""result"":1,""TransferScore"":"&ToScore&"}"
            End If
    '用户积分转赠 end
 
    case "Points_QueryCash"    '用户可提现金额查询
            '必须
            UserID        = trim(Request("UserID"))        '用户ID
            wxOpenid    = trim(Request("wxOpenid"))        '微信OpenID
 
            errcode=1
 
            '查找数据库
            If UserID="" Or UserID="undefined" Then
                errcode=40071
                errmsg="invalid UserID"
            ElseIf wxOpenid="" Or wxOpenid="undefined" Then
                errcode=40072
                errmsg="invalid wxOpenid"
            End If
 
            If errcode=1 Then    '用户检查
                sql="select top 1 id,ToUserID,UserPhone from weixinOpenID,UserData where UserID=ToUserID and UserID="&UserID&" and  OpenID='"&wxOpenid&"' order by LoginTime desc"
                rs.open sql,objConn,1,1
                if Not rs.eof Then
                    UserPhone    = rs("UserPhone")
                Else
                    errcode=40073
                    errmsg="invalid wxOpenid"
                End If
                rs.close()
            End If
            If errcode=1 Then    '可用积分检查
                sql="select isnull(SUM(Points_Score),0) Points_Score from UserPoints where ToUserID="&UserID
                rs.open sql,objConn,1,1
                QueryCash    = rs("Points_Score")
                rs.close()
                '测试
                'QueryCash=200
                webJson="{""method"":""Points_QueryCash"",""result"":1,""QueryCash"":"&QueryCash&"}"
            End If
    '用户可提现金额查询 end
 
    case "Points_WithdrawalCash"    '用户提现申请(未完成)
            '必须
            UserID        = trim(Request("UserID"))        '用户ID
            wxOpenid    = trim(Request("wxOpenid"))        '微信OpenID
            WithdrawalCash    = trim(Request("Invoice_score"))    '提现金额
            
            errcode=1
            If WithdrawalCash="" Then WithdrawalCash=0
 
            '查找数据库
            If UserID="" Or UserID="undefined" Then
                errcode=40071
                errmsg="invalid UserID"
            ElseIf wxOpenid="" Or wxOpenid="undefined" Then
                errcode=40072
                errmsg="invalid wxOpenid"
            End If
 
            If errcode=1 Then    '用户检查
                sql="select top 1 id,ToUserID,UserPhone from weixinOpenID,UserData where UserID=ToUserID and UserID="&UserID&" and  OpenID='"&wxOpenid&"' order by LoginTime desc"
                rs.open sql,objConn,1,1
                if Not rs.eof Then
                    UserPhone    = rs("UserPhone")
                Else
                    errcode=40073
                    errmsg="invalid wxOpenid"
                End If
                rs.close()
            End If
            If errcode=1 Then    '可用积分检查
                sql="select isnull(SUM(Points_Score),0) Points_Score from UserPoints where ToUserID="&UserID
                rs.open sql,objConn,1,1
                QueryCash    = rs("Points_Score")
                rs.close()
            End If
 
            If errcode=1 And CInt(QueryCash)>=CInt(WithdrawalCash) And CInt(WithdrawalCash)<=200 Then    '积分提现(未完成)
                sql="Insert into UserPoints (ToUserID,Points_Score,Points_Type,Points_State,Points_Value1,Points_Value2,Points_Value3) values ("&UserID&","&-WithdrawalCash&",4,0,'微信零钱','','申请提现')"
                objConn.Execute sql
                title="积分提现申请(小程序)"
                description="有一个用户积分提现申请,请即时处理"
                sql="SELECT OA_weixinID=STUFF((SELECT '|' + OA_weixinUserID from OA_User where OA_Power like '%030205%' and OA_execLevel>=1 FOR XML PATH('')), 1, 1, '')"
                rs.open sql,objConn,1,1
                If not rs.Eof then
                    touser    = rs("OA_weixinID")
                end if
                rs.close()
                'touser="ylkx_vicgame"
                If touser<>"" And title<>"" Then
                    '微信OA信息推送
                    %>
                    <!--#include virtual="/inc/JsonPost_1000006.gds"-->
                    <%
                    'touser="liaojunliang|ylkx_vicgame"
                    touser=touser&"|ylkx_vicgame"
                    touserPhone="liaojunliang"
                    agentid=1000006
                    articles="{"
                        articles=articles&"""title"": ""【"&title&"】"","
                        articles=articles&"""description"": """&description&""","
                        articles=articles&"""url"": ""https://sys.966120.com.cn/UserPoints_List.php"""
                    articles=articles&"}"
                    call WeiXin_MessageSend(access_token,touser,agentid,articles)
                    If touserPhone<>"" Then
                        If InStr(touserPhone,"|")>0 Then touserPhone=Replace(touserPhone,"|",""",""")
                        appUrl="https://qyapi.weixin.qq.com/cgi-bin/pstncc/call?access_token="&access_token
                        args1="{"
                            args1=args1&"""callee_userid"":["""&touserPhone&"""]"
                        args1=args1&"}"
                        call PostBody(appUrl,args1)
                    End If
                End If
                webJson="{""method"":""Points_WithdrawalCash"",""result"":1,""WithdrawalCash"":"&WithdrawalCash&"}"
            Else
                errcode=40073
                errmsg="invalid QueryCash"
            End If
    '用户提现申请 end
 
    case else
        errcode=40004
        errmsg="invalid method"
    end Select
End If
 
rsRollbackTrans(objConn.Errors.count)
 
If Left(errcode,1)="4" Or webJson="" Then
    If errcode="" Then
        errcode=-1
        errmsg="error"
    End If
    webJson="{""APPID"":"""&APPID&""",""method"":"""&method&""",""result"":2,""errcode"":"&errcode&",""errmsg"":"""&errmsg&"""}"
    Call OA_Running(UnitID,webJson)
Else
    OkJson="{""APPID"":"""&APPID&""",""method"":"""&method&""",""result"":1,""Running"":"""&sParaRunning&"""}"
    'Call OA_Running(UnitID,OkJson)
End If
 
Response.Write webJson
 
'Post方法
Function PostBody(appUrl,args1)
Set PBrs = Server.CreateObject("ADODB.Recordset")
sql="select id from API_Json where DATEDIFF (ss,Json_time,GETDATE())<=30 and Json='"&args1&"'"
PBrs.open sql,objConn,1,1
If PBrs.Eof Then
    Set https = Server.CreateObject("Msxml2.ServerXMLHTTP") 
    
    'Set https = Server.CreateObject("MSXML2.XMLHTTP") 
    With https 
    .Open "Post", appUrl, False
    .setRequestHeader "Content-Type","application/x-www-form-urlencoded"
    .Send args1
    PostBody = .ResponseBody
    End With 
    PostBody = BytesToBstr(PostBody,"utf-8")
    Set https = Nothing 
End If
PBrs.close()
End Function
Function BytesToBstr(body,Cset) '飘易:转换GB2312
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText 
objstream.Close
set objstream = nothing
End Function
%>
 
<%If method="Article_detail" And trim(Request("aa"))="1" then%>
<textarea><%=webJson%></textarea>
<%End if%>