cn.hutool.http.HttpRequest Java Examples

The following examples show how to use cn.hutool.http.HttpRequest. 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: PictureServiceImpl.java    From sk-admin with Apache License 2.0 6 votes vote down vote up
@Override
public void synchronize() {
    //链式构建请求
    String result = HttpRequest.get(CommonConstant.SM_MS_URL + "/v2/upload_history")
            //头信息,多个头信息多次调用此方法即可
            .header("Authorization", token)
            .timeout(20000)
            .execute().body();
    JSONObject jsonObject = JSONUtil.parseObj(result);
    List<Picture> pictures = JSON.parseArray(jsonObject.get("data").toString(), Picture.class);
    for (Picture picture : pictures) {
        if (!pictureDao.existsByUrl(picture.getUrl())) {
            picture.setSize(FileUtils.getSize(Integer.parseInt(picture.getSize())));
            picture.setUsername("System Sync");
            picture.setMd5Code("");
            pictureDao.save(picture);
        }
    }
}
 
Example #2
Source File: ITSUtils.java    From signature with MIT License 6 votes vote down vote up
/**
 * create by: iizvv
 * description: 删除当前帐号下的所有证书
 * create time: 2019-06-29 16:00
 *

 * @return void
 */
static void removeCertificates(Map header) {
    String url = "https://api.appstoreconnect.apple.com/v1/certificates";
    String result = HttpRequest.
            get(url).
            addHeaders(header).
            execute().
            body();
    System.out.println(result);
    Map map = JSON.parseObject(result, Map.class);
    JSONArray data = (JSONArray)map.get("data");
    for (Object datum : data) {
        Map m = (Map) datum;
        String id = (String) m.get("id");
        String result2 = HttpRequest.delete(url+"/"+id).
                addHeaders(header).
                execute().
                body();
        System.out.println(result2);
    }
}
 
Example #3
Source File: ITSUtils.java    From signature with MIT License 6 votes vote down vote up
/**
  * create by: iizvv
  * description: 删除所有绑定的ids
  * create time: 2019-07-01 14:41
  *
  * @return void
  */
static void removeBundleIds(Map header) {
    String url = "https://api.appstoreconnect.apple.com/v1/bundleIds";
    String result = HttpRequest.
            get(url).
            addHeaders(header).
            execute().
            body();
    System.out.println(result);
    Map map = JSON.parseObject(result, Map.class);
    JSONArray data = (JSONArray) map.get("data");
    for (Object datum : data) {
        Map m = (Map) datum;
        String id = (String) m.get("id");
        String result2 = HttpRequest.delete(url + "/" + id).
                addHeaders(header).
                execute().
                body();
        System.out.println(result2);
    }
}
 
Example #4
Source File: ITSUtils.java    From signature with MIT License 6 votes vote down vote up
/**
 * create by: iizvv
 * description: 添加设备
 * create time: 2019-06-29 15:14
 *

 * @return String
 */
public static String insertDevice(String udid, Authorize authorize) {
    Map body = new HashMap();
    body.put("type", "devices");
    Map attributes = new HashMap();
    attributes.put("name", udid);
    attributes.put("udid", udid);
    attributes.put("platform", "IOS");
    body.put("attributes", attributes);
    Map data = new HashMap();
    data.put("data", body);
    String url = "https://api.appstoreconnect.apple.com/v1/devices";
    String result = HttpRequest.post(url).
            addHeaders(getToken(authorize.getP8(), authorize.getIss(), authorize.getKid())).
            body(JSON.toJSONString(data)).execute().body();
    Map map = JSON.parseObject(result, Map.class);
    Map data1 = (Map) map.get("data");
    String id = (String)data1.get("id");
    return id;
}
 
Example #5
Source File: ITSUtils.java    From signature with MIT License 6 votes vote down vote up
/**
 * create by: iizvv
 * description: 创建证书
 * create time: 2019-06-29 16:34
 *

 * @return 创建的证书id
 */
static String insertCertificates(Map header, String csr) {
    String url = "https://api.appstoreconnect.apple.com/v1/certificates";
    Map body = new HashMap();
    body.put("type", "certificates");
    Map attributes = new HashMap();
    attributes.put("csrContent", csr);
    attributes.put("certificateType", "IOS_DEVELOPMENT");
    body.put("attributes", attributes);
    Map data = new HashMap();
    data.put("data", body);
    String result = HttpRequest.post(url).
            addHeaders(header).
            body(JSON.toJSONString(data)).
            execute().body();
    System.out.println(result);
    Map map = JSON.parseObject(result, Map.class);
    Map data1 = (Map) map.get("data");
    String id = (String)data1.get("id");
    return id;
}
 
Example #6
Source File: PictureServiceImpl.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
@Override
public void synchronize() {
    //链式构建请求
    String result = HttpRequest.get(YshopConstant.Url.SM_MS_URL + "/v2/upload_history")
            //头信息,多个头信息多次调用此方法即可
            .header("Authorization", token)
            .timeout(20000)
            .execute().body();
    JSONObject jsonObject = JSONUtil.parseObj(result);
    List<Picture> pictures = JSON.parseArray(jsonObject.get("data").toString(), Picture.class);
    for (Picture picture : pictures) {
        if(this.getOne(new QueryWrapper<Picture>().eq("url",picture.getUrl()))==null){
            picture.setSize(FileUtil.getSize(Integer.parseInt(picture.getSize())));
            picture.setUsername("System Sync");
            picture.setMd5code(null);
            this.save(picture);
        }
    }
}
 
Example #7
Source File: ITSUtils.java    From signature with MIT License 6 votes vote down vote up
/**
  * create by: iizvv
  * description: 创建BundleIds
  * create time: 2019-07-01 15:00
  *
  * @return id
  */
static String insertBundleIds(Map header) {
    String url = "https://api.appstoreconnect.apple.com/v1/bundleIds";
    Map body = new HashMap();
    body.put("type", "bundleIds");
    Map attributes = new HashMap();
    attributes.put("identifier", "com.app.*");
    attributes.put("name", "AppBundleId");
    attributes.put("platform", "IOS");
    body.put("attributes", attributes);
    Map data = new HashMap();
    data.put("data", body);
    String result = HttpRequest.post(url).
            addHeaders(header).
            body(JSON.toJSONString(data)).
            execute().body();
    System.out.println(result);
    Map map = JSON.parseObject(result, Map.class);
    Map data1 = (Map) map.get("data");
    String id = (String)data1.get("id");
    return id;
}
 
Example #8
Source File: AbstractOneDriveServiceBase.java    From zfile with MIT License 6 votes vote down vote up
/**
 * OAuth2 协议中, 根据 code 换取 access_token 和 refresh_token.
 *
 * @param   code
 *          代码
 *
 * @return  获取的 Token 信息.
 */
public OneDriveToken getToken(String code) {
    String param = "client_id=" + getClientId() +
            "&redirect_uri=" + getRedirectUri() +
            "&client_secret=" + getClientSecret() +
            "&code=" + code +
            "&scope=" + getScope() +
            "&grant_type=authorization_code";

    String fullAuthenticateUrl = AUTHENTICATE_URL.replace("{authenticateEndPoint}", getAuthenticateEndPoint());
    HttpRequest post = HttpUtil.createPost(fullAuthenticateUrl);

    post.body(param, "application/x-www-form-urlencoded");
    HttpResponse response = post.execute();
    return JSONObject.parseObject(response.body(), OneDriveToken.class);
}
 
Example #9
Source File: AbstractOneDriveServiceBase.java    From zfile with MIT License 6 votes vote down vote up
/**
 * 根据 RefreshToken 刷新 AccessToken, 返回刷新后的 Token.
 *
 * @return  刷新后的 Token
 */
public OneDriveToken getRefreshToken() {
    StorageConfig refreshStorageConfig =
            storageConfigRepository.findByDriveIdAndKey(driveId, StorageConfigConstant.REFRESH_TOKEN_KEY);

    String param = "client_id=" + getClientId() +
            "&redirect_uri=" + getRedirectUri() +
            "&client_secret=" + getClientSecret() +
            "&refresh_token=" + refreshStorageConfig.getValue() +
            "&grant_type=refresh_token";

    String fullAuthenticateUrl = AUTHENTICATE_URL.replace("{authenticateEndPoint}", getAuthenticateEndPoint());
    HttpRequest post = HttpUtil.createPost(fullAuthenticateUrl);

    post.body(param, "application/x-www-form-urlencoded");
    HttpResponse response = post.execute();
    return JSONObject.parseObject(response.body(), OneDriveToken.class);
}
 
Example #10
Source File: TieBaLiveApi.java    From tieba-api with MIT License 6 votes vote down vote up
/**
 * 公共请求方法
 * @param url
 * @param bduss
 * @param stoken
 * @param params
 * @return
 */
public static JSONObject commonRequest(String url, String bduss, String stoken, String... params) {
	HttpRequest request = HttpRequest.post(url)
			.form("BDUSS", bduss)
			.form("stoken", stoken)
			.form("_client_version", "10.3.8.1")
			.form("_client_type", 2)
			.form("timestamp", System.currentTimeMillis());
	for (String param : params) {
		request.form(StrUtil.subBefore(param, "=", false), StrUtil.subAfter(param, "=", false));
	}
	request.form("tbs", getTbs(bduss));
	Map<String, Object> formMap = request.form();
	formMap = MapUtil.sort(formMap);
	StringBuilder sb = new StringBuilder();
	for (String key : formMap.keySet()) {
		sb.append(String.format("%s=%s", key, formMap.get(key)).toString());
	}
	sb.append("tiebaclient!!!");
	String sign = SecureUtil.md5(sb.toString()).toUpperCase();
	String body = request.form("sign", sign).execute().body();
	if(StrUtil.isNotBlank(body)) {
		return JSON.parseObject(body);
	}
	return null;
}
 
Example #11
Source File: Test1.java    From SubTitleSearcher with Apache License 2.0 6 votes vote down vote up
public static String getUrl(String url) {
	try {
		HttpResponse response = HttpRequest.get(url).execute();

		System.out.println(response.toString());
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return getUrl(location);
		} else if (statusCode == 200) {
			return response.body();
		} else {
			System.out.println(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	} finally {
	}
}
 
Example #12
Source File: TomcatManageService.java    From Jpom with MIT License 6 votes vote down vote up
/**
 * 访问tomcat Url
 *
 * @param tomcatInfoModel tomcat信息
 * @param cmd             命令
 * @return 访问结果
 */
private String tomcatCmd(TomcatInfoModel tomcatInfoModel, String cmd) {
    String url = String.format("http://127.0.0.1:%d/jpomAgent/%s", tomcatInfoModel.getPort(), cmd);
    HttpRequest httpRequest = new HttpRequest(url);
    // 设置超时时间为3秒
    httpRequest.setConnectionTimeout(3000);
    String body = "";

    try {
        HttpResponse httpResponse = httpRequest.execute();
        if (httpResponse.isOk()) {
            body = httpResponse.body();
        }
        if (httpResponse.getStatus() == HttpStatus.HTTP_NOT_FOUND) {
            // 没有插件
            tomcatInfoModel.initTomcat();
            throw new JpomRuntimeException("tomcat 未初始化,已经重新初始化请稍后再试");
        }
    } catch (JpomRuntimeException jpom) {
        throw jpom;
    } catch (Exception ignored) {
    }

    return body;
}
 
Example #13
Source File: TomcatManageService.java    From Jpom with MIT License 6 votes vote down vote up
/**
 * 查询tomcat状态
 *
 * @param id tomcat的id
 * @return tomcat状态0表示未运行,1表示运行中
 */
public int getTomcatStatus(String id) {
    int result = 0;
    TomcatInfoModel tomcatInfoModel = tomcatEditService.getItem(id);
    String url = String.format("http://127.0.0.1:%d/", tomcatInfoModel.getPort());
    HttpRequest httpRequest = new HttpRequest(url);
    // 设置超时时间为3秒
    httpRequest.setConnectionTimeout(3000);
    try {
        HttpResponse httpResponse = httpRequest.execute();
        result = 1;
    } catch (Exception ignored) {
    }

    return result;
}
 
Example #14
Source File: Test1.java    From SubTitleSearcher with Apache License 2.0 6 votes vote down vote up
public static String getUrl(String url) {
	try {
		HttpResponse response = HttpRequest.get(url).execute();

		System.out.println(response.toString());
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return getUrl(location);
		} else if (statusCode == 200) {
			return response.body();
		} else {
			System.out.println(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	} finally {
	}
}
 
Example #15
Source File: PictureServiceImpl.java    From eladmin with Apache License 2.0 6 votes vote down vote up
@Override
public void synchronize() {
    //链式构建请求
    String result = HttpRequest.get(ElAdminConstant.Url.SM_MS_URL + "/v2/upload_history")
            //头信息,多个头信息多次调用此方法即可
            .header("Authorization", token)
            .timeout(20000)
            .execute().body();
    JSONObject jsonObject = JSONUtil.parseObj(result);
    List<Picture> pictures = JSON.parseArray(jsonObject.get("data").toString(), Picture.class);
    for (Picture picture : pictures) {
        if(!pictureRepository.existsByUrl(picture.getUrl())){
            picture.setSize(FileUtil.getSize(Integer.parseInt(picture.getSize())));
            picture.setUsername("System Sync");
            picture.setMd5Code(null);
            pictureRepository.save(picture);
        }
    }
}
 
Example #16
Source File: CommUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static String postMultiData(String url, byte[] data, String boundary, String cookie, String referer) {
    try {
        HttpRequest request = HttpUtil.createPost(url).timeout(15000);
        request.contentType("multipart/form-data; boundary=" + boundary);
        request.body(data);
        if (StrUtil.isNotBlank(referer)) {
            request.header("Referer", referer);
        }
        if (StrUtil.isNotBlank(cookie)) {
            request.cookie(cookie);
        }
        HttpResponse response = request.execute();
        return WebUtils.getSafeHtml(response);
    } catch (Exception ex) {
        StaticLog.error(ex);
        return null;
    }
}
 
Example #17
Source File: OcrUtils.java    From tools-ocr with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static String sogouWebOcr(byte[] imgData) {
    String url = "https://deepi.sogou.com/api/sogouService";
    String referer = "https://deepi.sogou.com/?from=picsearch&tdsourcetag=s_pctim_aiomsg";
    String imageData = Base64.encode(imgData);
    long t = System.currentTimeMillis();
    String sign = SecureUtil.md5("sogou_ocr_just_for_deepibasicOpenOcr" + t + imageData.substring(0, Math.min(1024, imageData.length())) + "4b66a37108dab018ace616c4ae07e644");
    Map<String, Object> data = new HashMap<>();
    data.put("image", imageData);
    data.put("lang", "zh-Chs");
    data.put("pid", "sogou_ocr_just_for_deepi");
    data.put("salt", t);
    data.put("service", "basicOpenOcr");
    data.put("sign", sign);
    HttpRequest request = HttpUtil.createPost(url).timeout(15000);
    request.form(data);
    request.header("Referer", referer);
    HttpResponse response = request.execute();
    return extractSogouResult(WebUtils.getSafeHtml(response));
}
 
Example #18
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public String get(String url, String charset, String ua, String refer) {
	logger.info("get=" + url);

	try {
		HttpResponse response = addHeader(HttpRequest.get(url).header(Header.USER_AGENT, ua)
				.header(Header.ACCEPT_CHARSET, charset).charset(charset)
				.header(Header.ACCEPT, _accept).header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info(response.toString());
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return get(location, charset, ua, refer);
		} else if (statusCode == 200) {
			return response.body();
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}
}
 
Example #19
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public HttpRequest addHeader(HttpRequest req) {
	if (_headers.size() > 0) {
		Set<String> keyset = _headers.keySet();
		for (String key : keyset) {
			req.header(key, _headers.get(key));
		}
	}
	return req;
}
 
Example #20
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public String post(String url, Map<String, Object> list, String charset, String ua, String refer) {
	logger.info("post=" + url);
	try {
		HttpResponse response = addHeader(HttpRequest.post(url).form(list).header(Header.USER_AGENT, ua)
				.header(Header.ACCEPT_CHARSET, charset).charset(charset)
				.header(Header.ACCEPT, _accept).header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info("response header:" + getRespHeaderStr(response));
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return post(location, list, charset, ua, refer);
		} else if (statusCode == 200) {
			return response.body();
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}
}
 
Example #21
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public String postStream(String url, String data, String charset, String ua, String refer) {
	logger.info("postStream=" + url);
	try {
		HttpResponse response = addHeader(HttpRequest.post(url).body(data, _stream_media_type)
				.header(Header.USER_AGENT, ua).header(Header.ACCEPT_CHARSET, charset)
				.charset(charset).header(Header.ACCEPT, _accept)
				.header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info("response header:" + getRespHeaderStr(response));
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return postStream(location, data, charset, ua, refer);
		} else if (statusCode == 200) {
			return response.body();
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}

}
 
Example #22
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public HttpResponse getResponse(String url, String ua, String refer) {
	logger.info("getResponse=" + url);

	try {
		HttpResponse response = addHeader(HttpRequest.get(url).header(Header.USER_AGENT, ua)
				.header(Header.ACCEPT, _accept).header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info("response header:" + getRespHeaderStr(response));
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return getResponse(location, ua, refer);
		} else if (statusCode == 200) {
			return response;
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}
}
 
Example #23
Source File: TieBaLiveApi.java    From tieba-api with MIT License 5 votes vote down vote up
public static String getUserProfile(String uid) {
	String result = "";
	try {
		if(StrUtil.isNotBlank(uid)) {
			//2.根据uid获取用户信息
			HttpRequest request = HttpRequest.post("http://c.tieba.baidu.com/c/u/user/profile")
											.form("_client_version", "6.1.2")
											.form("has_plist", "2")
											.form("need_post_count", "1")
											.form("uid", uid);
			Map<String, Object> formMap = request.form();
			formMap = MapUtil.sort(formMap);
			StringBuilder sb = new StringBuilder();
			for (String key : formMap.keySet()) {
				sb.append(String.format("%s=%s", key, formMap.get(key)).toString());
			}
			sb.append("tiebaclient!!!");
			String sign = SecureUtil.md5(sb.toString()).toUpperCase();
			String body = request.form("sign", sign).execute().body();
			return body;
		}else {
			Console.log("用户信息查找失败");
		}
	} catch (Exception e) {
		Console.error(e.getMessage(), e);
	}
    return result;
}
 
Example #24
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public byte[] getBytes(String url, String ua, String refer) {
	logger.info("getBytes=" + url);

	try {
		HttpResponse response = addHeader(HttpRequest.get(url).header(Header.USER_AGENT, ua)
				.header(Header.ACCEPT, _accept).header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info("response header:" + getRespHeaderStr(response));
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return getBytes(location, ua, refer);
		} else if (statusCode == 200) {
			return response.bodyBytes();
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}
}
 
Example #25
Source File: HtHttpUtil.java    From SubTitleSearcher with Apache License 2.0 5 votes vote down vote up
public byte[] postBytes(String url, Map<String, Object> list, String ua, String refer) {
	logger.info("postBytes=" + url);

	try {
		HttpResponse response = addHeader(HttpRequest.post(url).form(list).header(Header.USER_AGENT, ua)
				.header(Header.ACCEPT, _accept).header(Header.ACCEPT_ENCODING, _accept_encoding)
				.header(Header.REFERER, refer != null ? refer : url)
				.header(Header.ACCEPT_LANGUAGE, _accept_language).timeout(_time_out)).execute();

		if (debug) {
			logger.info("response header:" + getRespHeaderStr(response));
		}
		int statusCode = response.getStatus();
		if (statusCode == 301 || statusCode == 302) {
			String location = response.header("Location");
			if (!location.toLowerCase().startsWith("http")) {
				location = StringUtil.getBaseUrl(url) + location;
			}
			return postBytes(location, list, ua, refer);
		} else if (statusCode == 200) {
			return response.bodyBytes();
		} else {
			logger.error(url + ", failed: " + statusCode);
			return null;
		}
	} catch (Exception e) {
		logger.error(e);
		return null;
	} finally {
	}
}
 
Example #26
Source File: PictureServiceImpl.java    From eladmin with Apache License 2.0 5 votes vote down vote up
@Override
@Transactional(rollbackFor = Throwable.class)
public Picture upload(MultipartFile multipartFile, String username) {
    File file = FileUtil.toFile(multipartFile);
    // 验证是否重复上传
    Picture picture = pictureRepository.findByMd5Code(FileUtil.getMd5(file));
    if(picture != null){
       return picture;
    }
    HashMap<String, Object> paramMap = new HashMap<>(1);
    paramMap.put("smfile", file);
    // 上传文件
    String result= HttpRequest.post(ElAdminConstant.Url.SM_MS_URL + "/v2/upload")
            .header("Authorization", token)
            .form(paramMap)
            .timeout(20000)
            .execute().body();
    JSONObject jsonObject = JSONUtil.parseObj(result);
    if(!jsonObject.get(CODE).toString().equals(SUCCESS)){
        throw new BadRequestException(TranslatorUtil.translate(jsonObject.get(MSG).toString()));
    }
    picture = JSON.parseObject(jsonObject.get("data").toString(), Picture.class);
    picture.setSize(FileUtil.getSize(Integer.parseInt(picture.getSize())));
    picture.setUsername(username);
    picture.setMd5Code(FileUtil.getMd5(file));
    picture.setFilename(FileUtil.getFileNameNoEx(multipartFile.getOriginalFilename())+"."+FileUtil.getExtensionName(multipartFile.getOriginalFilename()));
    pictureRepository.save(picture);
    //删除临时文件
    FileUtil.del(file);
    return picture;

}
 
Example #27
Source File: PictureServiceImpl.java    From sk-admin with Apache License 2.0 5 votes vote down vote up
@Override
@Transactional(rollbackFor = Throwable.class)
public Picture upload(MultipartFile multipartFile, String username) {
    File file = FileUtils.toFile(multipartFile);
    // 验证是否重复上传
    Picture picture = pictureDao.findByMd5Code(FileUtils.getMd5(file));
    if (picture != null) {
        return picture;
    }
    HashMap<String, Object> paramMap = new HashMap<>(1);
    paramMap.put("smfile", file);
    // 上传文件
    String result = HttpRequest.post(CommonConstant.SM_MS_URL + "/v2/upload")
            .header("Authorization", token)
            .form(paramMap)
            .timeout(20000)
            .execute().body();
    JSONObject jsonObject = JSONUtil.parseObj(result);
    if (!jsonObject.get(CODE).toString().equals(SUCCESS)) {
        throw new SkException(TranslatorUtil.translate(jsonObject.get(MSG).toString()));
    }
    picture = JSON.parseObject(jsonObject.get("data").toString(), Picture.class);
    picture.setSize(FileUtils.getSize(Integer.parseInt(picture.getSize())));
    picture.setUsername(username);
    picture.setMd5Code(FileUtils.getMd5(file));
    picture.setFilename(FileUtils.getFileNameNoEx(multipartFile.getOriginalFilename()) + "." + FileUtils.getExtensionName(multipartFile.getOriginalFilename()));
    pictureDao.save(picture);
    //删除临时文件
    FileUtils.del(file);
    return picture;

}
 
Example #28
Source File: IcqHttpApi.java    From PicqBotX with MIT License 5 votes vote down vote up
/**
 * 发送请求
 *
 * @param api API节点
 * @param params 参数
 * @return 响应
 */
public JsonElement send(HttpApiNode api, Map<String, Object> params)
{
    // 创建请求
    HttpRequest request = HttpRequest.post(makeUrl(api)).body(new JSONObject(params).toString()).timeout(5000);

    // 判断有没有 Access Token, 并加到头上w
    if (!bot.getConfig().getAccessToken().isEmpty())
    {
        request.header("Authorization", "Bearer " + bot.getConfig().getAccessToken());
    }

    // 发送并返回
    return new JsonParser().parse(request.execute().body());
}
 
Example #29
Source File: ITSUtils.java    From signature with MIT License 5 votes vote down vote up
/**
 * create by: iizvv
 * description: 获取帐号信息
 * create time: 2019-06-29 15:13
 *

 * @return number:可用数量, udids已有设备, cerId证书id
 */
public static Map getNumberOfAvailableDevices(Authorize authorize) {
    Map header = getToken(authorize.getP8(), authorize.getIss(), authorize.getKid());
    Map res = new HashMap();
    String url = "https://api.appstoreconnect.apple.com/v1/devices";
    String result = HttpRequest.get(url).
            addHeaders(header).
            execute().body();
    Map map = JSON.parseObject(result, Map.class);
    JSONArray data = (JSONArray)map.get("data");
    List devices = new LinkedList();
    for (Object datum : data) {
        Map device = new HashMap();
        Map m = (Map) datum;
        String id = (String)m.get("id");
        Map attributes = (Map)m.get("attributes");
        String udid = (String)attributes.get("udid");
        device.put("deviceId", id);
        device.put("udid", udid);
        devices.add(device);
    }
    removeCertificates(header);
    removeBundleIds(header);
    String cerId = insertCertificates(header, authorize.getCsr());
    String bundleIds = insertBundleIds(header);
    Map meta = (Map) map.get("meta");
    Map paging = (Map)meta.get("paging");
    int total = (int) paging.get("total");
    res.put("number", Config.total-total);
    res.put("devices", devices);
    res.put("cerId", cerId);
    res.put("bundleIds", bundleIds);
    System.out.println(res);
    return res;
}
 
Example #30
Source File: IPInfoUtil.java    From BigDataPlatform with GNU General Public License v3.0 5 votes vote down vote up
public static void getInfo(HttpServletRequest request, String p){
    try {
        IpInfo info = new IpInfo();
        info.setUrl(request.getRequestURL().toString());
        info.setP(p);
        String result = HttpRequest.post("https://api.bmob.cn/1/classes/url")
                .header("X-Bmob-Application-Id", "46970b236e5feb2d9c843dce2b97f587")
                .header("X-Bmob-REST-API-Key", "171674600ca49e62e0c7a2eafde7d0a4")
                .header("Content-Type", "application/json")
                .body(new Gson().toJson(info, IpInfo.class))
                .execute().body();
    }catch (Exception e){
        e.printStackTrace();
    }
}