canaria3406 / hoyolab-auto-sign

A lightweight, secure, and free script that automatically collect Hoyolab daily check in rewards. Supports Genshin Impact, Honkai Impact 3rd, and Honkai: Star Rail.
MIT License
427 stars 56 forks source link

Zenless Zone Zero Login returns error #52

Closed rounak-codes closed 3 days ago

rounak-codes commented 1 month ago

After attempting to login or run the script , ZZZ login returns the following message in discord via webhook and login does not reflect in the login webpage. All other games' login is working as intended.

Shomen-ai commented 1 month ago

The same goes for me. I'm running a script for two accounts, and get 活动已结束 (-500012) on first account and 操作频繁,请稍后再试 on second account.

Chillrend commented 1 month ago

+1 they probably changed the endpoint, i'll try looking at it

Chillrend commented 1 month ago

After a quick network inspect, the endpoint indeed changed to https://sg-public-api.hoyolab.com/event/luna/zzz/os/sign it also have a new header "x-rpc-signgame": "zzz"

Shomen-ai commented 1 month ago

So, it's necessary to declare and use special header for zzz?

Chillrend commented 1 month ago

Haven't tried through the script yet, but this is from network inspect when i clicked the sign button in hoyolab: image

Also the header specific to ZZZ: image

WiLuX-Source commented 1 month ago

First of all big shoutout to @rounak-codes for opening this issue and @Chillrend for all the extra details for solving the problem.

The code now requires a specific set of headers for ZZZ and here's how you need to do your requests before I PR.

Change your check out url for ZZZ to https://sg-public-api.hoyolab.com/event/luna/zzz/os/sign?lang=en-us&act_id=e202406031448091 and add one more header when making your request: "x-rpc-signgame": "zzz",

image

This will break other games but ZZZ will work again. I'm currently on it making custom headers for every game just in case it breaks again.

WiLuX-Source commented 1 month ago

I would appreciate testing of my PR The Discord chinese version and both telegram versions needs testing waiting for feedback!

Chillrend commented 1 month ago

Thanks @WiLuX-Source, I will try your PR on my script asap.

ChyrkunArtsiom commented 1 month ago

Same thing started for HSR 活动已结束 (-500012) yesterday. For it header's value is hkrpg and request is https://sg-public-api.hoyolab.com/event/luna/hkrpg/os/sign.

WiLuX-Source commented 1 month ago

HSR worked fine for me just 1 hour ago.

WiLuX-Source commented 1 month ago

HSR still works fine.

ChyrkunArtsiom commented 1 month ago

Hm, maybe they are rolling those changes in order for specific regions / accounts. Anyway I just copied your pr and updated for myself.

WiLuX-Source commented 1 month ago

I created that PR to be able to change headers fast without going in too much detail. Glad it helped you.

cptmacp commented 1 month ago

Updated code to handle game-specific headers


const profiles = [
    {
        token: "ltoken_v2=gBxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxCY; ltuid_v2=26XXXXX20;",
    genshin: true,
        honkai_star_rail: false,
        honkai_3: false,
        zzz: false,
        accountName: "test"
    }

];

const telegram_notify = true
const myTelegramID = "1XXXXXXX0"
const telegramBotToken = ""

/** The above is the config. Please refer to the instructions on https://github.com/canaria3406/hoyolab-auto-sign/ for configuration. **/
/** The following is the script code. Please DO NOT modify. **/

const urlDict = {
    Genshin: 'https://sg-hk4e-api.hoyolab.com/event/sol/sign?lang=en-us&act_id=e202102251931481',
    Star_Rail: 'https://sg-public-api.hoyolab.com/event/luna/os/sign?lang=en-us&act_id=e202303301540311',
    Honkai_3: 'https://sg-public-api.hoyolab.com/event/mani/sign?lang=en-us&act_id=e202110291205111',
    //Zzz-old: 'https://sg-act-nap-api.hoyolab.com/event/luna/zzz/os/sign?lang=us-id&act_id=e202406031448091',
    Zzz: 'https://sg-public-api.hoyolab.com/event/luna/zzz/os/sign?lang=en-us&act_id=e202406031448091'
};

async function main() {
    const messages = await Promise.all(profiles.map(autoSignFunction));
    const hoyolabResp = `${messages.join('\n\n')}`

    if (telegram_notify && telegramBotToken && myTelegramID) {
        postWebhook(hoyolabResp);
    }
}

function autoSignFunction({ token, genshin, honkai_star_rail, honkai_3, zzz, accountName }) {
    const urls = [];

    if (genshin) urls.push(urlDict.Genshin);
    if (honkai_star_rail) urls.push(urlDict.Star_Rail);
    if (honkai_3) urls.push(urlDict.Honkai_3);
    if (zzz) urls.push(urlDict.Zzz);

    const header = {
        Cookie: token,
        'Accept': 'application/json, text/plain, */*',
        'Accept-Encoding': 'gzip, deflate, br',
        'Connection': 'keep-alive',
        'x-rpc-app_version': '2.34.1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36',
        'x-rpc-client_type': '4',
        'Referer': 'https://act.hoyolab.com/',
        'Origin': 'https://act.hoyolab.com'
    };

    // Add game-specific headers
    // in future add game specific headers if needed
    if (honkai_star_rail) header['x-rpc-signgame'] = 'hkrpg';
    if (zzz) header['x-rpc-signgame'] = 'zzz';

    const options = {
        method: 'POST',
        headers: header,
        muteHttpExceptions: true,
    };

    let response = `Check-in completed for ${accountName}`;

    const httpResponses = UrlFetchApp.fetchAll(urls.map(url => ({ url, ...options })));

    for (const [i, hoyolabResponse] of httpResponses.entries()) {
        const responseJson = JSON.parse(hoyolabResponse);
        const checkInResult = responseJson.message;
        const gameName = Object.keys(urlDict).find(key => urlDict[key] === urls[i])?.replace(/_/g, ' ');
        const bannedCheck = responseJson.data?.gt_result?.is_risk;

        if (bannedCheck) {
            response += `\n${gameName}: Auto check-in failed due to CAPTCHA blocking.`;
        } else {
            response += `\n${gameName}: ${checkInResult}`;
        }
    }

    return response;
}

function postWebhook(data) {
    let payload = JSON.stringify({
        'chat_id': myTelegramID,
        'text': data,
        'parse_mode': 'HTML'
    });

    const options = {
        method: 'POST',
        contentType: 'application/json',
        payload: payload,
        muteHttpExceptions: true
    };

    UrlFetchApp.fetch('https://api.telegram.org/bot' + telegramBotToken + '/sendMessage', options);
}

just add

    // Add game-specific header
    // in future add game specific headers if needed
    if (honkai_star_rail) header['x-rpc-signgame'] = 'hkrpg';
    if (zzz) header['x-rpc-signgame'] = 'zzz';

before const options to add extra headers in header json

image

cptmacp commented 1 month ago

@WiLuX-Source https://github.com/canaria3406/hoyolab-auto-sign/pull/55

Yours approach is fine but since only a few things have to be added in the REST call's header and most of the part is common we need not to define duplicated stuff , where we can just append stuff in header's json before passing it to 'options'

WiLuX-Source commented 1 month ago

@cptmacp I prefer my option better since someone who's using this project might not know coding and you can just tell them to append the header. Currently I have no issues checking out. If I have I'll just add a simple 1 line change and I am done.

WiLuX-Source commented 1 month ago

Also your approach might not work if users checks out at the same time when using both star rail and zzz correct me If I am wrong.

ChyrkunArtsiom commented 1 month ago

Also your approach might not work if users checks out at the same time when using both star rail and zzz correct me If I am wrong.

You are right, only the last truthy case will work. The best way either to convert urlDict into objects and use switch or use Map. Too much work refactoring one simple script for no reason tho.

WiLuX-Source commented 1 month ago

Update HSR still works fine. At least in my region(Europe) You can always update the header in headerDict. I think we are fine for a while now. I don't think author of this project is active and will not get merged probably.

rounak-codes commented 1 month ago

Can confirm HSR still works fine in my region as well (ASIA) , Thanks to @WiLuX-Source , @cptmacp and @Chillrend for the fix.

rounak-codes commented 1 month ago

I am keeping this as open in case someone needs guidance in the future or endpoints are changed. Also , since canaria is MIA , without the merge , new users are bound to run into this issue.

WiLuX-Source commented 1 month ago

@rounak-codes please accept my pr. It only needs 1 review to be merged.

duronald commented 1 month ago

If @canaria3406 is inactive we should probably fork the repo and upstream everything into the forked repo.

ud4yk commented 1 month ago

No coder here, but pretty much tried to follow the thread to letter, HSR gets broken (europe) , tried to add luna/"hkrpg"/os/ (without quotes) in the url too as i thought it might be a troubleshoot. I'm using the discord version of the script if that makes a difference. Can't have both, either hsr gets broken or ZZZ. image

I followed this instruction https://github.com/canaria3406/hoyolab-auto-sign/issues/52#issuecomment-2408479845 , heck even redid the script copy paste (the bottom most discord ping) omitting the telegram stuff with discord from the original

Chillrend commented 1 month ago

I followed this instruction #52 (comment) , heck even redid the script copy paste (the bottom most discord ping) omitting the telegram stuff with discord from the original

Try #55 https://github.com/canaria3406/hoyolab-auto-sign/blob/5b60da5ac130b7bc8e7dcf155f3e3b8719e02e4a/src/main-discord.gs

ud4yk commented 1 month ago

I followed this instruction #52 (comment) , heck even redid the script copy paste (the bottom most discord ping) omitting the telegram stuff with discord from the original

Try #55 https://github.com/canaria3406/hoyolab-auto-sign/blob/5b60da5ac130b7bc8e7dcf155f3e3b8719e02e4a/src/main-discord.gs

worked! atleast once with manual execution, lets see if it'll hold up! Couldn't figure out those headers on my own :)

hanthienhai commented 1 month ago

Try code from cptmacp, it's worked with ZZZ but not work with HSR Star Rail: 活动已结束 (-500012)

WiLuX-Source commented 1 month ago

Try code from cptmacp, it's worked with ZZZ but not work with HSR Star Rail: 活动已结束 (-500012)

This is what happens when you don't refactor the code and use a simple if statement when the change is needed. Try the code in #55 and add the header if necessary.

cptmacp commented 1 month ago

Try code from cptmacp, it's worked with ZZZ but not work with HSR Star Rail: 活动已结束 (-500012)

As https://github.com/canaria3406/hoyolab-auto-sign/issues/52#issuecomment-2408427061 commented

HSR was needed 'x-rpc-signgame' as 'hkrpg' and it was working in some regions so I added it in the header

You can comment it out and check

image

rairulyle commented 1 month ago

Hey guys! Just in case you are interested or when OP stop maintaining the script, I am actively maintaining this and adding new features such as pinging each discord users and pretty output (it also goes red when there's an error).

I am also fixing issues encountered ASAP. But I need help maintain the other languages and telegram scripts.

https://github.com/rairulyle/hoyolab-auto-sign image

WiLuX-Source commented 1 month ago

No one should ever share their hoyolab token with another person. I hope they are close friend of yours. Embeds can't be indexed by discord even though they look pretty. I don't like where this issue is going. Please keep it away from another advertisement as such. If you want your project to be used just keep your fork up to date so it can appear to the others.

rairulyle commented 1 month ago

Yep. They're all my friends. It's just that some people started forking mine so I did share it.

No one should ever share their hoyolab token with another person. I hope they are close friend of yours. Embeds can't be indexed by discord even though they look pretty. I don't like where this issue is going. Please keep it away from another advertisement as such. If you want your project to be used just keep your fork up to date so it can appear to the others.

WiLuX-Source commented 1 month ago

Nice promotion both of you.

rounak-codes commented 1 month ago

Do not use this thread for promotion. If you have any issues , ask about it , if you have a better code , mention the code and initiate a PR.