1
This commit is contained in:
parent
caa43d3504
commit
98a174d8e3
@ -207,7 +207,7 @@ class MarketController extends BaseController {
|
||||
myself()->_rspErr(100, 'invalid token');
|
||||
return;
|
||||
}
|
||||
$this->buyBoxVerifySignature(
|
||||
MarketService::buyBoxVerifySignature(
|
||||
$buyerAddress,
|
||||
$type,
|
||||
$paymentTokenAddress,
|
||||
@ -433,53 +433,6 @@ class MarketController extends BaseController {
|
||||
return str_replace("\n", '\n', $str);
|
||||
}
|
||||
|
||||
private function buyBoxVerifySignature($buyerAddress,
|
||||
$type,
|
||||
$paymentTokenAddress,
|
||||
$price,
|
||||
$nonce,
|
||||
$signature)
|
||||
|
||||
{
|
||||
$params = array(
|
||||
'c' => 'BcService',
|
||||
'a' => 'buyBoxVerifySignature',
|
||||
'type' => $type,
|
||||
'paymentTokenAddress' => $paymentTokenAddress,
|
||||
'price' => $price,
|
||||
'nonce' => $nonce,
|
||||
'signature' => $signature
|
||||
);
|
||||
$url = $this->getWeb3ServiceUrl();
|
||||
$response = '';
|
||||
if (!phpcommon\HttpClient::get
|
||||
($url,
|
||||
$params,
|
||||
$response)) {
|
||||
phpcommon\sendError(500, 'server internal error');
|
||||
die();
|
||||
return;
|
||||
}
|
||||
error_log(json_encode(array(
|
||||
'_REQUEST' => $_REQUEST,
|
||||
'params' => $params,
|
||||
'response' => $response
|
||||
)));
|
||||
$data = json_decode($response, true);
|
||||
if (getXVal($data, 'errcode', 0) != 0) {
|
||||
phpcommon\sendError(1, 'Signature verification failed');
|
||||
die();
|
||||
return;
|
||||
} else {
|
||||
$recovered = getXVal($data, 'recovered', '');
|
||||
if (!phpcommon\isSameAddress($recovered, $buyerAddress)) {
|
||||
phpcommon\sendError(1, 'Signature verification failed');
|
||||
die();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getNonce()
|
||||
{
|
||||
$account = getReqVal('account', '');
|
||||
@ -517,7 +470,7 @@ class MarketController extends BaseController {
|
||||
'nonce' => $nonce,
|
||||
'signature' => $signature
|
||||
);
|
||||
$url = $this->getWeb3ServiceUrl();
|
||||
$url = MarketService::getWeb3ServiceUrl();
|
||||
$response = '';
|
||||
if (!phpcommon\HttpClient::get
|
||||
($url,
|
||||
@ -551,18 +504,4 @@ class MarketController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
private function getWeb3ServiceUrl()
|
||||
{
|
||||
$web3ServiceCluster = require_once('../config/web3service.cluster.php');
|
||||
if (empty($web3ServiceCluster)) {
|
||||
if (SERVER_ENV == _TEST) {
|
||||
return 'http://127.0.0.1:7671/webapp/index.php';
|
||||
}
|
||||
myself()->_rspErr(1, 'server internal errror');
|
||||
die();
|
||||
return;
|
||||
}
|
||||
return $web3ServiceCluster[rand() % count($web3ServiceCluster)];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class MarketService extends BaseService {
|
||||
'nonce' => $nonce,
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
);
|
||||
$data['sign'] = md5(TOKEN_SALT .
|
||||
$data['sign'] = md5(self::TOKEN_SALT .
|
||||
$data['account'] .
|
||||
$data['rand'] .
|
||||
$data['nonce'] .
|
||||
@ -43,4 +43,57 @@ class MarketService extends BaseService {
|
||||
return base64_encode(json_encode($data));
|
||||
}
|
||||
|
||||
public static function buyBoxVerifySignature($buyerAddress,
|
||||
$type,
|
||||
$paymentTokenAddress,
|
||||
$price,
|
||||
$nonce,
|
||||
$signature)
|
||||
|
||||
{
|
||||
$params = array(
|
||||
'c' => 'BcService',
|
||||
'a' => 'buyBoxVerifySignature',
|
||||
'type' => $type,
|
||||
'paymentTokenAddress' => $paymentTokenAddress,
|
||||
'price' => $price,
|
||||
'nonce' => $nonce,
|
||||
'signature' => $signature
|
||||
);
|
||||
$url = self::getWeb3ServiceUrl();
|
||||
$response = '';
|
||||
if (!phpcommon\HttpClient::get
|
||||
($url,
|
||||
$params,
|
||||
$response)) {
|
||||
phpcommon\sendError(500, 'server internal error');
|
||||
die();
|
||||
return;
|
||||
}
|
||||
error_log(json_encode(array(
|
||||
'_REQUEST' => $_REQUEST,
|
||||
'params' => $params,
|
||||
'response' => $response
|
||||
)));
|
||||
$data = json_decode($response, true);
|
||||
if (getXVal($data, 'errcode', 0) != 0) {
|
||||
phpcommon\sendError(1, 'Signature verification failed');
|
||||
die();
|
||||
return;
|
||||
} else {
|
||||
$recovered = getXVal($data, 'recovered', '');
|
||||
if (!phpcommon\isSameAddress($recovered, $buyerAddress)) {
|
||||
phpcommon\sendError(1, 'Signature verification failed');
|
||||
die();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getWeb3ServiceUrl()
|
||||
{
|
||||
$web3ServiceCluster = require_once('../config/web3service.cluster.php');
|
||||
return $web3ServiceCluster[rand() % count($web3ServiceCluster)];
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user