zouxuan 6 rokov pred
rodič
commit
349063b625

+ 20 - 6
pom.xml

@@ -124,12 +124,26 @@
         <groupId>org.apache.commons</groupId>
         <artifactId>commons-lang3</artifactId>
       </dependency>
-      
-      <dependency>
-        <groupId>com.ym</groupId>
-        <artifactId>mec-task</artifactId>
-        <version>1.0</version>
-      </dependency>
+		<dependency>
+			<groupId>commons-beanutils</groupId>
+			<artifactId>commons-beanutils</artifactId>
+			<version>1.8.3</version>
+		</dependency>
+		<dependency>
+			<groupId>com.thoughtworks.xstream</groupId>
+			<artifactId>xstream</artifactId>
+			<version>1.4.11.1</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.httpcomponents</groupId>
+			<artifactId>httpclient</artifactId>
+			<version>4.5.2</version>
+		</dependency>
+		<dependency>
+			<groupId>com.alibaba</groupId>
+			<artifactId>fastjson</artifactId>
+			<version>1.2.28</version>
+		</dependency>
 	</dependencies>
 
 	<build>

+ 28 - 3
src/main/java/com/ym/mec/collectfee/controller/OrderController.java

@@ -1,13 +1,12 @@
 package com.ym.mec.collectfee.controller;
 
+import com.ym.mec.collectfee.common.web.BaseController;
+import com.ym.mec.collectfee.service.OrderService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import com.ym.mec.collectfee.common.web.BaseController;
-import com.ym.mec.collectfee.service.OrderService;
-
 @RestController()
 @RequestMapping("order")
 public class OrderController extends BaseController {
@@ -15,9 +14,35 @@ public class OrderController extends BaseController {
     @Autowired
     private OrderService orderService;
 
+    /**
+     * 获取订单列表
+     * @param userId
+     * @return
+     */
     @PostMapping("/get")
     public Object getOrders(Integer userId){
         return succeed(orderService.getOrderByUserId(userId));
     }
 
+    /**
+     * 查询报名人数
+     * @param poName
+     * @param voicePart
+     * @return
+     */
+    @PostMapping("/applyNum")
+    public Object queryNum(String poName,String voicePart){
+        return orderService.countOrder(poName, voicePart);
+    }
+
+    /**
+     * 推送订单
+     * @param batchNum
+     * @return
+     */
+    @PostMapping("/pushOrder")
+    public String pushOrder(String batchNum){
+        return orderService.pushOrder(batchNum);
+    }
+
 }

+ 43 - 30
src/main/java/com/ym/mec/collectfee/entity/Order.java

@@ -1,10 +1,15 @@
 package com.ym.mec.collectfee.entity;
 
+import com.thoughtworks.xstream.annotations.XStreamAlias;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 
+import java.math.BigDecimal;
+import java.util.Date;
+
 /**
  * 对应数据库表(order):
  */
+@XStreamAlias("order")
 public class Order {
 
 	/**  */
@@ -17,13 +22,13 @@ public class Order {
 	private Integer userId;
 	
 	/** 订单总金额(分) */
-	private Long amount;
+	private BigDecimal amount;
 	
 	/** 支付成功金额(分)。本次在线支付(充值)的金额,该金额通常应该等于订单总金额;如果该金额少于订单总金额,则自动使用学员账户余额补足订单总金额;该金额不能大于订单总金额 */
-	private Long pay;
+	private BigDecimal pay;
 	
 	/** 在线支付平台 */
-	private Integer bank;
+	private String bank;
 	
 	/** 公司收款帐号。本次接收学员款项的公司在线支付平台(支付宝、微信等)账户号 */
 	private String account;
@@ -35,7 +40,7 @@ public class Order {
 	private String payId;
 	
 	/** 支付到帐时间 */
-	private java.util.Date payTime;
+	private Date payTime;
 	
 	/** 交易订单明细 */
 	private String remark;
@@ -47,7 +52,7 @@ public class Order {
 	private Integer status;
 	
 	/** 创建时间 */
-	private java.util.Date createTime;
+	private Date createTime;
 	
 	/** 乐团名称 */
 	private String poName;
@@ -56,7 +61,7 @@ public class Order {
 	private String voicyPart;
 	
 	/** 账户扣款金额 */
-	private Long balance;
+	private BigDecimal balance;
 	
 	/** 批次号 */
 	private String batchNum;
@@ -84,31 +89,39 @@ public class Order {
 	public Integer getUserId(){
 		return this.userId;
 	}
-			
-	public void setAmount(Long amount){
+
+	public BigDecimal getAmount() {
+		return amount;
+	}
+
+	public void setAmount(BigDecimal amount) {
 		this.amount = amount;
 	}
-	
-	public Long getAmount(){
-		return this.amount;
+
+	public String getuAccount() {
+		return uAccount;
 	}
-			
-	public void setPay(Long pay){
+
+	public void setuAccount(String uAccount) {
+		this.uAccount = uAccount;
+	}
+
+	public BigDecimal getPay() {
+		return pay;
+	}
+
+	public void setPay(BigDecimal pay) {
 		this.pay = pay;
 	}
-	
-	public Long getPay(){
-		return this.pay;
+
+	public String getBank() {
+		return bank;
 	}
-			
-	public void setBank(Integer bank){
+
+	public void setBank(String bank) {
 		this.bank = bank;
 	}
-	
-	public Integer getBank(){
-		return this.bank;
-	}
-			
+
 	public void setAccount(String account){
 		this.account = account;
 	}
@@ -188,15 +201,15 @@ public class Order {
 	public String getVoicyPart(){
 		return this.voicyPart;
 	}
-			
-	public void setBalance(Long balance){
-		this.balance = balance;
+
+	public BigDecimal getBalance() {
+		return balance;
 	}
-	
-	public Long getBalance(){
-		return this.balance;
+
+	public void setBalance(BigDecimal balance) {
+		this.balance = balance;
 	}
-			
+
 	public void setBatchNum(String batchNum){
 		this.batchNum = batchNum;
 	}

+ 24 - 0
src/main/java/com/ym/mec/collectfee/entity/Orders.java

@@ -0,0 +1,24 @@
+package com.ym.mec.collectfee.entity;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+import java.util.List;
+
+public class Orders {
+    @XStreamAlias("body")
+    private List<Order> orders;
+
+    public Orders(List<Order> orders) {
+        this.orders = orders;
+    }
+
+    public Orders() {
+    }
+
+    public List<Order> getOrders() {
+        return orders;
+    }
+
+    public void setOrders(List<Order> orders) {
+        this.orders = orders;
+    }
+}

+ 94 - 0
src/main/java/com/ym/mec/collectfee/entity/RequestHead.java

@@ -0,0 +1,94 @@
+package com.ym.mec.collectfee.entity;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.SimpleTimeZone;
+
+@XStreamAlias("head")
+public class RequestHead {
+
+    //消息编号,不可重复
+    private String msgId;
+
+    //交易指令
+    private Integer cmd = 121512;
+
+    //调用接口的用户id
+    private Integer uid = 2;
+
+    //请求时间戳,yyyymmddhhmmss
+    private String ts;
+
+    //响应数据类别,xml
+    private String ret = "xml";
+
+    //加密类型 0不加密(默认),1DES加密,2专用算法1,3专用算法2,4DES加密(Ansi版, ECB模式,PKCS5)
+    private Integer encrypt = 0;
+
+    //签名
+    private String sign;
+
+    public RequestHead() {
+        String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
+        setTs(format);
+    }
+
+    public String getMsgId() {
+        return msgId;
+    }
+
+    public void setMsgId(String msgId) {
+        this.msgId = msgId;
+    }
+
+    public Integer getCmd() {
+        return cmd;
+    }
+
+    public void setCmd(Integer cmd) {
+        this.cmd = cmd;
+    }
+
+    public Integer getUid() {
+        return uid;
+    }
+
+    public void setUid(Integer uid) {
+        this.uid = uid;
+    }
+
+    public String getTs() {
+        return ts;
+    }
+
+    public void setTs(String ts) {
+        this.ts = ts;
+    }
+
+    public String getRet() {
+        return ret;
+    }
+
+    public void setRet(String ret) {
+        this.ret = ret;
+    }
+
+    public Integer getEncrypt() {
+        return encrypt;
+    }
+
+    public void setEncrypt(Integer encrypt) {
+        this.encrypt = encrypt;
+    }
+
+    public String getSign() {
+        return sign;
+    }
+
+    public void setSign(String sign) {
+        this.sign = sign;
+    }
+}

+ 40 - 0
src/main/java/com/ym/mec/collectfee/entity/RequestParamBean.java

@@ -0,0 +1,40 @@
+package com.ym.mec.collectfee.entity;
+
+import com.thoughtworks.xstream.annotations.XStreamAlias;
+
+@XStreamAlias("request")
+public class RequestParamBean {
+
+    @XStreamAlias("head")
+    private RequestHead head;
+
+    @XStreamAlias("body")
+    private String body;
+
+    public String getBody() {
+        return body;
+    }
+
+    public void setBody(String body) {
+        this.body = body;
+    }
+
+    //    private List<Order> orders = new ArrayList<>();
+
+    public RequestHead getHead() {
+        return head;
+    }
+
+    public void setHead(RequestHead head) {
+        this.head = head;
+    }
+
+//    public List<Order> getOrders() {
+//        return orders;
+//    }
+//
+//    public void setOrders(List<Order> orders) {
+//        this.orders = orders;
+//    }
+
+}

+ 2 - 2
src/main/java/com/ym/mec/collectfee/job/TaskDemo.java

@@ -11,7 +11,7 @@ import java.time.LocalDateTime;
 @EnableScheduling
 public class TaskDemo {
 
-    @Scheduled(cron = "0/5 * * * * ?")
+    /*@Scheduled(cron = "0/5 * * * * ?")
     //或直接指定时间间隔,例如:5秒
     //@Scheduled(fixedRate=5000)
     private void taskOne() {
@@ -24,5 +24,5 @@ public class TaskDemo {
     //@Scheduled(fixedRate=5000)
     private void taskTwo() {
         System.err.println("执行静态定时任务时间222: " + LocalDateTime.now());
-    }
+    }*/
 }

+ 2 - 1
src/main/java/com/ym/mec/collectfee/service/OrderService.java

@@ -3,6 +3,7 @@ package com.ym.mec.collectfee.service;
 import com.ym.mec.collectfee.common.service.BaseService;
 import com.ym.mec.collectfee.entity.Order;
 
+import javax.xml.bind.JAXBException;
 import java.util.List;
 
 public interface OrderService extends BaseService<Integer, Order> {
@@ -19,7 +20,7 @@ public interface OrderService extends BaseService<Integer, Order> {
      * @param batchNum 批次号
      * @return
      */
-    List<Order> pushOrder(String batchNum);
+    String pushOrder(String batchNum);
 
     /**
      * 查询某声部报名成功人数

+ 57 - 2
src/main/java/com/ym/mec/collectfee/service/impl/OrderServiceImpl.java

@@ -1,13 +1,22 @@
 package com.ym.mec.collectfee.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.thoughtworks.xstream.XStream;
 import com.ym.mec.collectfee.common.dao.BaseDAO;
 import com.ym.mec.collectfee.common.service.impl.BaseServiceImpl;
 import com.ym.mec.collectfee.dao.OrderDao;
 import com.ym.mec.collectfee.entity.Order;
+import com.ym.mec.collectfee.entity.Orders;
+import com.ym.mec.collectfee.entity.RequestParamBean;
+import com.ym.mec.collectfee.entity.RequestHead;
 import com.ym.mec.collectfee.service.OrderService;
+import com.ym.mec.collectfee.utils.XStreamUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Base64;
 import java.util.List;
 
 @Service
@@ -16,6 +25,9 @@ public class OrderServiceImpl extends BaseServiceImpl<Integer, Order> implements
 	@Autowired
 	private OrderDao orderDao;
 
+	//公共密钥
+	private String publicKey = "e99a18c428cb38d5f260853678922e03";
+
 	@Override
 	public BaseDAO<Integer, Order> getDAO() {
 		return orderDao;
@@ -27,8 +39,51 @@ public class OrderServiceImpl extends BaseServiceImpl<Integer, Order> implements
 	}
 
 	@Override
-	public List<Order> pushOrder(String batchNum) {
-		return orderDao.getOrderByBatch(batchNum);
+	public String pushOrder(String batchNum){
+		try {
+			RequestParamBean requestParamBean = new RequestParamBean();
+			List<Order> orderList = orderDao.getOrderByBatch(batchNum);
+			if(orderList == null || orderList.size() < 1){
+				return null;
+			}
+			XStream xs = new XStream();
+			xs.autodetectAnnotations(true);
+			Writer writer = new StringWriter();
+			Orders orders = new Orders(orderList);
+			xs.toXML(orders,writer);
+			String body = writer.toString();
+			body = body.substring(body.indexOf("<body>")+6,body.indexOf("</body>"));
+//			String body = "<id>1</id><oid>123456</oid><userId>100018</userId><amount>1000.00</amount><pay>1000.00</pay><bank>301</bank><account>2342345</account><uAccount>123423452</uAccount><payId>234562354234</payId><payTime>2019-08-19 16:33:42.0 UTC</payTime><remark>test</remark><classId>1</classId><status>0</status><createTime>2019-08-19 16:34:12.0 UTC</createTime><poName>er而为人</poName><voicyPart>阿道夫</voicyPart><balance>500.00</balance><batchNum>23452345</batchNum>";
+
+			body = Base64.getEncoder().encodeToString(body.getBytes());
+			requestParamBean.setBody(body);
+			requestParamBean.setHead(getOrdersHead(orderList,body));
+
+			xs.autodetectAnnotations(true);
+			writer = new StringWriter();
+			writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
+			xs.toXML(requestParamBean,writer);
+			return writer.toString();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	private RequestHead getOrdersHead(List<Order> orders,String body){
+		Order order = orders.get(0);
+		RequestHead head = new RequestHead();
+		head.setMsgId(order.getBatchNum());
+		head.setSign(getSign(head, body, publicKey));
+		return head;
+	}
+
+
+	private String getSign(RequestHead head,String body,String userSign){
+		//msgId+cmd+uid+ts+body+用户密钥/公共密钥
+		StringBuffer sb = new StringBuffer(head.getMsgId());
+		sb.append(head.getCmd()).append(head.getUid()).append(head.getTs()).append(body).append(userSign);
+		return XStreamUtil.encryption(sb.toString()).toLowerCase();
 	}
 
 	@Override

+ 0 - 14
src/main/java/com/ym/mec/collectfee/tasks/MyTask.java

@@ -1,14 +0,0 @@
-package com.ym.mec.collectfee.tasks;
-
-import com.ym.mec.task.core.BaseTask;
-import com.ym.mec.task.core.TaskException;
-
-public class MyTask extends BaseTask {
-
-	@Override
-	public void execute() throws TaskException {
-		// TODO Auto-generated method stub
-
-	}
-
-}

+ 267 - 0
src/main/java/com/ym/mec/collectfee/utils/HttpUtil.java

@@ -0,0 +1,267 @@
+package com.ym.mec.collectfee.utils;
+
+import org.apache.commons.beanutils.ConvertUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+import org.apache.tomcat.util.http.fileupload.IOUtils;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public class HttpUtil {
+
+	/**
+	 * POST请求http url
+	 * 
+	 * @param url
+	 *            URL
+	 * @param parameterMap
+	 *            请求参数
+	 * @return 返回结果
+	 * @throws IOException 
+	 */
+	public static String postForHttp(String url, Map<String, Object> parameterMap) throws IOException {
+		String result = null;
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		HttpPost httpPost = new HttpPost(url);
+		try {
+			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
+			if (parameterMap != null) {
+				for (Entry<String, Object> entry : parameterMap.entrySet()) {
+					String name = entry.getKey();
+					String value = ConvertUtils.convert(entry.getValue());
+					if (StringUtils.isNotEmpty(name)) {
+						nameValuePairs.add(new BasicNameValuePair(name, value));
+					}
+				}
+			}
+			httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
+			HttpResponse httpResponse = httpClient.execute(httpPost);
+			HttpEntity httpEntity = httpResponse.getEntity();
+			result = EntityUtils.toString(httpEntity, "UTF-8");
+			EntityUtils.consume(httpEntity);
+		} finally {
+			httpPost.releaseConnection();
+			httpClient.close();
+		}
+		return result;
+	}
+
+	/**
+	 * POST请求https url
+	 * 
+	 * @param url
+	 *            URL
+	 * @param parameterMap
+	 *            请求参数
+	 * @return 返回结果
+	 * @throws IOException 
+	 * @throws NoSuchAlgorithmException 
+	 * @throws KeyManagementException 
+	 * @throws KeyStoreException 
+	 */
+	public static String postForHttps(String url, Map<String, Object> parameterMap) throws IOException, NoSuchAlgorithmException, KeyManagementException,
+			KeyStoreException {
+		String result = null;
+		CloseableHttpClient httpClient = SimpleHttpsClient.getInstance();
+
+		HttpPost httpPost = new HttpPost(url);
+		try {
+			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
+			if (parameterMap != null) {
+				for (Entry<String, Object> entry : parameterMap.entrySet()) {
+					String name = entry.getKey();
+					String value = ConvertUtils.convert(entry.getValue());
+					if (StringUtils.isNotEmpty(name)) {
+						nameValuePairs.add(new BasicNameValuePair(name, value));
+					}
+				}
+			}
+			httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
+			HttpResponse httpResponse = httpClient.execute(httpPost);
+			HttpEntity httpEntity = httpResponse.getEntity();
+			result = EntityUtils.toString(httpEntity, "UTF-8");
+			EntityUtils.consume(httpEntity);
+		} finally {
+			httpPost.releaseConnection();
+			httpClient.close();
+		}
+		return result;
+	}
+
+	/**
+	 * POST请求https url
+	 * 
+	 * @param url
+	 *            URL
+	 * @param json
+	 *            请求参数
+	 * @param headers
+	 *            请求头参数
+	 * @return 返回结果
+	 * @throws IOException 
+	 * @throws NoSuchAlgorithmException 
+	 * @throws KeyManagementException 
+	 * @throws KeyStoreException 
+	 */
+	public static String postForHttps(String url, String json, Map<String, String> headers) throws IOException, NoSuchAlgorithmException,
+			KeyManagementException, KeyStoreException {
+		String result = null;
+		CloseableHttpClient httpClient = SimpleHttpsClient.getInstance();
+
+		HttpPost httpPost = new HttpPost(url);
+		if (headers != null && headers.size() > 0) {
+			for (Entry<String, String> entry : headers.entrySet()) {
+				httpPost.setHeader(entry.getKey(), entry.getValue());
+			}
+		}
+		try {
+			httpPost.setEntity(new StringEntity(json, "UTF-8"));
+
+			HttpResponse httpResponse = httpClient.execute(httpPost);
+			HttpEntity httpEntity = httpResponse.getEntity();
+			result = EntityUtils.toString(httpEntity, "UTF-8");
+			EntityUtils.consume(httpEntity);
+		} finally {
+			httpPost.releaseConnection();
+			httpClient.close();
+		}
+		return result;
+	}
+
+	/**
+	 * GET请求
+	 * 
+	 * @param url
+	 *            URL
+	 * @param parameterMap
+	 *            请求参数
+	 * @return 返回结果
+	 * @throws IOException 
+	 */
+	public static String get(String url, Map<String, Object> parameterMap) throws IOException {
+		return get(url, parameterMap, null);
+	}
+
+	/**
+	 * GET请求
+	 * 
+	 * @param url
+	 *            URL
+	 * @param parameterMap
+	 *            请求参数
+	 * @param headers
+	 *            请求头
+	 * @return 返回结果
+	 * @throws IOException 
+	 */
+	public static String get(String url, Map<String, Object> parameterMap, Map<String, String> headers) throws IOException {
+		String result = null;
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+		HttpGet httpGet = null;
+		try {
+			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
+			if (parameterMap != null) {
+				for (Entry<String, Object> entry : parameterMap.entrySet()) {
+					String name = entry.getKey();
+					String value = ConvertUtils.convert(entry.getValue());
+					if (StringUtils.isNotEmpty(name)) {
+						nameValuePairs.add(new BasicNameValuePair(name, value));
+					}
+				}
+			}
+			httpGet = new HttpGet(url + (StringUtils.contains(url, "?") ? "&" : "?") + EntityUtils.toString(new UrlEncodedFormEntity(nameValuePairs, "UTF-8")));
+			if (headers != null && headers.size() > 0) {
+				for (Entry<String, String> entry : headers.entrySet()) {
+					httpGet.setHeader(entry.getKey(), entry.getValue());
+				}
+			}
+			HttpResponse httpResponse = httpClient.execute(httpGet);
+			HttpEntity httpEntity = httpResponse.getEntity();
+			result = EntityUtils.toString(httpEntity, "UTF-8");
+			EntityUtils.consume(httpEntity);
+		} finally {
+			if (httpGet != null) {
+				httpGet.releaseConnection();
+			}
+			httpClient.close();
+		}
+		return result;
+	}
+
+	/**
+	 * POST请求https url
+	 * 
+	 * @param url
+	 *            URL
+	 * @param parameterMap
+	 *            请求参数
+	 * @return 返回结果
+	 * @throws IOException 
+	 * @throws NoSuchAlgorithmException 
+	 * @throws KeyManagementException 
+	 * @throws KeyStoreException 
+	 */
+	public static boolean downLoadPostForHttps(String url, Map<String, String> headerMap, Map<String, Object> parameterMap, String filePath)
+			throws IOException, NoSuchAlgorithmException, KeyManagementException, KeyStoreException {
+		CloseableHttpClient httpClient = HttpClients.createDefault();
+
+		HttpPost httpPost = new HttpPost(url);
+		if (headerMap != null) {
+			for (Entry<String, String> entry : headerMap.entrySet()) {
+				httpPost.addHeader(entry.getKey(), entry.getValue());
+			}
+		}
+		try {
+			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
+			if (parameterMap != null) {
+				for (Entry<String, Object> entry : parameterMap.entrySet()) {
+					String name = entry.getKey();
+					String value = ConvertUtils.convert(entry.getValue());
+					if (StringUtils.isNotEmpty(name)) {
+						nameValuePairs.add(new BasicNameValuePair(name, value));
+					}
+				}
+			}
+			httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
+			HttpResponse httpResponse = httpClient.execute(httpPost);
+			HttpEntity httpEntity = httpResponse.getEntity();
+			InputStream is = httpEntity.getContent();
+
+			File file = new File(filePath);
+			file.getParentFile().mkdirs();
+
+			FileOutputStream fileout = new FileOutputStream(file);
+
+			IOUtils.copy(is, fileout);
+			is.close();
+			fileout.flush();
+			fileout.close();
+
+			EntityUtils.consume(httpEntity);
+		} finally {
+			httpPost.releaseConnection();
+			httpClient.close();
+		}
+		return true;
+	}
+}

+ 38 - 0
src/main/java/com/ym/mec/collectfee/utils/SimpleHttpsClient.java

@@ -0,0 +1,38 @@
+package com.ym.mec.collectfee.utils;
+
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import org.apache.http.conn.ssl.NoopHostnameVerifier;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.impl.client.BasicCookieStore;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.ssl.SSLContextBuilder;
+import org.apache.http.ssl.TrustStrategy;
+
+public class SimpleHttpsClient {
+
+	public static CloseableHttpClient getInstance() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
+		SSLContextBuilder builder = new SSLContextBuilder();
+		builder.useProtocol("TLSv1.2");
+
+		builder.loadTrustMaterial(null, new TrustStrategy() {
+
+			@Override
+			public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+				return true;
+			}
+		});
+
+		SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), NoopHostnameVerifier.INSTANCE);
+
+		CloseableHttpClient httpClient = HttpClients.custom().setDefaultCookieStore(new BasicCookieStore()).setSSLSocketFactory(sslsf).build();
+
+		return httpClient;
+	}
+
+}

+ 177 - 178
src/main/java/com/ym/mec/collectfee/utils/WebUtil.java

@@ -1,195 +1,194 @@
 /**
- * WebUtil.java 
+ * WebUtil.java
  * Copyright © 2015-2015
- * 
+ *
  * @author pengdc
  * @create 2015年7月15日
  */
 package com.ym.mec.collectfee.utils;
 
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
+import org.apache.commons.lang3.StringUtils;
 
 import javax.servlet.http.Cookie;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.lang3.StringUtils;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
 
 /**
- * 
+ *
  */
 public class WebUtil {
 
-	public static String getRandomUUID() {
-		UUID uuid = UUID.randomUUID();
-		String str = uuid.toString();
-		String uuidStr = StringUtils.replace(str, "-", "");
-		return uuidStr;
-	}
-
-	public static void addCookie(String cookieName, String cookeValue, int age, String domain, String path, HttpServletResponse response) {
-		Cookie cookie = new Cookie(cookieName, cookeValue);
-		cookie.setMaxAge(age);// 单位:秒
-		if (StringUtils.isNotBlank(domain)) {
-			cookie.setDomain(domain);
-		}
-		if (StringUtils.isNotBlank(path)) {
-			cookie.setPath(path);
-		}
-		response.addCookie(cookie);
-		// response.addHeader("Set-Cookie", "HttpOnly");// 防止XSS
-	}
-
-	public static String getCookie(String key, HttpServletRequest request) {
-		Cookie[] cookies = request.getCookies();
-		if (cookies != null) {
-			for (Cookie cookie : cookies) {
-				if (cookie.getName().equals(key)) {
-					return cookie.getValue();
-				}
-			}
-		}
-		return null;
-	}
-
-	public static void removeCookie(String key, String domain, String path, HttpServletResponse response) {
-		Cookie cookie = new Cookie(key, null);
-		cookie.setMaxAge(0);
-		cookie.setPath(path);
-		cookie.setDomain(domain);
-		response.addCookie(cookie);
-	}
-
-	/**
-	 * 获取参数
-	 * 
-	 * @param queryString
-	 *            查询字符串
-	 * @param encoding
-	 *            编码格式
-	 * @param name
-	 *            参数名称
-	 * @return 参数
-	 */
-	public static Object getParameter(HttpServletRequest request, String name) {
-		Map<String, Object> parameterMap = getParameterMap(request);
-		return parameterMap.get(name);
-	}
-
-	/**
-	 * 获取所有参数
-	 * 
-	 */
-	@SuppressWarnings("rawtypes")
-	public static Map<String, Object> getParameterMap(HttpServletRequest request) {
-		Map<String, Object> parameterMap = new HashMap<String, Object>();
-		Object object = null;
-		Object[] objs = null;
-		Map params = request.getParameterMap();
-		Enumeration enu = request.getParameterNames();
-		while (enu.hasMoreElements()) {
-			String paraName = (String) enu.nextElement();
-			object = params.get(paraName);
-			if (object != null) {
-				if (object.getClass().isArray()) {
-					objs = (Object[]) object;
-					parameterMap.put(paraName, objs.length == 1 ? objs[0] : objs);
-				} else {
-					parameterMap.put(paraName, object);
-				}
-			}
-		}
-		return parameterMap;
-	}
-
-	/**
-	 * 获取所有Header参数
-	 * 
-	 */
-	@SuppressWarnings("rawtypes")
-	public static Map<String, Object> getHeaderMap(HttpServletRequest request) {
-		Map<String, Object> parameterMap = new HashMap<String, Object>();
-		Enumeration enu = request.getHeaderNames();
-		while (enu.hasMoreElements()) {
-			String paraName = (String) enu.nextElement();
-			Enumeration headerValues = request.getHeaders(paraName);
-			while (headerValues.hasMoreElements()) {
-				parameterMap.put(paraName, headerValues.nextElement());
-			}
-		}
-		return parameterMap;
-	}
-
-	/**
-	 * 获取客户端ip地址
-	 * @param request
-	 * @return
-	 */
-	public static String getRemoteIp(HttpServletRequest request) {
-		String remoteIp = request.getHeader("x-forwarded-for");
-		if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
-			remoteIp = request.getHeader("X-Real-IP");
-		}
-		if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
-			remoteIp = request.getHeader("Proxy-Client-IP");
-		}
-		if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
-			remoteIp = request.getHeader("WL-Proxy-Client-IP");
-		}
-		if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
-			remoteIp = request.getHeader("HTTP_CLIENT_IP");
-		}
-		if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
-			remoteIp = request.getHeader("HTTP_X_FORWARDED_FOR");
-		}
-		if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
-			remoteIp = request.getRemoteAddr();
-		}
-		if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
-			remoteIp = request.getRemoteHost();
-		}
-		if (remoteIp != null && remoteIp.indexOf(",") != -1) {
-			remoteIp = remoteIp.substring(remoteIp.lastIndexOf(",") + 1, remoteIp.length()).trim();
-		}
-		return remoteIp;
-	}
-
-	/**
-	 * 检查访问方式是否为移动端
-	 * @param domain cookie所在的域
-	 * @param request
-	 * @param response
-	 */
-	public static boolean isFromMobile(String domain, HttpServletRequest request, HttpServletResponse response) {
-		boolean isFromMobile = false;
-		String cookieKey = "access_resouce__";
-
-		String accessSource = getCookie(cookieKey, request);
-		// 检查是否已经记录访问方式(移动端或pc端)
-		if (null == accessSource) {
-			try {
-				// 获取ua,用来判断是否为移动端访问
-				String userAgent = request.getHeader("USER-AGENT").toLowerCase();
-				if (null == userAgent) {
-					userAgent = "";
-				}
-				isFromMobile = MobileChecker.check(userAgent);
-
-				// 判断是否为移动端访问
-				if (isFromMobile) {
-					addCookie(cookieKey, "mobile", -1, domain, "/", response);
-				} else {
-					addCookie(cookieKey, "pc", -1, domain, "/", response);
-				}
-			} catch (Exception e) {
-			}
-		} else {
-			isFromMobile = "mobile".equals(accessSource);
-		}
-
-		return isFromMobile;
-	}
+    public static String getRandomUUID() {
+        UUID uuid = UUID.randomUUID();
+        String str = uuid.toString();
+        String uuidStr = StringUtils.replace(str, "-", "");
+        return uuidStr;
+    }
+
+    public static void addCookie(String cookieName, String cookeValue, int age, String domain, String path, HttpServletResponse response) {
+        Cookie cookie = new Cookie(cookieName, cookeValue);
+        cookie.setMaxAge(age);// 单位:秒
+        if (StringUtils.isNotBlank(domain)) {
+            cookie.setDomain(domain);
+        }
+        if (StringUtils.isNotBlank(path)) {
+            cookie.setPath(path);
+        }
+        response.addCookie(cookie);
+        // response.addHeader("Set-Cookie", "HttpOnly");// 防止XSS
+    }
+
+    public static String getCookie(String key, HttpServletRequest request) {
+        Cookie[] cookies = request.getCookies();
+        if (cookies != null) {
+            for (Cookie cookie : cookies) {
+                if (cookie.getName().equals(key)) {
+                    return cookie.getValue();
+                }
+            }
+        }
+        return null;
+    }
+
+    public static void removeCookie(String key, String domain, String path, HttpServletResponse response) {
+        Cookie cookie = new Cookie(key, null);
+        cookie.setMaxAge(0);
+        cookie.setPath(path);
+        cookie.setDomain(domain);
+        response.addCookie(cookie);
+    }
+
+    /**
+     * 获取参数
+     *
+     * @param queryString
+     *            查询字符串
+     * @param encoding
+     *            编码格式
+     * @param name
+     *            参数名称
+     * @return 参数
+     */
+    public static Object getParameter(HttpServletRequest request, String name) {
+        Map<String, Object> parameterMap = getParameterMap(request);
+        return parameterMap.get(name);
+    }
+
+    /**
+     * 获取所有参数
+     *
+     */
+    @SuppressWarnings("rawtypes")
+    public static Map<String, Object> getParameterMap(HttpServletRequest request) {
+        Map<String, Object> parameterMap = new HashMap<String, Object>();
+        Object object = null;
+        Object[] objs = null;
+        Map params = request.getParameterMap();
+        Enumeration enu = request.getParameterNames();
+        while (enu.hasMoreElements()) {
+            String paraName = (String) enu.nextElement();
+            object = params.get(paraName);
+            if (object != null) {
+                if (object.getClass().isArray()) {
+                    objs = (Object[]) object;
+                    parameterMap.put(paraName, objs.length == 1 ? objs[0] : objs);
+                } else {
+                    parameterMap.put(paraName, object);
+                }
+            }
+        }
+        return parameterMap;
+    }
+
+    /**
+     * 获取所有Header参数
+     *
+     */
+    @SuppressWarnings("rawtypes")
+    public static Map<String, Object> getHeaderMap(HttpServletRequest request) {
+        Map<String, Object> parameterMap = new HashMap<String, Object>();
+        Enumeration enu = request.getHeaderNames();
+        while (enu.hasMoreElements()) {
+            String paraName = (String) enu.nextElement();
+            Enumeration headerValues = request.getHeaders(paraName);
+            while (headerValues.hasMoreElements()) {
+                parameterMap.put(paraName, headerValues.nextElement());
+            }
+        }
+        return parameterMap;
+    }
+
+    /**
+     * 获取客户端ip地址
+     * @param request
+     * @return
+     */
+    public static String getRemoteIp(HttpServletRequest request) {
+        String remoteIp = request.getHeader("x-forwarded-for");
+        if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
+            remoteIp = request.getHeader("X-Real-IP");
+        }
+        if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
+            remoteIp = request.getHeader("Proxy-Client-IP");
+        }
+        if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
+            remoteIp = request.getHeader("WL-Proxy-Client-IP");
+        }
+        if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
+            remoteIp = request.getHeader("HTTP_CLIENT_IP");
+        }
+        if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
+            remoteIp = request.getHeader("HTTP_X_FORWARDED_FOR");
+        }
+        if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
+            remoteIp = request.getRemoteAddr();
+        }
+        if (remoteIp == null || remoteIp.isEmpty() || "unknown".equalsIgnoreCase(remoteIp)) {
+            remoteIp = request.getRemoteHost();
+        }
+        if (remoteIp != null && remoteIp.indexOf(",") != -1) {
+            remoteIp = remoteIp.substring(remoteIp.lastIndexOf(",") + 1, remoteIp.length()).trim();
+        }
+        return remoteIp;
+    }
+
+    /**
+     * 检查访问方式是否为移动端
+     * @param domain cookie所在的域
+     * @param request
+     * @param response
+     */
+    public static boolean isFromMobile(String domain, HttpServletRequest request, HttpServletResponse response) {
+        boolean isFromMobile = false;
+        String cookieKey = "access_resouce__";
+
+        String accessSource = getCookie(cookieKey, request);
+        // 检查是否已经记录访问方式(移动端或pc端)
+        if (null == accessSource) {
+            try {
+                // 获取ua,用来判断是否为移动端访问
+                String userAgent = request.getHeader("USER-AGENT").toLowerCase();
+                if (null == userAgent) {
+                    userAgent = "";
+                }
+                isFromMobile = MobileChecker.check(userAgent);
+
+                // 判断是否为移动端访问
+                if (isFromMobile) {
+                    addCookie(cookieKey, "mobile", -1, domain, "/", response);
+                } else {
+                    addCookie(cookieKey, "pc", -1, domain, "/", response);
+                }
+            } catch (Exception e) {
+            }
+        } else {
+            isFromMobile = "mobile".equals(accessSource);
+        }
+
+        return isFromMobile;
+    }
 }

+ 82 - 0
src/main/java/com/ym/mec/collectfee/utils/XStreamUtil.java

@@ -0,0 +1,82 @@
+package com.ym.mec.collectfee.utils;
+
+import java.io.InputStream;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.converters.javabean.BeanProvider;
+import com.thoughtworks.xstream.converters.javabean.JavaBeanConverter;
+import com.ym.mec.collectfee.entity.RequestHead;
+
+public final class XStreamUtil {
+
+	private XStreamUtil() {
+
+	}
+
+	/**
+	 * 将包含xml内容的流转换成对�?
+	 * 
+	 * @param rootNode
+	 *            根节点名�?
+	 * @param rootNodeType
+	 *            根节点类�?
+	 * @param inputStream
+	 *            �?
+	 * @return 返回转换后的对象
+	 */
+	@SuppressWarnings("unchecked")
+	public static <T> T xmlToObject(String rootNode, Class<T> rootNodeType,
+			InputStream inputStream) {
+		XStream xStream = new XStream();// 默认用xppDriver
+		xStream.alias(rootNode, rootNodeType);// 尽可能的加上,否则会抛CannotResolveClassException异常
+		// 将xml转换成对�?
+		return (T) xStream.fromXML(inputStream);
+	}
+
+	/**
+	 * 将对象转换成xml
+	 * 
+	 * @param rootNodeName
+	 *            根节点名�?
+	 * @param obj
+	 *            对象�?
+	 * @return
+	 */
+	public static String objectToXml(String rootNodeName, Object obj) {
+		XStream xStream = new XStream();
+		xStream.registerConverter(new JavaBeanConverter(xStream.getMapper(),
+				new BeanProvider()), XStream.PRIORITY_VERY_LOW);
+		xStream.alias(rootNodeName, obj.getClass());
+		return xStream.toXML(obj);
+	}
+
+	public static String encryption(String body) {
+		String re_md5 = new String();
+		try {
+			MessageDigest md = MessageDigest.getInstance("MD5");
+			md.update(body.getBytes());
+			byte b[] = md.digest();
+
+			int i;
+
+			StringBuffer buf = new StringBuffer("");
+			for (int offset = 0; offset < b.length; offset++) {
+				i = b[offset];
+				if (i < 0)
+					i += 256;
+				if (i < 16)
+					buf.append("0");
+				buf.append(Integer.toHexString(i));
+			}
+
+			re_md5 = buf.toString();
+
+		} catch (NoSuchAlgorithmException e) {
+			e.printStackTrace();
+		}
+		return re_md5.toUpperCase();
+	}
+
+}