mirror of
https://github.com/daydreamer-json/ak-endfield-api-archive.git
synced 2026-03-23 15:52:28 +01:00
feat: add support for china bilibili channel resources
This commit is contained in:
41
src/utils/api/akEndfield/gameHub.ts
Normal file
41
src/utils/api/akEndfield/gameHub.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import ky from 'ky';
|
||||
import * as TypesApiAkEndfield from '../../../types/api/akEndfield/Api.js';
|
||||
import config from '../../config.js';
|
||||
import defaultSettings from './defaultSettings.js';
|
||||
|
||||
const overrideDefSetKy = {
|
||||
...defaultSettings.ky,
|
||||
headers: {
|
||||
'User-Agent': config.network.userAgent.qtHgSdk,
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
giftcode: {
|
||||
redeem: async (
|
||||
channelId: number,
|
||||
serverId: number,
|
||||
platform: 'Windows' | 'iOS' | 'Android',
|
||||
code: string,
|
||||
token: string,
|
||||
confirm: boolean = false,
|
||||
) => {
|
||||
const rsp = await ky
|
||||
.post(`https://${config.network.api.akEndfield.base.gameHub}/giftcode/api/redeem`, {
|
||||
...overrideDefSetKy,
|
||||
headers: {
|
||||
...overrideDefSetKy.headers,
|
||||
Origin: 'https://' + config.network.api.akEndfield.base.webview,
|
||||
Referer:
|
||||
'https://' +
|
||||
config.network.api.akEndfield.base.webview +
|
||||
`/page/giftcode?u8_token=${encodeURIComponent(token)}&platform=${platform}&channel=${channelId}&subChannel=${channelId}&lang=en-us&server=${serverId}`,
|
||||
'Accept-Language': 'en-us',
|
||||
},
|
||||
json: { channelId: String(channelId), serverId: String(serverId), platform, code, token, confirm },
|
||||
})
|
||||
.json();
|
||||
return rsp as TypesApiAkEndfield.GameHubGiftCodeRedeem;
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -1,15 +1,19 @@
|
||||
import accountService from './accountService.js';
|
||||
import binding from './binding.js';
|
||||
import gameHub from './gameHub.js';
|
||||
import launcher from './launcher.js';
|
||||
import launcherWeb from './launcherWeb.js';
|
||||
import u8 from './u8.js';
|
||||
import webview from './webview.js';
|
||||
import zonai from './zonai.js';
|
||||
|
||||
export default {
|
||||
accountService,
|
||||
binding,
|
||||
gameHub,
|
||||
launcher,
|
||||
launcherWeb,
|
||||
u8,
|
||||
webview,
|
||||
zonai,
|
||||
};
|
||||
|
||||
159
src/utils/api/akEndfield/zonai.ts
Normal file
159
src/utils/api/akEndfield/zonai.ts
Normal file
@@ -0,0 +1,159 @@
|
||||
// https://zonai.skport.com/web/v1/user/auth/generate_cred_by_code
|
||||
|
||||
import crypto from 'node:crypto';
|
||||
import ky from 'ky';
|
||||
import { DateTime } from 'luxon';
|
||||
import * as TypesApiAkEndfield from '../../../types/api/akEndfield/Api.js';
|
||||
import config from '../../config.js';
|
||||
import defaultSettings from './defaultSettings.js';
|
||||
|
||||
const overrideDefSetKy = {
|
||||
...defaultSettings.ky,
|
||||
headers: {
|
||||
'User-Agent': config.network.userAgent.chromeWindows,
|
||||
vname: '1.0.0',
|
||||
platform: '3',
|
||||
},
|
||||
};
|
||||
|
||||
function calcSignHeader(path: string, cred: string, salt: string) {
|
||||
const timestamp = DateTime.now().toUnixInteger().toString();
|
||||
const useV2Path: string[] = [
|
||||
'/web/v1/wiki/me',
|
||||
'/web/v2/user',
|
||||
'/api/v1/game/player/binding',
|
||||
'/web/v1/game/endfield/attendance',
|
||||
'/web/v1/game/endfield/attendance/record',
|
||||
];
|
||||
if (useV2Path.includes(path)) {
|
||||
const v2Payload = JSON.stringify({
|
||||
platform: String(overrideDefSetKy.headers.platform),
|
||||
timestamp,
|
||||
dId: '',
|
||||
vName: overrideDefSetKy.headers.vname,
|
||||
});
|
||||
return {
|
||||
sign: crypto
|
||||
.createHash('md5')
|
||||
.update(
|
||||
crypto
|
||||
.createHmac('sha256', salt)
|
||||
.update(path + timestamp + v2Payload)
|
||||
.digest('hex'),
|
||||
)
|
||||
.digest('hex'),
|
||||
timestamp,
|
||||
};
|
||||
} else {
|
||||
return { sign: crypto.hash('md5', `timestamp=${timestamp}&cred=${cred}`, 'hex'), timestamp };
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
web: {
|
||||
v1: {
|
||||
game: {
|
||||
endfield: {
|
||||
attendance: {
|
||||
get: async (cred: string, token: string, skGameRole: string) => {
|
||||
const path = '/web/v1/game/endfield/attendance';
|
||||
const rsp = await ky
|
||||
.get(`https://${config.network.api.akEndfield.base.zonai}` + path, {
|
||||
...overrideDefSetKy,
|
||||
headers: {
|
||||
...overrideDefSetKy.headers,
|
||||
cred,
|
||||
...calcSignHeader(path, cred, token),
|
||||
'sk-game-role': skGameRole,
|
||||
},
|
||||
})
|
||||
.json();
|
||||
return rsp as TypesApiAkEndfield.ZonaiWebV1GameEndfieldAttendance;
|
||||
},
|
||||
record: async (cred: string, token: string, skGameRole: string) => {
|
||||
const path = '/web/v1/game/endfield/attendance/record';
|
||||
const rsp = await ky
|
||||
.get(`https://${config.network.api.akEndfield.base.zonai}` + path, {
|
||||
...overrideDefSetKy,
|
||||
headers: {
|
||||
...overrideDefSetKy.headers,
|
||||
cred,
|
||||
...calcSignHeader(path, cred, token),
|
||||
'sk-game-role': skGameRole, // 3_4000000000_2
|
||||
},
|
||||
})
|
||||
.json();
|
||||
return rsp as TypesApiAkEndfield.ZonaiWebV1GameEndfieldAttendanceRecord;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
user: {
|
||||
auth: {
|
||||
generateCredByCode: async (code: string, kind: 1) => {
|
||||
const rsp = await ky
|
||||
.post(`https://${config.network.api.akEndfield.base.zonai}/web/v1/user/auth/generate_cred_by_code`, {
|
||||
...overrideDefSetKy,
|
||||
headers: { ...overrideDefSetKy.headers },
|
||||
json: { kind, code },
|
||||
})
|
||||
.json();
|
||||
return rsp as TypesApiAkEndfield.ZonaiWebV1UserAuthGenCredByCode;
|
||||
},
|
||||
},
|
||||
check: async (cred: string, token: string) => {
|
||||
const path = '/web/v1/user/check';
|
||||
const rsp = await ky
|
||||
.get(`https://${config.network.api.akEndfield.base.zonai}` + path, {
|
||||
...overrideDefSetKy,
|
||||
headers: { ...overrideDefSetKy.headers, cred, ...calcSignHeader(path, cred, token) },
|
||||
})
|
||||
.json();
|
||||
return rsp as TypesApiAkEndfield.ZonaiWebV1UserCheck;
|
||||
},
|
||||
},
|
||||
wiki: {
|
||||
me: async (cred: string, token: string) => {
|
||||
const path = '/web/v1/wiki/me';
|
||||
const rsp = await ky
|
||||
.get(`https://${config.network.api.akEndfield.base.zonai}` + path, {
|
||||
...overrideDefSetKy,
|
||||
headers: { ...overrideDefSetKy.headers, cred, ...calcSignHeader(path, cred, token) },
|
||||
})
|
||||
.json();
|
||||
return rsp as TypesApiAkEndfield.ZonaiWebV1WikiMe;
|
||||
},
|
||||
},
|
||||
},
|
||||
v2: {
|
||||
user: async (cred: string, token: string) => {
|
||||
const path = '/web/v2/user';
|
||||
const rsp = await ky
|
||||
.get(`https://${config.network.api.akEndfield.base.zonai}` + path, {
|
||||
...overrideDefSetKy,
|
||||
headers: { ...overrideDefSetKy.headers, cred, ...calcSignHeader(path, cred, token) },
|
||||
})
|
||||
.json();
|
||||
return rsp as TypesApiAkEndfield.ZonaiWebV2User;
|
||||
},
|
||||
},
|
||||
},
|
||||
api: {
|
||||
v1: {
|
||||
game: {
|
||||
player: {
|
||||
binding: async (cred: string, token: string) => {
|
||||
const path = '/api/v1/game/player/binding';
|
||||
const rsp = await ky
|
||||
.get(`https://${config.network.api.akEndfield.base.zonai}` + path, {
|
||||
...overrideDefSetKy,
|
||||
headers: { ...overrideDefSetKy.headers, cred, ...calcSignHeader(path, cred, token) },
|
||||
})
|
||||
.json();
|
||||
return rsp as TypesApiAkEndfield.ZonaiApiV1GamePlayerBinding;
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user