Skip to content

Commit

Permalink
fix: 修复网易云登录、日推
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSkidder committed Jul 15, 2024
1 parent 9260cc6 commit 149e2c4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
9 changes: 6 additions & 3 deletions shared/java/top/fpsmaster/modules/music/netease/NeteaseApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import top.fpsmaster.utils.os.HttpRequest.getWithCookie

object NeteaseApi {
private const val BASE_URL = "https://music.skidder.top/"

@JvmField
var cookies = ""

@JvmStatic
fun getVerbatimLyrics(id: String): String {
val url = BASE_URL + "lyric/new?id=" + id
Expand Down Expand Up @@ -44,9 +46,10 @@ object NeteaseApi {
@JvmStatic
val dailyList: String
get() {
val url = BASE_URL + "recommend/songs"
val url = BASE_URL + "recommend/songs" + "?timestamp=" + System.currentTimeMillis()
return getWithCookie(url, cookies)
}

@JvmStatic
val uniKey: String
get() {
Expand All @@ -62,14 +65,14 @@ object NeteaseApi {

@JvmStatic
fun checkLoginStatus(key: String): String {
val url = BASE_URL + "login/qr/check?key=" + key + "&timestamp=" + System.currentTimeMillis()
val url = BASE_URL + "login/qr/check?key=" + key + "&noCookie=true" + "&timestamp=" + System.currentTimeMillis()
return getWithCookie(url, "")
}

@JvmStatic
val anonmous: String
get() {
val url = BASE_URL + "/register/anonimous" + "&timestamp=" + System.currentTimeMillis()
val url = BASE_URL + "register/anonimous" + "&timestamp=" + System.currentTimeMillis()
return getWithCookie(url, "")
}
}
32 changes: 24 additions & 8 deletions shared/java/top/fpsmaster/ui/click/music/MusicPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ object MusicPanel {
searchThread = Thread { run() }
searchThread!!.start()
}
private var pages = arrayOf("music.name", "music.list")
private var pages = arrayOf("music.name", "music.list", "music.daily")
private var curSearch = 0
private var isWaitingLogin = false
private var key: String? = null
Expand Down Expand Up @@ -183,8 +183,12 @@ object MusicPanel {
mouseY
) && Mouse.isButtonDown(0)
) isWaitingLogin = false
val resourceLocation = ResourceLocation("music/qr")
Render2DUtils.drawImage(resourceLocation, x + width / 2 - 45, y + height / 2 - 45, 90f, 90f, -1)
try {
val resourceLocation = ResourceLocation("music/qr")
Render2DUtils.drawImage(resourceLocation, x + width / 2 - 45, y + height / 2 - 45, 90f, 90f, -1)
}catch (e: Exception){

}
var scan = ""
when (code) {
801 -> scan = "music.waitscan"
Expand Down Expand Up @@ -528,14 +532,22 @@ object MusicPanel {
FPSMaster.theme.textColorTitle
)
}

private fun extractMiddleContent(input: String, prefix: String, suffix: String): String {
val startIndex = input.indexOf(prefix)
if (startIndex != -1) {
val endIndex = input.indexOf(suffix, startIndex + prefix.length)
if (endIndex != -1) {
return input.substring(startIndex + prefix.length, endIndex)
}
}
return ""
}
private fun reloadImg() {
loginThread = Thread {
while (isWaitingLogin) {
try {
val loginStatus = MusicWrapper.getLoginStatus(key)
code = loginStatus["code"].asInt
println(code)
if (code == 802) {
val element = loginStatus["nickname"]
if (element != null) {
Expand All @@ -544,7 +556,11 @@ object MusicPanel {
}
}
if (code == 803) {
NeteaseApi.cookies = loginStatus["cookie"].asString
// parse cookie
var asString = loginStatus["cookie"].asString
val result = "MUSIC_U=" + extractMiddleContent(asString, "MUSIC_U=", ";")+ "; " + "NMTID=" + extractMiddleContent(asString, "NMTID=", ";")
NeteaseApi.cookies = result

saveTempValue("cookies", NeteaseApi.cookies)
println("cookies: " + NeteaseApi.cookies)
}
Expand All @@ -564,8 +580,8 @@ object MusicPanel {
val bytes = Base64.getDecoder().decode(base64)
// create resource location
val resourceLocation = ResourceLocation("music/qr")
val qr = File(FileUtils.cache, "/music/qr.png")
val qrf = File(FileUtils.cache, "/music")
val qr = File(FileUtils.dir, "/music/qr.png")
val qrf = File(FileUtils.dir, "/music")
qrf.mkdirs()
saveFileBytes("/music/qr.png", bytes)
val textureArt = ThreadDownloadImageData(qr, null, null, null)
Expand Down
2 changes: 1 addition & 1 deletion shared/java/top/fpsmaster/utils/os/FileUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object FileUtils {

@JvmStatic
fun saveFileBytes(s: String, bytes: ByteArray) {
val file = file(dir, s)
val file = File(dir, s)
try {
if (!file.exists()) {
file.createNewFile()
Expand Down

0 comments on commit 149e2c4

Please sign in to comment.