Commit add65b5c authored by rlgy's avatar rlgy

爬取交易状态DCR,BTY

parent fa6be74b
......@@ -21,11 +21,6 @@ class BrowerBusiness
*/
public static function getTransStatus(string $name, string $txhash)
{
$status = BrowerFactory::getInstance($name)->getStatus($txhash);
if ($status) {
return ['code' => 0, 'status' => $status];
} else {
return [];
}
return $status = BrowerFactory::getInstance($name)->getStatus($txhash);
}
}
\ No newline at end of file
......@@ -10,8 +10,27 @@ namespace common\service\brower;
class Brower implements BrowerInterface
{
const TRANS_OK = 1;//交易成功
const TRANS_FAIL = 2;//交易失败
const TRANS_PADDING = 3;//交易状态未知
const ERROR = 4;//接口返回错误
public static $msg = [
self::TRANS_OK => 'SUCCEED',
self::TRANS_FAIL => 'FAIL',
self::TRANS_PADDING => 'UNKNOW',
self::ERROR => 'ERROR',
];
public function getStatus(string $txhash)
{
return false;
return ['code' => self::ERROR, 'msg' => 'Coin not supported!'];
}
public function StatusReturn($code, $msg = '')
{
if ($msg) {
return ['code' => $code, 'msg' => $msg];
}
return ['code' => $code, 'msg' => self::$msg[$code]];
}
}
\ No newline at end of file
......@@ -18,7 +18,7 @@ interface BrowerInterface
{
/**
* @param string $txhash
* @return mixed|string|boolean 交易状态
* @return array 交易状态
*/
public function getStatus(string $txhash);
}
\ No newline at end of file
......@@ -12,18 +12,18 @@ use common\helpers\Curl;
class BtcBrower extends Brower
{
private $base_uri = 'https://btc.com/';
private $base_uri = 'https://chain.api.btc.com/v3/tx/';
public function getStatus(string $txhash)
{
$uri = $this->base_uri . $txhash;
$content = (new Curl())->get($uri, true);
$content = (new Curl())->get($uri, false);
if ($content) {
preg_match_all('/<dt> Confirmations<\/dt>(.*?)<dd>(.*?)<\/dd>/is', $content, $matchs);
if (isset($matchs[2][0])) {
return (int)trim($matchs[2][0]);
if ($content['err_no']) {
return $this->StatusReturn(self::ERROR, $content['err_msg']);
}
return $this->StatusReturn(self::TRANS_OK);
}
return 0;
return $this->StatusReturn(self::ERROR);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-7-13
* Time: 下午3:00
*/
namespace common\service\brower;
use common\helpers\Curl;
class BtyBrower extends Brower
{
private $base_uri = 'https://mainnet.bityuan.com/api';
public function getStatus(string $txhash)
{
$ch = new Curl();
$ch->setHeader('Content-Type', 'application/json');
$post = [
'jsonrpc' => '2.0',
'id' => 1,
'method' => 'Chain33.QueryTransaction',
'params' => [['hash' => $txhash]]
];
$post = json_encode($post);
$ch->setOption(CURLOPT_POSTFIELDS, $post);
$result = $ch->post($this->base_uri, false);
if ($result) {
if ($result['result']) {
return $this->StatusReturn(self::TRANS_OK);
} elseif ($result['error']) {
return $this->StatusReturn(self::ERROR, $result['error']);
}
}
return $this->StatusReturn(self::ERROR);
}
}
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: rlgyzhcn
* Date: 18-7-13
* Time: 下午4:33
*/
namespace common\service\brower;
use common\helpers\Curl;
class DcrBrower extends Brower
{
private $base_uri = 'https://mainnet.decred.org/api/tx/';
public function getStatus(string $txhash)
{
$uri = $this->base_uri . $txhash;
$content = (new Curl())->get($uri, true);
$result = json_decode($content, true);
if ($result) {
if (isset($result['confirmations']) && $result['confirmations'] > 0) {
return $this->StatusReturn(self::TRANS_OK);
} else {
return $this->StatusReturn(self::TRANS_PADDING);
}
}
return $this->StatusReturn(self::ERROR, $content);
}
}
\ No newline at end of file
......@@ -21,11 +21,11 @@ class EthBrower extends Brower
$content = $ch->get($uri, true);
if ($content) {
if (strpos($content, 'Success') !== false) {
return 'Success';
return $this->StatusReturn(self::TRANS_OK);
} elseif (strpos($content, 'Fail') !== false) {
return 'Fail';
return $this->StatusReturn(self::TRANS_FAIL);
}
}
return false;
return $this->StatusReturn(self::ERROR, 'txHash not exists');
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment