-
Notifications
You must be signed in to change notification settings - Fork 2
/
helper.php
80 lines (73 loc) · 2.54 KB
/
helper.php
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
<?php
/**
* Created by PhpStorm.
* User: baoxulong
* Date: 2018/6/5
* Time: 下午3:58
*/
if (!function_exists('app')) {
/**
* @param $service
* @param string $key
* @return mixed
*/
function app($service, $key = '')
{
$container = new \App\Utils\ServiceContainer();
return $container->$service->getInstance($key);
}
}
if (!function_exists('decrypt_6d')) {
function decrypt_6d($data)
{
if ($data != '') {
$encryptedData = fromHexString($data);
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, "5k3f4good\0\0\0\0\0\0\0", $encryptedData, MCRYPT_MODE_CBC, '0102030405060708');
//未加密的数据直接返回
if (preg_match('/([\d-]{5,})|(?!(\.|-|_))(?![a-zA-Z0-9\.\-_]*(\.|-|_)@)[a-zA-Z0-9\.\-_]+@(?!.{64,}\.)(?![\-_])(?![a-zA-Z0-9\-_]*[\-_]\.)[a-zA-Z0-9\-_]+(\.\w+)+\-*\d*$/', trim($decrypted))) {
return trim($decrypted);
} else {
file_put_contents('/tmp/bxl_debug_' . date('Ymd') . '.log', '[line: ' . __LINE__ . ']' . '[data]' . var_export($decrypted, true) . PHP_EOL, FILE_APPEND);
file_put_contents('/tmp/bxl_debug_' . date('Ymd') . '.log', '[line: ' . __LINE__ . ']' . '[data]' . var_export($data, true) . PHP_EOL, FILE_APPEND);
return trim($data);
}
}
return $data;
}
}
if (!function_exists('fromHexString')) {
/*
* @function fromHexString 把十六进制数转换成字符串
*/
function fromHexString($sa)
{
$buf = "";
for ($i = 0; $i < strlen($sa); $i += 2) {
$val = chr(hexdec(substr($sa, $i, 2)));
$buf .= $val;
}
return $buf;
}
}
if (!function_exists('curl_post')) {
function curl_post($url, $data, $header = "")
{
if (is_array($data)) {
$data = http_build_query($data, '&');
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);//https
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
if ($header != "")
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode != 201 && $httpCode != 200) return $httpCode;
return ($result);
}
}