From 53e9c94683b322490760efadfa8529b798f30a6b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 19 Jun 2023 13:07:49 +0800 Subject: [PATCH] 1 --- third_party/phpcommon | 2 +- webapp/services/BlockChainService.php | 60 +++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 webapp/services/BlockChainService.php diff --git a/third_party/phpcommon b/third_party/phpcommon index e658ed5f..a071cc2b 160000 --- a/third_party/phpcommon +++ b/third_party/phpcommon @@ -1 +1 @@ -Subproject commit e658ed5f7e4112801e59206f6da6f01db7131cd1 +Subproject commit a071cc2b7fcc2e5c9597d29d07378b4f29ace591 diff --git a/webapp/services/BlockChainService.php b/webapp/services/BlockChainService.php new file mode 100644 index 00000000..fea3a40f --- /dev/null +++ b/webapp/services/BlockChainService.php @@ -0,0 +1,60 @@ + 'GameItemMall', + 'a' => 'buy', + 'account' => $account, + 'price' => $price, + ); + { + $url = self::getWeb3ServiceUrl(); + $response = ''; + if (!phpcommon\HttpClient::get + ($url, + $params, + $response)) { + myself()->_rspErr(500, 'server internal error'); + die(); + return; + } + error_log($response); + $rspObj = json_decode($response, true); + if ($rspObj['errcode'] == 0) { + $transId = $rspObj['trans_id']; + Transaction::add( + $transId, + Transaction::MINT_721_ACTION_TYPE, + $tokenId, + $tokenType, + $itemUniId, + $itemId, + 1 + ); + myself()->_rspData(array( + 'trans_id' => $transId, + 'params' => $rspObj['params'] + )); + } else { + myself()->_rspErr(500, 'server internal error'); + die(); + return; + } + } + } + + private static function getWeb3ServiceUrl() + { + if (SERVER_ENV == _TEST) { + return 'http://127.0.0.1:7672/webapp/index.php'; + } + $web3ServiceCluster = require_once('../config/web3service.cluster.php'); + return $web3ServiceCluster[rand() % count($web3ServiceCluster)]; + } + +}