Java Code Examples for cn.hutool.http.HttpUtil#post()

The following examples show how to use cn.hutool.http.HttpUtil#post() . 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: ThirdPartyLoginHelper.java    From feiqu-opensource with Apache License 2.0 6 votes vote down vote up
/**
 * 获取微信的认证token和用户OpenID
 * 
 * @param code
 * @return
 */
public static final Map<String, String> getWxTokenAndOpenid(String code, String host) throws Exception {
	Map<String, String> map = new HashMap<String, String>();
	// 获取令牌
	String tokenUrl = Global.getPropertiesConfig("accessTokenURL_wx");
	tokenUrl = tokenUrl + "?appid=" + Global.getPropertiesConfig("app_id_wx") + "&secret="
			+ Global.getPropertiesConfig("app_key_wx") + "&code=" + code + "&grant_type=authorization_code";
	String tokenRes = HttpUtil.post(tokenUrl,"");
	if (tokenRes != null && tokenRes.indexOf("access_token") > -1) {
		Map<String, String> tokenMap = toMap(tokenRes);
		map.put("access_token", tokenMap.get("access_token"));
		// 获取微信用户的唯一标识openid
		map.put("openId", tokenMap.get("openid"));
	} else {
		throw new IllegalArgumentException(("THIRDPARTY.LOGIN.NOTOKEN weixin"));
	}
	return map;
}
 
Example 2
Source File: ThirdPartyLoginHelper.java    From feiqu-opensource with Apache License 2.0 6 votes vote down vote up
/**
	 * 获取新浪登录认证token和用户id
	 * 
	 * @param code
	 * @return
	 */
	public static final JSONObject getSinaTokenAndUid(String code, String host) {
		JSONObject json = null;
		try {
			// 获取令牌
			String tokenUrl = Global.getPropertiesConfig("accessTokenURL_sina");
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("client_id",Global.getPropertiesConfig("app_id_sina"));
			map.put("client_secret",Global.getPropertiesConfig("app_key_sina"));
//			map.put("grant_type",Global.getPropertiesConfig("authorization_code"));
			map.put("grant_type","authorization_code");
			map.put("redirect_uri","http://" + host + Global.getPropertiesConfig("redirect_url_sina"));
			map.put("code",code);
			String tokenRes = HttpUtil.post(tokenUrl, map);
			// String tokenRes = httpClient(tokenUrl);
			// {"access_token":"2.00AvYzKGWraycB344b3eb242NUbiQB","remind_in":"157679999","expires_in":157679999,"uid":"5659232590"}
			if (tokenRes != null && tokenRes.indexOf("access_token") > -1) {
				json = JSONObject.parseObject(tokenRes);
			} else {
				throw new IllegalArgumentException("THIRDPARTY.LOGIN.NOTOKEN sina");
			}
		} catch (Exception e) {
			logger.error("getSinaTokenAndUid",e);
		}
		return json;
	}
 
Example 3
Source File: ExpressService.java    From yshopmall with Apache License 2.0 6 votes vote down vote up
/**
 * Json方式 查询订单物流轨迹
 *
 * @throws Exception
 */
private String getOrderTracesByJson(String OrderCode,String ShipperCode, String LogisticCode) throws Exception {
    if (!properties.isEnable()) {
        return null;
    }

    String requestData = "{'OrderCode':'"+OrderCode+"','ShipperCode':'" + ShipperCode + "','LogisticCode':'" + LogisticCode + "'}";

    Map<String, Object> params = new HashMap<>();
    params.put("RequestData", URLEncoder.encode(requestData, "UTF-8"));
    params.put("EBusinessID", properties.getAppId());
    params.put("RequestType", "1002");
    String dataSign = encrypt(requestData, properties.getAppKey(), "UTF-8");
    params.put("DataSign", URLEncoder.encode(dataSign, "UTF-8"));
    params.put("DataType", "2");

    String result = HttpUtil.post(ReqURL, params);

    //根据公司业务处理返回的信息......

    return result;
}
 
Example 4
Source File: GiteeOAuth2Template.java    From pre with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected AccessGrant postForAccessGrant(String accessTokenUrl, MultiValueMap<String, String> parameters) {

    // https://gitee.com/oauth/token?grant_type=authorization_code&code={code}&client_id={client_id}&redirect_uri={redirect_uri}&client_secret={client_secret}
    // 自己拼接url
    String clientId = parameters.getFirst("client_id");
    String clientSecret = parameters.getFirst("client_secret");
    String code = parameters.getFirst("code");
    String redirectUri = parameters.getFirst("redirect_uri");

    String url = String.format("https://gitee.com/oauth/token?grant_type=authorization_code&code=%s&client_id=%s&redirect_uri=%s&client_secret=%s", code, clientId, redirectUri, clientSecret);
    String post = HttpUtil.post(url, "",5000);

    log.info("获取accessToke的响应:" + post);
    JSONObject object = JSONObject.parseObject(post);
    String accessToken = (String) object.get("access_token");
    String scope = (String) object.get("scope");
    String refreshToken = (String) object.get("refresh_token");
    int expiresIn = (Integer) object.get("expires_in");

    log.info("获取Toke的响应:{},scope响应:{},refreshToken响应:{},expiresIn响应:{}", accessToken, scope, refreshToken, expiresIn);
    return new AccessGrant(accessToken, scope, refreshToken, (long) expiresIn);
}
 
Example 5
Source File: AddressUtils.java    From RuoYi with Apache License 2.0 6 votes vote down vote up
public static String getRealAddressByIp(String ip) {
    String address = "XX XX" ;

    // 内网不查询
    if (IpUtils.internalIp(ip)) {
        return "内网IP" ;
    }
    if (Global.isAddressEnabled()) {
        String rspStr = HttpUtil.post(IP_URL, "ip=" + ip);
        if (StrUtil.isEmpty(rspStr)) {
            log.error("获取地理位置异常 {}" , ip);
            return address;
        }
        JSONObject obj;
        try {
            obj = JSON.unmarshal(rspStr, JSONObject.class);
            JSONObject data = obj.getObj("data");
            String region = data.getStr("region");
            String city = data.getStr("city");
            address = region + " " + city;
        } catch (Exception e) {
            log.error("获取地理位置异常 {}" , ip);
        }
    }
    return address;
}
 
Example 6
Source File: AddressUtil.java    From albedo with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static String getRealAddressByIp(String ip) {
	String address = "XX XX";

	// 内网不查询
	if (NetUtil.isInnerIP(ip)) {
		return "内网IP";
	}
	if (ApplicationConfig.isAddressEnabled()) {
		String rspStr = HttpUtil.post(IP_URL, "ip=" + ip);
		if (StringUtil.isEmpty(rspStr)) {
			log.error("获取地理位置异常 {}", ip);
			return address;
		}
		JSONObject obj;
		try {
			obj = JSON.parseObject(rspStr, JSONObject.class);
			JSONObject data = obj.getJSONObject("data");
			String region = data.getString("region");
			String city = data.getString("city");
			address = region + " " + city;
		} catch (Exception e) {
			log.error("获取地理位置异常 {}", ip);
		}
	}
	return address;
}
 
Example 7
Source File: ThirdPartyLoginHelper.java    From feiqu-opensource with Apache License 2.0 5 votes vote down vote up
/** 获取微信用户信息 */
public static final ThirdPartyUser getWxUserinfo(String token, String openid) throws Exception {
	ThirdPartyUser user = new ThirdPartyUser();
	String url = Global.getPropertiesConfig("getUserInfoURL_wx");
	url = url + "?access_token=" + token + "&openid=" + openid;
	String res = HttpUtil.post(url,"");

	JSONObject json = JSONObject.parseObject(res);
	if (json.getString("errcode") == null) {
		user.setUserName(json.getString("nickname"));
		String img = json.getString("headimgurl");
		if (img != null && !"".equals(img)) {
			user.setAvatarUrl(img);
		}
		String sex = json.getString("sex");
		if ("0".equals(sex)) {
			user.setGender("0");
		} else {
			user.setGender("1");
		}
		user.setToken(token);
		user.setOpenid(openid);
	} else {
		throw new IllegalArgumentException(json.getString("errmsg"));
	}
	return user;
}
 
Example 8
Source File: DingTalkMessageSender.java    From magic-starter with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 业务处理
 *
 * @param message 消息实体
 * @return boolean
 */
@Override
protected boolean process(AbstractDingTalkMessage message) {
	String webhook = messageProperties.getDingtalk().getWebhook();
	try {
		String result = HttpUtil.post(webhook, JSONUtil.toJsonPrettyStr(message), MessageConstants.DINGTALK_DEFAULT_TIMEOUT);
		log.debug("钉钉提醒成功,报文响应: {}", result);
		return true;
	} catch (Exception e) {
		log.error("钉钉消息发送异常!", e);
		return false;
	}
}
 
Example 9
Source File: AdminRootController.java    From Tbed with GNU Affero General Public License v3.0 5 votes vote down vote up
@PostMapping("/sysupdate")
@ResponseBody
public Integer sysupdate(String  dates) {
    HashMap<String, Object> paramMap = new HashMap<>();
    String urls ="http://tc.hellohao.cn/systemupdate";
    paramMap.put("dates",dates);
    String result= HttpUtil.post(urls, paramMap);
    return Integer.parseInt( result );
}
 
Example 10
Source File: SmUtil.java    From uccn with Apache License 2.0 5 votes vote down vote up
/**
 * @param multipartFile 表单名称。上传图片用到
 * @param ssl 是否使用 https 输出,强制开启
 * @param format 输出的格式。可选值有 json、xml。默认为 json
 * @return
 */
public static Sm saveFile(MultipartFile multipartFile, boolean ssl, String format){
    Map<String, Object> map = new HashMap<>(16);
    map.put("smfile", getFile(multipartFile));
    map.put("ssl", ssl);
    map.put("format", format);

    String smStr = HttpUtil.post(Config.SM_URL, map);

    return JSONUtil.toBean(smStr, Sm.class);
}
 
Example 11
Source File: SmUtil.java    From uccn with Apache License 2.0 5 votes vote down vote up
/**
 * @param multipartFile 表单名称。上传图片用到
 * @param format 输出的格式。可选值有 json、xml。默认为 json
 * @return
 */
public static Sm saveFile(MultipartFile multipartFile, String format){
    Map<String, Object> map = new HashMap<>(16);
    map.put("smfile", getFile(multipartFile));
    map.put("format", format);

    String smStr = HttpUtil.post(Config.SM_URL, map);

    return JSONUtil.toBean(smStr, Sm.class);
}
 
Example 12
Source File: SmUtil.java    From uccn with Apache License 2.0 5 votes vote down vote up
/**
 * @param multipartFile 表单名称。上传图片用到
 * @param ssl 是否使用 https 输出,强制开启
 * @return
 */
public static Sm saveFile(MultipartFile multipartFile, boolean ssl){
    Map<String, Object> map = new HashMap<>(16);
    map.put("smfile", getFile(multipartFile));
    map.put("ssl", ssl);

    String smStr = HttpUtil.post(Config.SM_URL, map);

    return JSONUtil.toBean(smStr, Sm.class);
}
 
Example 13
Source File: SmUtil.java    From uccn with Apache License 2.0 5 votes vote down vote up
/**
 * @param multipartFile 表单名称。上传图片用到
 * @return
 */
public static Sm saveFile(MultipartFile multipartFile){
    Map<String, Object> map = new HashMap<>(16);
    map.put("smfile", getFile(multipartFile));

    String smStr = HttpUtil.post(Config.SM_URL, map);

    return JSONUtil.toBean(smStr, Sm.class);
}
 
Example 14
Source File: AoomsHttpTemplate.java    From Aooms with Apache License 2.0 4 votes vote down vote up
public String post(String url) {
    String result = HttpUtil.post(url, Maps.newHashMap());
    return result;
}
 
Example 15
Source File: AoomsHttpTemplate.java    From Aooms with Apache License 2.0 4 votes vote down vote up
public String post(String url,Map<String, Object> params) {
    String result = HttpUtil.post(url, params);
    return result;
}
 
Example 16
Source File: AoomsHttpTemplate.java    From Aooms with Apache License 2.0 4 votes vote down vote up
public String upload(String url,Map<String, Object> params, Map<String,File> files) {
    params.putAll(files);
    String result = HttpUtil.post(url, params);
    return result;
}