|
@@ -879,12 +879,12 @@
|
|
|
return reqData;
|
|
|
}
|
|
|
sendPost2025(reqUrl, data, call) {
|
|
|
- let isDev = true;
|
|
|
+ let isDev = false;
|
|
|
let urlTop = "https://api.kessongame.site/";
|
|
|
- let urlMid = urlTop + "prod-api/api/game/";
|
|
|
+ let urlMid = urlTop + "prod-api/api/";
|
|
|
if (isDev) {
|
|
|
urlTop = "http://192.168.1.13:8090/";
|
|
|
- urlMid = urlTop + "api/game/";
|
|
|
+ urlMid = urlTop + "api/";
|
|
|
}
|
|
|
let url = urlMid + reqUrl;
|
|
|
if (reqUrl == "registerForApp" || reqUrl == "loginForApp") {
|
|
@@ -895,11 +895,28 @@
|
|
|
url = urlTop + "prod-api/" + reqUrl;
|
|
|
}
|
|
|
}
|
|
|
+ let headers = ["Content-Type", "application/json; charset=UTF-8"];
|
|
|
+ if (reqUrl.indexOf("/api/game/") >= 0) {
|
|
|
+ }
|
|
|
+ const keyForLoginInfo = "userInfo";
|
|
|
+ const userInfoData = Laya.LocalStorage.getItem(keyForLoginInfo);
|
|
|
+ if (userInfoData != null) {
|
|
|
+ try {
|
|
|
+ let bb = JSON.parse(userInfoData);
|
|
|
+ if (bb) {
|
|
|
+ let token = bb.token;
|
|
|
+ headers.push("Authorization");
|
|
|
+ headers.push(`Bearer ${token}`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
let httpObj = new Laya.HttpRequest();
|
|
|
httpObj.http.timeout = 5000;
|
|
|
httpObj.once(Laya.Event.COMPLETE, this, completeHandler);
|
|
|
httpObj.once(Laya.Event.ERROR, this, errorHandler);
|
|
|
- httpObj.send(url, data, 'post', 'text', ["Content-Type", "application/json; charset=UTF-8"]);
|
|
|
+ httpObj.send(url, data, 'post', 'text', headers);
|
|
|
function errorHandler(error) {
|
|
|
if (call) {
|
|
|
call("{'msg':'Network exception','code':500}");
|
|
@@ -5924,7 +5941,7 @@
|
|
|
let pd = JSON.parse(reqData);
|
|
|
pd.splx = "Consumable";
|
|
|
reqData = JSON.stringify(pd);
|
|
|
- xGame.httpMgr.sendPost2025('getProductList', reqData, (res) => {
|
|
|
+ xGame.httpMgr.sendPost2025('game2/getProductList', reqData, (res) => {
|
|
|
try {
|
|
|
let code = res.code;
|
|
|
let msg = res.msg;
|
|
@@ -7553,7 +7570,24 @@
|
|
|
xGame.uiMgr.Show(UIMsg, "Network not ready. Try again later.");
|
|
|
console.log('zh:✅❌ 5秒后重新尝试加载网络资源');
|
|
|
Laya.timer.once(5000, this, () => {
|
|
|
- xGame.cfgMgr.getConfigFromServer();
|
|
|
+ let retryCount = 0;
|
|
|
+ const maxRetries = 3;
|
|
|
+ const tryFetchConfig = () => {
|
|
|
+ try {
|
|
|
+ xGame.cfgMgr.getConfigFromServer();
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ if (retryCount < maxRetries) {
|
|
|
+ retryCount++;
|
|
|
+ console.log(`🔄 第${retryCount}次重试获取配置...`);
|
|
|
+ Laya.timer.once(5000, this, tryFetchConfig);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.error("❌ 达到最大重试次数,配置获取失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ tryFetchConfig();
|
|
|
});
|
|
|
return false;
|
|
|
}
|
|
@@ -17649,28 +17683,44 @@
|
|
|
this.httpReqOkCount = 0;
|
|
|
let reqData = xGame.httpMgr.getReqData();
|
|
|
console.log('zh:第1个请求getClassicCfg');
|
|
|
- const classicCfg = yield this.sendPostAsync('getClassicCfg', reqData);
|
|
|
+ const classicCfg = yield this.sendPostAsync('game2/getClassicCfg', reqData);
|
|
|
this.classicCfg = classicCfg;
|
|
|
this.httpReqOkCount++;
|
|
|
console.log('zh:第2个请求getLevelCfg');
|
|
|
- const levelCfg = yield this.sendPostAsync('getLevelCfg', reqData);
|
|
|
+ const levelCfg = yield this.sendPostAsync('game2/getLevelCfg', reqData);
|
|
|
this.levelCfg = levelCfg;
|
|
|
this.httpReqOkCount++;
|
|
|
console.log('zh:第3个请求 getPlaceBallCfg');
|
|
|
- const placeBallCfg = yield this.sendPostAsync('getPlaceBallCfg', reqData);
|
|
|
+ const placeBallCfg = yield this.sendPostAsync('game2/getPlaceBallCfg', reqData);
|
|
|
this.placeBallCfg = placeBallCfg;
|
|
|
this.httpReqOkCount++;
|
|
|
console.log('zh:第4个请求 npc');
|
|
|
- const npc = yield this.sendPostAsync('getNpc', reqData);
|
|
|
+ const npc = yield this.sendPostAsync('game2/getNpc', reqData);
|
|
|
this.npcJson = npc.Data;
|
|
|
this.httpReqOkCount++;
|
|
|
console.log('zh:所有配置加载完成');
|
|
|
}
|
|
|
catch (error) {
|
|
|
console.error('❌请求失败:', error);
|
|
|
- Laya.timer.once(500, this, () => {
|
|
|
- console.log('zh:✅重新尝试加载网络资源');
|
|
|
- xGame.cfgMgr.getConfigFromServer();
|
|
|
+ Laya.timer.once(5000, this, () => {
|
|
|
+ let retryCount = 0;
|
|
|
+ const maxRetries = 3;
|
|
|
+ const tryFetchConfig = () => {
|
|
|
+ try {
|
|
|
+ xGame.cfgMgr.getConfigFromServer();
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ if (retryCount < maxRetries) {
|
|
|
+ retryCount++;
|
|
|
+ console.log(`🔄 第${retryCount}次重试获取配置...`);
|
|
|
+ Laya.timer.once(5000, this, tryFetchConfig);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.error("❌ 达到最大重试次数,配置获取失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ tryFetchConfig();
|
|
|
});
|
|
|
}
|
|
|
finally {
|
|
@@ -17723,7 +17773,7 @@
|
|
|
}
|
|
|
test() {
|
|
|
let reqData = xGame.httpMgr.getReqData();
|
|
|
- xGame.httpMgr.sendPost2025('getClassicCfg', reqData, (res) => {
|
|
|
+ xGame.httpMgr.sendPost2025('game2/getClassicCfg', reqData, (res) => {
|
|
|
console.log('zh:1s');
|
|
|
try {
|
|
|
let code = res.code;
|
|
@@ -18225,6 +18275,7 @@
|
|
|
this.userData.coin += val;
|
|
|
this.saveUserData();
|
|
|
xGame.eventMgr.event(COIN_CHANGE);
|
|
|
+ this.updateUserInfo2Server("jb");
|
|
|
}
|
|
|
static getCoin() {
|
|
|
return this.userData.coin;
|
|
@@ -18243,6 +18294,7 @@
|
|
|
this.userData.diamond += val;
|
|
|
this.saveUserData();
|
|
|
xGame.eventMgr.event(DIAMOND_CHANGE);
|
|
|
+ this.updateUserInfo2Server("zs");
|
|
|
}
|
|
|
static getDiamond() {
|
|
|
return this.userData.diamond;
|
|
@@ -18516,6 +18568,48 @@
|
|
|
this.diyGameData.challengeMode_overLev = levNum;
|
|
|
this.saveDiyGameData();
|
|
|
}
|
|
|
+ static updateUserInfo2Server(type, count = 0) {
|
|
|
+ const keyForLoginInfo = "userInfo";
|
|
|
+ const userInfoData = Laya.LocalStorage.getItem(keyForLoginInfo);
|
|
|
+ if (userInfoData == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let reqData = xGame.httpMgr.getReqData();
|
|
|
+ let rd = JSON.parse(reqData);
|
|
|
+ rd.dataType = type;
|
|
|
+ let dataValue = 0;
|
|
|
+ if (type == "zs") {
|
|
|
+ dataValue = this.getDiamond();
|
|
|
+ }
|
|
|
+ if (type == "jb") {
|
|
|
+ dataValue = this.getCoin();
|
|
|
+ }
|
|
|
+ rd.dataValue = dataValue;
|
|
|
+ reqData = JSON.stringify(rd);
|
|
|
+ xGame.httpMgr.sendPost2025('user/update', reqData, (res) => {
|
|
|
+ try {
|
|
|
+ let code = res.code;
|
|
|
+ let data = res.data;
|
|
|
+ if (code == 401) {
|
|
|
+ Laya.LocalStorage.setItem(keyForLoginInfo, null);
|
|
|
+ alert('Please log in.');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (code == 200) {
|
|
|
+ console.log('zh:更新账号资产OK' + JSON.stringify(res));
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log('zh:更新账号资产fa' + JSON.stringify(res));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ console.log('error=' + error);
|
|
|
+ alert("Please check your network connection.");
|
|
|
+ }
|
|
|
+ finally {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
DataMgr.isNewUser = false;
|
|
|
DataMgr.fristEnter = true;
|
|
@@ -22623,7 +22717,7 @@
|
|
|
let pd = JSON.parse(reqData);
|
|
|
pd.splx = "Consumable";
|
|
|
reqData = JSON.stringify(pd);
|
|
|
- xGame.httpMgr.sendPost2025('getProductList', reqData, (res) => {
|
|
|
+ xGame.httpMgr.sendPost2025('game2/getProductList', reqData, (res) => {
|
|
|
try {
|
|
|
let code = res.code;
|
|
|
let msg = res.msg;
|
|
@@ -23946,7 +24040,24 @@
|
|
|
xGame.uiMgr.Show(UIMsg$1, "Network not ready. Try again later.");
|
|
|
console.log('zh:✅❌ 5秒后重新尝试加载网络资源');
|
|
|
Laya.timer.once(5000, this, () => {
|
|
|
- xGame.cfgMgr.getConfigFromServer();
|
|
|
+ let retryCount = 0;
|
|
|
+ const maxRetries = 3;
|
|
|
+ const tryFetchConfig = () => {
|
|
|
+ try {
|
|
|
+ xGame.cfgMgr.getConfigFromServer();
|
|
|
+ }
|
|
|
+ catch (error) {
|
|
|
+ if (retryCount < maxRetries) {
|
|
|
+ retryCount++;
|
|
|
+ console.log(`🔄 第${retryCount}次重试获取配置...`);
|
|
|
+ Laya.timer.once(5000, this, tryFetchConfig);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.error("❌ 达到最大重试次数,配置获取失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ tryFetchConfig();
|
|
|
});
|
|
|
return false;
|
|
|
}
|