提交 21e33a8a 编写于 作者: L LENG小鑫 提交者: GitHub

Merge pull request #1 from Binaryify/master

1
# 更新日志 # 更新日志
### 2.8.3 | 2018.01.12
优化部分功能和文档
### 2.8.2 | 2018.01.05
增加 Dockerfile,支持以 Docker 容器模式运行
### 2.8.1 | 2018.01.04
添加了 proxy 功能
### 2.8.0 | 2018.01.04
用 'request' 重写了请求函数
### 2.7.9 | 2017.12.11 ### 2.7.9 | 2017.12.11
更新排行榜接口,新增云音乐ACG音乐榜,云音乐嘻哈榜 更新排行榜接口 , 新增云音乐 ACG 音乐榜 , 云音乐嘻哈榜
### 2.7.7 | 2017.11.27 ### 2.7.7 | 2017.11.27
......
FROM mhart/alpine-node:8
WORKDIR /app
COPY . /app
RUN npm install
EXPOSE 3000
CMD ["node", "app.js"]
# 网易云音乐 API # 网易云音乐 API
网易云音乐 Node.js 版 API 网易云音乐 Node.js API service
<p> <p>
<a href="https://www.npmjs.com/package/NeteaseCloudMusicApi"><img src="https://img.shields.io/npm/v/NeteaseCloudMusicApi.svg" alt="Version"></a> <a href="https://www.npmjs.com/package/NeteaseCloudMusicApi"><img src="https://img.shields.io/npm/v/NeteaseCloudMusicApi.svg" alt="Version"></a>
<a href="https://www.npmjs.com/package/NeteaseCloudMusicApi"><img src="https://img.shields.io/npm/l/NeteaseCloudMusicApi.svg" alt="License"></a> <a href="https://www.npmjs.com/package/NeteaseCloudMusicApi"><img src="https://img.shields.io/npm/l/NeteaseCloudMusicApi.svg" alt="License"></a>
<a href="https://www.npmjs.com/package/NeteaseCloudMusicApi"><img src="https://img.shields.io/david/dev/binaryify/NeteaseCloudMusicApi.svg" alt="devDependencies" ></a> <a href="https://www.npmjs.com/package/NeteaseCloudMusicApi"><img src="https://img.shields.io/david/dev/binaryify/NeteaseCloudMusicApi.svg" alt="devDependencies" ></a>
<a href="https://www.npmjs.com/package/NeteaseCloudMusicApi"><img src="https://img.shields.io/david/binaryify/NeteaseCloudMusicApi.svg" alt="devDependencies" ></a> <a href="https://www.npmjs.com/package/NeteaseCloudMusicApi"><img src="https://img.shields.io/david/binaryify/NeteaseCloudMusicApi.svg" alt="devDependencies" ></a>
<a href="https://codeclimate.com/github/Binaryify/NeteaseCloudMusicApi"><img src="https://codeclimate.com/github/Binaryify/NeteaseCloudMusicApi/badges/gpa.svg" /></a> <a href="https://codeclimate.com/github/Binaryify/NeteaseCloudMusicApi"><img src="https://codeclimate.com/github/Binaryify/NeteaseCloudMusicApi/badges/gpa.svg" /></a>
</p> </p>
## 灵感来自 ## 灵感来自
[disoul/electron-cloud-music](https://github.com/disoul/electron-cloud-music) [disoul/electron-cloud-music](https://github.com/disoul/electron-cloud-music)
...@@ -17,13 +17,22 @@ ...@@ -17,13 +17,22 @@
## 版本新特性 ## 版本新特性
### 2.8.2 | 2018.01.05
增加Dockerfile,支持以Docker容器模式运行
### 2.8.1 | 2018.01.04
添加了proxy功能
### 2.8.0 | 2018.01.04
用 'request' 重写了请求函数
### 2.6.5 | 2017.7.16 ### 2.6.5 | 2017.7.16
优化 CORS 设置 优化 CORS 设置
### 2.6.4 | 2017.7.16 ### 2.6.4 | 2017.7.16
添加缓存机制和随机 UA 机制 感谢[@u3u](https://github.com/u3u) 添加缓存机制和随机 UA 机制 感谢[@u3u](https://github.com/u3u)
[issue:77](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/77) [issue:77](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/77)
优化请求代码 感谢 [@huhuime](https://github.com/huhuime) 优化请求代码 感谢 [@huhuime](https://github.com/huhuime)
[issue:83](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/83) [issue:83](https://github.com/Binaryify/NeteaseCloudMusicApi/issues/83)
### 2.6.2 | 2017.7.16 ### 2.6.2 | 2017.7.16
...@@ -153,39 +162,45 @@ ...@@ -153,39 +162,45 @@
## 环境要求 ## 环境要求
需要 NodeJS 6.0+ 环境 需要 NodeJS 6.0+ 环境
## 安装 ## 安装
``` shell ``` shell
$ git clone git@github.com:Binaryify/NeteaseCloudMusicApi.git $ git clone git@github.com:Binaryify/NeteaseCloudMusicApi.git
$ npm install $ npm install
``` ```
## 运行 ## 运行
``` shell ``` shell
$ node app.js $ node app.js
``` ```
服务器启动默认端口为3000,若不想使用3000端口,可使用以下命令: 服务器启动默认端口为3000,若不想使用3000端口,可使用以下命令:
Mac/Linux Mac/Linux
```shell ```shell
$ PORT=4000 node app.js $ PORT=4000 node app.js
``` ```
windows 下使用 git-bash 或者 cmder 等终端执行以下命令: windows 下使用 git-bash 或者 cmder 等终端执行以下命令:
```shell ```shell
$ set PORT=4000 && node app.js $ set PORT=4000 && node app.js
``` ```
## Docker容器运行
```shell
docker pull pengxiao/netease-music-api
docker run -d -p 3000:3000 pengxiao/netease-music-api
```
## 使用文档 ## 使用文档
[文档地址](https://binaryify.github.io/NeteaseCloudMusicApi) [文档地址](https://binaryify.github.io/NeteaseCloudMusicApi)
![文档](https://raw.githubusercontent.com/Binaryify/NeteaseCloudMusicApi/master/static/docs.png) ![文档](https://raw.githubusercontent.com/Binaryify/NeteaseCloudMusicApi/master/static/docs.png)
## 更新日志 ## 更新日志
[changelog](https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/CHANGELOG.MD) [changelog](https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/CHANGELOG.MD)
## 单元测试 ## 单元测试
``` shell ``` shell
$ npm test $ npm test
``` ```
![单元测试](https://raw.githubusercontent.com/Binaryify/NeteaseCloudMusicApi/master/static/screenshot1.png) ![单元测试](https://raw.githubusercontent.com/Binaryify/NeteaseCloudMusicApi/master/static/screenshot1.png)
![单元测试](https://raw.githubusercontent.com/Binaryify/NeteaseCloudMusicApi/master/static/screenshot2.png) ![单元测试](https://raw.githubusercontent.com/Binaryify/NeteaseCloudMusicApi/master/static/screenshot2.png)
......
const express = require("express"); const express = require("express");
const http = require("http");
const apicache = require("apicache"); const apicache = require("apicache");
const path = require("path"); const path = require("path");
...@@ -7,23 +6,32 @@ const app = express(); ...@@ -7,23 +6,32 @@ const app = express();
let cache = apicache.middleware; let cache = apicache.middleware;
// 跨域设置 // 跨域设置
// app.all('*', function (req, res, next) { app.all("*", function(req, res, next) {
// if (req.path !== '/' && !req.path.includes('.')) { if (req.path !== "/" && !req.path.includes(".")) {
// res.header('Access-Control-Allow-Credentials', true) res.header("Access-Control-Allow-Credentials", true);
// // 这里获取 origin 请求头 而不是用 * // 这里获取 origin 请求头 而不是用 *
// res.header('Access-Control-Allow-Origin', req.headers['origin'] || '*') res.header("Access-Control-Allow-Origin", req.headers["origin"] || "*");
// res.header('Access-Control-Allow-Headers', 'X-Requested-With') res.header("Access-Control-Allow-Headers", "X-Requested-With");
// res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS') res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
// res.header('Content-Type', 'application/json;charset=utf-8') res.header("Content-Type", "application/json;charset=utf-8");
// } }
// next() next();
// }) });
const onlyStatus200 = (req, res) => res.statusCode === 200; const onlyStatus200 = (req, res) => res.statusCode === 200;
app.use(cache("2 minutes", onlyStatus200)); app.use(cache("2 minutes", onlyStatus200));
app.use(express.static(path.resolve(__dirname, "public"))); 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}`;
}
next();
});
// 获取专辑内容 // 获取专辑内容
app.use("/album", require("./router/album")); app.use("/album", require("./router/album"));
...@@ -248,7 +256,7 @@ app.use("/user/record", require("./router/user_playrecord")); ...@@ -248,7 +256,7 @@ app.use("/user/record", require("./router/user_playrecord"));
const port = process.env.PORT || 3000; const port = process.env.PORT || 3000;
app.listen(port, () => { app.listen(port, () => {
console.log(`server running @${port}`); console.log(`server running @ http://localhost:${port}`);
}); });
module.exports = app; module.exports = app;
此差异已折叠。
{ {
"name": "NeteaseCloudMusicApi", "name": "NeteaseCloudMusicApi",
"version": "2.7.9", "version": "2.8.3",
"description": "网易云音乐 NodeJS 版 API", "description": "网易云音乐 NodeJS 版 API",
"scripts": { "scripts": {
"start": "node app.js", "start": "node app.js",
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>test</title>
</head>
<body>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script>
$.ajax({
url: "http://localhost:3000/login/cellphone?phone=phone&password=password",
xhrFields: {
withCredentials: true
},
success: function (data) {
console.log(data)
$.ajax({
url: "http://localhost:3000/recommend/songs ",
xhrFields: {
withCredentials: true
},
success: function (data) {
console.log(data)
},
error: function (err) {
console.log(err)
}
})
},
error: function (err) {
console.log(err)
}
})
</script>
</body>
</html>
\ No newline at end of file
const express = require('express') const express = require("express");
const router = express() const router = express();
const { createWebAPIRequest } = require('../util/util') const { createWebAPIRequest } = require("../util/util");
router.get('/', (req, res) => { router.get("/", (req, res) => {
const rid = req.query.id const rid = req.query.id;
const cookie = req.get('Cookie') ? req.get('Cookie') : '' const cookie = req.get("Cookie") ? req.get("Cookie") : "";
const data = { const data = {
offset: req.query.offset || 0, offset: req.query.offset || 0,
rid: rid, rid: rid,
limit: req.query.limit || 20, limit: req.query.limit || 20,
csrf_token: '' csrf_token: ""
} };
createWebAPIRequest( createWebAPIRequest(
'music.163.com', "music.163.com",
`/weapi/v1/resource/comments/R_SO_4_${rid}/?csrf_token=`, `/weapi/v1/resource/comments/R_SO_4_${rid}/?csrf_token=`,
'POST', "POST",
data, data,
cookie, cookie,
music_req => { music_req => {
res.send(music_req) res.send(music_req);
}, },
err => res.status(502).send('fetch error') err => res.status(502).send(err.message)
) );
}) });
module.exports = router module.exports = router;
const express = require('express') const express = require("express");
const crypto = require('crypto') const crypto = require("crypto");
const router = express() const router = express();
const { createWebAPIRequest } = require('../util/util') const { createWebAPIRequest } = require("../util/util");
router.get('/', (req, res) => { router.get("/", (req, res) => {
const phone = req.query.phone const phone = req.query.phone;
const cookie = req.get('Cookie') ? req.get('Cookie') : '' const cookie = req.get("Cookie") ? req.get("Cookie") : "";
const md5sum = crypto.createHash('md5') const md5sum = crypto.createHash("md5");
md5sum.update(req.query.password) md5sum.update(req.query.password);
const data = { const data = {
phone: phone, phone: phone,
password: md5sum.digest('hex'), password: md5sum.digest("hex"),
rememberLogin: 'true' rememberLogin: "true"
} };
createWebAPIRequest( createWebAPIRequest(
'music.163.com', "music.163.com",
'/weapi/login/cellphone', "/weapi/login/cellphone",
'POST', "POST",
data, data,
cookie, cookie,
(music_req, cookie) => { (music_req, cookie) => {
// console.log(music_req) cookie =
cookie = cookie&&cookie.map(x => x.replace("Domain=.music.163.com", "")) cookie && cookie.map(x => x.replace("Domain=.music.163.com", ""));
res.set({ res.set({
'Set-Cookie': cookie "Set-Cookie": cookie
}) });
res.send(music_req) res.send(music_req);
}, },
err => res.status(502).send('fetch error') err => res.status(502).send("fetch error")
) );
}) });
module.exports = router module.exports = router;
const http = require('http') const http = require("http");
const express = require('express') const express = require("express");
const router = express() const router = express();
const { createWebAPIRequest } = require('../util/util') const { createWebAPIRequest } = require("../util/util");
router.get('/', (req, res) => { router.get("/", (req, res) => {
const cookie = req.get('Cookie') ? req.get('Cookie') : '' const cookie = req.get("Cookie") ? req.get("Cookie") : "";
let detail, imgurl
const data = { const data = {
id: req.query.id, id: req.query.id,
offset: 0, csrf_token: ""
total: true, };
limit: 1000,
n: 1000,
csrf_token: ''
}
createWebAPIRequest( createWebAPIRequest(
'music.163.com', "music.163.com",
'/weapi/v3/playlist/detail', "/weapi/v3/playlist/detail",
'POST', "POST",
data, data,
cookie, cookie,
music_req => { music_req => {
console.log(music_req) // console.log(music_req)
// detail = music_req res.send(music_req);
res.send(music_req)
// mergeRes()
}, },
err => { err => {
res.status(502).send('fetch error') res.status(502).send("fetch error");
} }
) );
// FIXME:i dont know the api to get coverimgurl // FIXME:i dont know the api to get coverimgurl
// so i get it by parsing html // so i get it by parsing html
...@@ -62,6 +55,6 @@ router.get('/', (req, res) => { ...@@ -62,6 +55,6 @@ router.get('/', (req, res) => {
// res.send(detail) // res.send(detail)
// } // }
// } // }
}) });
module.exports = router module.exports = router;
const express = require('express') const express = require("express");
const router = express() const router = express();
const { createWebAPIRequest } = require('../util/util') const { createWebAPIRequest } = require("../util/util");
router.get('/', (req, res) => { router.get("/", (req, res) => {
const cookie = req.get('Cookie') ? req.get('Cookie') : '' const cookie = req.get("Cookie") ? req.get("Cookie") : "";
const data = { const data = {
offset: 0, offset: req.query.offset || 0,
uid: req.query.uid, uid: req.query.uid,
limit: 1000, limit: req.query.limit || 30, //貌似无效
csrf_token: '' csrf_token: ""
} };
createWebAPIRequest( createWebAPIRequest(
'music.163.com', "music.163.com",
'/weapi/user/playlist', "/weapi/user/playlist",
'POST', "POST",
data, data,
cookie, cookie,
music_req => res.send(music_req), music_req => {
err => res.status(502).send('fetch error') res.send(music_req);
) // console.log(JSON.parse(music_req))
}) },
err => res.status(502).send("fetch error")
);
});
module.exports = router module.exports = router;
const assert = require('assert') const assert = require("assert");
const crypto = require('crypto') const crypto = require("crypto");
const { createWebAPIRequest } = require('../util/util') const { createWebAPIRequest } = require("../util/util");
describe('测试获取歌曲是否正常', () => { describe("测试获取歌曲是否正常", () => {
it('歌曲的 url 不应该为空', done => { it("歌曲的 url 不应该为空", done => {
const id = 347230 const id = 462791935;
const br = 999000 const br = 999000;
const data = { const data = {
ids: [id], ids: [id],
br: br, br: br,
csrf_token: '' csrf_token: ""
} };
const cookie = '' const cookie = "";
createWebAPIRequest( createWebAPIRequest(
'music.163.com', "music.163.com",
'/weapi/song/enhance/player/url', "/weapi/song/enhance/player/url",
'POST', "POST",
data, data,
cookie, cookie,
music_req => { music_req => {
console.log(JSON.parse(music_req).data[0].url) console.log(music_req);
assert(!!JSON.parse(music_req).data[0].url) console.log(JSON.parse(music_req).data[0].url);
done() assert(!!JSON.parse(music_req).data[0].url);
done();
}, },
err => { err => {
done(err) done(err);
} }
) );
}) });
}) });
const Encrypt = require('./crypto.js') const Encrypt = require("./crypto.js");
const http = require('http') const request = require("request");
const querystring = require('querystring') const querystring = require("querystring");
// request.debug = true;
function randomUserAgent() { function randomUserAgent() {
const userAgentList = [ const userAgentList = [
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36', "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1",
'Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1', "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1",
'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36', "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36",
'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36', "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36",
'Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36', "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Mobile Safari/537.36",
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) Mobile/14F89;GameHelper', "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) Mobile/14F89;GameHelper",
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4', "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4",
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1', "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1",
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36', "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36",
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:46.0) Gecko/20100101 Firefox/46.0', "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:46.0) Gecko/20100101 Firefox/46.0",
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:46.0) Gecko/20100101 Firefox/46.0', "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:46.0) Gecko/20100101 Firefox/46.0",
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)', "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)', "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)",
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)', "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)', "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)",
'Mozilla/5.0 (Windows NT 6.3; Win64, x64; Trident/7.0; rv:11.0) like Gecko', "Mozilla/5.0 (Windows NT 6.3; Win64, x64; Trident/7.0; rv:11.0) like Gecko",
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/13.10586', "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/13.10586",
'Mozilla/5.0 (iPad; CPU OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1' "Mozilla/5.0 (iPad; CPU OS 10_0 like Mac OS X) AppleWebKit/602.1.38 (KHTML, like Gecko) Version/10.0 Mobile/14A300 Safari/602.1"
] ];
const num = Math.floor(Math.random() * userAgentList.length) const num = Math.floor(Math.random() * userAgentList.length);
return userAgentList[num] return userAgentList[num];
} }
function createWebAPIRequest( function createWebAPIRequest(
host, host,
path, path,
...@@ -36,94 +39,66 @@ function createWebAPIRequest( ...@@ -36,94 +39,66 @@ function createWebAPIRequest(
callback, callback,
errorcallback errorcallback
) { ) {
let music_req = '' console.log(cookie);
const cryptoreq = Encrypt(data) const proxy = cookie.split("__proxy__")[1];
const http_client = http.request( cookie = cookie.split("__proxy__")[0];
{ const cryptoreq = Encrypt(data);
hostname: host, const options = {
method: method, url: `http://${host}${path}`,
path: path, method: method,
headers: { headers: {
Accept: '*/*', Accept: "*/*",
'Accept-Language': 'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4', "Accept-Language": "zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4",
Connection: 'keep-alive', Connection: "keep-alive",
'Content-Type': 'application/x-www-form-urlencoded', "Content-Type": "application/x-www-form-urlencoded",
Referer: 'http://music.163.com', Referer: "http://music.163.com",
Host: 'music.163.com', Host: "music.163.com",
Cookie: cookie, Cookie: cookie,
'User-Agent': randomUserAgent() "User-Agent": randomUserAgent()
}
}, },
function(res) { body: querystring.stringify({
res.on('error', function(err) {
errorcallback(err)
})
res.setEncoding('utf8')
if (res.statusCode != 200) {
createWebAPIRequest(host, path, method, data, cookie, callback)
return
} else {
res.on('data', function(chunk) {
music_req += chunk
})
res.on('end', function() {
if (music_req == '') {
createWebAPIRequest(host, path, method, data, cookie, callback)
return
}
if (res.headers['set-cookie']) {
callback(music_req, res.headers['set-cookie'])
} else {
callback(music_req)
}
})
}
}
)
http_client.write(
querystring.stringify({
params: cryptoreq.params, params: cryptoreq.params,
encSecKey: cryptoreq.encSecKey encSecKey: cryptoreq.encSecKey
}) }),
) proxy: proxy
http_client.end() };
request(options, function(error, res, body) {
if (error) {
errorcallback(error);
} else {
callback(body, res.headers["set-cookie"]);
}
});
} }
function createRequest(path, method, data, callback, errorcallback) { function createRequest(path, method, data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let ne_req = '' const options = {
const http_client = http.request( url: `http://music.163.com${path}`,
{ method: method,
hostname: 'music.163.com', headers: {
method: method, Referer: "http://music.163.com",
path: path, Cookie: "appver=1.5.2",
headers: { "Content-Type": "application/x-www-form-urlencoded",
Referer: 'http://music.163.com', "User-Agent": randomUserAgent()
Cookie: 'appver=1.5.2',
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': randomUserAgent()
}
},
res => {
res.setEncoding('utf8')
res.on('error', err => {
reject(err)
})
res.on('data', chunk => {
ne_req += chunk
})
res.on('end', () => {
resolve(ne_req)
})
} }
) };
if (method == 'POST') {
http_client.write(data) if (method.toLowerCase() === "post") {
options.body = data;
} }
http_client.end()
}) request(options, function(error, res, body) {
if (error) {
reject(error);
} else {
resolve(body);
}
});
});
} }
module.exports = { module.exports = {
createWebAPIRequest, createWebAPIRequest,
createRequest createRequest
} };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册