card_svr/src/common/WebApi.ts
2021-01-15 16:59:08 +08:00

78 lines
1.8 KiB
TypeScript

import axios from "axios";
import {Config} from "../cfg/Config";
import {debugRoom, error} from "./Debug";
let config: Config = require('../../config/config.json');
/**
* 获取卡组详情
* @param {string} accountid
* @param {number} heroid
* @param {string} cardgroup
* @return {Promise<AxiosResponse<any>>}
*/
export function getCardGroup(accountid: string, heroid: number, cardgroup: string) {
return axios.get(`${config.info_svr}/${accountid}/group_info/${heroid}/${cardgroup}`, )
.then(function (response) {
let res = response.data;
if (res.errcode) {
throw new Error(res.errmsg);
} else {
return res.data;
}
})
}
/**
* 解锁英雄
* @param {string} accountid
* @param {number | string} heroid
* @return {Promise<AxiosResponse<any>>}
*/
export function requestUnlockHero(accountid: string, heroid: number | string) {
let data = {"type": 0};
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);
});
}
/**
* 创建机器人
* @param data
*/
export function createRobot(data: any) {
axios.get('http://127.0.0.1:2500/robot/create', {
params: data
}).then((res) => {
debugRoom(`caeate robot result: `,res.data);
}).catch((err) => {
error(err);
})
}