HEX
Server: nginx/1.24.0
System: Linux prod-btpayments-io 6.14.0-1018-aws #18~24.04.1-Ubuntu SMP Mon Nov 24 19:46:27 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.3.19
Disabled: NONE
Upload Files
File: /var/www/BtMiners/BtMiners-store/json/get_json.php
<?php
// return;
// $btApp=false;
// if (!empty($_GET['BTAPP'])&&!empty($_GET['timestamp'])) {
//     $btKey='mejifThl5oDbPukaVeaSIB5k1QPGVFTruDYz5DXRKDAF7S9it';
//     $btSign=md5($btKey.$_GET['timestamp']);
//     if ($btSign===$_GET['BTAPP']) {
//         $btApp=true;
//     }
// }
// if (!$btApp) {
//     return;
// }
if (strpos($_SERVER['REQUEST_URI'], 'get_coins_markets') === false){
    return;
}
// function limitExecution() {
//     $filename = 'last_execution.txt';
//     if (file_exists($filename)) {
//         $lastExecution = file_get_contents($filename);
//         if (time() - $lastExecution < 60) {
//             // echo "距离上次执行不足一分钟,禁止执行。";
//             return false;
//         }
//     }
//     file_put_contents($filename, time(),  LOCK_EX);
//     return true;
// }

$request=$_GET;
$lastData=[];
header('Content-type:application/json');

// 读取数据json文件 
$filename = 'recommend_coins_markets.json';
$json = file_get_contents($filename);
$recommend_coins_markets = json_decode($json,true);

$result=[];
$result['time'] =  time();
// $result['cache'] = $lastData['cache'];
$result['page'] =  1 ;
$result['json_cache'] =  1 ;
// 推荐币种
if ( isset( $request['recommend']) ) {
    $data = $recommend_coins_markets;
    if ( $data ) {
        $result['per_page'] = $result['total'] = count($data);
        $result['data'] = array_values($data);
        echo json_encode($result);exit;
    }
}

$filename = 'coins_markets.json';
$json = file_get_contents($filename);
$coinsMarkets = json_decode($json,true);
if (!empty($recommend_coins_markets)) {
    $coinsMarkets = array_column($coinsMarkets,null,'id');
    $recommend_coins_markets = array_column($recommend_coins_markets, null,'id');
    $coinsMarkets = array_merge($coinsMarkets,$recommend_coins_markets);
    $coinsMarkets = array_values($coinsMarkets);
}
// 已添加自选币种
if ( isset($request['coins']) ) {
    $coins = explode(',', $request['coins']);
    $coinsMarkets = array_column($coinsMarkets,null,'id');
    $data=[];
    foreach ($coins as $key => $value) {
        $data[]=empty($coinsMarkets[$value])?[]:$coinsMarkets[$value];
    }

    $result['per_page'] = $result['total'] = count($data);
    $result['data'] = array_values($data);
	echo json_encode($result);exit;
}

// 自选搜索
if ( isset($request['keywords']) ) {
    // 搜索字符转小写
    $keywords = strtolower($request['keywords']);
    $data = array_filter($coinsMarkets, function($item) use ($keywords) {
        // 与symbol、name、id进行匹配
        return  strpos(strtolower($item['symbol']), $keywords) !== false ||
            strpos(strtolower($item['name']), $keywords)   !== false ||
            strpos(strtolower($item['id']), $keywords)     !== false;
    });
    $result['per_page'] = $result['total'] = count($data);
    $result['data'] = array_values($data);
	echo json_encode($result);exit;
}

// 币种市场信息,按分页查询
$page = isset($request["page"]) ? $request["page"]  : 1;
$perPage = isset($request["per_page"]) ? $request["per_page"] : 261;

$result['page'] = intval($page);
$result['per_page'] = intval($perPage);
$result['total'] = count($coinsMarkets);
$result['data'] = array_slice($coinsMarkets, ($page - 1) * $perPage, $perPage);
$result['data'] = array_values($result['data']);
echo json_encode($result);exit;

// $url="https://bt-miners.com/wp-json/api/flutter_secials/get_coins_markets?BTAPP=bfdc711cb398c13f874dcc7c3dc97283&timestamp=1731493664373&page=1&per_page=20";

// $url = "https://api.coingecko.com/api/v3/coins/markets";
function get_data(){
	$lastData=[];
	$recommend_coins = "zilliqa,helium,zcash,ethereum-classic,optimism,dash,polkadot,handshake,siacoin,iron-fish,kaspa,litecoin,ergo,filecoin,aptos,nervos-network,kadena,monero,dogecoin,grin,lbry-credits,siaprime-coin,alephium,bellscoin,radiant,aleo,mimblewimblecoin";

	$url = "https://api.coingecko.com/api/v3/coins/markets?locale=en&order=market_cap_desc&vs_currency=usd&price_change_percentage=24h&page=1&per_page=250&sparkline=true";
	// 设置默认参数
	$_args = array(
	    'headers' => [
		    'accept' => 'application/json',
		],
	    'timeout' => 5,
	    'sslverify' => true,
	    'user-agent' => 'WordPress/6.2.2',
	);
	$res=custom_remote_get($url, $_args);
	if (!empty($res['body'])) {
		$json=$res['body'];
        $coins_markets_arr = json_decode($json,true);
        foreach ($coins_markets_arr as $key => $item) {
            // 从URL中提取文件名
            $filename = basename(parse_url($item['image'], PHP_URL_PATH));
            // 获取文件的扩展名
            $extension = pathinfo($filename, PATHINFO_EXTENSION);
            // 添加图标字段
            $coins_markets_arr[$key]['icon'] = strtolower($item['id'] . '.' . $extension);
        }
		// 数据写入json文件 
    	$filename = 'coins_markets.json';
		file_put_contents($filename, $json,  LOCK_EX);
		$lastData['coins_markets'] = $coins_markets_arr;
	}else{
		// 读取数据json文件 
		$filename = 'coins_markets.json';
		$json = file_get_contents($filename);
		$lastData['coins_markets'] = json_decode($json,true);
	}
	
	$url_recommend = $url."&ids=".$recommend_coins;
	$res_recommend=custom_remote_get($url_recommend, $_args);
	if (!empty($res_recommend['body'])) {
		$json=$res_recommend['body'];
        $coins_markets_recommend_arr = json_decode($json,true);
        foreach ($coins_markets_recommend_arr as $key => $item) {
            // 从URL中提取文件名
            $filename = basename(parse_url($item['image'], PHP_URL_PATH));
            // 获取文件的扩展名
            $extension = pathinfo($filename, PATHINFO_EXTENSION);
            // 添加图标字段
            $coins_markets_recommend_arr[$key]['icon'] = strtolower($item['id'] . '.' . $extension);
        }
		// 数据写入json文件 
    	$filename = 'recommend_coins_markets.json';
		file_put_contents($filename, $json,  LOCK_EX);
		$lastData['recommend_coins_markets'] = $coins_markets_recommend_arr;
	}else{
		// 读取数据json文件 
		$filename = 'recommend_coins_markets.json';
		$json = file_get_contents($filename);
		$lastData['recommend_coins_markets'] = json_decode($json,true);
	}

	return $lastData;
}
function custom_remote_get($url, $args = array()) {
    // 在这里实现类似于wp_remote_get的功能
    $response = array();

    // 初始化一个cURL会话
    $ch = curl_init();

    // 设置请求的URL
    curl_setopt($ch, CURLOPT_URL, $url);

    // 设置请求类型为GET
    curl_setopt($ch, CURLOPT_HTTPGET, true);

    // 设置是否返回响应内容,设置为true表示返回
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // 设置请求头
    if (!empty($args['headers'])) {
        curl_setopt($ch, CURLOPT_HTTPHEADER, $args['headers']);
    }

    // 设置超时时间
    curl_setopt($ch, CURLOPT_TIMEOUT, $args['timeout']);

    // 设置是否验证SSL证书
    if ($args['sslverify'] === false) {
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    }

    // 设置用户代理
    curl_setopt($ch, CURLOPT_USERAGENT, $args['user-agent']);

    // 发送请求并获取响应
    $response['body'] = curl_exec($ch);

    // 检查是否有错误发生
    if (curl_error($ch)) {
        $response['error'] = curl_error($ch);
    }

    // 关闭cURL会话
    curl_close($ch);

    return $response;
}