From 87dbf1d35e801184db6a42aa03d40da4470ce5fa Mon Sep 17 00:00:00 2001 From: trazyn Date: Sat, 19 Jan 2019 19:21:51 +0800 Subject: [PATCH 1/2] Add pac proxy support --- package.json | 1 + util/request.js | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 7af7f12..9227230 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "dependencies": { "apicache": "^1.2.1", "express": "^4.16.3", + "pac-proxy-agent": "^3.0.0", "request": "^2.85.0" }, "devDependencies": { diff --git a/util/request.js b/util/request.js index 361031d..ff8ff91 100644 --- a/util/request.js +++ b/util/request.js @@ -1,6 +1,7 @@ const encrypt = require('./crypto') const request = require('request') const queryString = require('querystring') +const PacProxyAgent = require('pac-proxy-agent') // request.debug = true // 开启可看到更详细信息 @@ -67,14 +68,21 @@ const createRequest = (method, url, data, options) => { } const answer = { status: 500, body: {}, cookie: [] } + const settings = { + method: method, + url: url, + headers: headers, + body: queryString.stringify(data) + } + + if (/\.pac$/i.test(options.proxy)) { + settings.agent = new PacProxyAgent(options.proxy) + } else { + settings.proxy = options.proxy + } + request( - { - method: method, - url: url, - headers: headers, - body: queryString.stringify(data), - proxy: options.proxy - }, + settings, (err, res, body) => { if (err) { answer.status = 502 From 903c2de7cafdbcc565657b805cdc313583bbb2c5 Mon Sep 17 00:00:00 2001 From: trazyn Date: Thu, 24 Jan 2019 21:07:46 +0800 Subject: [PATCH 2/2] Log in foreign phone --- docs/README.md | 2 ++ module/login_cellphone.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 92320b3..27f076e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -227,6 +227,8 @@ $ sudo docker run -d -p 3000:3000 netease-music-api **接口地址 :** `/login/cellphone` +**可选参数 :** `countrycode`: 国家码,用于国外手机号登陆,例如美国传入:`1` + **调用例子 :** `/login/cellphone?phone=xxx&password=yyy` #### 2. 邮箱登录 diff --git a/module/login_cellphone.js b/module/login_cellphone.js index a3f4525..9e5c9c4 100644 --- a/module/login_cellphone.js +++ b/module/login_cellphone.js @@ -5,6 +5,7 @@ const crypto = require('crypto') module.exports = (query, request) => { const data = { phone: query.phone, + countrycode: query.countrycode, password: crypto.createHash('md5').update(query.password).digest('hex'), rememberLogin: 'true' } @@ -12,4 +13,4 @@ module.exports = (query, request) => { 'POST', `https://music.163.com/weapi/login/cellphone`, data, {crypto: 'weapi', ua: 'pc', cookie: query.cookie, proxy: query.proxy} ) -} \ No newline at end of file +}