1.需求背景:和第三方API对接,post提交数据并获取返回值
a.post提交
package com.uxun.uxungate.util;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import com.alibaba.fastjson.JSON;
import com.uxun.uxungate.entity.LfHuafei.LFHuafeiResponse;
import com.uxun.uxungate.manger.LFHFRunnable;
import com.uxunemall.gate.util.properties.PropertiesUtil;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.Map.Entry;
public class HttpPostUtil {
private static final Logger logger = Logger.getLogger(HttpPostUtil.class);
private static RequestConfig requestConfig;
private static CloseableHttpClient httpClinet;
public static Integer connectionTimeout = 30 * 1000;// 设置请求超时2秒钟 根据业务调整
public static Integer soTimeout = 30 * 1000; // 设置等待数据超时时间2秒钟 根据业务调整
static {
requestConfig = RequestConfig.custom().setSocketTimeout(soTimeout).setConnectTimeout(connectionTimeout).build();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(200);
cm.setDefaultMaxPerRoute(100);
httpClinet = HttpClients.custom().setConnectionManager(cm).build();
}
public static String post(String url, LinkedHashMap<String, String> parameterMap) {
logger.info("===========LF HttpPostUtil");
Strin