mirror of
https://gitlab.com/Binaryify/neteasecloudmusicapi.git
synced 2025-05-23 22:37:41 +08:00
feat: 游客登录机制完善
This commit is contained in:
parent
eb92cef0b2
commit
780f30f0b1
@ -1,6 +1,10 @@
|
||||
# 更新日志
|
||||
### 4.17.0 | 2024.04.29
|
||||
# song/url 参数问题修复
|
||||
### 4.18.0 | 2024.04.30
|
||||
- 补充游客 deviceid,防止都指向相同账户,避免网络拥堵提示问题
|
||||
- ip 设置问题修复
|
||||
|
||||
### 4.17.1 | 2024.04.29
|
||||
- song/url 参数问题修复
|
||||
|
||||
### 4.17.0 | 2024.04.29
|
||||
- ua 更新
|
||||
|
24641
data/deviceid.txt
Normal file
24641
data/deviceid.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,10 +1,11 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { register_anonimous } = require('./main')
|
||||
const { cookieToJson } = require('./util/index')
|
||||
|
||||
const { cookieToJson, generateRandomChineseIP } = require('./util/index')
|
||||
const tmpPath = require('os').tmpdir()
|
||||
|
||||
async function generateConfig() {
|
||||
global.cnIp = generateRandomChineseIP()
|
||||
try {
|
||||
const res = await register_anonimous()
|
||||
const cookie = res.body.cookie
|
||||
|
@ -1,7 +1,17 @@
|
||||
const CryptoJS = require('crypto-js')
|
||||
const path = require('path')
|
||||
const fs = require('fs')
|
||||
const ID_XOR_KEY_1 = '3go8&$8*3*3h0k(2)2'
|
||||
const deviceidText = fs.readFileSync(
|
||||
path.resolve(__dirname, '../data/deviceid.txt'),
|
||||
'utf-8',
|
||||
)
|
||||
|
||||
const ID_XOR_KEY_1 = '3go8&$833h0k(2)2'
|
||||
const deviceidList = deviceidText.split('\n')
|
||||
|
||||
function getRandomFromList(list) {
|
||||
return list[Math.floor(Math.random() * list.length)]
|
||||
}
|
||||
function cloudmusic_dll_encode_id(some_id) {
|
||||
let xoredString = ''
|
||||
for (let i = 0; i < some_id.length; i++) {
|
||||
@ -16,7 +26,8 @@ function cloudmusic_dll_encode_id(some_id) {
|
||||
|
||||
module.exports = async (query, request) => {
|
||||
query.cookie.os = 'iOS'
|
||||
const deviceId = `NMUSIC`
|
||||
const deviceId = getRandomFromList(deviceidList)
|
||||
global.deviceId = deviceId
|
||||
const encodedId = CryptoJS.enc.Base64.stringify(
|
||||
CryptoJS.enc.Utf8.parse(
|
||||
`${deviceId} ${cloudmusic_dll_encode_id(deviceId)}`,
|
||||
|
@ -1,5 +1,4 @@
|
||||
// 相似歌手
|
||||
const config = require('../util/config.json')
|
||||
module.exports = (query, request) => {
|
||||
const data = {
|
||||
artistid: query.id,
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "NeteaseCloudMusicApi",
|
||||
"version": "4.17.1",
|
||||
"version": "4.18.0",
|
||||
"description": "网易云音乐 NodeJS 版 API",
|
||||
"scripts": {
|
||||
"start": "node app.js",
|
||||
|
@ -227,6 +227,9 @@ async function consturctServer(moduleDefs) {
|
||||
if (ip.substr(0, 7) == '::ffff:') {
|
||||
ip = ip.substr(7)
|
||||
}
|
||||
if (ip == '::1') {
|
||||
ip = global.cnIp
|
||||
}
|
||||
// console.log(ip)
|
||||
obj[3] = {
|
||||
...obj[3],
|
||||
|
@ -8,6 +8,8 @@ if (!fs.existsSync(path.resolve(tmpPath, 'anonymous_token'))) {
|
||||
}
|
||||
const serverMod = require('./server')
|
||||
before(async () => {
|
||||
const generateConfig = require('./generateConfig')
|
||||
await generateConfig()
|
||||
app = await serverMod.serveNcmApi({})
|
||||
|
||||
if (app.server && app.server.address) {
|
||||
|
@ -1,12 +1,11 @@
|
||||
const assert = require('assert')
|
||||
const { default: axios } = require('axios')
|
||||
const host = global.host || 'http://localhost:3000'
|
||||
const config = require('../util/config.json')
|
||||
describe('测试获取歌手专辑列表是否正常', () => {
|
||||
it('数据的 code 应该为200', (done) => {
|
||||
const qs = {
|
||||
id: 32311,
|
||||
realIP: '116.25.146.177',
|
||||
realIP: global.cnIp,
|
||||
}
|
||||
|
||||
axios
|
||||
|
@ -1,12 +1,11 @@
|
||||
const assert = require('assert')
|
||||
const { default: axios } = require('axios')
|
||||
const host = global.host || 'http://localhost:3000'
|
||||
const config = require('../util/config.json')
|
||||
describe('测试获取评论是否正常', () => {
|
||||
it('数据的 code 应该为200', (done) => {
|
||||
const qs = {
|
||||
id: 32311,
|
||||
realIP: '116.25.146.177',
|
||||
realIP: global.cnIp,
|
||||
}
|
||||
|
||||
axios
|
||||
|
@ -1,12 +1,11 @@
|
||||
const assert = require('assert')
|
||||
const { default: axios } = require('axios')
|
||||
const host = global.host || 'http://localhost:3000'
|
||||
const config = require('../util/config.json')
|
||||
describe('测试获取歌词是否正常', () => {
|
||||
it('数据应该有 lrc 字段', (done) => {
|
||||
const qs = {
|
||||
id: 347230,
|
||||
realIP: '116.25.146.177',
|
||||
realIP: global.cnIp,
|
||||
}
|
||||
|
||||
axios
|
||||
|
@ -1,13 +1,12 @@
|
||||
const assert = require('assert')
|
||||
const { default: axios } = require('axios')
|
||||
const host = global.host || 'http://localhost:3000'
|
||||
const config = require('../util/config.json')
|
||||
describe('测试获取歌曲是否正常', () => {
|
||||
it('歌曲的 url 不应该为空', (done) => {
|
||||
const qs = {
|
||||
id: 464315036,
|
||||
br: 999000,
|
||||
realIP: '116.25.146.177',
|
||||
realIP: global.cnIp,
|
||||
}
|
||||
|
||||
axios
|
||||
|
@ -1,13 +1,12 @@
|
||||
const assert = require('assert')
|
||||
const { default: axios } = require('axios')
|
||||
const host = global.host || 'http://localhost:3000'
|
||||
const config = require('../util/config.json')
|
||||
describe('测试搜索是否正常', () => {
|
||||
it('获取到的数据的 name 应该和搜索关键词一致', (done) => {
|
||||
const qs = {
|
||||
keywords: '海阔天空',
|
||||
type: 1,
|
||||
realIP: '116.25.146.177',
|
||||
realIP: global.cnIp,
|
||||
}
|
||||
axios
|
||||
.get(`${host}/search`, {
|
||||
|
@ -29,4 +29,21 @@ module.exports = {
|
||||
)
|
||||
return random
|
||||
},
|
||||
generateRandomChineseIP() {
|
||||
const chinaIPPrefixes = ['116.25', '116.76', '116.77', '116.78']
|
||||
|
||||
const randomPrefix =
|
||||
chinaIPPrefixes[Math.floor(Math.random() * chinaIPPrefixes.length)]
|
||||
return `${randomPrefix}.${generateIPSegment()}.${generateIPSegment()}}`
|
||||
},
|
||||
}
|
||||
|
||||
// 生成一个随机整数
|
||||
function getRandomInt(min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min
|
||||
}
|
||||
|
||||
// 生成一个随机IP地址段
|
||||
function generateIPSegment() {
|
||||
return getRandomInt(1, 255)
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ const createRequest = (method, url, data = {}, options) => {
|
||||
const csrfToken = cookie['__csrf'] || ''
|
||||
const header = {
|
||||
osver: cookie.osver || '17.4.1', //系统版本
|
||||
deviceId: cookie.deviceId || '', //encrypt.base64.encode(imei + '\t02:00:00:00:00:00\t5106025eb79a5247\t70ffbaac7')
|
||||
deviceId: cookie.deviceId || global.deviceId,
|
||||
appver: cookie.appver || iosAppVersion, // app版本
|
||||
versioncode: cookie.versioncode || '140', //版本号
|
||||
mobilename: cookie.mobilename || '', //设备model
|
||||
@ -113,7 +113,7 @@ const createRequest = (method, url, data = {}, options) => {
|
||||
resolution: cookie.resolution || '1920x1080', //设备分辨率
|
||||
__csrf: csrfToken,
|
||||
os: cookie.os || 'ios',
|
||||
channel: cookie.channel,
|
||||
channel: cookie.channel || '',
|
||||
requestId: `${Date.now()}_${Math.floor(Math.random() * 1000)
|
||||
.toString()
|
||||
.padStart(4, '0')}`,
|
||||
|
Loading…
x
Reference in New Issue
Block a user