-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmusic163.php
71 lines (55 loc) · 2.22 KB
/
music163.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
<?
/*
http://music.163.com/#/song?id=423406359
makes post-call to get the mp3-stream,
with params & enseckey
params is a json like {"ids":"['.$id.']","br":'.$br.',"csrf_token":"'.$csrf_token.'"}
params is twice aes-128-cbc padding encrypted:
1- with key 0CoJUm6Qyw8W8jud
2- with a random 16 bytes key, $key
Then, enseckey is rsa encryption of $key with:
- modulus 00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7
- exponent 010001
*/
function getenseckey($key)
{
$e = "0x10001";
$m = "0xe0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7";
$key=implode(array_Reverse(str_split($key)));
return gmp_strval(gmp_powm('0x'.bin2hex($key), $e, $m),16);
}
function pkcs5_pad ($text, $blocksize)
{
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
function encrypt($input,$key)
{
$size = mcrypt_get_block_size('rijndael-128', 'cbc');
$input = pkcs5_pad($input, $size);
$td = mcrypt_module_open('rijndael-128', '', 'cbc', '');
$iv = "0102030405060708";
mcrypt_generic_init($td, $key, $iv);
$data = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $data;
}
function getparams($json,$key)
{
$p=base64_encode(encrypt($json,"0CoJUm6Qyw8W8jud"));
return urlencode(base64_encode(encrypt($p,$key)));
}
$b = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$key = "";
for ($d = 0; 16 > $d; $d++)
{
$e = intval(rand(0,strlen($b)-1));
$key.= $b[$e];
}
$json='{"ids":"['.$id.']","br":'.$br.',"csrf_token":"'.$csrf_token.'"}';
$params=getparams($json,$key);
$enseckey=getenseckey($key);
$post='params='.$params.'&encSecKey='.$enseckey;
$callurl="http://music.163.com/weapi/song/enhance/player/url?csrf_token=$csrf_token";
?>