forked from MaksimSuvorovBringo/wechatTestSMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyFunc.php
73 lines (61 loc) · 1.48 KB
/
myFunc.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
<?php
require_once dirname(__FILE__) . '/vendor/autoload.php';
function imeiRandom()
{
$code = intRandom(14);
$position = 0;
$total = 0;
while ($position < 14) {
if ($position % 2 == 0) {
$prod = 1;
} else {
$prod = 2;
}
$actualNum = $prod * $code[$position];
if ($actualNum > 9) {
$strNum = strval($actualNum);
$total += $strNum[0] + $strNum[1];
} else {
$total += $actualNum;
}
$position++;
}
$last = 10 - ($total % 10);
if ($last == 10) {
$imei = $code . 0;
} else {
$imei = $code . $last;
}
return $imei;
}
/**
* @param int $size
* @return $int
*/
function intRandom($size)
{
$validCharacters = utf8_decode("0123456789");
$validCharNumber = strlen($validCharacters);
$int = '';
while (strlen($int) < $size) {
$index = mt_rand(0, $validCharNumber - 1);
$int .= $validCharacters[$index];
}
return $int;
}
function md5ToUUID($md5)
{
$result = preg_replace('#(.{8})(.{4})(.{4})(.{4})(.{12})#', '\\1-\\2-\\3-\\4-\\5', $md5);
$result = strtoupper($result);
return $result;
}
function md5ToMac($md5)
{
$result = preg_replace('#(.{2})(.{2})(.{2})(.{2})(.{2})(.{2})#', '\\1:\\2:\\3:\\4:\\5:\\6', substr($md5, 0, 12));
return $result;
}
function deleteHeaderFromResponse($response)
{
$response = substr($response, ord($response[1]) >> 2 );
return $response;
}