Browse Source

Merge remote-tracking branch 'origin/master'

kirin 6 months ago
parent
commit
41efb466c8
1 changed files with 81 additions and 68 deletions
  1. 81 68
      application/api/controller/Pay.php

+ 81 - 68
application/api/controller/Pay.php

@@ -933,14 +933,23 @@ class Pay extends Api
             $user_address = Db::name('user_usdt_address')->where('id', $v['uid'])->find();
             $user_address = Db::name('user_usdt_address')->where('id', $v['uid'])->find();
             if ($v['recharge_type'] == 'trx'){
             if ($v['recharge_type'] == 'trx'){
                 $service = TronService::instance('usdt');
                 $service = TronService::instance('usdt');
-                $info=$service->getTransfer($user_address['trx_address'], $v['add_time']);
-                var_dump($info);die();
+                $info=$service->getTransfer($user_address['trx_address'], $user_address['last_time']);
+
             }elseif ($v['recharge_type'] == 'bsc'){
             }elseif ($v['recharge_type'] == 'bsc'){
                 $service = Web3Service::instance('bsc', 'usdt', '');
                 $service = Web3Service::instance('bsc', 'usdt', '');
 //                $info =$service->getLastTransfer([], [$user_address['bsc_address']], $v['add_time']);
 //                $info =$service->getLastTransfer([], [$user_address['bsc_address']], $v['add_time']);
-                $info =$service->getLastTransfer([], [0x8f5f8daC38461E5b1A6b230D30433f8A593CCD57], 1748315888);
-                var_dump($info);die();
+//                $info =$service->getLastTransfer([], ['0x8f5f8daC38461E5b1A6b230D30433f8A593CCD57'], 1748315888);
+                $info =$service->getLastTransfer([], [$user_address['bsc_address']], $user_address['last_time']);
+                foreach ($info as $k2 => $v2){
+                    $value = $v2->params['value']->toString();
+
+                    $value2 = bcdiv($value, bcpow(10, get_token_info('bsc',$v2['token'], 'decimal')), 12);
+
+                }
             }
             }
+
+
+            sleep(10);
         }
         }
     }
     }
     public function test(){
     public function test(){
@@ -972,75 +981,79 @@ class Pay extends Api
 //        } else {
 //        } else {
 //            echo "未找到符合条件的转账记录";
 //            echo "未找到符合条件的转账记录";
 //        }
 //        }
+
         foreach ($info as $k => $v){
         foreach ($info as $k => $v){
             $value = $v->params['value']->toString();
             $value = $v->params['value']->toString();
             var_dump($value);
             var_dump($value);
-            $value = bcdiv($value, bcpow(10, get_token_info('bsc',$v['token'], 'decimal')), 12);
-            var_dump($value);die();
-        }
-
-        var_dump($info);die();
-
-    }
-    function paginatedTransferQuery($service, $toAddress, $targetTimestamp) {
-        $BPS = 3; // BSC每秒区块数
-        $currentBlock = intval(time() * $BPS);
-        $startBlock = intval($targetTimestamp * $BPS);
-        $pageSize = 500;
-        $results = [];
-        $attempts = 0;
-
-        while ($startBlock <= $currentBlock && $attempts < 50) {
-            $endBlock = min($startBlock + $pageSize - 1, $currentBlock);
-
-            try {
-                $transfers = $service->getLastTransfer(
-                    [],
-                    [$toAddress],
-                    0,
-                    $startBlock,
-                    $endBlock
-                );
-
-                // 只有当有结果时才处理
-                if (!empty($transfers)) {
-                    $results = array_merge($results, $transfers);
-
-                    // 检查是否达到目标时间
-                    $newest = end($transfers);
-                    reset($transfers); // 重置数组指针
-
-                    // 确保有 timestamp 属性再检查
-                    if (property_exists($newest, 'timestamp') && $newest->timestamp >= time() - 60) {
-                        break; // 已查询到最新区块
-                    }
-                }
+            $transactionHash = $v->transactionHash;
+            var_dump($transactionHash);
 
 
-                // 成功时增加分页大小
-                $pageSize = min(5000, $pageSize * 2);
-                $startBlock = $endBlock + 1;
-
-            } catch (RequestException $e) {
-                if (strpos($e->getMessage(), '413') !== false) {
-                    $pageSize = max(100, $pageSize / 2);
-                    $attempts++;
-                    continue;
-                }
-                throw $e;
-            } catch (\Throwable $e) {
-                // 捕获所有类型错误
-                error_log("查询错误: " . $e->getMessage());
-                $pageSize = max(100, $pageSize / 2);
-                $attempts++;
-                continue;
-            }
-
-            usleep(100000);
-            $attempts++;
+//            $value = bcdiv($value, bcpow(10, get_token_info('bsc',$v->token, 'decimal')), 12);  //把后面的0去掉
+            var_dump($v->token);
         }
         }
 
 
-        return array_filter($results, function($t) use ($targetTimestamp) {
-            return property_exists($t, 'timestamp') && $t->timestamp >= $targetTimestamp;
-        });
+        die();
+
     }
     }
+//    function paginatedTransferQuery($service, $toAddress, $targetTimestamp) {
+//        $BPS = 3; // BSC每秒区块数
+//        $currentBlock = intval(time() * $BPS);
+//        $startBlock = intval($targetTimestamp * $BPS);
+//        $pageSize = 500;
+//        $results = [];
+//        $attempts = 0;
+//
+//        while ($startBlock <= $currentBlock && $attempts < 50) {
+//            $endBlock = min($startBlock + $pageSize - 1, $currentBlock);
+//
+//            try {
+//                $transfers = $service->getLastTransfer(
+//                    [],
+//                    [$toAddress],
+//                    0,
+//                    $startBlock,
+//                    $endBlock
+//                );
+//
+//                // 只有当有结果时才处理
+//                if (!empty($transfers)) {
+//                    $results = array_merge($results, $transfers);
+//
+//                    // 检查是否达到目标时间
+//                    $newest = end($transfers);
+//                    reset($transfers); // 重置数组指针
+//
+//                    // 确保有 timestamp 属性再检查
+//                    if (property_exists($newest, 'timestamp') && $newest->timestamp >= time() - 60) {
+//                        break; // 已查询到最新区块
+//                    }
+//                }
+//
+//                // 成功时增加分页大小
+//                $pageSize = min(5000, $pageSize * 2);
+//                $startBlock = $endBlock + 1;
+//
+//            } catch (RequestException $e) {
+//                if (strpos($e->getMessage(), '413') !== false) {
+//                    $pageSize = max(100, $pageSize / 2);
+//                    $attempts++;
+//                    continue;
+//                }
+//                throw $e;
+//            } catch (\Throwable $e) {
+//                // 捕获所有类型错误
+//                error_log("查询错误: " . $e->getMessage());
+//                $pageSize = max(100, $pageSize / 2);
+//                $attempts++;
+//                continue;
+//            }
+//
+//            usleep(100000);
+//            $attempts++;
+//        }
+//
+//        return array_filter($results, function($t) use ($targetTimestamp) {
+//            return property_exists($t, 'timestamp') && $t->timestamp >= $targetTimestamp;
+//        });
+//    }
 }
 }