Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Little_xu
NeteaseCloudMusicApi
提交
d4b7b531
N
NeteaseCloudMusicApi
项目概览
Little_xu
/
NeteaseCloudMusicApi
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
NeteaseCloudMusicApi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d4b7b531
编写于
9月 25, 2018
作者:
N
Nzix
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
allocate js cookie in middleware, update res cookie distribution
上级
d9a03d36
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
40 addition
and
46 deletion
+40
-46
app.js
app.js
+10
-1
router/login.js
router/login.js
+1
-4
router/loginCellphone.js
router/loginCellphone.js
+2
-9
router/login_refresh.js
router/login_refresh.js
+1
-3
util/init.js
util/init.js
+24
-10
util/util.js
util/util.js
+2
-19
未找到文件。
app.js
浏览文件 @
d4b7b531
...
...
@@ -45,11 +45,20 @@ app.use(express.static(path.resolve(__dirname, 'public')))
app
.
use
(
function
(
req
,
res
,
next
)
{
const
proxy
=
req
.
query
.
proxy
if
(
proxy
)
{
req
.
headers
.
cookie
=
req
.
headers
.
cookie
+
`__proxy__
${
proxy
}
`
req
.
headers
.
cookie
+=
`__proxy__
${
proxy
}
`
}
next
()
})
// 补全缺失的cookie
const
{
completeCookie
}
=
require
(
'
./util/init
'
)
app
.
use
(
function
(
req
,
res
,
next
)
{
let
cookie
=
completeCookie
(
req
.
headers
.
cookie
)
req
.
headers
.
cookie
=
cookie
.
map
(
x
=>
x
[
0
]).
concat
(
req
.
headers
.
cookie
||
[]).
join
(
'
;
'
)
res
.
append
(
'
Set-Cookie
'
,
cookie
.
map
(
x
=>
(
x
.
concat
(
'
Path=/
'
).
join
(
'
;
'
))))
next
()
})
// 因为这几个文件对外所注册的路由 和 其他文件对外注册的路由规则不一样, 所以专门写个MAP对这些文件做特殊处理
const
UnusualRouteFileMap
=
{
// key 为文件名, value 为对外注册的路由
...
...
router/login.js
浏览文件 @
d4b7b531
...
...
@@ -21,10 +21,7 @@ module.exports = (req, res, createWebAPIRequest, request) => {
cookie
,
(
music_req
,
cookie
)
=>
{
// console.log(music_req)
cookie
=
cookie
&&
cookie
.
map
(
x
=>
x
.
replace
(
'
Domain=.music.163.com
'
,
''
))
res
.
set
({
'
Set-Cookie
'
:
cookie
})
res
.
append
(
"
Set-Cookie
"
,
cookie
)
res
.
send
(
music_req
)
},
err
=>
res
.
status
(
502
).
send
(
'
fetch error
'
)
...
...
router/loginCellphone.js
浏览文件 @
d4b7b531
...
...
@@ -17,15 +17,8 @@ module.exports = (req, res, createWebAPIRequest, request) => {
"
POST
"
,
data
,
cookie
,
(
music_req
,
cookie
=
[])
=>
{
const
cookieStr
=
"
appver=1.5.9;os=osx; channel=netease;osver=%E7%89%88%E6%9C%AC%2010.13.2%EF%BC%88%E7%89%88%E5%8F%B7%2017C88%EF%BC%89
"
;
cookieStr
.
split
(
"
;
"
).
forEach
(
item
=>
{
cookie
.
push
(
item
+
"
;Path=/
"
);
});
res
.
set
({
"
Set-Cookie
"
:
cookie
});
(
music_req
,
cookie
)
=>
{
res
.
append
(
"
Set-Cookie
"
,
cookie
);
res
.
send
(
music_req
);
},
err
=>
res
.
status
(
502
).
send
(
"
fetch error
"
)
...
...
router/login_refresh.js
浏览文件 @
d4b7b531
...
...
@@ -11,9 +11,7 @@ module.exports = (req, res, createWebAPIRequest, request) => {
data
,
cookie
,
(
music_req
,
cookie
)
=>
{
res
.
set
({
"
Set-Cookie
"
:
cookie
});
res
.
append
(
"
Set-Cookie
"
,
cookie
);
res
.
send
(
music_req
);
},
err
=>
res
.
status
(
502
).
send
(
"
fetch error
"
)
...
...
util/init.js
浏览文件 @
d4b7b531
function
randomString
(
pattern
,
length
){
return
Array
.
apply
(
null
,
{
length
:
length
}).
map
(()
=>
(
pattern
[
Math
.
floor
(
Math
.
random
()
*
pattern
.
length
)])).
join
(
''
)
;
return
Array
.
apply
(
null
,
{
length
:
length
}).
map
(()
=>
(
pattern
[
Math
.
floor
(
Math
.
random
()
*
pattern
.
length
)])).
join
(
''
)
}
function
generateCookie
(){
const
jsessionid
=
randomString
(
'
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKMNOPQRSTUVWXYZ
\\
/+
'
,
176
)
+
'
:
'
+
(
new
Date
).
getTime
();
const
nuid
=
randomString
(
'
0123456789abcdefghijklmnopqrstuvwxyz
'
,
32
);
return
{
'
JSESSIONID-WYYY
'
:
jsessionid
,
'
_iuqxldmzr_
'
:
32
,
'
_ntes_nnid
'
:
nuid
+
'
,
'
+
(
new
Date
).
getTime
(),
'
_ntes_nuid
'
:
nuid
function
completeCookie
(
cookie
){
let
origin
=
(
cookie
||
''
).
split
(
/;
\s
*/
).
map
(
element
=>
(
element
.
split
(
'
=
'
)[
0
])),
extra
=
[]
let
now
=
(
new
Date
).
getTime
()
if
(
!
origin
.
includes
(
'
JSESSIONID-WYYY
'
)){
let
expire
=
new
Date
(
now
+
1800000
)
//30 minutes
let
jessionid
=
randomString
(
'
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKMNOPQRSTUVWXYZ
\\
/+
'
,
176
)
+
'
:
'
+
expire
.
getTime
()
extra
.
push
([
'
JSESSIONID-WYYY=
'
+
jessionid
,
'
Expires=
'
+
expire
.
toGMTString
()])
}
if
(
!
origin
.
includes
(
'
_iuqxldmzr_
'
)){
let
expire
=
new
Date
(
now
+
157680000000
)
//5 years
extra
.
push
([
'
_iuqxldmzr_=32
'
,
'
Expires=
'
+
expire
.
toGMTString
()])
}
if
((
!
origin
.
includes
(
'
_ntes_nnid
'
))
||
(
!
origin
.
includes
(
'
_ntes_nuid
'
))){
let
expire
=
new
Date
(
now
+
3153600000000
)
//100 years
let
nnid
=
randomString
(
'
0123456789abcdefghijklmnopqrstuvwxyz
'
,
32
)
+
'
,
'
+
now
extra
.
push
([
'
_ntes_nnid=
'
+
nnid
,
'
Expires=
'
+
expire
.
toGMTString
()])
extra
.
push
([
'
_ntes_nuid=
'
+
nnid
.
slice
(
0
,
32
),
'
Expires=
'
+
expire
.
toGMTString
()])
}
return
extra
}
module
.
exports
=
generateCookie
\ No newline at end of file
module
.
exports
=
{
completeCookie
}
\ No newline at end of file
util/util.js
浏览文件 @
d4b7b531
const
Encrypt
=
require
(
"
./crypto.js
"
);
const
request
=
require
(
"
request
"
);
const
queryString
=
require
(
"
querystring
"
);
const
randomCookie
=
require
(
"
./init.js
"
);
request
.
debug
=
true
;
...
...
@@ -49,15 +48,6 @@ function createWebAPIRequest(
const
proxy
=
cookie
.
split
(
"
__proxy__
"
)[
1
];
cookie
=
cookie
.
split
(
"
__proxy__
"
)[
0
];
const
jsCookie
=
randomCookie
();
const
missingCookie
=
[];
for
(
let
key
in
jsCookie
){
if
(
cookie
.
indexOf
(
key
)
==
-
1
){
missingCookie
.
push
(
`
${
key
}
=
${
jsCookie
[
key
]}
`
);
}
}
cookie
=
cookie
.
split
(
/;
\s
*/
).
concat
(
missingCookie
).
join
(
"
;
"
);
const
encryptedData
=
Encrypt
(
data
);
const
options
=
{
url
:
`http://
${
host
}${
path
}
`
,
...
...
@@ -87,15 +77,8 @@ function createWebAPIRequest(
console
.
error
(
error
);
errorCallback
(
error
);
}
else
{
//解决 网易云 cookie 添加 .music.163.com 域设置。
//如: Domain=.music.163.com
let
cookie
=
res
.
headers
[
"
set-cookie
"
];
if
(
Array
.
isArray
(
cookie
))
{
cookie
=
cookie
.
map
(
x
=>
x
.
replace
(
/.music.163.com/g
,
""
))
.
sort
((
a
,
b
)
=>
a
.
length
-
b
.
length
);
cookie
=
cookie
.
concat
(
missingCookie
.
map
(
x
=>
x
+
'
; Expires=
'
+
(
new
Date
((
new
Date
).
getTime
()
+
157680000000
)).
toGMTString
()));
}
let
cookie
=
res
.
headers
[
"
set-cookie
"
]
||
[];
cookie
=
cookie
.
map
(
x
=>
x
.
replace
(
/
\s
*Domain=
[^
(;|$)
]
+;*/
,
""
));
callback
(
body
,
cookie
);
}
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录