Compare commits

...
9 Commits
Author SHA1 Message Date
Fd 10f171ffb3 Merge branch 'master' of github.com:fdvky1/endfield-auto-daily 2026-02-07 18:17:35 +07:00
Seya af3ce2901c bump version 2026-02-04 07:42:36 +07:00
Seya 31ea5fbce1 update docs for new login flow 2026-02-04 07:39:55 +07:00
Seya 5690e7c476 update login flow, again, to refresh tokens 2026-02-04 07:23:13 +07:00
SeyaandGitHub 631238fbcc minor README formatting 2026-02-03 22:03:37 +07:00
Seya 742612e335 fix new environments not defined 2026-02-03 22:02:03 +07:00
Seya 79ba5040cf bump version 2026-02-03 22:00:07 +07:00
SeyaandGitHub 56b3c69a8b update README with new environment variables 2026-02-03 21:59:44 +07:00
Seya 81615744fb fixed login by adding request sign header 2026-02-03 21:43:24 +07:00
4 changed files with 167 additions and 158 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ jobs:
- name: Check In - name: Check In
run: node index.js run: node index.js
env: env:
CRED: ${{ secrets.CRED }} ACCOUNT_TOKEN: ${{ secrets.ACCOUNT_TOKEN }}
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
DISCORD_USER: ${{ secrets.DISCORD_USER }} DISCORD_USER: ${{ secrets.DISCORD_USER }}
workflow-keepalive: workflow-keepalive:
+21 -23
View File
@@ -6,21 +6,23 @@ Today's check in status:
Repository version: Repository version:
[![Do your setup!](../../actions/workflows/version.yml/badge.svg)](../../actions/workflows/version.yml) [![Do your setup!](../../actions/workflows/version.yml/badge.svg)](../../actions/workflows/version.yml)
> [!NOTE]
> The script might stop working after a few months, there is currently no way of knowing when it will definitely break.
> If the status failed several times, try to redo your setup again before reporting it as an issue.
## Table of Contents ## Table of Contents
- [Getting your auth token](#getting-your-auth-token) - [Getting your account token](#getting-your-account-token)
- [Usage](#usage) - [Usage](#usage)
- [Multiple Accounts](#multiple-accounts)
- [Discord Webhook](#discord-webhook) - [Discord Webhook](#discord-webhook)
- [FAQ](#faq) - [FAQ](#faq)
- [Is this safe?](#is-this-safe) - [Is this safe?](#is-this-safe)
- [How to update my (fork) repository version?](#how-to-update-my-fork-repository-version) - [How to update my (fork) repository version?](#how-to-update-my-fork-repository-version)
- [Error not logged in](#error-not-logged-in)
- [I have other issues](#i-have-other-issues) - [I have other issues](#i-have-other-issues)
## Getting your auth token ## Getting your account token
You have to check in manually first to get your auth token, follow these steps (click to open screenshot): You have to check in manually first to get your account token, follow these steps (click to open screenshot):
1. Open [SKPORT Arknights: Endfield Daily Sign In](https://game.skport.com/endfield/sign-in) and login if you haven't (obviously) 1. Open [SKPORT Arknights: Endfield Daily Sign In](https://game.skport.com/endfield/sign-in) and login if you haven't (obviously)
@@ -30,25 +32,15 @@ You have to check in manually first to get your auth token, follow these steps (
</details> </details>
4. <details> 4. <details>
<summary>For Chromium users, click on the Application tab. If not found, click on the arrow.</summary> <summary>For Chromium users, click on the Application tab -> Cookies, click on <code>ACCOUNT_TOKEN</code>, and check <code>Show URL-encoded</code>.</summary>
<img width="1121" height="448" alt="image" src="https://github.com/user-attachments/assets/eadfb030-f0b1-4fbb-86f1-1dcea6c61964" /> <img width="1057" height="369" alt="image" src="https://github.com/user-attachments/assets/fd4e6f55-f0c6-4f07-934c-d46b3a5bde12" />
</details> </details>
<details> <details>
<summary>For Firefox/Gecko-based browsers, click on the Storage tab.</summary> <summary>For Firefox/Gecko-based browsers, click on the Storage tab -> Cookies, and copy <code>ACCOUNT_TOKEN</code> value.</summary>
<img width="926" height="297" alt="image" src="https://github.com/user-attachments/assets/fb824970-f43e-4bd6-8d78-427ca01675df" /> <img width="970" height="244" alt="image" src="https://github.com/user-attachments/assets/1b54d2a3-4b23-4b7a-b9cf-cf47d5ca45d8" />
</details> </details>
5. <details> 5. That's your account token, keep it save and do NOT share it with anyone!
<summary>Just like the screenshot above, click on Local Storage and look for `SK_OAUTH_CRED_KEY`</summary>
<img width="1212" height="801" alt="image" src="https://github.com/user-attachments/assets/8b4e1158-3914-448c-93fb-9759e1c28717" />
</details>
6. <details>
<summary>Copy the value by clicking on it, then selecting the text below. Or just double-click and Ctrl+C</summary>
<img width="861" height="170" alt="image" src="https://github.com/user-attachments/assets/e29ad0d1-0d40-408b-8fc4-ea0b0f8acfed" />
</details>
7. That's your auth token, keep it save and do NOT share it with anyone!
## Usage ## Usage
@@ -61,10 +53,16 @@ You have to check in manually first to get your auth token, follow these steps (
5. <details> 5. <details>
<summary> <summary>
Insert name with <code>CRED</code> and secret with Insert the name <code>ACCOUNT_TOKEN</code> and the secret of your account token from before, then click Add secret. You can input as many accounts, separate it with a new line (Enter).
<a href="#getting-your-auth-token">your token</a>, then click Add secret. You can input as many accounts, separate it with a new line (Enter).
</summary> </summary>
<img width="801" height="427" alt="image" src="https://github.com/user-attachments/assets/8110e0d2-2c11-4870-bb95-01ec0d99942b" /> <img width="798" height="422" alt="image" src="https://github.com/user-attachments/assets/3f1242f0-550d-42c3-97b5-399ecdade4ed" />
</details>
6. <details>
<summary>
Here is the example secret value for multiple accounts.
</summary>
<img width="348" height="426" alt="image" src="https://github.com/user-attachments/assets/d5d816b6-f11d-4782-b881-df0fd27d68e7" />
</details> </details>
7. <details> 7. <details>
+144 -133
View File
@@ -5,67 +5,140 @@
* Simple script for automated daily attendance via SKPort API * Simple script for automated daily attendance via SKPort API
*/ */
const creds = process.env.CRED.split('\n').map(s => s.trim()).filter(Boolean) import crypto from 'crypto'
const accountTokens = (process.env.ACCOUNT_TOKEN || "").split('\n').map(s => decodeURIComponent(s.trim())).filter(Boolean)
const discordWebhook = process.env.DISCORD_WEBHOOK const discordWebhook = process.env.DISCORD_WEBHOOK
const discordUser = process.env.DISCORD_USER const discordUser = process.env.DISCORD_USER
const BINDING_URL = 'https://zonai.skport.com/api/v1/game/player/binding' const BINDING_URL = 'https://zonai.skport.com/api/v1/game/player/binding'
const ATTENDANCE_URL = 'https://zonai.skport.com/web/v1/game/endfield/attendance' const ATTENDANCE_URL = 'https://zonai.skport.com/web/v1/game/endfield/attendance'
const GENERATE_CRED_URL = 'https://zonai.skport.com/web/v1/user/auth/generate_cred_by_code'
const OAUTH_GRANT_URL = 'https://as.gryphline.com/user/oauth2/v2/grant'
const BASIC_INFO_URL = 'https://as.gryphline.com/user/info/v1/basic'
const ENDFIELD_GAME_ID = '3' const ENDFIELD_GAME_ID = '3'
const APP_CODE = '6eb76d4e13aa36e6'
const VNAME = '1.0.0'
const PLATFORM = '3'
const messages = [] const messages = []
let hasErrors = false let hasErrors = false
function sleep(ms) { return new Promise(r => setTimeout(r, ms)) }
function log(type, ...data) {
console[type](...data)
switch (type) {
case 'debug': return
case 'error': hasErrors = true
}
const string = data.map(v => typeof v === 'object' ? JSON.stringify(v, null, 2) : v).join(' ')
messages.push({ type, string })
}
/** /**
* Build headers for SKPort API * Exchange ACCOUNT_TOKEN -> cred + salt via OAuth flow (3 steps)
*/ */
function buildHeaders(cred, gameRole = null) { async function performOAuthFlow(accountToken) {
if (!accountToken) throw new Error('No account token supplied for OAuth flow')
// Step 1: basic info (validate token)
const infoUrl = `${BASIC_INFO_URL}?token=${encodeURIComponent(accountToken)}`
const infoRes = await fetch(infoUrl, { method: 'GET', headers: { 'Accept': 'application/json' } })
const infoData = await infoRes.json()
if (infoData.status !== 0) {
throw new Error(`OAuth Step 1 Failed: ${infoData.msg || JSON.stringify(infoData)}`)
}
// Step 2: grant OAuth code
const grantRes = await fetch(OAUTH_GRANT_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
body: JSON.stringify({ token: accountToken, appCode: APP_CODE, type: 0 })
})
const grantData = await grantRes.json()
if (grantData.status !== 0 || !grantData.data?.code) {
throw new Error(`OAuth Step 2 Failed: ${grantData.msg || JSON.stringify(grantData)}`)
}
// Step 3: exchange code for cred (+ token)
const credRes = await fetch(GENERATE_CRED_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'platform': PLATFORM,
'Referer': 'https://www.skport.com/',
'Origin': 'https://www.skport.com'
},
body: JSON.stringify({ code: grantData.data.code, kind: 1 })
})
const credData = await credRes.json()
if (credData.code !== 0 || !credData.data?.cred) {
throw new Error(`OAuth Step 3 Failed: ${credData.message || JSON.stringify(credData)}`)
}
return {
cred: credData.data.cred,
salt: credData.data.token,
userId: credData.data.userId,
}
}
/**
* Build headers for SKPort API (uses provided timestamp to match sign)
*/
function buildHeaders(cred, gameRole = null, timestamp = null) {
const ts = timestamp || Math.floor(Date.now() / 1000).toString()
const headers = { const headers = {
'accept': 'application/json, text/plain, */*', 'accept': 'application/json, text/plain, */*',
'content-type': 'application/json', 'content-type': 'application/json',
'origin': 'https://game.skport.com', 'origin': 'https://game.skport.com',
'referer': 'https://game.skport.com/', 'referer': 'https://game.skport.com/',
'cred': cred, 'cred': cred,
'platform': '3', 'platform': PLATFORM,
'sk-language': 'en', 'sk-language': 'en',
'timestamp': Math.floor(Date.now() / 1000).toString(), 'timestamp': ts,
'vname': '1.0.0', 'vname': VNAME,
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36', 'User-Agent': 'Skport/0.7.0 (com.gryphline.skport; build:700089; Android 33; ) Okhttp/5.1.0'
} }
if (gameRole) headers['sk-game-role'] = gameRole
if (gameRole) {
headers['sk-game-role'] = gameRole
}
return headers return headers
} }
/** /**
* Fetch player binding to get all roles * Compute V2 sign: MD5( HMAC-SHA256( path + timestamp + headers_json, salt ) )
* Returns array of roles with gameRole formatted
*/ */
async function getPlayerRoles(cred) { function computeSignV2(path, timestamp, salt) {
const headers = buildHeaders(cred) if (!salt) return null
const headerJson = JSON.stringify({ platform: PLATFORM, timestamp, dId: "", vName: VNAME })
const s = `${path}${timestamp}${headerJson}`
const hmac = crypto.createHmac('sha256', salt).update(s).digest('hex')
return crypto.createHash('md5').update(hmac).digest('hex')
}
/**
* Get all player roles via binding endpoint (signed with salt)
*/
async function getPlayerRoles(cred, salt) {
const path = '/api/v1/game/player/binding'
const timestamp = Math.floor(Date.now() / 1000).toString()
const headers = buildHeaders(cred, null, timestamp)
const sign = computeSignV2(path, timestamp, salt)
if (!sign) throw new Error('Missing salt for V2 signing (binding required)')
headers['sign'] = sign
const res = await fetch(BINDING_URL, { method: 'GET', headers }) const res = await fetch(BINDING_URL, { method: 'GET', headers })
const json = await res.json() const json = await res.json()
if (json.code !== 0) throw new Error(json.message || `Binding API error: ${json.code}`)
if (json.code !== 0) {
throw new Error(json.message || `Binding API error: ${json.code}`)
}
// Find endfield binding
const endfieldApp = json.data?.list?.find(app => app.appCode === 'endfield') const endfieldApp = json.data?.list?.find(app => app.appCode === 'endfield')
if (!endfieldApp || !endfieldApp.bindingList?.length) throw new Error('No Endfield account binding found')
if (!endfieldApp || !endfieldApp.bindingList?.length) {
throw new Error('No Endfield account binding found')
}
// Collect all roles from all bindings
const allRoles = [] const allRoles = []
for (const binding of endfieldApp.bindingList) { for (const binding of endfieldApp.bindingList) {
const roles = binding.roles || [] const roles = binding.roles || []
for (const role of roles) { for (const role of roles) {
allRoles.push({ allRoles.push({
gameRole: `${ENDFIELD_GAME_ID}_${role.roleId}_${role.serverId}`, gameRole: `${ENDFIELD_GAME_ID}_${role.roleId}_${role.serverId}`,
@@ -77,185 +150,123 @@ async function getPlayerRoles(cred) {
}) })
} }
} }
if (!allRoles.length) throw new Error('No roles found in binding')
if (!allRoles.length) {
throw new Error('No roles found in binding')
}
return allRoles return allRoles
} }
/**
* Check if already signed in today
*/
async function checkAttendance(headers) { async function checkAttendance(headers) {
const res = await fetch(ATTENDANCE_URL, { method: 'GET', headers }) const res = await fetch(ATTENDANCE_URL, { method: 'GET', headers })
const json = await res.json() const json = await res.json()
if (json.code !== 0) throw new Error(json.message || `Attendance status check failed: ${json.code}`)
if (json.code !== 0) {
throw new Error(json.message || `API error code: ${json.code}`)
}
return { return {
hasToday: json.data?.hasToday ?? false, hasToday: json.data?.hasToday ?? false,
totalSignIns: json.data?.records?.length ?? 0 totalSignIns: json.data?.records?.length ?? 0
} }
} }
/**
* Claim daily attendance
*/
async function claimAttendance(headers) { async function claimAttendance(headers) {
const res = await fetch(ATTENDANCE_URL, { method: 'POST', headers, body: null }) const res = await fetch(ATTENDANCE_URL, { method: 'POST', headers, body: null })
const json = await res.json() const json = await res.json()
if (json.code !== 0) throw new Error(json.message || `Claim failed: ${json.code}`)
if (json.code !== 0) {
throw new Error(json.message || `API error code: ${json.code}`)
}
// Parse rewards
const rewards = [] const rewards = []
const awardIds = json.data?.awardIds ?? [] const awardIds = json.data?.awardIds ?? []
const resourceMap = json.data?.resourceInfoMap ?? {} const resourceMap = json.data?.resourceInfoMap ?? {}
for (const award of awardIds) { for (const award of awardIds) {
const info = resourceMap[award.id] const info = resourceMap[award.id]
if (info) { if (info) rewards.push(`${info.name} x${info.count}`)
rewards.push(`${info.name} x${info.count}`)
}
} }
return { rewards } return { rewards }
} }
/** /**
* Run check-in for a single role * Check-in for a single role (uses cred + salt to sign)
*/ */
async function checkInRole(cred, role) { async function checkInRole(cred, role, salt) {
const headers = buildHeaders(cred, role.gameRole) const path = '/web/v1/game/endfield/attendance'
const timestamp = Math.floor(Date.now() / 1000).toString()
const headers = buildHeaders(cred, role.gameRole, timestamp)
const sign = computeSignV2(path, timestamp, salt)
if (!sign) throw new Error('Missing salt for V2 signing (attendance requires sign)')
headers['sign'] = sign
// Check status
const status = await checkAttendance(headers) const status = await checkAttendance(headers)
if (status.hasToday) return { success: true, alreadyClaimed: true }
if (status.hasToday) {
return { success: true, alreadyClaimed: true }
}
// Claim if not signed in
const result = await claimAttendance(headers) const result = await claimAttendance(headers)
return { success: true, alreadyClaimed: false, rewards: result.rewards } return { success: true, alreadyClaimed: false, rewards: result.rewards }
} }
/** /**
* Run check-in for a single account (all roles) * Process one ACCOUNT_TOKEN: get cred+salt, fetch roles, check-in all roles
*/ */
async function run(cred, accountIndex) { async function runAccount(accountToken, accountIndex) {
log('debug', `\n----- CHECKING IN FOR ACCOUNT ${accountIndex} -----`) log('debug', `\n----- CHECKING IN FOR ACCOUNT ${accountIndex} -----`)
try { try {
// Step 1: Get all player roles const oauth = await performOAuthFlow(accountToken)
log('debug', 'Fetching player binding...') const { cred, salt } = oauth
const roles = await getPlayerRoles(cred) log('info', `Account ${accountIndex}: obtained cred and salt`)
log('info', `Account ${accountIndex}:`, `Found ${roles.length} role(s)`) const roles = await getPlayerRoles(cred, salt)
log('info', `Account ${accountIndex}: Found ${roles.length} role(s)`)
// Step 2: Check in for each role
for (const role of roles) { for (const role of roles) {
const roleLabel = `${role.nickname} (Lv.${role.level}) [${role.server}]` const roleLabel = `${role.nickname} (Lv.${role.level}) [${role.server}]`
try { try {
const result = await checkInRole(cred, role) const result = await checkInRole(cred, role, salt)
if (result.alreadyClaimed) { if (result.alreadyClaimed) {
log('info', `${roleLabel}:`, 'Already checked in today') log('info', `${roleLabel}: Already checked in today`)
} else if (result.rewards?.length > 0) { } else if (result.rewards?.length > 0) {
log('info', `${roleLabel}:`, `Checked in! Rewards: ${result.rewards.join(', ')}`) log('info', `${roleLabel}: Checked in! Rewards: ${result.rewards.join(', ')}`)
} else { } else {
log('info', `${roleLabel}:`, 'Successfully checked in!') log('info', `${roleLabel}: Successfully checked in!`)
} }
} catch (error) { } catch (err) {
log('error', `${roleLabel}:`, error.message) log('error', `${roleLabel}:`, err.message)
} }
await sleep(500)
// Small delay between roles to avoid rate limiting
await new Promise(resolve => setTimeout(resolve, 500))
} }
} catch (err) {
} catch (error) { log('error', `Account ${accountIndex}:`, err.message)
log('error', `Account ${accountIndex}:`, error.message)
} }
} }
/** /**
* Custom log function to store messages * Send Discord notification (optional)
*/
function log(type, ...data) {
console[type](...data)
switch (type) {
case 'debug': return
case 'error': hasErrors = true
}
const string = data
.map(value => typeof value === 'object' ? JSON.stringify(value, null, 2) : value)
.join(' ')
messages.push({ type, string })
}
/**
* Send results to Discord webhook
*/ */
async function discordWebhookSend() { async function discordWebhookSend() {
log('debug', '\n----- DISCORD WEBHOOK -----') log('debug', '\n----- DISCORD WEBHOOK -----')
if (!discordWebhook || !discordWebhook.toLowerCase().trim().startsWith('https://discord.com/api/webhooks/')) {
if (!discordWebhook.toLowerCase().trim().startsWith('https://discord.com/api/webhooks/')) { log('debug', 'No valid DISCORD_WEBHOOK configured, skipping webhook send')
log('error', 'DISCORD_WEBHOOK is not a Discord webhook URL')
return return
} }
let discordMsg = '' let discordMsg = ''
if (discordUser) { if (discordUser) discordMsg = `<@${discordUser}>\n`
discordMsg = `<@${discordUser}>\n`
}
discordMsg += '**Endfield Daily Check-in**\n' discordMsg += '**Endfield Daily Check-in**\n'
discordMsg += messages.map(msg => `(${msg.type.toUpperCase()}) ${msg.string}`).join('\n') discordMsg += messages.map(msg => `(${msg.type.toUpperCase()}) ${msg.string}`).join('\n')
const res = await fetch(discordWebhook, { const res = await fetch(discordWebhook, {
method: 'POST', method: 'POST',
headers: { 'content-type': 'application/json' }, headers: { 'content-type': 'application/json' },
body: JSON.stringify({ content: discordMsg }) body: JSON.stringify({ content: discordMsg })
}) })
if (res.status === 204) { log('info', 'Successfully sent message to Discord webhook!'); return }
if (res.status === 204) {
log('info', 'Successfully sent message to Discord webhook!')
return
}
log('error', 'Error sending message to Discord webhook') log('error', 'Error sending message to Discord webhook')
} }
// Main execution // Main
if (!creds || !creds.length) { if (!accountTokens || accountTokens.length === 0) {
throw new Error('CRED environment variable not set!') throw new Error('ACCOUNT_TOKEN environment variable is required (one or more tokens separated by newlines)')
} }
for (const index in creds) { for (let i = 0; i < accountTokens.length; i++) {
await run(creds[index], Number(index) + 1) await runAccount(accountTokens[i], i + 1)
if (i < accountTokens.length - 1) await sleep(1000)
// Delay between accounts
if (index < creds.length - 1) {
await new Promise(resolve => setTimeout(resolve, 1000))
}
} }
if (discordWebhook && URL.canParse(discordWebhook)) { if (discordWebhook) {
await discordWebhookSend() await discordWebhookSend()
} }
if (hasErrors) { if (hasErrors) {
console.log('') console.log('')
throw new Error('Error(s) occurred.') throw new Error('One or more errors occurred.')
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "endfield-auto-daily", "name": "endfield-auto-daily",
"version": "1.0.0", "version": "3.0.0",
"description": "Easiest, full free, and no BS SKPORT Arknights: Endfield daily check-in using GitHub Actions", "description": "Easiest, full free, and no BS SKPORT Arknights: Endfield daily check-in using GitHub Actions",
"private": true, "private": true,
"main": "index.js", "main": "index.js",