1
This commit is contained in:
parent
0b1121b9fc
commit
caa43d3504
@ -12,12 +12,15 @@ require_once('models/BoxOrder.php');
|
|||||||
require_once('models/Nft.php');
|
require_once('models/Nft.php');
|
||||||
require_once('models/BuyRecord.php');
|
require_once('models/BuyRecord.php');
|
||||||
|
|
||||||
|
require_once('services/MarketService.php');
|
||||||
|
|
||||||
require_once('phpcommon/bchelper.php');
|
require_once('phpcommon/bchelper.php');
|
||||||
|
|
||||||
use phpcommon\SqlHelper;
|
use phpcommon\SqlHelper;
|
||||||
use models\BoxOrder;
|
use models\BoxOrder;
|
||||||
use models\Nft;
|
use models\Nft;
|
||||||
use models\BuyRecord;
|
use models\BuyRecord;
|
||||||
|
use services\MarketService;
|
||||||
|
|
||||||
const CURRENCY_DECIMALS = 8;
|
const CURRENCY_DECIMALS = 8;
|
||||||
const PRICE_PAD = '0000000000';
|
const PRICE_PAD = '0000000000';
|
||||||
@ -27,8 +30,6 @@ const PRESALE_PREPARE = 1;
|
|||||||
const PRESALE_STARTED = 2;
|
const PRESALE_STARTED = 2;
|
||||||
const PRESALE_SOLD_OUT = 3;
|
const PRESALE_SOLD_OUT = 3;
|
||||||
|
|
||||||
const TOKEN_SALT = 'B8E6BD4F-FD7B-E2B8-6688-80A2D8632064';
|
|
||||||
|
|
||||||
class MarketController extends BaseController {
|
class MarketController extends BaseController {
|
||||||
|
|
||||||
private function isTestMode()
|
private function isTestMode()
|
||||||
@ -202,7 +203,7 @@ class MarketController extends BaseController {
|
|||||||
$signature = getReqVal('signature', '');
|
$signature = getReqVal('signature', '');
|
||||||
$gameId = 2006;
|
$gameId = 2006;
|
||||||
$funcId = 1;
|
$funcId = 1;
|
||||||
if (!$this->isValidToken($buyerAddress, $token)) {
|
if (!MarketService::isValidToken($buyerAddress, $token)) {
|
||||||
myself()->_rspErr(100, 'invalid token');
|
myself()->_rspErr(100, 'invalid token');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -328,7 +329,7 @@ class MarketController extends BaseController {
|
|||||||
$token = getReqVal('token', '');
|
$token = getReqVal('token', '');
|
||||||
$account = getReqVal('account', '');
|
$account = getReqVal('account', '');
|
||||||
$orderId = getReqVal('order_id', '');
|
$orderId = getReqVal('order_id', '');
|
||||||
if (!$this->isValidToken($account, $token)) {
|
if (!MarketService::isValidToken($account, $token)) {
|
||||||
myself()->_rspErr(100, 'invalid token');
|
myself()->_rspErr(100, 'invalid token');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -361,7 +362,7 @@ class MarketController extends BaseController {
|
|||||||
{
|
{
|
||||||
$account = getReqVal('account', '');
|
$account = getReqVal('account', '');
|
||||||
$token = getReqVal('token', '');
|
$token = getReqVal('token', '');
|
||||||
if (!$this->isValidToken($account, $token)) {
|
if (!MarketService::isValidToken($account, $token)) {
|
||||||
myself()->_rspErr(100, 'invalid token');
|
myself()->_rspErr(100, 'invalid token');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -381,7 +382,7 @@ class MarketController extends BaseController {
|
|||||||
$account = getReqVal('account', '');
|
$account = getReqVal('account', '');
|
||||||
$token = getReqVal('token', '');
|
$token = getReqVal('token', '');
|
||||||
$tokenId = getReqVal('token_id', '');
|
$tokenId = getReqVal('token_id', '');
|
||||||
if (!$this->isValidToken($account, $token)) {
|
if (!MarketService::isValidToken($account, $token)) {
|
||||||
myself()->_rspErr(100, 'invalid token');
|
myself()->_rspErr(100, 'invalid token');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -485,7 +486,7 @@ class MarketController extends BaseController {
|
|||||||
$token = getReqVal('token', '');
|
$token = getReqVal('token', '');
|
||||||
$nonce = uniqid() . '_' . myself()->_getNowTime();
|
$nonce = uniqid() . '_' . myself()->_getNowTime();
|
||||||
myself()->_rspData(array(
|
myself()->_rspData(array(
|
||||||
'state' => $this->isValidToken($account, $token) ? 1 : 0,
|
'state' => MarketService::isValidToken($account, $token) ? 1 : 0,
|
||||||
'nonce' => $nonce,
|
'nonce' => $nonce,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -494,7 +495,7 @@ class MarketController extends BaseController {
|
|||||||
{
|
{
|
||||||
$account = getReqVal('account', '');
|
$account = getReqVal('account', '');
|
||||||
$token = getReqVal('token', '');
|
$token = getReqVal('token', '');
|
||||||
if (!$this->isValidToken($account, $token)) {
|
if (!MarketService::isValidToken($account, $token)) {
|
||||||
myself()->_rspErr(1, 'invalid token');
|
myself()->_rspErr(1, 'invalid token');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -544,7 +545,7 @@ class MarketController extends BaseController {
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
myself()->_rspData(array(
|
myself()->_rspData(array(
|
||||||
'token' => $this->genToken($account, $nonce)
|
'token' => MarketService::genToken($account, $nonce)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -564,33 +565,4 @@ class MarketController extends BaseController {
|
|||||||
return $web3ServiceCluster[rand() % count($web3ServiceCluster)];
|
return $web3ServiceCluster[rand() % count($web3ServiceCluster)];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function genToken($account, $nonce)
|
|
||||||
{
|
|
||||||
$data = array(
|
|
||||||
'account' => $account,
|
|
||||||
'rand' => uniqid(),
|
|
||||||
'nonce' => $nonce,
|
|
||||||
'createtime' => myself()->_getNowTime(),
|
|
||||||
);
|
|
||||||
$data['sign'] = md5(TOKEN_SALT . $data['account'] . $data['rand'] . $data['nonce'] . $data['createtime']);
|
|
||||||
return base64_encode(json_encode($data));
|
|
||||||
}
|
|
||||||
|
|
||||||
private function isValidToken($account, $token)
|
|
||||||
{
|
|
||||||
$deToken = base64_decode($token);
|
|
||||||
if (empty($deToken)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (empty($account)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$data = json_decode($deToken, true);
|
|
||||||
$sign = md5(TOKEN_SALT . $data['account'] . $data['rand'] . $data['nonce'] . $data['createtime']);
|
|
||||||
if ($sign == $data['sign']) {
|
|
||||||
return phpcommon\isSameAddress($data['account'], $account);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
46
webapp/services/MarketService.php
Normal file
46
webapp/services/MarketService.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace services;
|
||||||
|
|
||||||
|
class MarketService extends BaseService {
|
||||||
|
|
||||||
|
const TOKEN_SALT = 'B8E6BD4F-FD7B-E2B8-6688-80A2D8632064';
|
||||||
|
|
||||||
|
public static function isValidToken($account, $token)
|
||||||
|
{
|
||||||
|
$deToken = base64_decode($token);
|
||||||
|
if (empty($deToken)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (empty($account)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$data = json_decode($deToken, true);
|
||||||
|
$sign = md5(self::TOKEN_SALT .
|
||||||
|
$data['account'] .
|
||||||
|
$data['rand'] .
|
||||||
|
$data['nonce'] .
|
||||||
|
$data['createtime']);
|
||||||
|
if ($sign == $data['sign']) {
|
||||||
|
return phpcommon\isSameAddress($data['account'], $account);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function genToken($account, $nonce)
|
||||||
|
{
|
||||||
|
$data = array(
|
||||||
|
'account' => $account,
|
||||||
|
'rand' => uniqid(),
|
||||||
|
'nonce' => $nonce,
|
||||||
|
'createtime' => myself()->_getNowTime(),
|
||||||
|
);
|
||||||
|
$data['sign'] = md5(TOKEN_SALT .
|
||||||
|
$data['account'] .
|
||||||
|
$data['rand'] .
|
||||||
|
$data['nonce'] .
|
||||||
|
$data['createtime']);
|
||||||
|
return base64_encode(json_encode($data));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user