将上报游戏结果的接口统一到webapi中

This commit is contained in:
zhl 2021-01-14 10:13:52 +08:00
parent 17ea5b847e
commit a577f28ceb
2 changed files with 29 additions and 22 deletions

View File

@ -1,5 +1,6 @@
import axios from "axios";
import {Config} from "../cfg/Config";
import {debugRoom, error} from "./Debug";
let config: Config = require('../../config/config.json');
@ -33,4 +34,30 @@ export function requestUnlockHero(accountid: string, heroid: number | string) {
return axios.post(`${config.info_svr}/${accountid}/hero/unlock/${heroid}`, data);
}
/**
*
* @param data
*/
export function reportGameResult(data: any) {
let dataStr = JSON.stringify(data);
let reqConfig = {
method: 'post',
url: `${config.info_svr}/record/save`,
headers: {
'Content-Type': 'application/json',
},
data : dataStr
};
// @ts-ignore
axios(reqConfig)
.then(function (response) {
debugRoom(JSON.stringify(response.data));
})
.catch(function (err) {
error(err);
});
}

View File

@ -9,11 +9,9 @@ import gameUtil from "../../utils/game.util";
import {Card} from "../schema/Card";
import {MapSchema, SetSchema} from "@colyseus/schema";
import {StateTypeEnum} from "../enums/StateTypeEnum";
import axios from "axios";
import {Config} from "../../cfg/Config";
import {reportGameResult} from "../../common/WebApi";
let config: Config = require('../../../config/config.json');
/**
*
*/
@ -207,25 +205,7 @@ export class GameResultCommand extends Command<CardGameState, {}> {
});
}
data.players = players;
let dataStr = JSON.stringify(data);
let reqConfig = {
method: 'post',
url: `${config.info_svr}/record/save`,
headers: {
'Content-Type': 'application/json',
},
data : dataStr
};
// @ts-ignore
axios(reqConfig)
.then(function (response) {
debugRoom(JSON.stringify(response.data));
})
.catch(function (err) {
error(err);
});
reportGameResult(data);
}
}