thesadru / genshinstats

PLEASE USE GENSHIN.PY A python library that can get the stats of Genshin Impact players using Mihoyo's API. PLEASE USE GENSHIN.PY
https://thesadru.github.io/pdoc/genshinstats/
MIT License
265 stars 38 forks source link

DS token issue #54

Closed BRAVO68WEB closed 2 years ago

BRAVO68WEB commented 2 years ago

I am Nodejs developer. I found your python SDK useful.

But When I manually tried to fetch my Player info through Postman it did not work. I used your DS token generator with OS Salt "6cqshh5dhw73bzxn20oexa9k516chk7s", on both "https://bbs-api-os.mihoyo.com/game_record/genshin/api/index?server=os_asia&role_id=807715736" and "https://api-os-takumi.mihoyo.com/game_record/genshin/api/index?server=os_asia&role_id=834338997" but it gave me an error every time. But your ones work just fine.

Can you pls help? I need this I need to integrate into my Nodejs Code.

thesadru commented 2 years ago

May I see the code you have tried? I may not really be a js programmer but I think I can try and look for some possible cause of an error.

BRAVO68WEB commented 2 years ago

DS Token Generator:-

var CryptoJS = require("crypto-js");
var DS_SALT = "6cqshh5dhw73bzxn20oexa9k516chk7s";
function makeid(length) {
  var result = [];
  var characters =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  var charactersLength = characters.length;
  for (var i = 0; i < length; i++) {
    result.push(
      characters.charAt(Math.floor(Math.random() * charactersLength))
    );
  }
  return result.join("");
}

var ds1 = (Date.now() / 1000) | 0,
  ds2 = makeid(6),
  ds3 = CryptoJS.MD5(`salt=${DS_SALT}&t=${ds1}&r=${ds2}`).toString();
var dsToken = ds1 + `,` + ds2 + `,` + ds3;

console.log(dsToken);
var axios = require('axios');

var config = {
  method: 'get',
  url: 'https://api-os-takumi.mihoyo.com/game_record/genshin/api/index?server=os_asia&role_id=834338997',
  headers: { 
    'Cookie': '<Cookie-Here>', 
    'DS': '<DS-Token-Here>', 
    'Host': 'api-os-takumi.mihoyo.com', 
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41', 
    'x-rpc-app_version': '1.5.0', 
    'x-rpc-client_type': '5', 
    'x-rpc-language': 'en-us'
  }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

This use to work earlier but for 2 weeks it doesn't work anymore.

thesadru commented 2 years ago

Honestly, I just don't see the issue.

You can try referring to some js/ts SDK and see if that'd help more. Most popular one afaik:

https://github.com/genshin-kit/genshin-kit-node/blob/c5ad3f8fd2ffaec764ec86da9fb039c7883399a8/packages/core/src/module/_getDS.ts#L37-L46

BRAVO68WEB commented 2 years ago

Bro Thx so much

I think the DS Salt actually changed Thx

DS_SALT :- 6s25p5ox5y14umn1p61aqyyvbvvl3lrt

grisha2217 commented 2 years ago

Bro Thx so much

I think the DS Salt actually changed Thx

DS_SALT :- 6s25p5ox5y14umn1p61aqyyvbvvl3lrt

Thanks man a lot!