Java Code Examples for cn.hutool.http.HttpUtil#get()
The following examples show how to use
cn.hutool.http.HttpUtil#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CityStats.java From zuihou-admin-cloud with Apache License 2.0 | 6 votes |
public static void parseVillagetr(String url, Area countyArea) { String htmlStr = HttpUtil.get(url, CHARSET); Document document = Jsoup.parse(htmlStr); Elements trs = document.getElementsByClass("villagetr"); List<Area> counties = new LinkedList<Area>(); int sort = 1; for (Element tr : trs) { Elements tds = tr.getElementsByTag("td"); if (tds == null || tds.size() != 3) { continue; } String villagetrCode = tds.get(0).text(); String villagetrName = tds.get(2).text(); Area villagetrArea = Area.builder().code(villagetrCode).label(villagetrName).source(url) .sortValue(sort++).level(new RemoteData<>("VILLAGETR")).fullName(countyArea.getFullName() + villagetrName) .build(); StaticLog.info(" 村级数据: {} ", villagetrArea); counties.add(villagetrArea); } countyArea.setChildren(counties); }
Example 2
Source File: AboutListener.java From WePush with MIT License | 6 votes |
/** * 初始化二维码 */ public static void initQrCode() { String qrCodeContent = HttpUtil.get(UiConsts.QR_CODE_URL); if (StringUtils.isNotEmpty(qrCodeContent)) { Map<String, String> urlMap = JSONUtil.toBean(qrCodeContent, Map.class); JLabel qrCodeLabel = AboutForm.getInstance().getQrCodeLabel(); try { URL url = new URL(urlMap.get("url")); BufferedImage image = ImageIO.read(url); qrCodeLabel.setIcon(new ImageIcon(image)); } catch (IOException e) { e.printStackTrace(); logger.error(e); } MainWindow.getInstance().getAboutPanel().updateUI(); } }
Example 3
Source File: ThirdPartyLoginHelper.java From feiqu-opensource with Apache License 2.0 | 6 votes |
/** * 获取新浪用户信息 * * @param token * @param uid * @return */ public static final ThirdPartyUser getSinaUserinfo(String token, String uid) throws Exception { ThirdPartyUser user = new ThirdPartyUser(); String url = Global.getPropertiesConfig("getUserInfoURL_sina"); url = url + "?access_token=" + token + "&uid=" + uid; String res = HttpUtil.get(url); logger.info("url:"+url+",获取到新浪用户信息:"+res); JSONObject json = JSONObject.parseObject(res); String name = json.getString("name"); String nickName = StringUtils.isBlank(json.getString("screen_name")) ? name : json.getString("screen_name"); user.setAvatarUrl(json.getString("avatar_large")); user.setUserName(nickName); if ("f".equals(json.getString("gender"))) { user.setGender("2"); } else { user.setGender("1"); } user.setDescription(json.getString("description")); user.setLocation(json.getString("location")); user.setToken(token); user.setOpenid(uid); return user; }
Example 4
Source File: ArticleController.java From feiqu-opensource with Apache License 2.0 | 6 votes |
@GetMapping("caiji") public void caiji(){ String result = HttpUtil.get("http://hd.zt.raiyi.com/v9/private/682265b8574104c64c262c1b3f7a3eb771f01e126687b1a14b048025a9b639918ae7d834f2c3158c646add7a52ab8e78/weibo/theme/list?appCode=other_browser&tag=hot"); AllDataRes allDataRes = JSON.parseObject(result, AllDataRes.class); List<SingleData> data = allDataRes.getData(); for(SingleData singleData : data){ String content = singleData.getContent(); String html = singleData.getHtml(); String htmlUn = HtmlUtils.htmlUnescape(html); Article article = new Article(); article.setArticleTitle(content); article.setCreateTime(new Date()); article.setArticleContent(htmlUn); article.setUserId(22); articleService.insert(article); } }
Example 5
Source File: CityParser.java From zuihou-admin-boot with Apache License 2.0 | 6 votes |
private List<Area> parseCity(String provinceName, String url) { String htmlStr = HttpUtil.get(url, CHARSET); Document document = Jsoup.parse(htmlStr); Elements trs = document.getElementsByClass("citytr"); List<Area> cities = new LinkedList<Area>(); int sort = 1; for (Element tr : trs) { Elements links = tr.getElementsByTag("a"); String href = links.get(0).attr("href"); String cityCode = links.get(0).text(); // String cityCode = links.get(0).text().substring(0, 4); String cityName = links.get(1).text(); Area cityArea = Area.builder() .label(cityName).code(cityCode).source(url).sortValue(sort++) .level(new RemoteData<>("CITY")) .fullName(provinceName + cityName) .build(); cityArea.setChildren(parseCounty(provinceName + cityName, COMMON_URL + href)); StaticLog.info(" 市级数据: {} ", cityArea); cities.add(cityArea); } return cities; }
Example 6
Source File: DeliveryController.java From mall4j with GNU Affero General Public License v3.0 | 6 votes |
/** * 查看物流接口 */ @GetMapping("/check") @ApiOperation(value="查看物流", notes="根据订单号查看物流") @ApiImplicitParam(name = "orderNumber", value = "订单号", required = true, dataType = "String") public ResponseEntity<DeliveryDto> checkDelivery(String orderNumber) { Order order = orderService.getOrderByOrderNumber(orderNumber); Delivery delivery = deliveryService.getById(order.getDvyId()); String url = delivery.getQueryUrl().replace("{dvyFlowId}", order.getDvyFlowId()); String deliveryJson = HttpUtil.get(url); DeliveryDto deliveryDto = Json.parseObject(deliveryJson, DeliveryDto.class); deliveryDto.setDvyFlowId(order.getDvyFlowId()); deliveryDto.setCompanyHomeUrl(delivery.getCompanyHomeUrl()); deliveryDto.setCompanyName(delivery.getDvyName()); return ResponseEntity.ok(deliveryDto); }
Example 7
Source File: CityParser.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
private List<Area> parseCounty(String fullName, String url) { String htmlStr = HttpUtil.get(url, CHARSET); Document document = Jsoup.parse(htmlStr); Elements trs = document.getElementsByClass("countytr"); List<Area> counties = new LinkedList<Area>(); int sort = 1; for (Element tr : trs) { Elements links = tr.getElementsByTag("a"); if (links == null || links.size() != 2) { continue; } String href = links.get(0).attr("href"); String countyCode = links.get(0).text(); // String countyCode = links.get(0).text().substring(0, 6); String countyName = links.get(1).text(); Area countyArea = Area.builder().code(countyCode) .label(countyName) .source(url) .fullName(fullName + countyName) .sortValue(sort++) .level(new RemoteData<>("COUNTY")) // .nodes(parseTowntr(fullName + countyName, COMMON_URL + href.subSequence(2, 5).toString() + "/" + href)) .build(); StaticLog.info(" 县级数据: {} ", countyArea); counties.add(countyArea); } return counties; }
Example 8
Source File: PictureServiceImpl.java From sk-admin with Apache License 2.0 | 5 votes |
@Override public void deleteAll(Long[] ids) { for (Long id : ids) { Picture picture = findById(id); try { HttpUtil.get(picture.getDelete()); pictureDao.delete(picture); } catch (Exception e) { pictureDao.delete(picture); } } }
Example 9
Source File: CityParser.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
private List<Area> parseProvince(String url) { String htmlStr = HttpUtil.get(url, CHARSET); Document document = Jsoup.parse(htmlStr); // 获取 class='provincetr' 的元素 Elements elements = document.getElementsByClass("provincetr"); List<Area> provinces = new LinkedList<Area>(); int sort = 1; for (Element element : elements) { // 获取 elements 下属性是 href 的元素 Elements links = element.getElementsByAttribute("href"); for (Element link : links) { String provinceName = link.text(); String href = link.attr("href"); String provinceCode = href.substring(0, 2); Area provinceArea = Area.builder().code(provinceCode + "0000") .label(provinceName).source(url) .sortValue(sort++) .level(new RemoteData<>("PROVINCE")) .fullName(provinceName) .build(); provinceArea.setChildren(parseCity(provinceName, COMMON_URL + href)); StaticLog.info("省级数据: {} ", provinceArea); provinces.add(provinceArea); } } return provinces; }
Example 10
Source File: CityStats.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
public static void parseTowntr(String url, Area countyArea) { String htmlStr = HttpUtil.get(url, CHARSET); Document document = Jsoup.parse(htmlStr); Elements trs = document.getElementsByClass("towntr"); List<Area> counties = new LinkedList<Area>(); int sort = 1; for (Element tr : trs) { Elements links = tr.getElementsByTag("a"); if (links == null || links.size() != 2) { continue; } String href = links.get(0).attr("href"); String towntrCode = links.get(0).text().substring(0, 9); String towntrName = links.get(1).text(); Area towntrArea = Area.builder().label(towntrName).code(towntrCode).source(url) .sortValue(sort++).level(new RemoteData<>("TOWNTR")).fullName(countyArea.getFullName() + towntrName) .build(); StaticLog.info(" 乡镇级数据: {} ", towntrArea); parseVillagetr(COMMON_URL + href.subSequence(2, 5).toString() + "/" + href.substring(5, 7) + "/" + href, countyArea); counties.add(towntrArea); } countyArea.setChildren(counties); }
Example 11
Source File: SystemStoreController.java From yshopmall with Apache License 2.0 | 5 votes |
@PostMapping(value = "/getL") @Log("获取经纬度") @ApiOperation("获取经纬度") @PreAuthorize("@el.check('yxSystemStore:getl')") public ResponseEntity<Object> create(@Validated @RequestBody String jsonStr){ String key = RedisUtil.get(ShopKeyUtils.getTengXunMapKey()); if(StrUtil.isBlank(key)) throw new BadRequestException("请先配置腾讯地图key"); JSONObject jsonObject = JSON.parseObject(jsonStr); String addr = jsonObject.getString("addr"); String url = StrUtil.format("?address={}&key={}",addr,key); String json = HttpUtil.get(ShopConstants.QQ_MAP_URL+url); return new ResponseEntity<>(json,HttpStatus.CREATED); }
Example 12
Source File: CityParser.java From zuihou-admin-cloud with Apache License 2.0 | 5 votes |
private List<Area> parseProvince(String url) { String htmlStr = HttpUtil.get(url, CHARSET); Document document = Jsoup.parse(htmlStr); // 获取 class='provincetr' 的元素 Elements elements = document.getElementsByClass("provincetr"); List<Area> provinces = new LinkedList<Area>(); int sort = 1; for (Element element : elements) { // 获取 elements 下属性是 href 的元素 Elements links = element.getElementsByAttribute("href"); for (Element link : links) { String provinceName = link.text(); String href = link.attr("href"); String provinceCode = href.substring(0, 2); Area provinceArea = Area.builder().code(provinceCode + "0000") .label(provinceName).source(url) .sortValue(sort++) .level(new RemoteData<>("PROVINCE")) .fullName(provinceName) .build(); provinceArea.setChildren(parseCity(provinceName, COMMON_URL + href)); StaticLog.info("省级数据: {} ", provinceArea); provinces.add(provinceArea); } } return provinces; }
Example 13
Source File: TieBaApi.java From tieba-api with MIT License | 5 votes |
/** * 根据百度盘分享url查询完整用户名(大部分可查) * @param panUrl 百度云盘分享url * @return 完整用户名 */ public String getFullNameByPanUrl(String panUrl) { try { panUrl = StrUtil.replace(panUrl, "wap", "share"); String html = EntityUtils.toString(hk.execute(panUrl).getEntity()); String uk = StrKit.substring(html, "uk\":", ","); String json = HttpUtil.get(String.format(Constants.UK_UN, uk)); JSONObject jsonObject = JSON.parseObject(json); String un = JSONPath.eval(jsonObject, "$.user_info.uname").toString(); return un; } catch (Exception e) { logger.error(e.getMessage(), e); } return null; }
Example 14
Source File: CityStats.java From zuihou-admin-boot with Apache License 2.0 | 5 votes |
public static void parseProvince(String url) { String htmlStr = HttpUtil.get(url, CHARSET); Document document = Jsoup.parse(htmlStr); // 获取 class='provincetr' 的元素 Elements elements = document.getElementsByClass("provincetr"); List<Area> provinces = new LinkedList<Area>(); int sort = 1; for (Element element : elements) { // 获取 elements 下属性是 href 的元素 Elements links = element.getElementsByAttribute("href"); for (Element link : links) { String provinceName = link.text(); String href = link.attr("href"); String provinceCode = href.substring(0, 2); StaticLog.info("provinceName: {} , provinceCode: {} .", provinceName, provinceCode); Area provinceArea = Area.builder().code(provinceCode).label(provinceName).source(url) .sortValue(sort++).fullName(provinceName).level(new RemoteData<>("PROVINCE")) .build(); StaticLog.info("省级数据: {} ", provinceArea); parseCity(COMMON_URL + href, provinceArea); provinces.add(provinceArea); } } StaticLog.info(JSONUtil.toJsonPrettyStr(provinces)); }
Example 15
Source File: PictureServiceImpl.java From yshopmall with Apache License 2.0 | 5 votes |
@Override public void deleteAll(Long[] ids) { for (Long id : ids) { Picture picture = findById(id); try { HttpUtil.get(picture.getDeleteUrl()); this.removeById(id); } catch(Exception e){ this.removeById(id); } } }
Example 16
Source File: ThirdPartyLoginHelper.java From feiqu-opensource with Apache License 2.0 | 5 votes |
/** * 获取QQ的认证token和用户OpenID * * @param code * @return */ public static final Map<String, String> getQQTokenAndOpenid(String code, String host) throws Exception { Map<String, String> map = new HashMap<String, String>(); // 获取令牌 String tokenUrl = Global.getPropertiesConfig("accessTokenURL_qq"); tokenUrl = tokenUrl + "?grant_type=authorization_code&client_id=" + Global.getPropertiesConfig("app_id_qq") + "&client_secret=" + Global.getPropertiesConfig("app_key_qq") + "&code=" + code + "&redirect_uri=http://" + host + Global.getPropertiesConfig("redirect_url_qq"); logger.info("tokenUrl:{}"+tokenUrl); String tokenRes = HttpUtil.get(tokenUrl); logger.info("qq res:"+tokenRes); if (tokenRes != null && tokenRes.indexOf("access_token") > -1) { Map<String, String> tokenMap = toMap(tokenRes); map.put("access_token", tokenMap.get("access_token")); // 获取QQ用户的唯一标识openID String openIdUrl = Global.getPropertiesConfig("getOpenIDURL_qq"); openIdUrl = openIdUrl + "?access_token=" + tokenMap.get("access_token"); String openIdRes = HttpUtil.get(openIdUrl); logger.info("qq:openIdRes:"+openIdRes); int i = openIdRes.indexOf("("); int j = openIdRes.indexOf(")"); openIdRes = openIdRes.substring(i + 1, j); JSONObject openidObj = JSONObject.parseObject(openIdRes); map.put("openId", openidObj.getString("openid")); } else { throw new IllegalArgumentException("qq 获取tokens参数错误"); } return map; }
Example 17
Source File: WxMaServiceClusterImpl.java From mall4j with GNU Affero General Public License v3.0 | 4 votes |
@Override public String getAccessToken(boolean forceRefresh) throws WxErrorException { if (!this.getWxMaConfig().isAccessTokenExpired() && !forceRefresh) { return this.getWxMaConfig().getAccessToken(); } RLock rLock = redissonClient.getLock(REDISSON_LOCK_PREFIX + ":WxMaServiceCluster:getAccessToken"); try { boolean lockSuccess; try { lockSuccess = rLock.tryLock(10, TimeUnit.SECONDS); } catch (InterruptedException e) { return this.getWxMaConfig().getAccessToken(); } if (!lockSuccess) { throw new YamiShopBindException("服务器繁忙,请稍后再试"); } if (!this.getWxMaConfig().isAccessTokenExpired()) { return this.getWxMaConfig().getAccessToken(); } String url = String.format(WxMaService.GET_ACCESS_TOKEN_URL, this.getWxMaConfig().getAppid(), this.getWxMaConfig().getSecret()); String resultContent = HttpUtil.get(url); WxError error = WxError.fromJson(resultContent); if (error.getErrorCode() != 0) { throw new WxErrorException(error); } WxAccessToken accessToken = WxAccessToken.fromJson(resultContent); this.getWxMaConfig().updateAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn()); return this.getWxMaConfig().getAccessToken(); } finally { rLock.unlock(); } }
Example 18
Source File: BlogUtils.java From NoteBlog with MIT License | 4 votes |
public static IpInfo getIpInfo(String ip) { String url = "http://ip.taobao.com/service/getIpInfo.php?ip=" + ip; String resp = HttpUtil.get(url); return JsonParser.create().parse(resp, IpInfo.class); }
Example 19
Source File: UserCaseForm.java From WePush with MIT License | 4 votes |
/** * 初始化他们都在用tab */ public static void init() { userCaseForm = getInstance(); userCaseForm.getUserCaseScrollPane().getVerticalScrollBar().setUnitIncrement(15); userCaseForm.getUserCaseScrollPane().getVerticalScrollBar().setDoubleBuffered(true); // 从github获取用户案例相关信息 String userCaseInfoContent = HttpUtil.get(UiConsts.USER_CASE_URL); if (StringUtils.isNotEmpty(userCaseInfoContent)) { List<UserCase> userCaseInfoList = JSONUtil.toList(JSONUtil.parseArray(userCaseInfoContent), UserCase.class); JPanel userCaseListPanel = userCaseForm.getUserCaseListPanel(); int listSize = userCaseInfoList.size(); userCaseListPanel.setLayout(new GridLayoutManager((int) Math.ceil(listSize / 2.0) + 1, 3, new Insets(0, 0, 0, 0), -1, -1)); for (int i = 0; i < listSize; i++) { UserCase userCase = userCaseInfoList.get(i); JPanel userCasePanel = new JPanel(); userCasePanel.setLayout(new GridLayoutManager(2, 2, new Insets(10, 10, 0, 0), -1, -1)); JLabel qrCodeLabel = new JLabel(); try { URL url = new URL(userCase.getQrCodeUrl()); BufferedImage image = ImageIO.read(url); qrCodeLabel.setIcon(new ImageIcon(image)); } catch (IOException e) { e.printStackTrace(); log.error("从github获取用户案例相关信息失败", e); } JLabel titleLabel = new JLabel(); titleLabel.setText(userCase.getTitle()); Font fnt = new Font(App.config.getFont(), Font.BOLD, 20); titleLabel.setFont(fnt); JLabel descLabel = new JLabel(); descLabel.setText(userCase.getDesc()); userCasePanel.add(qrCodeLabel, new GridConstraints(0, 0, 2, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); userCasePanel.add(titleLabel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); userCasePanel.add(descLabel, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); userCaseListPanel.add(userCasePanel, new GridConstraints(i / 2, i % 2, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); } final Spacer spacer1 = new Spacer(); userCaseListPanel.add(spacer1, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); final Spacer spacer2 = new Spacer(); userCaseListPanel.add(spacer2, new GridConstraints((int) Math.ceil(listSize / 2.0), 0, 1, 3, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); userCaseListPanel.updateUI(); } }
Example 20
Source File: MerchantOrderService.java From runscore with Apache License 2.0 | 4 votes |
/** * 支付成功异步通知 * * @param merchantOrderId */ @Transactional public String paySuccessAsynNotice(@NotBlank String merchantOrderId) { MerchantOrderPayInfo payInfo = merchantOrderPayInfoRepo.findByMerchantOrderId(merchantOrderId); if (Constant.商户订单支付通知状态_通知成功.equals(payInfo.getNoticeState())) { log.warn("商户订单支付已通知成功,无需重复通知;商户订单id为{}", merchantOrderId); return Constant.商户订单通知成功返回值; } Merchant merchant = merchantRepo.findByMerchantNum(payInfo.getMerchantNum()); if (merchant == null) { throw new BizException(BizError.商户未接入); } String sign = Constant.商户订单支付成功 + payInfo.getMerchantNum() + payInfo.getOrderNo() + new DecimalFormat("###################.###########").format(payInfo.getAmount()) + merchant.getSecretKey(); sign = new Digester(DigestAlgorithm.MD5).digestHex(sign); Map<String, Object> paramMap = new HashMap<>(); paramMap.put("merchantNum", payInfo.getMerchantNum()); paramMap.put("orderNo", payInfo.getOrderNo()); paramMap.put("platformOrderNo", payInfo.getMerchantOrder().getOrderNo()); paramMap.put("amount", payInfo.getAmount()); paramMap.put("attch", payInfo.getAttch()); paramMap.put("state", Constant.商户订单支付成功); paramMap.put("payTime", DateUtil.format(payInfo.getMerchantOrder().getConfirmTime(), DatePattern.NORM_DATETIME_PATTERN)); paramMap.put("sign", sign); String result = "fail"; // 通知3次 for (int i = 0; i < 3; i++) { try { result = HttpUtil.get(payInfo.getNotifyUrl(), paramMap, 2500); if (Constant.商户订单通知成功返回值.equals(result)) { break; } } catch (Exception e) { result = e.getMessage(); log.error(MessageFormat.format("商户订单支付成功异步通知地址请求异常,id为{0}", merchantOrderId), e); } } payInfo.setNoticeState( Constant.商户订单通知成功返回值.equals(result) ? Constant.商户订单支付通知状态_通知成功 : Constant.商户订单支付通知状态_通知失败); merchantOrderPayInfoRepo.save(payInfo); return result; }