-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* @file http request getCookieToken.js | ||
* @description 获取cookieToken | ||
* @author BTMuli<bt-muli@outlook.com> | ||
* @since 1.1.0 | ||
*/ | ||
|
||
// Node | ||
import axios from "axios"; | ||
// TGAssistant | ||
import getHeader from "../tools/getHeader.js"; | ||
|
||
|
||
/** | ||
* @description 根据 stoken 获取 cookieToken | ||
* @param {string} cookie cookie | ||
* @param {string} SToken sToken | ||
* @returns {Promise<string>} cookieToken | ||
*/ | ||
export async function getCookieTokenBySToken(cookie, SToken) { | ||
const urlPre = "https://passport-api.mihoyo.com/account/auth/api/getCookieAccountInfoBySToken"; | ||
const urlCur = `stoken=${SToken}`; | ||
const url = `${urlPre}?${urlCur}`; | ||
const header = getHeader(cookie, "GET", urlCur); | ||
return await axios.get(url, { headers: header }).then(res => { | ||
return res.data["data"]["cookie_token"]; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @file test http getCookieToken.test.js | ||
* @description 测试 CookieToken 的获取 | ||
* @author BTMuli<bt-muli@outlook.com> | ||
* @since 1.1.0 | ||
*/ | ||
|
||
// Node | ||
import { describe, it } from "mocha"; | ||
import assert from "node:assert"; | ||
// TGAssistant | ||
import { getCookieTokenBySToken } from "../../http/request/getCookieToken.js"; | ||
import LocalSqlite from "../../http/tools/operSQLite.js"; | ||
|
||
describe("测试 cookieToken 获取", ()=>{ | ||
it("通过 stoken", async ()=>{ | ||
const stoken = await LocalSqlite.getCookieItem("stoken"); | ||
const cookie = JSON.stringify(await LocalSqlite.getCookie()); | ||
const res = await getCookieTokenBySToken(cookie, stoken); | ||
const cookieToken = await LocalSqlite.getCookieItem("cookie_token"); | ||
assert.strictEqual(res, cookieToken); | ||
}); | ||
}); |