hxp
2025-06-04 f4a514d5ac952110da846636ecbb9de951eaf3d2
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
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
<?php
 
namespace CommFunc;
 
include_once 'ConfigReader.php';
 
static $interfaceConfig = null;
 
function parseConfigIni()
{
    global $interfaceConfig;
    if ($interfaceConfig == null) {
        $interfaceConfig = parse_ini_file("/InterfaceConfig.php", true);
        if ($interfaceConfig) {
            \Logging\LogInfo("do parse_ini_file InterfaceConfig.php");
        }
    }
    return $interfaceConfig;
}
 
function GetConfig($section, $option, &$value, $defaultValue = null)
{
    $interfaceConfig = parseConfigIni();
    if (array_key_exists($section, $interfaceConfig)) {
        if (array_key_exists($option, $interfaceConfig[$section])) {
            $value = $interfaceConfig[$section][$option];
            return true;
        } else {
            \Logging\LogError("InterfaceConfig.php can not found option:" . $option . " in section:" . $section);
        }
    } else {
        \Logging\LogError("InterfaceConfig.php can not found section:" . $section);
    }
    $value = $defaultValue;
    return false;
}
 
function Has_section($section)
{
    $interfaceConfig = parseConfigIni();
    if (array_key_exists($section, $interfaceConfig)) {
        return true;
    }
    return false;
}
 
function Has_option($section, $option)
{
    $interfaceConfig = parseConfigIni();
    if (array_key_exists($section, $interfaceConfig)) {
        if (array_key_exists($option, $interfaceConfig[$section])) {
            return true;
        }
    }
    return false;
}
 
function GetGameName()
{
    GetConfig("ServerInfo", "GameName", $gameName);
    return $gameName;
}
 
/**
 * 获取该游戏所有运营渠道
 */
function GetAllChannel()
{
    GetConfig("ServerInfo", "ChannelList", $channelInfo);
    return explode(",", $channelInfo);
}
 
/**
 * 获取该游戏所有管理组织
 */
function GetAllOrganization()
{
    GetConfig("ServerInfo", "OrganizationList", $OrganizationList);
    return explode(",", $OrganizationList);
}
 
/**
 * 获取该组织对应可管理的渠道
 */
function GetOrganizationChannel($Organization)
{
    GetConfig("ServerInfo", "Channel_" . $Organization, $channels);
    return explode(",", $channels);
}
 
function EchoDateTimeSelect($dateName, $hourName, $minuteName, $secondName, $setDateStr = "", $hours = null, $minutes = null, $seconds = null)
{
    $defaultDate = "";
    $defaultHour = 0;
    $defaultMinute = 0;
    $defaultSecond = 0;
    if ($setDateStr == "") {
        $setDateStr = date("Y-m-d H:i:s");
    }
    if ($setDateStr) {
        // 2022-05-08 04:38:44
        $defaultDate = substr($setDateStr, 0, 10);
        $defaultHour =  substr($setDateStr, 11, 2);
        $defaultMinute = substr($setDateStr, 14, 2);
        $defaultSecond = substr($setDateStr, 17, 2);
    }
 
    $html = "<input type=\"text\" name=\"" . $dateName . "\" id=\"" . $dateName
        . "\" onclick=\"new Calendar().show(this);\" readonly value=\"" . $defaultDate . "\" size=\"8\"/>";
    // hour
    $html .= "<select name=\"" . $hourName . "\">";
    if (!isset($hours)) {
        $hours = range(0, 23);
    }
    foreach ($hours as $h) {
        if ($h < 10) {
            $hourStr = "0" . $h;
        } else {
            $hourStr = "" . $h;
        }
        $html .= "<option value=\"" . $hourStr . "\"";
        if ($hourStr <= $defaultHour) {
            $html .= " selected";
        }
        $html .= ">" . $hourStr . "</option>";
    }
    $html .= "</select>:";
    // minute
    $html .= "<select name=\"" . $minuteName . "\">";
    if (!isset($minutes)) {
        $minutes = range(0, 59);
    }
    foreach ($minutes as $m) {
        if ($m < 10) {
            $minuteStr = "0" . $m;
        } else {
            $minuteStr = "" . $m;
        }
        $html .= "<option value=\"" . $minuteStr . "\"";
        if ($minuteStr <= $defaultMinute) {
            $html .= " selected";
        }
        $html .= ">" . $minuteStr . "</option>";
    }
    $html .= "</select>:";
    // second
    if (!isset($seconds)) {
        $seconds = range(0, 59);
    }
    $html .= "<select name=\"" . $secondName . "\">";
    foreach ($seconds as $s) {
        if ($s < 10) {
            $secondStr = "0" . $s;
        } else {
            $secondStr = "" . $s;
        }
        $html .= "<option value=\"" . $secondStr . "\"";
        if ($secondStr <= $defaultSecond) {
            $html .= " selected";
        }
        $html .= ">" . $secondStr . "</option>";
    }
    $html .= "</select>";
    echo $html;
}
 
/**
 * 比较版本号
 * @param string $curVersion 当前版本
 * @param string $cmpVersion 要比较的版本
 * @return -1-小于比较版本;0-等于比较版本;1-大于比较版本
 */
function CheckVersion($curVersion, $cmpVersion)
{
    $curValue = VersionNum($curVersion);
    $cmpValue = VersionNum($cmpVersion);
    if ($curValue < $cmpValue) {
        return -1;
    }
    if ($curValue > $cmpValue) {
        return 1;
    }
    return 0;
}
 
function VersionNum($version)
{
    $arrver = explode('.', $version);
    if (isset($arrver[2])) {
        $integer_version = $arrver[0] * 10000 + $arrver[1] * 100 + $arrver[2];
    } else if (isset($arrver[1])) {
        $integer_version = $arrver[0] * 10000 + $arrver[1] * 100;
    } else {
        $integer_version = $arrver[0];
    }
    return intval($integer_version);
}
 
/**
 * 优化的require_once
 * @param string $filename 文件地址
 * @return boolean
 */
function require_cache($filename)
{
    static $_importFiles = array();
    if (!isset($_importFiles[$filename])) {
        if (file_exists_case($filename)) {
            require $filename;
            $_importFiles[$filename] = true;
        } else {
            $_importFiles[$filename] = false;
        }
    }
    return $_importFiles[$filename];
}
 
/**
 * 强制类型转换
 * @param mixed &$value 数据
 * @param string $valueType 数据类型(int, str, float, array)
 * @return boolean
 */
function ConvValue(&$value, $valueType = "str")
{
    if ($valueType == 'array') {
        $newValue = is_array($value) ? $value : array($value);
    } else {
        $valueType .= "val";
        $newValue = @$valueType($value);
    }
    $ret = $newValue == $value;
    if ($ret) {
        $value = $newValue;
        return true;
        # 如果转换后不等 说明原数据类型差异过大
    } else {
        return false;
    }
}
 
#检查GET参数是否被设置,如果设置则返回true,否则返回false,
#$strModuleLogName:如果检查失败,记录log的文件名字
#$checkErrorPintValue:在检查参数失败的时候,传回给浏览器的内容
function CheckGetParam($param, $checkErrorPrintValue = null)
{
    return CheckParam($_GET, $param, $checkErrorPrintValue);
}
 
#检查POST参数是否被设置,如果设置则返回true,否则返回false,
#$strModuleLogName:如果检查失败,记录log的文件名字
#$checkErrorPintValue:在检查参数失败的时候,传回给浏览器的内容
function CheckPostParam($param, $checkErrorPrintValue = null)
{
    return CheckParam($_POST, $param, $checkErrorPrintValue);
}
 
function CheckParam($arrayToCheck, $param, $checkErrorPrintValue = null)
{
    if (!isset($arrayToCheck[$param])) {
        \Logging\LogWarn("" . var_export($arrayToCheck, True) . " query:$param is null!");
 
        if ($checkErrorPrintValue != null) {
            echo $checkErrorPrintValue;
        }
        return false;
    }
 
    return true;
}
 
#从配置文件获得key,返回值为true则成功,否则失败
#需要传入配置文件名(全路径),section名和ident名以及日志对象
#$strErrorPrintValue:用来在发生读取失败时打印的内容
 
function GetKeyFromConfig(
    $strConfigName,
    $strSection,
    $strIdent,
    &$strRet,
    $strErrorPrintValue = ''
) {
    static $arrayConfig = array();
 
    $config = null;
 
    if (!array_key_exists($strConfigName, $arrayConfig)) {
        $config = new \ConfigReader\ConfigReader($strConfigName);
        $arrayConfig[$strConfigName] = $config;
    } else {
        $config = $arrayConfig[$strConfigName];
    }
 
 
    if (!$config->load()) {
        \Logging\LogError('配置文件载入失败!文件路径:' . $strConfigName);
        echo $strErrorPrintValue;
        return false;
    }
    if (!$config->GetData($strSection, $strIdent, $strRet)) {
        \Logging\LogError('read config Key error!Error:' . $config->GetErrInfo());
        echo $strErrorPrintValue;
        return false;
    }
 
    \Logging\LogInfo(sprintf(
        '配置文件:%s, section:%s, ident:%s载入成功!',
        $strConfigName,
        $strSection,
        $strIdent
    ));
    return true;
}
 
#判断是否有Section存在于指定的配置中
function IsSectionExist($strSection, $strConfigName)
{
    $config = new \ConfigReader\ConfigReader($strConfigName);
    if (!$config->load()) {
        \Logging\LogError('配置文件载入失败!文件路径:' . $strConfigName);
        return false;
    }
 
    return $config->IsSectionExist($strSection);
}
 
 
#传入数组参数,批量检测数组中的参数是否都存在(CheckGetParam的批量处理版)
function ArrayCheckGetParam($arrayParam, $checkErrorPrintValue = null)
{
    $bRet = true;
    foreach ($arrayParam as $strValue) {
        if (!CheckGetParam($strValue, $strValue . ' ' . $checkErrorPrintValue)) {
            $bRet = false;
        }
    }
 
    return $bRet;
}
 
/**
 * 根据游戏账号返回平台账号明细
 */
function GetAccountInfoByAccID($accID)
{
    $accIDInfoList = explode("@", $accID);
    $infoCount = count($accIDInfoList);
    if ($infoCount < 3) {
        return array();
    }
    $sid = $accIDInfoList[$infoCount  - 1];
    $platform = $accIDInfoList[$infoCount  - 2];
    $AccountID = join("@", array_slice($accIDInfoList, 0, $infoCount  - 2));
    $accountInfo = array(
        "AccountID" => $AccountID,
        "Channel" => $platform,
        "ServerID" => GetServerIDBySid($sid),
    );
    return $accountInfo;
}
 
/**
 * 根据字符串取服务器id,一般正常的格式为 sxxx
 * @param string $sid 字符串 s+服务器ID
 * @return number 大于等于0代表服务器ID
 */
function GetServerIDBySid($sid)
{
    if (!substr($sid, 0, 1) == "s") {
        return 0;
    }
    if (!is_numeric(substr($sid, 1))) {
        return 0;
    }
    return intval(substr($sid, 1));
}
 
static $gameservers = null;
function GetGameServers($spid)
{
    global $gameservers;
    if ($gameservers != null) {
        return $gameservers;
    }
    $gameservers = array();
    $ConfigFile = dirname(__FILE__) . "\\..\\Account\Server\Server_" . $spid . ".ini";
    if (!file_exists($ConfigFile)) {
        \Logging\LogError("file is not exist:" . $ConfigFile);
        return $gameservers;
    }
    $serverCfg = parse_ini_file($ConfigFile, true);
    foreach ($serverCfg as $Name => $serverInfo) {
        $gameservers[$serverInfo["ServerID"]] = array(
            "Page" => $serverInfo["Page"],
            "MainServer" => $serverInfo["MainServer"],
            "Name" => $Name,
        );
    }
    return $gameservers;
}
 
function GetGameServerInfo($spid, $queryServerID)
{
    $ConfigFile = dirname(__FILE__) . "\\..\\Account\Server\Server_" . $spid . ".ini";
    if (!file_exists($ConfigFile)) {
        return;
    }
 
    $serverCfg = parse_ini_file($ConfigFile, true);
 
    foreach ($serverCfg as $serverName => $serverInfo) {
        $Page = $serverInfo["Page"];
        $serverID = $serverInfo["ServerID"];
        $mainServerID = $serverInfo["MainServer"];
        if (!$mainServerID) {
            !$mainServerID = $serverID;
        }
        if (!$mainServerID) {
            continue;
        }
        if (!$serverID) {
            continue;
        }
        $serverID = intval($serverID);
 
        if ($queryServerID != $serverID) {
            continue;
        }
 
        return array(
            "Name" => $serverName,
            "ServerID" => $serverID,
            "Page" => $Page,
            "MainServer" => $mainServerID,
        );
    }
    return;
}
 
function GetGameServerInfoByName($spid, $serverName)
{
    $ConfigFile = dirname(__FILE__) . "\\..\\Account\Server\Server_" . $spid . ".ini";
    if (!file_exists($ConfigFile)) {
        return;
    }
 
    $serverCfg = parse_ini_file($ConfigFile, true);
    $serverInfo = $serverCfg[$serverName];
    if ($serverInfo) {
        $Page = $serverInfo["Page"];
        $serverID = $serverInfo["ServerID"];
        $mainServerID = $serverInfo["MainServer"];
        if (!$mainServerID) {
            !$mainServerID = $serverID;
        }
        return array(
            "Name" => $serverName,
            "ServerID" => $serverID,
            "Page" => $Page,
            "MainServer" => $mainServerID,
        );
    }
    return;
}
 
/**
 * 获取游戏服务器地址信息列表
 * @param string $spid 运营id
 * @param array $serverIDArray 服务器ID数组,为空时返回所有服务器
 * @return array (mainServerID=>("MixServerIDList"=>(区服ID1,2,3,...), "Page"=>"主服地址"), ...)
 */
function GetGameServerPageInfo($spid, $serverIDArray = null)
{
    $serverArray = array();
    $ConfigFile = dirname(__FILE__) . "\\..\\Account\Server\Server_" . $spid . ".ini";
    if (!file_exists($ConfigFile)) {
        return $serverArray;
    }
 
    $serverCfg = parse_ini_file($ConfigFile, true);
 
    foreach ($serverCfg  as $serverInfo) {
        $Page = $serverInfo["Page"];
        $serverID = $serverInfo["ServerID"];
        $mainServerID = $serverInfo["MainServer"];
        if (!$mainServerID) {
            !$mainServerID = $serverID;
        }
        if (!$mainServerID) {
            continue;
        }
        if (!$serverID) {
            continue;
        }
        $serverID = intval($serverID);
 
        if ($serverIDArray) {
            if (in_array($serverID, $serverIDArray)) {
                $serverArray[$mainServerID] = array("Page" => $Page);
                break;
            }
            continue;
        }
 
        if (!array_key_exists($mainServerID, $serverArray)) {
            $serverArray[$mainServerID] = array("MixServerIDList" => array(), "Page" => $Page);
        }
        array_push($serverArray[$mainServerID]["MixServerIDList"], $serverID);
    }
    return $serverArray;
}
 
/**
 * 发送GMT命令到游戏服务器
 * @param bool $isSuperGMT 是否高级命令
 * @param string $pack_type GMT命令,一般是 GMT_XXX
 * @param array $pack_data 命令参数数值
 * @param string $spid 运营id
 * @param array $serverIDArray 服务器ID数组,为空时发给所有服务器
 * @return 返回发送结果列表
 */
function SendGMTToGameServers($isSuperGMT, $pack_type, $pack_data, $spid, $serverIDArray = null)
{
    $serverPageInfo = \CommFunc\GetGameServerPageInfo($spid, $serverIDArray);
    if (count($serverPageInfo) <= 0) {
        return;
    }
 
    if ($isSuperGMT) {
        \CommFunc\GetKeyFromConfig(dirname(__FILE__) . '\\..\\InterfaceConfig.php', "Config", "GMKey2", $key);
    } else {
        \CommFunc\GetKeyFromConfig(dirname(__FILE__) . '\\..\\InterfaceConfig.php', "Config", "GMKey", $key);
    }
 
    $pack_data["pack_type"] = $pack_type;
    $pack_data["key"] = $key;
    $pack_data["coding"] = "utf8";
 
    $mainServerID = 0;
    $sendServers = array();
    foreach ($serverPageInfo as $mainServerID => $serverInfo) {
        //其他每个服可能不同的参数处理
        //$pack_data[""] = "";
 
        //使用key加密
        $pack_data_dict = json_encode($pack_data);
        $sign = md5($pack_data_dict . $key);
        $post = array();
        $post['pack'] = $pack_data_dict;
        $post['sign'] = $sign;
        $post['toServerID'] = $mainServerID;
 
        $sendServers[$mainServerID] = array($mainServerID, $serverInfo['Page'], $post);
    }
 
    if (count($sendServers) == 1) {
        $retStr = \CommFunc\DoPost($sendServers[$mainServerID][1], $sendServers[$mainServerID][2]);
        $ServerIDValues = array_values($serverIDArray);
        $ServerID = $ServerIDValues[0];
        $retList = array($ServerID => $retStr);
    } else {
        $retList = \CommFunc\DoPostMulti($sendServers);
    }
    return $retList;
}
 
/**
 * 向指定游戏服务器发送个人邮件
 * @param string $spid 渠道id
 * @param string $serverID 服务器id,账号对应的服务器id即可
 * @param string $title 邮件标题
 * @param string $content 邮件内容
 * @param array $playerList 目标玩家列表,可以是账号、角色名、仙盟id,由 queryType 参数决定,默认为账号
 * @param array $itemList 物品列表,[[itemID,个数,可选参数是否拍品], ...]
 * @param int $endDays 有效天数,默认30
 * @param string $queryType 决定参数 playerList 中的玩家类型
 * @return 返回发送结果列表
 */
function SendMailPersonal($spid, $serverID, $title, $content, $playerList, $itemList, $endDays = 30, $queryType = "accID")
{
    // 参数值必须都是字符串
    $pack_data = array();
    $pack_data["playerList"] = implode(",", $playerList);
    $pack_data["queryType"] = $queryType;
    $pack_data['playerFind'] = "0"; // 实际不用该参数,兼容旧版用
 
    $pack_data['EndTime'] = date('Y-m-d', strtotime('+' . $endDays . ' day')) . " 00:00:00";
    $pack_data["Title"] = $title;
    $pack_data["Text"] =  $content;
    $pack_data["Gold"] = "0";
    $pack_data["GoldPaper"] = "0";
    $pack_data["Silver"] = "0";
 
    # 物品信息
    $pack_data["itemNums"] = implode(",", array_keys($itemList));
    foreach ($itemList as $itemIndex => $itemInfo) {
        $pack_data["ItemID" . $itemIndex] = "" . $itemInfo[0];
        $pack_data["ItemCnt" . $itemIndex] = "" . $itemInfo[1];
        $pack_data["IsBind" . $itemIndex] = "" . (count($itemInfo) > 2 ? $itemInfo[2] : 0);
    }
 
    \Logging\LogInfo("SendMailPersonal: spid=" . $spid . " serverID=" . $serverID . " pack_data:" . print_r($pack_data, true));
 
    $serverIDArray = array($serverID);
    $retList = \CommFunc\SendGMTToGameServers(true, "GMT_AddPersonalCompensation", $pack_data, $spid, $serverIDArray);
    if (!$retList || !is_array($retList)) {
        \Logging\LogError("retList error:" . $retList);
        return array(false, null);
    }
    $ret = json_decode($retList[$serverID], true);
    if (!$ret || !array_key_exists("ResultType", $ret) || $ret["ResultType"] != 0) {
        \Logging\LogError("error retList:" . print_r($retList, true));
        return array(false, $ret);
    }
    \Logging\LogInfo("retList:" . print_r($retList, true));
    return array(true, $ret);
}
 
/**
 * 查询流向数据
 * @param \User\User $user
 */
function QueryEventData($user, &$retList)
{
    \Logging\LogInfo("QueryEventData _POST:" . print_r($_POST, true));
 
    $pack_data = $_POST;
 
    $sendServers = array();
    $serversArray = $user->GetServers();
    $onlyServerID = $_POST['OnlyServerID'];
    // 多服查询的
    if ($_POST["MultiServer"] == 1) {
        // $onlyServerID = 0; // 默认0
        foreach ($serversArray as $serverName => $serverInfo) {
            $postServerName = urlencode($serverName);
            if (!array_key_exists($postServerName, $_POST)) {
                continue;
            }
            if (!$_POST[$postServerName] == 'on') {
                continue;
            }
            unset($pack_data[$postServerName]);
 
            if ($serverInfo['MainServer'] && !$onlyServerID && $serverInfo['MainServer'] != $serverInfo['ServerID']) {
                # 有主服的代表是合服的,只发主服;因为子服是同一台服务器,没必要重复发送
                continue;
            }
            $sendServers[] = array($serverName, GetQueryEventToolUrl($serverInfo['Page'], array()));
        }
    } else if ($_SESSION['server_id']) {
        $sendServers[] = array($_SESSION['server_id'], GetQueryEventToolUrl($_SESSION['tool_page']), array());
    }
 
    if (!$sendServers) {
        echo "Error. " . \Lang\gettext("请先选择服务器");
        return;
    }
 
    // 去除参数
    unset($pack_data['submit']);
    unset($pack_data["OnlyServerID"]);
    unset($pack_data["server_select_all"]);
 
    $pack_data["spID"] = $user->GetSPID();
    for ($i = 0; $i < count($sendServers); $i++) {
        $serverName = $sendServers[$i][0];
        if ($serversArray[$serverName]["MixServerStr"]) {
            $pack_data["mixServerIDInfo"] = $serversArray[$serverName]["MixServerStr"];
        } else {
            $pack_data["mixServerIDInfo"] = $serversArray[$serverName]["ServerID"];
        }
        $pack_data["serverID"] = $serversArray[$serverName]["ServerID"];
        $pack_data["mainServer"] = $serversArray[$serverName]["MainServer"];
        if ($onlyServerID) {
            $pack_data["OnlyServerID"] = $pack_data["serverID"];
        }
        $sendServers[$i][2] = $pack_data;
    }
 
    \Logging\LogInfo("待发送的服务器信息: " . count($sendServers) . " " . print_r($sendServers, true));
 
    if (count($sendServers) == 1) {
        $retStr = DoPost($sendServers[0][1], $sendServers[0][2]);
        $ret = json_decode($retStr, true);
        if (!isset($ret)) {
            $retList[$sendServers[0][0]] = $retStr;
        } else {
            $retList[$sendServers[0][0]] = $ret;
        }
    } else {
        $retMulti = DoPostMulti($sendServers);
        if ($retMulti && count($retMulti) == count($sendServers)) {
            for ($i = 0; $i < count($sendServers); $i++) {
                $ret = json_decode($retMulti[$i], true);
                if (!isset($ret)) {
                    $retList[$sendServers[$i][0]] = $retMulti[$i];
                } else {
                    $retList[$sendServers[$i][0]] = $ret;
                }
            }
        }
    }
    $retCount = count($retList);
    \Logging\LogInfo("返回查询结果条数: " .  $retCount);
    // \Logging\LogInfo("返回查询结果: " .  $retCount . " " .  print_r($retList, true));
}
 
/**获取目标服务器流向查询url地址 */
function GetQueryEventToolUrl($tool_page)
{
    // 在原GM工具地址下同层级
    return substr($tool_page, 0,  -strlen("tool.php")) . "eventdata/tool.php";
}
 
#批量进行post请求
function DoPostMulti($sendServers)
{
    if (!is_array($sendServers))
        return false;
 
    $handle  = array();
    foreach ($sendServers as $key => $value) {
        $server_url = $value[1];
        $post = $value[2];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $server_url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        $handle[$key] = $ch;
    }
 
    //创建批处理curl句柄
    $mh = curl_multi_init();
    //将单个curl句柄添加到批处理curl句柄中
    foreach ($handle as $ch) {
        curl_multi_add_handle($mh, $ch);
    }
    $active = null;
    /* 执行 */
    do {
        $mrc = curl_multi_exec($mh, $active);
    } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    // 升级5.5版本后, curl_multi_select 一直等于-1,导致不执行 curl_multi_exec ,然后卡到超时,暂不明原因,先特殊处理
    if (CheckVersion(phpversion(), "5.5.0") >= 0) {
        do {
            usleep(10000); // 10ms
            curl_multi_exec($mh, $active);
            // \Logging\LogInfo("while active:" . $active);
        } while ($active > 0);
    } else {
        while ($active && $mrc == CURLM_OK) {
            if (curl_multi_select($mh) != -1) {
                do {
                    $mrc = curl_multi_exec($mh, $active);
                } while ($mrc == CURLM_CALL_MULTI_PERFORM);
            }
        }
    }
 
    $data    = array();
    /* 读取资料 */
    foreach ($handle as $key => $ch) {
        $content  = curl_multi_getcontent($ch);
        //$data[$i] = (curl_errno($ch) == 0) ? $content : false;
        $data[$key] = $content;
    }
    /* 移除 handle*/
    foreach ($handle as $ch) {
        curl_multi_remove_handle($mh, $ch);
    }
    curl_multi_close($mh);
    return $data;
}
 
#进行post请求
function DoPost($url, $post, $passSession = false, $timeout = 30)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    if ($passSession) {
        curl_setopt($ch, CURLOPT_COOKIE, 'PHPSESSID=' . $_COOKIE['PHPSESSID']);
    }
    $result = curl_exec($ch);
    curl_close($ch);
    unset($ch);
    return $result;
}
 
#进行postjson请求
function DoPostJson($url, $post)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_TIMEOUT, 2);
    $result = curl_exec($ch);
    curl_close($ch);
    unset($ch);
    return $result;
}
 
 
 
#进行Get请求
function DoGet($url, $get, $delay = 30)
{
    $getData = http_build_query($get);
    $getData = str_replace("%3D", "=", $getData);
    $url = $url . '?' . $getData;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, $delay);
    $result = curl_exec($ch);
    curl_close($ch);
    unset($ch);
    return $result;
}
 
function curl_get($url, $get, $timeout = 10)
{
    $getData = http_build_query($get);
    $getData = str_replace("%3D", "=", $getData);
    $url = $url . '?' . $getData;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    $ret = curl_exec($ch);
    curl_close($ch);
    unset($ch);
    return $ret;
}
 
function curl_post($url, $post, $timeout = 10, $bulid = false)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $bulid ? http_build_query($post) : json_encode($post));
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    $ret = curl_exec($ch);
    curl_close($ch);
    unset($ch);
    return $ret;
}
 
/**
 * 使用 SessionStart SessionSave 
 * 防止出现 session_start 时该php还未执行完毕又调用另一个存在 session_start 的php时卡主的问题
 * 比如 a.php 页面逻辑中有 post 到 b.php 的逻辑时,a b两页面同时session_start时会卡主
 * 原因:因为 session_start 后会锁住该回话session文件,直到回话结束,可以使用 session_write_close 释放该session锁,防止同时调用 session_start 卡主
 */
function SessionStart()
{
    session_start();
    session_write_close();
}
 
function SessionSave($set)
{
    session_start();
    foreach ($set as $key => $value) {
        $_SESSION[$key] = $value;
    }
    session_write_close();
}
 
// 测试http请求
function TestQuery($url, $data, $method = "Get", $resultFunc = null)
{
    echo '<pre>url:' . $url . "\n";
    echo '参数:' . var_export($data, true) . "\n";
    $method = $method ? ucfirst(strtolower($method)) : "Get";
    echo '请求类型: ' . $method . "\n";
    $func = "\CommFunc\Do{$method}";
    $result = $func($url, $data);
    if ($resultFunc) $result = $resultFunc($result);
    echo '结果:' . var_export($result, true) . "\n\n</pre>";
    return $result;
}
 
//字符串时间格式的数据转换成time格式的,如2000-02-12 16:20:35转成time 950368835
function StrDateTimeToTime($strDateTime)
{
    $array = explode("-", $strDateTime);
    $year = $array[0];
    $month = $array[1];
 
    $array = explode(":", $array[2]);
    $minute = $array[1];
    $second = $array[2];
 
    $array = explode(" ", $array[0]);
    $day = $array[0];
    $hour = $array[1];
 
    $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
    return $timestamp;
}
 
//time格式转换成字符串时间格式,如time 950368835转成2000-02-12 16:20:35
function TimeToStrDateTime($time, $format = "Y-m-d H:i:s")
{
    return date($format, $time);
}
 
/**
 * 计算时间转化为字符串时间
 * @param string $datetime The string to parse. Before PHP 5.0.0, microseconds weren't allowed in the time, since PHP 5.0.0 they are allowed but ignored.
 */
function CalcToStrDateTime($datetime, $format = "Y-m-d H:i:s")
{
    return TimeToStrDateTime(strtotime($datetime, StrDateTimeToTime(date($format))), $format);
}
 
/**
 * 字符串时间格式转换
 * @param string $datetimeStr 需要转化的时间字符串
 * @param string $format 需要转化的格式,默认 Y-m-d H:i:s , 或 DATE_ISO8601 等
 * @return string 返回转化后的时间格式字符串
 */
function StrDateTimeFormatConver($datetimeStr = "", $format = "Y-m-d H:i:s")
{
    if ($datetimeStr == "") {
        $datetimeStr = date("Y-m-d H:i:s");
    }
    $time2 = strtotime($datetimeStr);
    return date($format, $time2);
}
 
#加解密算法需要的定义
 
#加密的次数
const NUM_ENCODE_CNT = 3;
#异或的key
const NUM_XOR_KEY = 151;
 
#公司内部通用解密算法
function GetDecodePsw($strPsw)
{
    $strResult = $strPsw;
    for ($nIndex = 0; $nIndex < NUM_ENCODE_CNT; $nIndex++) {
        $strResult = base64_decode($strResult);
    }
 
    $nLen = strlen($strResult);
    for ($nIndex = 0; $nIndex < $nLen; $nIndex++) {
        $strResult[$nIndex] = chr(ord($strResult[$nIndex]) ^ NUM_XOR_KEY);
    }
 
    return $strResult;
}
 
#公司内部用加密算法
function GetEncodePsw($strPsw)
{
    $strResult = $strPsw;
    $nLen = strlen($strResult);
 
    for ($nIndex = 0; $nIndex < $nLen; $nIndex++) {
        $strResult[$nIndex] = chr(ord($strResult[$nIndex]) ^ NUM_XOR_KEY);
    }
 
    for ($nIndex = 0; $nIndex < NUM_ENCODE_CNT; $nIndex++) {
        $strResult = base64_encode($strResult);
    }
 
    return $strResult;
}
 
#数字字符串转换为数字
function NumStringToNum($strSrc)
{
    if (!is_numeric($strSrc)) {
        return intval($strSrc);
    }
 
    return $strSrc;
}
 
#全局接收,不管是POST或者GET调用此接口即可
#$ProcessFunc:函数定义必须是$ProcessFunc($RecvArray, $Decribe),$RecvArray可能是$_POST或者$_GET, $Decribe相对的是POST或者GET 
function GLOBAL_RECV($ProcessFunc)
{
    if (!function_exists($ProcessFunc)) {
        \Logging\LogError("not exist func:" . $ProcessFunc);
        return;
    }
    $RecvArray = $_GET;
    $Decribe = 'GET';
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        $RecvArray = $_POST;
        $Decribe = 'POST';
    }
 
    $ProcessFunc($RecvArray, $Decribe);
}
 
#二进制转换为十六进制的字符串,每个字符中间用空格隔开,便于查看
function BinToStr($strSource)
{
    $nLen = strlen($strSource);
 
    $strHexConverted = '0x';
    for ($nIndex = 0; $nIndex < $nLen; $nIndex++) {
        $strHexConverted = $strHexConverted . bin2hex($strSource{
            $nIndex}) . ' ';
    }
 
    return $strHexConverted;
}
 
#记录错误日志信息的同时打印到浏览器上
function LogErrorAndPrint($strError)
{
    \Logging\LogError($strError);
    echo $strError;
}
 
function str_xor($astring, $xornum = 150)
{
    $ret = '';
    $nLen = strLen($astring);
    for ($nIndex = 0; $nIndex < $nLen; $nIndex++) {
        $ret .= chr(ord($astring[$nIndex]) ^ $xornum);
    }
    return $ret;
}
 
function ParseBuff($buff)
{
    $ret = '';
    $nLen = strLen($buff);
    for ($nIndex = 0; $nIndex < $nLen; $nIndex++) {
        if ($nIndex % 2 == 0 && $nIndex != 0) {
            $ret = $ret . ' ' . $buff[$nIndex];
        } else {
            $ret = $ret . $buff[$nIndex];
        }
    }
    return $ret;
}
 
/**
 * 客户端IP,
 */
function GetIP()
{
    if (@$_SERVER["HTTP_X_FORWARDED_FOR"])
        $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
    else if (@$_SERVER["HTTP_CLIENT_IP"])
        $ip = $_SERVER["HTTP_CLIENT_IP"];
    else if (@$_SERVER["REMOTE_ADDR"])
        $ip = $_SERVER["REMOTE_ADDR"];
    else if (@getenv("HTTP_X_FORWARDED_FOR"))
        $ip = getenv("HTTP_X_FORWARDED_FOR");
    else if (@getenv("HTTP_CLIENT_IP"))
        $ip = getenv("HTTP_CLIENT_IP");
    else if (@getenv("REMOTE_ADDR"))
        $ip = getenv("REMOTE_ADDR");
    else
        $ip = "Unknown";
    if (preg_match('/^((?:(?:25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(?:25[0-5]|2[0-4]\d|((1\d{2})|([1 -9]?\d))))$/', $ip))
        return $ip;
    else
        return '';
    return $ip;
}
 
/**
 * 服务器端IP
 * @return string
 */
function ServerIP()
{
    return gethostbyname($_SERVER["SERVER_NAME"]);
}
 
/**
 * 是否内网测试
 */
function IsInnerTest()
{
    return GetIP() == "127.0.0.1" || substr(GetIP(), 0, 8) == "192.168.";
}
 
//获得当前的年月
function GetMonth()
{
    return date("Y-m", time());
}
 
//获得当前的年月日
function GetDay()
{
    return date("Y-m-d", time());
}
 
//获得兑换历史记录对象
function GetExchangeHistorySaveObj($strDirName = 'ExchangeHistory', $strFileName = 'DirectionFlow')
{
    return new \MultiLogging\MultiLogging(dirname(__FILE__) . "\\..", $strDirName, $strFileName);
}
 
function guid()
{
    if (function_exists('com_create_guid')) {
        return com_create_guid();
    } else {
        mt_srand((float) microtime() * 10000); //optional for php 4.2.0 and up.
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45); // "-"
        $uuid = chr(123) // "{"
            . substr($charid, 0, 8) . $hyphen
            . substr($charid, 8, 4) . $hyphen
            . substr($charid, 12, 4) . $hyphen
            . substr($charid, 16, 4) . $hyphen
            . substr($charid, 20, 12)
            . chr(125); // "}"
        return $uuid;
    }
}
 
function GetBrowser()
{
    $agent = $_SERVER["HTTP_USER_AGENT"];
 
    if (strpos($agent, 'MSIE') !== false) {
        $agentArr = explode('.', strstr($agent, 'MSIE'));
        return $agentArr[0];
    } else if (strpos($agent, 'rv:11.0'))
        return 'IE11';
    else if (strpos($agent, 'Firefox') !== false) {
        $agentArr = explode('.', strstr($agent, 'Firefox'));
        return $agentArr[0];
    } else if (strpos($agent, 'OPR') !== false) {
        $agentArr = explode('.', strstr($agent, 'OPR'));
        return $agentArr[0];
    } else if (strpos($agent, 'QQBrowser') !== false) {
        $agentArr = explode('.', strstr($agent, 'QQBrowser'));
        return $agentArr[0];
    } else if (strpos($agent, 'SE 2') !== false) {
        $agentArr = explode('.', strstr($agent, 'SE 2'));
        return $agentArr[0];
    } else if (strpos($agent, 'BIDUBrowser') !== false) {
        $agentArr = explode('.', strstr($agent, 'BIDUBrowser'));
        return $agentArr[0];
    } else if (strpos($agent, 'LBBROWSER') !== false) {
        return 'LBBROWSER';
    } else if (strpos($agent, 'Edge') !== false) {
        $agentArr = explode('.', strstr($agent, 'Edge'));
        return $agentArr[0];
    } else if (strpos($agent, 'Chrome') !== false) {
        $agentArr = explode('.', strstr($agent, 'Chrome'));
        return $agentArr[0];
    } else if (strpos($agent, 'Safari') !== false) {
        $agentArr = explode('.', strstr($agent, 'Safari'));
        return $agentArr[0];
    } else
        return 'others';
}
 
function GetOS()
{
    $agent = $_SERVER["HTTP_USER_AGENT"];
 
    if (strpos($agent, 'NT 5.1') !== false) {
        return 'Windows XP';
    } else if (strpos($agent, 'NT 6.1') !== false) {
        return 'Windows 7';
    } else if (strpos($agent, 'NT 5.2') !== false) {
        return 'Windows 8';
    } else if (strpos($agent, 'NT 10') !== false) {
        return 'Windows 10';
    } else if (strpos($agent, 'Windows') !== false) {
        return 'Windows';
    } else
        return 'others';
}
 
 
function myopen($reportHost, $reportPort, $reportUrl, $reportData)
{
    $fp = fsockopen($reportHost, $reportPort, $errno, $errstr, 1);
    if (!$fp) {
        \Logging\LogInfo('fsockopen error' . $errno . $errstr);
    } else {
        stream_set_blocking($fp, 0);
        $getData = http_build_query($reportData);
        $getData = str_replace("%3D", "=", $getData);
        $url = $reportUrl . '?' . $getData;
 
        $out = "GET " . $url . " HTTP/1.1\r\n";
        $out .= "Host: " . $reportHost . "\r\n";
        $out .= "Connection: Close\r\n\r\n";
 
        fwrite($fp, $out);
        fclose($fp);
    }
}
 
#进行Get请求 毫秒级超时
function MS_DoGet($url, $get)
{
    $getData = http_build_query($get);
    $getData = str_replace("%3D", "=", $getData);
    $url = $url . '?' . $getData;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_NOSIGNAL, true);
    curl_setopt($ch, CURLOPT_TIMEOUT_MS, 100);
    $result = curl_exec($ch);
    curl_close($ch);
    unset($ch);
    return $result;
}
 
function GetFileContents($filePath, $defaultContent = "", $isutf8 = true)
{
    $c = "";
    if (file_exists($filePath)) {
        $c = file_get_contents($filePath);
    }
    if (!$c) {
        $c = $defaultContent;
    }
    if ($isutf8) {
        return TrimUTF8BOM($c);
    }
    return $c;
}
 
# 去除UTF8 BOM 头
function TrimUTF8BOM($str)
{
    return trim($str, "\xEF\xBB\xBF");
}
 
/**
 * 数组转化为Json,支持utf8中文处理,如需要排版格式化则在调用 JsonFormat
 * json_encode 值支持utf8
 * 数组中所有中文在json_encode之后都不见了或者出现\u2353等。
 * 解决方法是用 urlencode()函数处理以下,在json_encode之前,把所有数组内所有内容都用urlencode()处理一下
 * 然用json_encode()转换成json字符串,最后再用urldecode()将编码过的中文转回来。
 */
function MyJson_encode($code)
{
    $code = json_encode(urlencodeAry($code));
    return urldecode($code);
}
 
# 对数组内容进行 urlencode
function urlencodeAry($data)
{
    if (is_array($data)) {
        foreach ($data as $key => $val) {
            $data[$key] = urlencodeAry($val);
        }
        return $data;
    } elseif (is_string($data)) {
        return urlencode($data);
    } else {
        return $data;
    }
}
 
/** 
 * Json数据格式化
 * @param  String $data   json数据字符串
 * @param  String $indent 缩进字符,默认4个空格
 * @return 排版格式化后的Json字符串
 */
function JsonFormat($data, $indent = null)
{
    // 缩进处理
    $ret = '';
    $pos = 0;
    $length = strlen($data);
    $indent = isset($indent) ? $indent : '    ';
    $newline = "\r\n";
    $prevchar = '';
    $outofquotes = true;
 
    for ($i = 0; $i <= $length; $i++) {
 
        $char = substr($data, $i, 1);
 
        if ($char == '"' && $prevchar != '\\') {
            $outofquotes = !$outofquotes;
        } elseif (($char == '}' || $char == ']') && $outofquotes) {
            $ret .= $newline;
            $pos--;
            for ($j = 0; $j < $pos; $j++) {
                $ret .= $indent;
            }
        }
 
        $ret .= $char;
 
        if (($char == ',' || $char == '{' || $char == '[') && $outofquotes) {
            $ret .= $newline;
            if ($char == '{' || $char == '[') {
                $pos++;
            }
 
            for ($j = 0; $j < $pos; $j++) {
                $ret .= $indent;
            }
        }
 
        $prevchar = $char;
    }
 
    return $ret;
}
 
static $CfgKeyNameContent = null;
function getCfgKeyNameContent($cfgName, $toArray, $spid = "")
{
    global $CfgKeyNameContent;
    if (!isset($CfgKeyNameContent)) {
        $CfgKeyNameContent = array();
    }
    if (!array_key_exists($cfgName, $CfgKeyNameContent)) {
        if (!$spid) {
            $spid = $_SESSION['spid'];
        }
        $lang = \Lang\getLang();
        $fdir = dirname(__FILE__) . "\config\\" . $spid . "\\" . $lang . "\\" . $cfgName . ".txt";
        if (!file_exists($fdir)) {
            $fdir = dirname(__FILE__) . "\config\\" . $spid . "\\" . $cfgName . ".txt";
        }
        $kvArray = array();
        if (file_exists($fdir)) {
            $rf = fopen($fdir, "r");
            while (!feof($rf)) {
                $line = trim(fgets($rf));
                if (!$line) {
                    continue;
                }
                $ls = explode("\t", $line);
                $kvArray[$ls[0]] = $ls[1];
            }
        } else {
            echo "file is not exist: " . $fdir, "<br/>";
        }
        $CfgKeyNameContent[$cfgName] = $kvArray;
    }
    $kvArray = $CfgKeyNameContent[$cfgName];
    if ($toArray) {
        return $kvArray;
    }
    return MyJson_encode($kvArray);
}
 
static $SPConfig = null;
/**
 * 获取sp运营项目对应专属配置
 * @param string $section 配置节点
 * @param string $option 配置项
 * @param string $value 获取对应的值对象
 * @param string $toArray 是否转为array,默认false
 * @return 是否成功获取到配置
 */
function GetSPConfig($section, $option, &$value, $toArray = false)
{
    global $SPConfig;
    if (!isset($SPConfig)) {
        $spid = $_SESSION['spid'];
        $iniPath = dirname(__FILE__) . "\config\\" . $spid . "\\config.ini";
        if (!file_exists($iniPath)) {
            return false;
        }
 
        $SPConfig = parse_ini_file($iniPath, true);
    }
 
    if (array_key_exists($section, $SPConfig) && array_key_exists($option, $SPConfig[$section])) {
        $value = $SPConfig[$section][$option];
        if ($toArray) {
            $value = json_decode($value, true);
        }
    } else {
        // 不存在该配置
    }
    return true;
}
 
function getPayOrderTypeName($payOrderType)
{
    $PayOrderTypeName = array(
        1 => \Lang\gettext("人民币"),
        2 => \Lang\gettext("美元"),
        3 => \Lang\gettext("越南盾"),
        4 => \Lang\gettext("soha币"),
        5 => \Lang\gettext("金票点券"),
        6 => \Lang\gettext("代币"),
    );
    if (!array_key_exists($payOrderType, $PayOrderTypeName)) {
        return \Lang\gettext("未知订单类型");
    }
    return $PayOrderTypeName[$payOrderType];
}
 
function getPayOrderCoinRate($payOrderType)
{
    $rateSet = array(
        3 => 1,
        6 => 1,
    );
    if (!array_key_exists($payOrderType, $rateSet)) {
        return 100;
    }
    return $rateSet[$payOrderType];
}
 
function startsWith($text, $prefix)
{
    return strpos($text, $prefix) === 0;
}
 
// 邮件类型
function GetMailTypes()
{
    return json_decode(GetFileContents(dirname(__FILE__) . "/mailtypes.json", "[]"), true);
}
 
// 组合服务器ID查询条件,搭配 common.js AddServerIDCondition 使用
function MatchServerIDCond(&$find, &$serverIDCondArray)
{
    if (!isset($serverIDCondArray)) {
        $serverIDCondArray = array();
    }
    $serverIDCondNumMax = 20;
    $serverIDCondIn = array();
    $serverIDCondFind = array();
    for ($i = 1; $i < $serverIDCondNumMax + 1; $i++) {
        if (!array_key_exists("ServerIDGTE" . $i, $_POST)) {
            continue;
        }
        $eValue = intval($_POST["ServerIDE" . $i]);
        $gteValue = intval($_POST["ServerIDGTE" . $i]);
        $lteValue = intval($_POST["ServerIDLTE" . $i]);
        // \Logging\LogInfo("serverIDCond." . $i . " : eValue:" . $eValue . " gteValue:" . $gteValue . " lteValue:" . $lteValue);
        if ($eValue <= 0 && $gteValue <= 0 && $lteValue <= 0) {
            continue;
        }
        if ($gteValue > 0 && $lteValue > 0 && $gteValue > $lteValue) {
            continue;
        }
        if ($eValue > 0) {
            array_push($serverIDCondIn, $eValue);
        }
        $cond = array();
        if ($gteValue > 0) {
            $cond['$gte'] = $gteValue;
        }
        if ($lteValue > 0) {
            $cond['$lte'] = $lteValue;
        }
        if (count($cond)) {
            array_push($serverIDCondFind, array("ServerID" => $cond));
        }
        array_push($serverIDCondArray, array($eValue, $gteValue, $lteValue));
    }
    if (count($serverIDCondIn) > 0) {
        array_push($serverIDCondFind, array("ServerID" => array('$in' => $serverIDCondIn)));
    }
    if (count($serverIDCondFind) > 0) {
        $find['$or'] = $serverIDCondFind;
    }
    // \Logging\LogInfo("find:" . json_encode($find));
}
 
// 组合服务器ID列表,搭配 common.js AddServerIDCondition 使用
function MatchServerIDList(&$serverIDCondArray, &$serverIDList)
{
    if (!isset($serverIDCondArray)) {
        $serverIDCondArray = array();
    }
    if (!isset($serverIDList)) {
        $serverIDList = array();
    }
    $serverIDCondNumMax = 20;
    for ($i = 1; $i < $serverIDCondNumMax + 1; $i++) {
        if (!array_key_exists("ServerIDGTE" . $i, $_POST)) {
            continue;
        }
        $eValue = intval($_POST["ServerIDE" . $i]);
        $gteValue = intval($_POST["ServerIDGTE" . $i]);
        $lteValue = intval($_POST["ServerIDLTE" . $i]);
        // \Logging\LogInfo("serverIDCond." . $i . " : eValue:" . $eValue . " gteValue:" . $gteValue . " lteValue:" . $lteValue);
        if ($eValue <= 0 && $gteValue <= 0 && $lteValue <= 0) {
            continue;
        }
        if ($gteValue > 0 && $lteValue > 0 && $gteValue > $lteValue) {
            continue;
        }
        if ($eValue > 0) {
            array_push($serverIDList, array($eValue, $eValue));
        }
        if ($gteValue > 0 && $lteValue > 0) {
            array_push($serverIDList, array($gteValue, $lteValue));
        } else if ($gteValue > 0) {
            array_push($serverIDList, array($gteValue, 10000));
        } else if ($lteValue > 0) {
            array_push($serverIDList, array(1, $lteValue));
        }
        array_push($serverIDCondArray, array($eValue, $gteValue, $lteValue));
    }
}