diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 6ac9510..ccf612a 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -1,6 +1,7 @@ # 更新日志 -### 4.16.5 | 2024.04.25 +### 4.16.6 | 2024.04.25 - ua 问题修复 +- 使用 crypto-js 重构 crypto 部分 ### 4.16.4 | 2024.04.23 @@ -18,7 +19,7 @@ ### 4.16.0 | 2024.04.18 - ua 更新,修复接口提示网络拥挤问题 -- 支持手动传入 ua 参数,修改 user-agent +- 支持手动传入 ua 参数,修改 user-agents ### 4.15.8 | 2024.03.29 diff --git a/module/login.js b/module/login.js index 35a14a8..44ee1de 100644 --- a/module/login.js +++ b/module/login.js @@ -1,15 +1,13 @@ // 邮箱登录 -const crypto = require('crypto') +const CryptoJS = require('crypto-js') module.exports = async (query, request) => { query.cookie.os = 'ios' query.cookie.appver = '9.0.65' const data = { username: query.email, - password: - query.md5_password || - crypto.createHash('md5').update(query.password).digest('hex'), + password: query.md5_password || CryptoJS.MD5(query.password).toString(), rememberLogin: 'true', } let result = await request('POST', `https://music.163.com/api/login`, data, { diff --git a/module/login_cellphone.js b/module/login_cellphone.js index 68a28df..baec21d 100644 --- a/module/login_cellphone.js +++ b/module/login_cellphone.js @@ -1,6 +1,6 @@ // 手机登录 -const crypto = require('crypto') +const CryptoJS = require('crypto-js') module.exports = async (query, request) => { query.cookie.os = 'ios' @@ -11,8 +11,7 @@ module.exports = async (query, request) => { captcha: query.captcha, [query.captcha ? 'captcha' : 'password']: query.captcha ? query.captcha - : query.md5_password || - crypto.createHash('md5').update(query.password).digest('hex'), + : query.md5_password || CryptoJS.MD5(query.password).toString(), rememberLogin: 'true', } let result = await request( diff --git a/module/register_cellphone.js b/module/register_cellphone.js index 7d99f38..f8222e1 100644 --- a/module/register_cellphone.js +++ b/module/register_cellphone.js @@ -1,12 +1,12 @@ // 注册账号 -const crypto = require('crypto') +const CryptoJS = require('crypto-js') module.exports = (query, request) => { query.cookie.os = 'pc' const data = { captcha: query.captcha, phone: query.phone, - password: crypto.createHash('md5').update(query.password).digest('hex'), + password: CryptoJS.MD5(query.password).toString(), nickname: query.nickname, countrycode: query.countrycode || '86', } diff --git a/module/user_bindingcellphone.js b/module/user_bindingcellphone.js index 67ea793..9451043 100644 --- a/module/user_bindingcellphone.js +++ b/module/user_bindingcellphone.js @@ -1,11 +1,10 @@ +const CryptoJS = require('crypto-js') module.exports = (query, request) => { const data = { phone: query.phone, countrycode: query.countrycode || '86', captcha: query.captcha, - password: query.password - ? crypto.createHash('md5').update(query.password).digest('hex') - : '', + password: query.password ? CryptoJS.MD5(query.password).toString() : '', } return request( 'POST', diff --git a/package.json b/package.json index 703a17a..663fe41 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "NeteaseCloudMusicApi", - "version": "4.16.5", + "version": "4.16.6", "description": "网易云音乐 NodeJS 版 API", "scripts": { "start": "node app.js", diff --git a/util/request.js b/util/request.js index 9165b67..ac429eb 100644 --- a/util/request.js +++ b/util/request.js @@ -1,5 +1,5 @@ const encrypt = require('./crypto') -const crypto = require('crypto') +const CryptoJS = require('crypto-js') const { default: axios } = require('axios') const { PacProxyAgent } = require('pac-proxy-agent') const http = require('http') @@ -51,11 +51,11 @@ const createRequest = (method, url, data = {}, options) => { options.cookie = { ...options.cookie, __remember_me: true, - // NMTID: crypto.randomBytes(16).toString('hex'), - _ntes_nuid: crypto.randomBytes(16).toString('hex'), + // NMTID: CryptoJS.lib.WordArray.random(16).toString(), + _ntes_nuid: CryptoJS.lib.WordArray.random(16).toString(), } if (url.indexOf('login') === -1) { - options.cookie['NMTID'] = crypto.randomBytes(16).toString('hex') + options.cookie['NMTID'] = CryptoJS.lib.WordArray.random(16).toString() } if (!options.cookie.MUSIC_U) { // 游客