1
This commit is contained in:
parent
0e4469c7a7
commit
748f6ad15f
@ -1,116 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
require_once('models/Hero.php');
|
|
||||||
require_once('models/Nft.php');
|
|
||||||
require_once('mt/NftDesc.php');
|
|
||||||
require_once('mt/Hero.php');
|
|
||||||
|
|
||||||
use models\Hero;
|
|
||||||
use models\Nft;
|
|
||||||
|
|
||||||
class RestApiController extends BaseController {
|
|
||||||
|
|
||||||
public function dispatch()
|
|
||||||
{
|
|
||||||
//REQUEST_URI /api/nft/$netId/$nftType/$tokenId
|
|
||||||
$requestUri = $_SERVER['REQUEST_URI'];
|
|
||||||
if (!empty($requestUri)) {
|
|
||||||
$idx = strpos($requestUri, '/api/nft/');
|
|
||||||
if ($idx == 0) {
|
|
||||||
$tmpStrs = explode('?', $requestUri);
|
|
||||||
$requestUri = count($tmpStrs) > 0 ? $tmpStrs[0] : '';
|
|
||||||
$this->nftInfo(explode('/', $requestUri));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
https://game2006api.cebggame.com/api/nft/$netId/$nftType/$tokenId
|
|
||||||
$netId: 链id(网络id)
|
|
||||||
$nftType: 目前就hero,planet
|
|
||||||
$tokenId:tokenid
|
|
||||||
*/
|
|
||||||
private function nftInfo($path)
|
|
||||||
{
|
|
||||||
if (count($path) < 5) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$netId = $path[3];
|
|
||||||
$nftType = $path[4];
|
|
||||||
$tokenId = $path[5];
|
|
||||||
$info = array(
|
|
||||||
"name" => "",
|
|
||||||
"description" => "",
|
|
||||||
"image" => "",
|
|
||||||
"attributes" => array(),
|
|
||||||
);
|
|
||||||
switch ($nftType){
|
|
||||||
case "hero" :{
|
|
||||||
$heroDb = Hero::findByTokenId2($tokenId);
|
|
||||||
if (!$heroDb){
|
|
||||||
echo json_encode($info);
|
|
||||||
die;
|
|
||||||
}
|
|
||||||
$heroMeta = \mt\Hero::get($heroDb['hero_id']);
|
|
||||||
$NftMeta = \mt\NftDesc::getByItemId($heroDb['hero_id']);
|
|
||||||
//https://www.cebg.games/res/nfts/30100.png
|
|
||||||
$info['name'] = $heroMeta['name'];
|
|
||||||
$info['description'] = $NftMeta['desc'];
|
|
||||||
$info['image'] = "https://www.cebg.games/res/nfts/".$heroDb['hero_id'].".png";
|
|
||||||
array_push($info['attributes'],array(
|
|
||||||
"trait_type" => "level",
|
|
||||||
"value" => intval($heroDb['hero_lv']),
|
|
||||||
"max_value" => 15,
|
|
||||||
));
|
|
||||||
$randAttr = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
|
|
||||||
foreach ($randAttr as $attr){
|
|
||||||
switch ($attr['quality']){
|
|
||||||
case 1 : $quality = "D";break;
|
|
||||||
case 2 : $quality = "C";break;
|
|
||||||
case 3 : $quality = "B";break;
|
|
||||||
case 4 : $quality = "A";break;
|
|
||||||
case 5 : $quality = "S";break;
|
|
||||||
default : $quality = "";
|
|
||||||
}
|
|
||||||
switch ($attr['attr_id']){
|
|
||||||
case kHAT_Hp : {
|
|
||||||
array_push($info['attributes'],array(
|
|
||||||
"trait_type" => "Hp",
|
|
||||||
"value" => $quality,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case kHAT_Atk : {
|
|
||||||
array_push($info['attributes'],array(
|
|
||||||
"trait_type" => "Atk",
|
|
||||||
"value" => $quality,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case kHAT_Def : {
|
|
||||||
array_push($info['attributes'],array(
|
|
||||||
"trait_type" => "Def",
|
|
||||||
"value" => $quality,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "planet" : {
|
|
||||||
$planetDb = Nft::getNft($tokenId);
|
|
||||||
if (!$planetDb){
|
|
||||||
echo json_encode($info);
|
|
||||||
die;
|
|
||||||
}
|
|
||||||
$NftMeta = \mt\NftDesc::getByItemId($planetDb['item_id']);
|
|
||||||
$info['name'] = $NftMeta['name'] ? : "planet";
|
|
||||||
$info['description'] = $NftMeta['desc'] ? : "planet";
|
|
||||||
$info['image'] = "https://www.cebg.games/res/nfts/".$planetDb['item_id'].".png";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
echo json_encode($info);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user