koul пре 4 година
родитељ
комит
0833cffbe6

BIN
lib/b2c-erp-api-0.0.2-SNAPSHOT.jar


+ 6 - 1
pom.xml

@@ -84,7 +84,12 @@
 		    <artifactId>jjwt</artifactId>
 		    <version>0.6.0</version>
 		</dependency>
-		
+		<dependency>
+			<groupId>com.uas.api</groupId>
+			<artifactId>b2c-erp-api</artifactId>
+			<version>0.0.2</version>
+			<systemPath>${project.basedir}/lib/ojdbc7.jar</systemPath>
+		</dependency>
 		<dependency>
 		    <groupId>org.codehaus.jackson</groupId>
 		    <artifactId>jackson-core-asl</artifactId>

+ 2 - 3
src/main/java/com/uas/eis/controller/MESController.java

@@ -41,12 +41,11 @@ public class MESController {
 
     /**
      * 成品半成品入库
-     * @param data
      * @return
      */
     @RequestMapping("/mes/prodInOutMakeIn")
-    public ApiResult<String> prodInOutMakeIn(HttpServletRequest request,String data){
-        return mesService.prodInOutMakeIn(request,data);
+    public ApiResult<String> prodInOutMakeIn(HttpServletRequest request){
+        return mesService.prodInOutMakeIn(request);
     }
     /**
      * 工单删除校验接口

+ 30 - 0
src/main/java/com/uas/eis/entity/Make.java

@@ -49,6 +49,36 @@ public class Make {
     private String ma_modifydate;
     @JSONField(name = "modifiedUser")
     private String ma_modifier;
+    @JSONField(name = "mesUser")
+    private String mesUser;
+    @JSONField(name = "mesPwd")
+    private String mesPwd;
+    @JSONField(name = "flag")
+    private int flag;
+
+    public String getMesUser() {
+        return mesUser;
+    }
+
+    public void setMesUser(String mesUser) {
+        this.mesUser = mesUser;
+    }
+
+    public String getMesPwd() {
+        return mesPwd;
+    }
+
+    public void setMesPwd(String mesPwd) {
+        this.mesPwd = mesPwd;
+    }
+
+    public int getFlag() {
+        return flag;
+    }
+
+    public void setFlag(int flag) {
+        this.flag = flag;
+    }
 
     public String getMa_code() {
         return ma_code;

+ 30 - 0
src/main/java/com/uas/eis/entity/MakeMaterial.java

@@ -47,6 +47,36 @@ public class MakeMaterial {
     private String ma_modifydate;
     @JSONField(name = "modifiedUser")
     private String ma_modifier;
+    @JSONField(name = "mesUser")
+    private String mesUser;
+    @JSONField(name = "mesPwd")
+    private String mesPwd;
+    @JSONField(name = "flag")
+    private int flag;
+
+    public String getMesUser() {
+        return mesUser;
+    }
+
+    public void setMesUser(String mesUser) {
+        this.mesUser = mesUser;
+    }
+
+    public String getMesPwd() {
+        return mesPwd;
+    }
+
+    public void setMesPwd(String mesPwd) {
+        this.mesPwd = mesPwd;
+    }
+
+    public int getFlag() {
+        return flag;
+    }
+
+    public void setFlag(int flag) {
+        this.flag = flag;
+    }
 
     public String getMm_code() {
         return mm_code;

+ 28 - 25
src/main/java/com/uas/eis/service/Impl/ERPServiceImpl.java

@@ -9,9 +9,7 @@ import com.uas.eis.entity.Make;
 import com.uas.eis.entity.MakeMaterial;
 import com.uas.eis.entity.Product;
 import com.uas.eis.service.ERPService;
-import com.uas.eis.utils.BaseUtil;
-import com.uas.eis.utils.HttpUtil;
-import com.uas.eis.utils.StringUtil;
+import com.uas.eis.utils.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.stereotype.Service;
@@ -34,17 +32,17 @@ public class ERPServiceImpl implements ERPService {
     @Override
     public String syncProduct(String data) {
         Map<Object, Object> store = BaseUtil.parseFormStoreToMap(data);
-        Product product = baseDao.getJdbcTemplate().queryForObject("select pr_kh_user,pr_code ,pr_detail ,pr_spec ," +
-                "nvl(pr_unit,'PCS') pr_unit,nvl(pr_cop,'BYT') pr_cop,nvl(pr_version,0) pr_version," +
-                "pr_serial ,nvl(pr_validdays,0) pr_validdays ,pr_msdlevel ,pr_fhelpcode ,pr_f_115 ,pr_f_116 ,pr_f_102" +
-                " ,pr_kind ,pr_whcode from product where pr_id=?",
+        Product product = baseDao.getJdbcTemplate().queryForObject("select nvl(pr_kh_user,'') pr_kh_user,nvl(pr_code,'') pr_code ,nvl" +
+                        "(pr_detail,'') pr_detail ," + "nvl(pr_spec,'') pr_spec ," +
+                "nvl(pr_unit,'PCS') pr_unit,nvl(pr_cop,'BYT') pr_cop,nvl(pr_version,'0') pr_version," +
+                "nvl(pr_serial,'') pr_serial ,nvl(pr_validdays,'0') pr_validdays ,nvl(pr_msdlevel,'') pr_msdlevel ,nvl(pr_fhelpcode,'') pr_fhelpcode ," +
+                        "nvl(pr_f_115,'') pr_f_115 ,nvl(pr_f_116,'') pr_f_116 ,nvl(pr_f_102,'') pr_f_102" +
+                " ,nvl(pr_kind,'') pr_kind ,nvl(pr_whcode,'') pr_whcode from product where pr_id=?",
                 new BeanPropertyRowMapper<Product>(Product.class),store.get("pr_id"));
-        product.setFlag(Integer.parseInt(StringUtil.nvl(store.get("flag"),"0")));
+        product.setFlag(StringUtil.nvl(store.get("flag"),"-1"));
         product.setMesUser(tokenConfig.get("mesUser"));
-        product.setMesPwd(tokenConfig.get("mesPwd"));
-        HashMap<String, String> map = new HashMap<>();
-        map.put("Json",JSON.toJSONString(product, SerializerFeature.WriteMapNullValue));
-        return syncMES(map,tokenConfig.get("syncProduct"));
+        product.setMesPwd(MD5Util.encodeByMD5(tokenConfig.get("mesPwd")));
+        return syncMES(JSON.toJSONString(product, SerializerFeature.WriteMapNullValue),tokenConfig.get("syncProduct"));
 
     }
 
@@ -53,36 +51,41 @@ public class ERPServiceImpl implements ERPService {
         Map<Object, Object> store = BaseUtil.parseFormStoreToMap(data);
         Make make = baseDao.getJdbcTemplate().queryForObject("select ma_code,ma_prodcode,ma_qty,ma_custcode,pr_unit,pr_detail,pr_spec,ma_salecode,to_char(ma_planbegindate,'yyyy-MM-dd') ma_planbegindate,to_char(ma_planenddate,'yyyy-MM-dd') ma_planenddate,nvl(ma_cop,'BYT') ma_cop,'S' status,to_char(ma_date,'yyyy-MM-dd HH24:mi:ss') ma_date,ma_recorder,nvl(ma_version,0) ma_version,ma_id,wc_id,pr_id,to_char(ma_modifydate,'yyyy-MM-dd HH24:mi:ss') ma_modifydate,ma_modifier from make left join product on ma_prodcode=pr_code left join workcenter on ma_wccode=wc_code where ma_id=?",
                 new BeanPropertyRowMapper<Make>(Make.class),store.get("ma_id"));
-        Map map = JSON.parseObject(JSON.toJSONString(make), Map.class);
-        map.put("flag",store.get("flag"));
-        return syncMES(map,tokenConfig.get("syncMakeBase"));
+        make.setFlag(Integer.parseInt(StringUtil.nvl(store.get("flag"),"-1")));
+        make.setMesPwd(MD5Util.encodeByMD5(tokenConfig.get("mesPwd")));
+        make.setMesUser(tokenConfig.get("mesUser"));
+        return syncMES(JSON.toJSONString(make, SerializerFeature.WriteMapNullValue),tokenConfig.get("syncMakeBase"));
     }
 
     @Override
     public String syncMakeBaseDetail(String data) {
         Map<Object, Object> store = BaseUtil.parseFormStoreToMap(data);
-        MakeMaterial makeMaterial = baseDao.getJdbcTemplate().queryForObject("select * from MakeMaterial left join " +
+        MakeMaterial makeMaterial = baseDao.getJdbcTemplate().queryForObject("select mm_code,mm_detno,mm_prodcode," +
+                        "pr_detail,pr_spec,pr_unit,mm_qty qty,mm_qty,mm_oneuseqty,'main' type,ma_recorder,to_char" +
+                        "(ma_date,'yyyy-MM-dd HH24:mi:ss') ma_date,nvl(ma_version,0) ma_version,nvl(ma_cop,'BYT') ma_cop," +
+                        "mm_repprodcode,mm_balance,ma_custcode,to_char(ma_modifydate,'yyyy-MM-dd HH24:mi:ss') " +
+                        "ma_modifydate,ma_modifier from MakeMaterial left join make on ma_id=mm_maid left join " +
                         "Product on mm_prodcode=pr_code where mm_id=?",
                 new BeanPropertyRowMapper<MakeMaterial>(MakeMaterial.class),store.get("mm_id"));
-        Map map = JSON.parseObject(JSON.toJSONString(makeMaterial, SerializerFeature.WriteMapNullValue), Map.class);
-        map.put("flag",store.get("flag"));
-        return syncMES(map,tokenConfig.get("syncMakeBaseDetail"));
+        HashMap<String, String> map = new HashMap<>();
+        makeMaterial.setFlag(Integer.parseInt(StringUtil.nvl(store.get("flag"),"-1")));
+        makeMaterial.setMesUser(tokenConfig.get("mesUser"));
+        makeMaterial.setMesPwd(MD5Util.encodeByMD5(tokenConfig.get("mesPwd")));
+        return syncMES(JSON.toJSONString(makeMaterial, SerializerFeature.WriteMapNullValue),tokenConfig.get("syncMakeBaseDetail"));
     }
 
-    private String syncMES(Map<String,String> params,String url){
+    private String syncMES(String params,String url){
         try {
-            HashMap<String, String> header = new HashMap<>();
-            header.put("Content-Type","application/json");
             System.err.println(params);
-            HttpUtil.Response response = HttpUtil.sendPostRequest(tokenConfig.get("mesHttp") + url, header, params);
-            JSONObject jsonObject = JSON.parseObject(response.getResponseText());
+            String post = PSHttpUtils.sendPost(tokenConfig.get("mesHttp") + url, params);
+            JSONObject jsonObject = JSON.parseObject(post);
             int code = jsonObject.getIntValue("result");
             if (code==0){
                 return "同步MES成功";
             }else if(code==1){
                 return jsonObject.getString("message");
             }else {
-                return "调用非法!";
+                return "接口调用异常,请联系MES处理!";
             }
         }catch (Exception e){
             e.printStackTrace();

+ 8 - 1
src/main/java/com/uas/eis/service/Impl/MESServiceImpl.java

@@ -17,6 +17,7 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.stereotype.Service;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
 import java.util.*;
 
 /**
@@ -140,7 +141,13 @@ public class MESServiceImpl implements MESService {
     }
 
     @Override
-    public ApiResult<String> prodInOutMakeIn(HttpServletRequest request,String data) {
+    public ApiResult<String> prodInOutMakeIn(HttpServletRequest request) {
+        String data="";
+        try {
+            data = PSHttpUtils.readRaw(request.getInputStream());
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
         JSONObject jsonObject = JSON.parseObject(data);
         Object data1 = jsonObject.get("Data");
         JSONObject jsonObject1 = JSON.parseObject(StringUtil.nvl(data1,""));

+ 1 - 2
src/main/java/com/uas/eis/service/MESService.java

@@ -27,10 +27,9 @@ public interface MESService {
 
     /**
      * 成品半成品入库
-     * @param data
      * @return
      */
-    ApiResult<String> prodInOutMakeIn(HttpServletRequest request,String data);
+    ApiResult<String> prodInOutMakeIn(HttpServletRequest request);
 
     /**
      * 工单删除校验接口

+ 0 - 1
src/main/java/com/uas/eis/utils/HttpUtil.java

@@ -28,7 +28,6 @@ import javax.net.ssl.TrustManager;
 import javax.net.ssl.X509TrustManager;
 
 import org.apache.http.Consts;
-import org.apache.http.Header;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.NameValuePair;

+ 87 - 35
src/main/java/com/uas/eis/utils/MD5Util.java

@@ -1,35 +1,87 @@
-package com.uas.eis.utils;
-
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-public class MD5Util {
-
-	/**
-	 * MD5加密
-	 * @param message
-	 * @return
-	 */
-	public static String getEncryption(String message){
-		String result = "";
-		if(message != null){
-			try {
-				MessageDigest md = MessageDigest.getInstance("MD5");		//指定加密方式
-				//加密
-				byte[] bytes = md.digest(message.getBytes());
-				for(int i = 0; i < bytes.length; i++){
-					// 将整数转换成十六进制形式的字符串 这里与0xff进行与运算的原因是保证转换结果为32位
-					String str = Integer.toHexString(bytes[i] & 0xFF);
-					if(str.length() == 1){
-						str += "F";
-					}
-					result += str;
-				}
-			} catch (NoSuchAlgorithmException e) {
-				e.printStackTrace();
-			}	
-		}
-		return result;
-		
-	}
-}
+package com.uas.eis.utils;
+
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class MD5Util {
+
+	/**
+	 * MD5加密
+	 * @param message
+	 * @return
+	 */
+	public static String getEncryption(String message){
+		String result = "";
+		if(message != null){
+			try {
+				MessageDigest md = MessageDigest.getInstance("MD5");		//指定加密方式
+				//加密
+				byte[] bytes = md.digest(message.getBytes());
+				for(int i = 0; i < bytes.length; i++){
+					// 将整数转换成十六进制形式的字符串 这里与0xff进行与运算的原因是保证转换结果为32位
+					String str = Integer.toHexString(bytes[i] & 0xFF);
+					if(str.length() == 1){
+						str += "F";
+					}
+					result += str;
+				}
+			} catch (NoSuchAlgorithmException e) {
+				e.printStackTrace();
+			}	
+		}
+		return result;
+		
+	}
+
+	public static String encodeByMD5(String originString) {
+		if (originString != null) {
+			try {
+				MessageDigest md = MessageDigest.getInstance("MD5");
+				byte[] results = md.digest(originString.getBytes());
+				String resultString = byteArrayToHexString(results);
+				return resultString.toUpperCase();
+			} catch (Exception ex) {
+				ex.printStackTrace();
+			}
+		}
+		return null;
+	}
+
+	public static String byteArrayToHexString(byte[] bArr) {
+		StringBuffer sb = new StringBuffer(bArr.length);
+		String sTmp;
+
+		for (int i = 0; i < bArr.length; i++) {
+			sTmp = Integer.toHexString(0xFF & bArr[i]);
+			if (sTmp.length() < 2){
+				sb.append(0);
+			}
+			sb.append(sTmp.toUpperCase());
+		}
+		return sb.toString();
+	}
+	/**
+	 * hex字符串转byte数组
+	 * @param inHex 待转换的Hex字符串
+	 * @return  转换后的byte数组结果
+	 */
+	public static byte[] hexToByteArray(String inHex){
+		int hexlen = inHex.length();
+		byte[] result;
+		if (hexlen % 2 == 1){
+			//奇数
+			hexlen++;
+			result = new byte[(hexlen/2)];
+			inHex="0"+inHex;
+		}else {
+			//偶数
+			result = new byte[(hexlen/2)];
+		}
+		int j=0;
+		for (int i = 0; i < hexlen; i+=2){
+			result[j]=(byte)Integer.parseInt(inHex.substring(i,i+2),16);
+			j++;
+		}
+		return result;
+	}
+}

+ 697 - 0
src/main/java/com/uas/eis/utils/PSHttpUtils.java

@@ -0,0 +1,697 @@
+package com.uas.eis.utils;
+
+import com.uas.api.crypto.util.FlexJsonUtils;
+import org.apache.http.Consts;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.*;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.entity.mime.MultipartEntityBuilder;
+import org.apache.http.entity.mime.content.FileBody;
+import org.apache.http.entity.mime.content.StringBody;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.util.EntityUtils;
+import org.springframework.http.HttpStatus;
+import org.springframework.util.StreamUtils;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+/**
+ * 公共服务HTTP请求
+ *
+ * @author hejq
+ * @date 2018-01-26 14:31
+ */
+public class PSHttpUtils {
+
+	/**
+	 * 发送GET请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendGetRequest(String url, Map<String, ?> params) throws Exception {
+		return sendGetRequest(url, params, false);
+	}
+
+	/**
+	 * 发送GET请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	@SuppressWarnings("unchecked")
+	public static Response sendGetRequest(String url, Map<String, ?> params, boolean sign) throws Exception {
+		return sendRequest(RequestMethod.GET, url, (Map<String, Object>) params, sign, false);
+	}
+
+	/**
+	 * 暂时先使用这种方法(短信接口调用)
+	 */
+	public static String sendPost(String url, String param) {
+		PrintWriter out = null;
+		BufferedReader in = null;
+		String result = "";
+		try {
+			URL realUrl = new URL(url);
+			// 打开和URL之间的连接
+			URLConnection conn = realUrl.openConnection();
+			// 设置通用的请求属性
+			conn.setRequestProperty("content-type", "application/json");
+			conn.setRequestProperty("accept", "*/*");
+			conn.setRequestProperty("connection", "Keep-Alive");
+			conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
+			// 发送POST请求必须设置如下两行
+			conn.setDoOutput(true);
+			conn.setDoInput(true);
+			// 获取URLConnection对象对应的输出流
+			out = new PrintWriter(conn.getOutputStream());
+			// 发送请求参数
+			out.print(param);
+			// flush输出流的缓冲
+			out.flush();
+			// 定义BufferedReader输入流来读取URL的响应
+			in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+			String line;
+			while ((line = in.readLine()) != null) {
+				result += line;
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		// 使用finally块来关闭输出流、输入流
+		finally {
+			try {
+				if (out != null) {
+					out.close();
+				}
+				if (in != null) {
+					in.close();
+				}
+			} catch (IOException ex) {
+				ex.printStackTrace();
+			}
+		}
+		return result;
+	}
+
+	/**
+	 * 发送POST请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendPostRequest(String url, Map<String, ?> params) throws Exception {
+		return sendPostRequest(url, params, false);
+	}
+
+	/**
+	 * 发送POST请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	@SuppressWarnings("unchecked")
+	public static Response sendPostRequest(String url, Map<String, ?> params, boolean sign) throws Exception {
+		return sendRequest(RequestMethod.POST, url, (Map<String, Object>) params, sign, true);
+	}
+
+	/**
+	 * 发送POST请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @param encode
+	 *            是否使用URLEncode
+	 * @return
+	 * @throws Exception
+	 */
+	@SuppressWarnings("unchecked")
+	public static Response sendPostRequest(String url, Map<String, ?> params, boolean sign, boolean encode)
+			throws Exception {
+		return sendRequest(RequestMethod.POST, url, (Map<String, Object>) params, sign, encode);
+	}
+
+	/**
+	 * 发送Post请求,直接将List类型放入其中
+	 *
+	 * @param postUrl
+	 * @param formData
+	 * @return
+	 * @throws Exception
+	 */
+	public static String doPost(String postUrl, String formData) throws Exception {
+		HttpClient httpClient = new DefaultHttpClient();
+		HttpPost post = new HttpPost(postUrl);
+		StringEntity postingString = new StringEntity(formData,  HTTP.UTF_8);
+		post.setEntity(postingString);
+		post.setHeader("Content-type", "application/json");
+		HttpResponse response = httpClient.execute(post);
+		String content = EntityUtils.toString(response.getEntity());
+		return content;
+	}
+
+	/**
+	 * 发送DELETE请求
+	 * 
+	 * @param url
+	 * @param params
+	 * 
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendDeleteRequest(String url, Map<String, ?> params) throws Exception {
+		return sendDeleteRequest(url, params, false);
+	}
+
+	/**
+	 * 发送DELETE请求
+	 * 
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否发送签名
+	 * @return
+	 * @throws Exception
+	 */
+	@SuppressWarnings("unchecked")
+	public static Response sendDeleteRequest(String url, Map<String, ?> params, boolean sign) throws Exception {
+		return sendRequest(RequestMethod.DELETE, url, (Map<String, Object>) params, sign, false);
+	}
+
+	/**
+	 * 发起http请求
+	 *
+	 * @param method
+	 *            请求方法GET、POST、PUT、DELETE
+	 * @param url
+	 *            请求链接
+	 * @param params
+	 *            参数
+	 * @param sign
+	 *            是否签名
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendRequest(RequestMethod method, String url, Map<String, Object> params, boolean sign,
+                                       boolean encode) throws Exception {
+		switch (method) {
+		case GET:
+			return sendHttpUriRequest(new HttpGet(getRequestUrl(url, params, sign)));
+		case POST:
+			return sendHttpEntityEnclosingRequest(new HttpPost(getRequestUrl(url, sign)), params, encode);
+		case PUT:
+			return sendHttpEntityEnclosingRequest(new HttpPut(getRequestUrl(url, sign)), params, encode);
+		case DELETE:
+			return sendHttpUriRequest(new HttpDelete(getRequestUrl(url, params, sign)));
+		default:
+			return sendHttpUriRequest(new HttpGet(getRequestUrl(url, params, sign)));
+		}
+	}
+
+	/**
+	 * 发起GET、DELETE请求
+	 * 
+	 * @param request
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendHttpUriRequest(HttpRequestBase request) throws Exception {
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		CloseableHttpResponse response = null;
+		try {
+			response = httpClient.execute(request);
+			return Response.getResponse(response);
+		} finally {
+			try {
+				httpClient.close();
+			} catch (IOException e) {
+			}
+			if (response != null) {
+				try {
+					response.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+	}
+
+	/**
+	 * 发起POST、PUT请求
+	 * 
+	 * @param request
+	 * @param params
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendHttpEntityEnclosingRequest(HttpEntityEnclosingRequestBase request,
+                                                          Map<String, Object> params, boolean encode) throws Exception {
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		CloseableHttpResponse response = null;
+		try {
+			if (!encode) {
+				request.setEntity(new StringEntity(FlexJsonUtils.toJson(params), ContentType.APPLICATION_JSON));
+			} else {
+				List<NameValuePair> nvps = new ArrayList<NameValuePair>();
+				if (params != null && !params.isEmpty()) {
+					Set<Entry<String, Object>> entrys = params.entrySet();
+					for (Entry<String, Object> entry : entrys) {
+						Object entryValue = entry.getValue();
+						String entryValueStr = null;
+						if (entryValue instanceof String) {
+							entryValueStr = entryValue.toString();
+						} else {
+							entryValueStr = FlexJsonUtils.toJson(entry.getValue());
+						}
+						nvps.add(new BasicNameValuePair(entry.getKey(), URLEncoder.encode(entryValueStr, "UTF-8")));
+					}
+				}
+				request.setEntity(new UrlEncodedFormEntity(nvps));
+			}
+			System.out.println("Post request: "+request);
+			response = httpClient.execute(request);
+			return Response.getResponse(response);
+		} finally {
+			request.releaseConnection();
+			try {
+				httpClient.close();
+			} catch (IOException e) {
+			}
+			if (response != null) {
+				try {
+					response.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+	}
+
+	public static Response sendNotEnRequest(String url, Map<String, Object> params, boolean sign) throws Exception {
+		return sendHttpEntityNotEnclosingRequest(new HttpPost(getRequestUrl(url, sign)), params);
+	}
+
+	/**
+	 * 发起POST请求
+	 *
+	 * @param request
+	 * @param params
+	 * @return
+	 * @throws Exception
+	 */
+	public static Response sendHttpEntityNotEnclosingRequest(HttpEntityEnclosingRequestBase request,
+                                                             Map<String, Object> params) throws Exception {
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		CloseableHttpResponse response = null;
+		try {
+			List<NameValuePair> nvps = new ArrayList<NameValuePair>();
+			if (params != null && !params.isEmpty()) {
+				Set<Entry<String, Object>> entrys = params.entrySet();
+				for (Entry<String, Object> entry : entrys) {
+					Object entryValue = entry.getValue();
+					String entryValueStr = null;
+					if (entryValue instanceof String) {
+						entryValueStr = entryValue.toString();
+					} else {
+						entryValueStr = FlexJsonUtils.toJson(entry.getValue());
+					}
+					//String str = new String(entryValueStr.getBytes(),"UTF-8");
+					nvps.add(new BasicNameValuePair(entry.getKey(), entryValueStr));
+				}
+			}
+//			request.addHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
+			request.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
+
+			System.out.println("Post request: "+request);
+
+			response = httpClient.execute(request);
+			return Response.getResponse(response);
+		} finally {
+			request.releaseConnection();
+			try {
+				httpClient.close();
+			} catch (IOException e) {
+			}
+			if (response != null) {
+				try {
+					response.close();
+				} catch (IOException e) {
+				}
+			}
+		}
+	}
+
+	/**
+	 * 将请求参数添加到链接中
+	 *
+	 * @param url
+	 * @param params
+	 * @param sign
+	 *            是否签名
+	 * @return
+	 * @throws UnsupportedEncodingException
+	 */
+	public static String getRequestUrl(String url, Map<String, Object> params, boolean sign)
+			throws UnsupportedEncodingException {
+		StringBuilder buf = new StringBuilder(url);
+		if (url.indexOf("?") == -1)
+			buf.append("?");
+		else if (!url.endsWith("&"))
+			buf.append("&");
+		// 如果是GET请求,则请求参数在URL中
+		if (params != null && !params.isEmpty()) {
+			Set<Entry<String, Object>> entrys = params.entrySet();
+			for (Entry<String, Object> entry : entrys) {
+				buf.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue().toString(), "UTF-8"))
+						.append("&");
+			}
+		}
+		if (sign) {
+			// 加时间戳,保持相同请求每次签名均不一样
+			buf.append("_timestamp=").append(System.currentTimeMillis());
+			String message = buf.toString();
+			// 对请求串进行签名
+//			buf.append("&_signature=").append(HmacUtils.encode(message));
+		} else
+			buf.deleteCharAt(buf.length() - 1);
+		return buf.toString();
+	}
+
+	/**
+	 * 将签名信息添加到链接中
+	 *
+	 * @param url
+	 * @param sign
+	 *            是否签名
+	 * @return
+	 */
+	public static String getRequestUrl(String url, boolean sign) {
+		try {
+			return getRequestUrl(url, null, sign);
+		} catch (UnsupportedEncodingException e) {
+		}
+		return null;
+	}
+
+	/**
+	 * 将输入流转为字节数组
+	 * 
+	 * @param inStream
+	 * @return
+	 * @throws Exception
+	 */
+	public static byte[] read2Byte(InputStream inStream) throws Exception {
+		ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
+		byte[] buffer = new byte[1024];
+		int len = 0;
+		while ((len = inStream.read(buffer)) != -1) {
+			outSteam.write(buffer, 0, len);
+		}
+		outSteam.close();
+		inStream.close();
+		return outSteam.toByteArray();
+	}
+
+	/**
+	 * 将输入流转为字符串
+	 * 
+	 * @param inStream
+	 * @return
+	 * @throws Exception
+	 */
+	public static String read2String(InputStream inStream) throws Exception {
+		ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
+		byte[] buffer = new byte[1024];
+		int len = 0;
+		while ((len = inStream.read(buffer)) != -1) {
+			outSteam.write(buffer, 0, len);
+		}
+		try {
+			outSteam.close();
+			inStream.close();
+		} catch (Exception e) {
+
+		}
+		return new String(outSteam.toByteArray(), "UTF-8");
+	}
+
+	/**
+	 * 发送xml数据
+	 * 
+	 * @param path
+	 *            请求地址
+	 * @param xml
+	 *            xml数据
+	 * @param encoding
+	 *            编码
+	 * @return
+	 * @throws Exception
+	 */
+	public static byte[] postXml(String path, String xml, String encoding) throws Exception {
+		byte[] data = xml.getBytes(encoding);
+		URL url = new URL(path);
+		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+		conn.setRequestMethod("POST");
+		conn.setDoOutput(true);
+		conn.setRequestProperty("Content-Type", "text/xml; charset=" + encoding);
+		conn.setRequestProperty("Content-Length", String.valueOf(data.length));
+		conn.setConnectTimeout(5 * 1000);
+		OutputStream outStream = conn.getOutputStream();
+		outStream.write(data);
+		outStream.flush();
+		outStream.close();
+		if (conn.getResponseCode() == HttpStatus.OK.value()) {
+			return read2Byte(conn.getInputStream());
+		}
+		return null;
+	}
+
+	/**
+	 * http上传文件
+	 * 
+	 * @param postUrl
+	 *            请求地址
+	 * @param filePath
+	 *            附件路径
+	 * @param params
+	 *            参数
+	 * @return
+	 * @throws Exception
+	 * @throws IOException
+	 * @throws IllegalStateException
+	 */
+	public static Response upload(String postUrl, String filePath, Map<String, String> params)
+			throws IllegalStateException, IOException, Exception {
+		CloseableHttpClient httpClient = null;
+		CloseableHttpResponse response = null;
+		try {
+			httpClient = HttpClients.createDefault();
+			HttpPost httpPost = new HttpPost(postUrl);
+			FileBody fileBody = new FileBody(new File(filePath));
+			MultipartEntityBuilder builder = MultipartEntityBuilder.create();
+			builder.addPart("file", fileBody);
+			if (params != null) {
+				for (String paramKey : params.keySet()) {
+					StringBody body = new StringBody(params.get(paramKey), ContentType.create("text/plain",
+							Consts.UTF_8));
+					builder.addPart(paramKey, body);
+				}
+			}
+			HttpEntity reqEntity = builder.build();
+			httpPost.setEntity(reqEntity);
+			response = httpClient.execute(httpPost);
+		} finally {
+			try {
+				if (response != null) {
+					response.close();
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+			try {
+				if (httpClient != null) {
+					httpClient.close();
+				}
+			} catch (IOException e) {
+				e.printStackTrace();
+			}
+		}
+		return Response.getResponse(response);
+	}
+
+	/**
+	 * 下载
+	 * 
+	 * @param postUrl
+	 * @return
+	 * @throws ClientProtocolException
+	 * @throws IOException
+	 */
+	public static InputStream download(String postUrl) throws ClientProtocolException, IOException {
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		HttpGet httpGet = new HttpGet(postUrl);
+		CloseableHttpResponse response = httpClient.execute(httpGet);
+		return response.getEntity().getContent();
+	}
+
+	/**
+	 * 获取请求客户端的IP地址
+	 * 
+	 * @param request
+	 * @return
+	 * @throws Exception
+	 */
+	public static String getIpAddr(HttpServletRequest request) {
+		String ip = request.getHeader("x-forwarded-for");
+		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			ip = request.getHeader("Proxy-Client-IP");
+		}
+		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			ip = request.getHeader("WL-Proxy-Client-IP");
+		}
+		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			ip = request.getHeader("HTTP_CLIENT_IP");
+		}
+		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			ip = request.getHeader("HTTP_X_FORWARDED_FOR");
+		}
+		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+			ip = request.getRemoteAddr();
+		}
+		return ip;
+	}
+	
+	/**
+	 * POST发送
+	 * 
+	 * @param url
+	 * @param data
+	 * @throws Exception
+	 */
+	public static String post(String url, String data) throws Exception {
+		URL urls = new URL(url);
+		HttpURLConnection http = (HttpURLConnection) urls.openConnection();
+		http.setRequestMethod("POST");
+		http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
+		http.setDoOutput(true);
+		http.setDoInput(true);
+		System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
+		System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
+		http.connect();
+		OutputStream os = http.getOutputStream();
+		os.write(data.getBytes("UTF-8"));// 传入参数
+		os.flush();
+		os.close();
+		// 从服务器读取响应
+		String encoding = http.getContentEncoding();
+		if (encoding == null)
+			encoding = "UTF-8";
+		return StreamUtils.copyToString(http.getInputStream(), Charset.forName(encoding));
+	}
+
+	public static class Response {
+		private int statusCode;
+		private String responseText;
+		private HttpResponse response;
+
+		public int getStatusCode() {
+			return statusCode;
+		}
+
+		public void setStatusCode(int statusCode) {
+			this.statusCode = statusCode;
+		}
+
+		public String getResponseText() {
+			return responseText;
+		}
+
+		public void setResponseText(String responseText) {
+			this.responseText = responseText;
+		}
+
+		public HttpResponse getResponse() {
+			return response;
+		}
+
+		public void setResponse(HttpResponse response) {
+			this.response = response;
+		}
+
+		public Response() {
+		}
+
+		public Response(HttpResponse response) throws IllegalStateException, IOException, Exception {
+			this.statusCode = response.getStatusLine().getStatusCode();
+			this.responseText = PSHttpUtils.read2String(response.getEntity().getContent());
+			this.response = response;
+		}
+
+		public static Response getResponse(HttpResponse response) throws IllegalStateException, IOException, Exception {
+			if (response != null)
+				return new Response(response);
+			return null;
+		}
+	}
+
+	/**
+	 * java获取raw
+	 */
+	public static String readRaw(InputStream inputStream) {
+
+		String result = "";
+		try {
+			ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
+			byte[] buffer = new byte[1024];
+
+			int len;
+			while ((len = inputStream.read(buffer)) != -1) {
+				outSteam.write(buffer, 0, len);
+			}
+
+			outSteam.close();
+			inputStream.close();
+
+			result = new String(outSteam.toByteArray(), "UTF-8");
+
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+
+		return result;
+	}
+}