| | |
| | | // 模拟浏览器 |
| | | String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36"; |
| | | try { |
| | | URL url = new URL("https://otc-api-hk.eiijo.cn/v1/data/config/purchase-price?coinId=2¤cyId=1&matchType=0"); |
| | | URL url = new URL("https://freecurrencyrates.com/api/action.php?s=fcr&iso=USD-CNH&f=USD&v=1&do=cvals&ln=zh-hans"); |
| | | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| | | connection.setRequestMethod("GET"); |
| | | connection.setReadTimeout(30000); |
| | |
| | | } |
| | | reader.close(); |
| | | result = sbf.toString(); |
| | | |
| | | JSONObject jsonObject = (JSONObject) JSONObject.parse(result); |
| | | String code = jsonObject.getString("code"); |
| | | if ("200".equals(code)) { |
| | | JSONObject jsonData = (JSONObject) jsonObject.get("data"); |
| | | cnyUsdtExchangeDao.updateUsdt(BigDecimal.valueOf(jsonData.getDouble("price"))); |
| | | } |
| | | // String code = jsonObject.getString("code"); |
| | | // if ("200".equals(code)) { |
| | | // JSONObject jsonData = (JSONObject) jsonObject.get("data"); |
| | | // cnyUsdtExchangeDao.updateUsdt(BigDecimal.valueOf(jsonData.getDouble("price"))); |
| | | // } |
| | | cnyUsdtExchangeDao.updateUsdt(new BigDecimal(jsonObject.getString("CNH"))); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |