zouxuan 5 년 전
부모
커밋
d86ceb118b

+ 10 - 0
src/main/java/com/ym/mec/collectfee/entity/RenewBean.java

@@ -20,6 +20,16 @@ public class RenewBean {
 
     private String remark;
 
+    private BigDecimal price;
+
+    public BigDecimal getPrice() {
+        return price;
+    }
+
+    public void setPrice(BigDecimal price) {
+        this.price = price;
+    }
+
     public Integer getUserId() {
         return userId;
     }

+ 0 - 26
src/main/java/com/ym/mec/collectfee/filter/XssFilter.java

@@ -1,26 +0,0 @@
-package com.ym.mec.collectfee.filter;
-
-import java.io.IOException;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.annotation.WebFilter;
-
-import org.springframework.core.annotation.Order;
-
-@Order(1)
-// 执行的顺序,值越小,越先执行
-@WebFilter(urlPatterns = "/*")
-public class XssFilter implements Filter {
-
-	@Override
-	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
-		System.out.println("******************XssFilter ****************");
-
-		chain.doFilter(request, response);
-	}
-
-}

+ 29 - 19
src/main/java/com/ym/mec/collectfee/service/impl/ApplyInfoServiceImpl.java

@@ -7,10 +7,7 @@ import com.ym.mec.collectfee.common.service.impl.BaseServiceImpl;
 import com.ym.mec.collectfee.dao.*;
 import com.ym.mec.collectfee.entity.*;
 import com.ym.mec.collectfee.service.ApplyInfoService;
-import com.ym.mec.collectfee.utils.DES;
-import com.ym.mec.collectfee.utils.HttpUtil;
-import com.ym.mec.collectfee.utils.MapUtil;
-import com.ym.mec.collectfee.utils.XStreamUtil;
+import com.ym.mec.collectfee.utils.*;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -70,7 +67,7 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 				String body = xs.toXML(applyInfo);
 				body = body.substring(body.indexOf("<user>")+6,body.indexOf("</user>"));
 				//推送mec注册接口
-				body = getBody(body,12301,null,null);
+				body = getBody(body,12301);
 				Date date = new Date();
 				try {
 					applyInfo.setUpdateTime(date);
@@ -81,7 +78,7 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 					body = xs.toXML(applyClass);
 					body = body.substring(body.indexOf("<body>")+6,body.indexOf("</body>"));
 					//推送mec用户缴费
-					getBody(body,125218,null,null);
+					getBody(body,125218);
 					applyInfoDao.update(applyInfo);
 					return true;
 				}catch (Exception e){
@@ -146,7 +143,7 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 			List<Branch> branchList = branchDao.findAll(null);
 			if(branchList == null || branchList.size() < 1){
 				String body = "<province>0</province>";
-				body = getBody(body,121002,null,null);
+				body = getBody(body,121002);
 				body = "<body><branches>" + new String(Base64.getDecoder().decode(body)) + "</branches></body>";
 				ResponseBranchesBean branches = XStreamUtil.xmlToObject("body", ResponseBranchesBean.class, body);
 				branchDao.batchInsert(branches.getBranches());
@@ -169,7 +166,7 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 					break;
 				}
 				String body = "<branchId>" + branch.getBranchId() + "</branchId>";
-				body = getBody(body,121107,null,null);
+				body = getBody(body,121107);
 				body = "<body><schools>" + new String(Base64.getDecoder().decode(body)) + "</schools></body>";
 				ResponseSeminariesBean seminaries = XStreamUtil.xmlToObject("body", ResponseSeminariesBean.class, body);
 				if(seminaries.getSchools() == null || seminaries.getSchools().size() < 1){
@@ -221,7 +218,7 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 			MecUser mecUser = mecUserDao.get(userId);
 			if(mecUser == null){
 				String body = "<body><userId>" + userId + "</userId></body>";
-				body = getBody(body, 121313,null,null);
+				body = getBody(body, 121313);
 				if(!StringUtils.isEmpty(body)){
 					body = new String(Base64.getDecoder().decode(body));
 					mecUser = XStreamUtil.xmlToObject("student", MecUser.class, body);
@@ -264,13 +261,19 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 			xs.autodetectAnnotations(true);
 			String body = xs.toXML(renewBean);
 			body = body.substring(body.indexOf("<body>")+6,body.indexOf("</body>"));
-//			while (body.length()%8 != 0){
-//				body = body+"0";
-//			}
-			byte[] encrypt = DES.encrypt(body.getBytes(), key.getBytes());
-			body = getBody(new String(encrypt), 123255, 2,1);
-			body = new String(Base64.getDecoder().decode(body),"UTF-8");
-			if(StringUtils.isEmpty(body)){
+			body = CDesECB.encode(key,body);
+			RequestParamBean requestParamBean = new RequestParamBean();
+			requestParamBean.setBody(body);
+			requestParamBean.setHead(XStreamUtil.getOrdersHead(body,123255,publicKey,2,4));
+			Writer writer = new StringWriter();
+			writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
+			xs = new XStream();
+			xs.autodetectAnnotations(true);
+			xs.toXML(requestParamBean,writer);
+			body = HttpUtil.postXmlData(writer.toString(), url);
+			String errCode = body.substring(body.indexOf("<errCode>") + 9, body.indexOf("</errCode>"));
+//			body = new String(CDesECB.decode(key,body.getBytes()));
+			if(!StringUtils.equals(errCode,"0")){
 				return false;
 			}
 			return true;
@@ -282,7 +285,7 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 
 
 	private List<MecCourse> getCourses(String body) throws Exception{
-		body = getBody(body,123031,null,null);
+		body = getBody(body,123031);
 		if(StringUtils.isEmpty(body)){
 			return null;
 		}
@@ -291,11 +294,11 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 		return parseMecCourse.getCourses();
 	}
 
-	private String getBody(String body,Integer cmd,Integer uid,Integer encrypt) throws Exception{
+	private String getBody(String body,Integer cmd) throws Exception{
 		body = Base64.getEncoder().encodeToString(body.getBytes());
 		RequestParamBean requestParamBean = new RequestParamBean();
 		requestParamBean.setBody(body);
-		requestParamBean.setHead(XStreamUtil.getOrdersHead(body,cmd,publicKey,uid,encrypt));
+		requestParamBean.setHead(XStreamUtil.getOrdersHead(body,cmd,publicKey,null,null));
 		Writer writer = new StringWriter();
 		writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
 		XStream xs = new XStream();
@@ -305,6 +308,13 @@ public class ApplyInfoServiceImpl extends BaseServiceImpl<Integer, ApplyInfo> im
 		return body.substring(body.indexOf("<body>")+6,body.indexOf("</body>"));
 	}
 
+	public static void main(String[] args) throws Exception {
+		DES des = new DES();
+//		body = des.encryption(body,key);
+		String s = des.decryption("e99a18c428cb38d5f260853678922e03","5qbrivhrKEHws/iz25I6bg==");
+		System.out.println(s);
+	}
+
 	private ResponseUserInfo parseRegisterInfo(String body){
 		body = "<body>" + new String(Base64.getDecoder().decode(body)) + "</body>";
 		ResponseUserInfo userInfo = XStreamUtil.xmlToObject("body", ResponseUserInfo.class, body);

+ 71 - 0
src/main/java/com/ym/mec/collectfee/utils/CDesECB.java

@@ -0,0 +1,71 @@
+package com.ym.mec.collectfee.utils;
+
+import javax.crypto.Cipher;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.DESKeySpec;
+import java.security.Key;
+import java.util.Base64;
+
+public class CDesECB
+{
+    public static final String ALGORITHM_DES = "DES/ECB/PKCS5Padding";
+
+    /**
+     * 加密
+     * @param data 待加密字符串
+     * @param key 加密私钥,长度不能够小于8位
+     * @return 加密后的字节数组,一般结合Base64编码使用
+     */
+    public static String encode(String key, String data) throws Exception
+    {
+        return encode(key, data.getBytes());
+    }
+    /**
+     * 加密
+     * @param data 待加密字符串
+     * @param key 加密私钥,长度不能够小于8位
+     * @return 加密后的字节数组,一般结合Base64编码使用
+     */
+    public static String encode(String key, byte[] data) throws Exception
+    {
+        try
+        {
+            DESKeySpec dks = new DESKeySpec(key.getBytes());
+            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
+            // key的长度不能够小于8位字节
+            Key secretKey = keyFactory.generateSecret(dks);
+            Cipher cipher = Cipher.getInstance(ALGORITHM_DES);
+            cipher.init(Cipher.ENCRYPT_MODE, secretKey);
+            byte[] bytes = cipher.doFinal(data);
+            return Base64.getEncoder().encodeToString(bytes);
+        }
+        catch (Exception e)
+        {
+            throw new Exception(e);
+        }
+    }
+    /**
+     * 解密
+     * @param data 待解密字符串
+     * @param key 解密私钥,长度不能够小于8位
+     * @return 解密后的字节数组
+     * @throws Exception 异常
+     */
+    public static byte[] decode(String key, byte[] data) throws Exception
+    {
+        try
+        {
+            DESKeySpec dks = new DESKeySpec(key.getBytes());
+            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
+            // key的长度不能够小于8位字节
+            Key secretKey = keyFactory.generateSecret(dks);
+            Cipher cipher = Cipher.getInstance(ALGORITHM_DES);
+            cipher.init(Cipher.DECRYPT_MODE, secretKey);
+            return cipher.doFinal(data);
+        }
+        catch (Exception e)
+        {
+            throw new Exception(e);
+        }
+    }
+}

+ 0 - 54
src/main/java/com/ym/mec/collectfee/utils/DES.java

@@ -1,54 +0,0 @@
-package com.ym.mec.collectfee.utils;
-
-import javax.crypto.Cipher;
-import javax.crypto.SecretKey;
-import javax.crypto.SecretKeyFactory;
-import javax.crypto.spec.DESKeySpec;
-import java.security.Key;
-import java.security.SecureRandom;
-import java.security.spec.KeySpec;
-
-public class DES {
-    //加密算是是des
-    private static final String ALGORITHM = "DES";
-    //转换格式
-    private static final String TRANSFORMATION = "DES/ECB/PKCS5Padding";
-
-    //利用8个字节64位的key给src加密
-    @SuppressWarnings("unused")
-    public static byte[] encrypt(byte[] src,byte[]key)
-    {
-        try {
-            //加密
-            Cipher cipher = Cipher.getInstance(TRANSFORMATION);
-            SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(ALGORITHM);
-            KeySpec keySpec = new DESKeySpec(key);
-            SecretKey secretKey = secretKeyFactory.generateSecret(keySpec);
-            cipher.init(Cipher.ENCRYPT_MODE, secretKey,new SecureRandom());
-            byte[] enMsgBytes = cipher.doFinal(src);
-            return enMsgBytes;
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-
-    //利用8个字节64位的key给src解密
-    @SuppressWarnings("unused")
-    public static byte[] decrypt(byte[] encryptBytes,byte[]key){
-        try {
-            //解密
-            //Cipher deCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
-            Cipher deCipher = Cipher.getInstance(TRANSFORMATION);
-            SecretKeyFactory deDecretKeyFactory = SecretKeyFactory.getInstance(ALGORITHM);
-            KeySpec deKeySpec = new DESKeySpec(key);
-            SecretKey deSecretKey = deDecretKeyFactory.generateSecret(deKeySpec);
-            deCipher.init(Cipher.DECRYPT_MODE, deSecretKey,new SecureRandom());
-            byte[] deMsgBytes = deCipher.doFinal(encryptBytes);
-            return deMsgBytes;
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        return null;
-    }
-}