|
|
@@ -43,7 +43,7 @@ class UsdtWalletService extends BaseService
|
|
|
protected $apiUrl = '';
|
|
|
protected $config = [];
|
|
|
protected $apiUrls = [
|
|
|
- 'usdt_trx2_transfer_log' => '/v1/accounts/%s/transactions/trc20?limit=%s&only_to=%s&only_confirmed=true&contract_address=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'
|
|
|
+ 'usdt_trx2_transfer_log' => '/v1/accounts/%s/transactions/trc20?limit=%s&only_to=%s&only_from=%s&only_confirmed=true&contract_address=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'
|
|
|
];
|
|
|
|
|
|
/**
|
|
|
@@ -183,21 +183,21 @@ class UsdtWalletService extends BaseService
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 监听转账记录并进账
|
|
|
+ * 监听USDT-TRC2.0转账记录并进账
|
|
|
* @param $userId 用户ID
|
|
|
* @param $address 用户钱包地址
|
|
|
* @param int $coinType 币种:1-usdt
|
|
|
* @param int $limit 转账记录数,最新的
|
|
|
* @return array|false
|
|
|
*/
|
|
|
- public function getTransferInLog($userId, $address, $coinType= 1, $limit = 50)
|
|
|
+ public function getTrc20TransferLog($userId, $address, $coinType= 1, $limit = 50)
|
|
|
{
|
|
|
if($userId<=0 || empty($address)){
|
|
|
$this->error = '1013';
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- $url = sprintf($this->apiUrls['usdt_trx2_transfer_log'], $address, $limit, 'true');
|
|
|
+ $url = sprintf($this->apiUrls['usdt_trx2_transfer_log'], $address, $limit, 'true','false');
|
|
|
$headers = ["TRON-PRO-API-KEY"=> $this->config['tron_api_key']];
|
|
|
$result = curl_get($this->config['tron_api_url'] . $url, [], $headers, 10);
|
|
|
$result = $result? json_decode($result, true) : [];
|
|
|
@@ -242,6 +242,67 @@ class UsdtWalletService extends BaseService
|
|
|
return $logs;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 监听USDT-TRC2.0充值记录并进账
|
|
|
+ * @param $userId 用户ID
|
|
|
+ * @param $address 用户钱包地址
|
|
|
+ * @param int $coinType 币种:1-usdt
|
|
|
+ * @param int $limit 转账记录数,最新的
|
|
|
+ * @return array|false
|
|
|
+ */
|
|
|
+ public function getTrc20RechargeLog($userId, $address, $coinType= 1, $limit = 50)
|
|
|
+ {
|
|
|
+ if($userId<=0 || empty($address)){
|
|
|
+ $this->error = '1013';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $url = sprintf($this->apiUrls['usdt_trx2_transfer_log'], $address, $limit, 'false','true');
|
|
|
+ $headers = ["TRON-PRO-API-KEY"=> $this->config['tron_api_key']];
|
|
|
+ $result = curl_get($this->config['tron_api_url'] . $url, [], $headers, 10);
|
|
|
+ $result = $result? json_decode($result, true) : [];
|
|
|
+ $datas = isset($result['data']) ? $result['data'] : [];
|
|
|
+ $status = isset($result['success']) ? $result['success'] : '';
|
|
|
+ if ($status != true || empty($datas)) {
|
|
|
+ $this->error = '2207';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ $logs = [];
|
|
|
+ foreach ($datas as $v) {
|
|
|
+ $amount = isset($v['value'])? intval($v['value']) : 0;
|
|
|
+ $amount = moneyFormat($amount/1000000, 6);
|
|
|
+ $time = isset($v['block_timestamp'])? intval($v['block_timestamp']) : 0;
|
|
|
+ $txid = isset($v['transaction_id'])? $v['transaction_id'] : '';
|
|
|
+ if(!CoinLogService::make()->checkExists('txid', $txid)){
|
|
|
+ $balance = $this->memberModel->where(['id'=> $userId])->value('usdt_num');
|
|
|
+ $log = [
|
|
|
+ 'user_id'=> $userId,
|
|
|
+ 'change_type'=> 2,
|
|
|
+ 'coin_type'=> $coinType,
|
|
|
+ 'contact_type'=> 1,
|
|
|
+ 'order_no'=> get_order_num('OT'),
|
|
|
+ 'from_address'=> isset($v['from'])? $v['from'] : '',
|
|
|
+ 'to_address'=> isset($v['to'])? $v['to'] : '',
|
|
|
+ 'txid'=> $txid,
|
|
|
+ 'num'=> $amount,
|
|
|
+ 'balance'=> $balance,
|
|
|
+ 'create_time'=> intval($time/1000),
|
|
|
+ 'status'=> 1,
|
|
|
+ 'mark'=> 1,
|
|
|
+ ];
|
|
|
+
|
|
|
+ if($this->memberModel->where(['id'=> $userId])->decrement('usdt_num', $amount)){
|
|
|
+ $logs[] = $log;
|
|
|
+ $this->coinModel->insert($log);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $logs;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param $address
|
|
|
* @return false|float|string
|