post(config('app.tg_url'), [ 'headers' => [ 'User-Agent' => self::USER_AGENT, 'Content-Type' => 'application/json', 'Token' => $token, ], 'json' => [ 'groupid' => $groupid, 'msg' => $msg, ] ]); // In fact, we dont care the result. return true; } /** * Price of Coin in USD. * * API Sample Return: * * { * "data": { * "symbol": "ETH", * "id": "1027", * "name": "Ethereum", * "amount": 1, * "last_updated": 1653295260000, * "quote": [ * { * "cryptoId": 2781, * "symbol": "USD", * "price": 2057.2269068671376, * "lastUpdated": 1653295336000 * } * ] * }, * "status": { * "timestamp": "2022-05-23T08:43:37.410Z", * "error_code": "0", * "error_message": "SUCCESS", * "elapsed": "1", * "credit_count": 0 * } * } * * @param {integer} id: id of coin.(CoinMarketCap API) * @return {float} */ public static function getPrice($id): float { $base_url = 'https://api.coinmarketcap.com/data-api/v3/tools/price-conversion'; $amount = 1; $convert_id = 2781; // USD $url = $base_url . "?amount=$amount&convert_id=$convert_id&id=$id"; $hc = new \GuzzleHttp\Client(); $resp = $hc->get($url, [ 'headers' => [ 'User-Agent' => self::USER_AGENT, ] ]); if ($resp->getStatusCode() == 200 && $body = $resp->getBody()) { $body->seek(0); $data = $body->read(1024); $d = json_decode($data, true); if ( $d['status'] && $d['status']['error_code'] == 0 && $d['data'] && $d['data']['id'] == $id && $d['data']['quote'] ) { return $d['data']['quote'][0]['price'] ?? 0.0; } } return 0.0; } /** * Get Price of ETH in USD. */ public static function getETHPrice(): float { return self::getPrice(self::ID_ETH); } public static function getUSDTBalance($address): float { /* { "code":1, "msg":"成功", "data":[ { "network":"ETH", "hash":"0xdac17f958d2ee523a2206206994597c13d831ec7", "tokenInfo":{ "h":"0xdac17f958d2ee523a2206206994597c13d831ec7", "f":"Tether USD", "s":"USDT", "d":"6" }, "transferCnt":2, "balance":"17095417" } ] } */ $data = file_get_contents('https://eth.tokenview.com/api/eth/address/tokenbalance/' . strtolower($address)); $data_array = json_decode($data, true); if ($data_array['code'] == 1) { foreach ($data_array['data'] as $v) { if ($v['hash'] == self::ADDR_USDT_ERC20) { return $v['balance'] / pow(10, $v['tokenInfo']['d']); } } } return 0.0; } }