From b41341a545139c437b2dbc6ffbac29deed57a086 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 21 Feb 2022 19:38:12 +0800 Subject: [PATCH] 1 --- doc/Market.py | 5 +- third_party/phpcommon | 2 +- webapp/controller/MarketController.class.php | 106 +++++++++++++++++++ 3 files changed, 111 insertions(+), 2 deletions(-) diff --git a/doc/Market.py b/doc/Market.py index 62a89f30..c5361288 100644 --- a/doc/Market.py +++ b/doc/Market.py @@ -13,6 +13,7 @@ class Market(object): 'url': 'webapp/index.php?c=Market&a=getNonce', 'params': [ ['account', '', '钱包账号'], + ['net_id', '', '网络id'], ], 'response': [ _common.RspHead(), @@ -26,8 +27,10 @@ class Market(object): 'url': 'webapp/index.php?c=Market&a=auth', 'params': [ ['account', '', '钱包账号'], - ['data', '', '待签名的原始数据(注意给的是完整的待签名数据),格式{name:"Auth", version: "1", nonce:"", signer:""}'], + ['version', '', '版本号'], + ['nonce', '', 'nonce'], ['signature', '', '签名'], + ['net_id', '', '网络id'], ], 'response': [ _common.RspHead(), diff --git a/third_party/phpcommon b/third_party/phpcommon index eeeac902..996e3904 160000 --- a/third_party/phpcommon +++ b/third_party/phpcommon @@ -1 +1 @@ -Subproject commit eeeac90264e4cd3d4de575d9ad504cacd85cb288 +Subproject commit 996e3904f872001de8fd3080ba54607b09f3e824 diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 66533a62..977a8700 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -199,6 +199,13 @@ class MarketController extends BaseController { $signature = getReqVal('signature', ''); $gameId = 2006; $funcId = 1; + $this->buyBoxVerifySignature( + $buyerAddress, + $type, + $paymentTokenAddress, + $price, + $nonce, + $signature); $batchIdx = 0; $idx = 0; @@ -404,4 +411,103 @@ 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 = 'http://192.168.100.39:7671/webapp/index.php'; + $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() + { + $nonce = myself()->_getNowTime(); + myself()->_rspData(array( + 'nonce' => $nonce + )); + } + + public function auth() + { + $version = getReqVal('version', ''); + $nonce = getReqVal('nonce', ''); + $signature = getReqVal('signature', ''); + $params = array( + 'c' => 'BcService', + 'a' => 'authVerifySignature', + 'version' => $version, + 'nonce' => $nonce, + 'signature' => $signature + ); + $url = 'http://192.168.100.39:7671/webapp/index.php'; + $response = ''; + if (!phpcommon\HttpClient::get + ($url, + $params, + $response)) { + myself()->_rspErr(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) { + myself()->_rspErr(1, 'Signature verification failed'); + die(); + return; + } else { + $recovered = getXVal($data, 'recovered', ''); + if (!phpcommon\isSameAddress($recovered, $buyerAddress)) { + myself()->_rspErr(1, 'Signature verification failed'); + die(); + return; + } else { + myself()->_rspOk(); + } + } + } + }