Browse Source

Merge remote-tracking branch 'origin/master'

周箭河 6 năm trước cách đây
mục cha
commit
e0954e4264

+ 8 - 8
src/main/java/com/ym/mec/collectfee/entity/MecCourse.java

@@ -25,7 +25,7 @@ public class MecCourse {
 	private Integer courseId;
 	
 	/**  */
-	private String subName;
+	private String subNames;
 	
 	/**  */
 	private Integer studentId;
@@ -105,15 +105,15 @@ public class MecCourse {
 	public Integer getCourseId(){
 		return this.courseId;
 	}
-			
-	public void setSubName(String subName){
-		this.subName = subName;
+
+	public String getSubNames() {
+		return subNames;
 	}
-	
-	public String getSubName(){
-		return this.subName;
+
+	public void setSubNames(String subNames) {
+		this.subNames = subNames;
 	}
-			
+
 	public void setStudentId(Integer studentId){
 		this.studentId = studentId;
 	}

+ 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;
     }

+ 23 - 16
src/main/java/com/ym/mec/collectfee/service/impl/ApplyInfoServiceImpl.java

@@ -7,7 +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.CDesECB;
 import com.ym.mec.collectfee.utils.HttpUtil;
 import com.ym.mec.collectfee.utils.MapUtil;
 import com.ym.mec.collectfee.utils.XStreamUtil;
@@ -70,7 +70,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 +81,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 +146,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 +169,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 +221,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 +264,20 @@ 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);
+			body = body.substring(body.indexOf("<errCode>") + 9, body.indexOf("</errCode>"));
+//			body = new String(CDesECB.decode(key,body.getBytes()));
+//			body = CDesECB.decodeValue(key,body);
+			if(!StringUtils.equals(body,"0")){
 				return false;
 			}
 			return true;
@@ -282,7 +289,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 +298,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();

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

@@ -0,0 +1,104 @@
+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);
+        }
+    }
+
+    /**
+     * 获取编码后的值
+     *
+     * @param key
+     * @param data
+     * @return
+     * @throws Exception
+     */
+    public static String decodeValue(String key, String data)
+    {
+        byte[] datas;
+        String value = null;
+        try
+        {
+            if (System.getProperty("os.name") != null
+                    && (System.getProperty("os.name").equalsIgnoreCase("sunos") || System
+                    .getProperty("os.name").equalsIgnoreCase("linux")))
+            {
+                datas = decode(key, Base64.getDecoder().decode(data));
+            }
+            else
+            {
+                datas = decode(key, Base64.getDecoder().decode(data));
+            }
+            value = new String(datas);
+        }
+        catch (Exception e)
+        {
+            value = "";
+        }
+        return value;
+    }
+}

+ 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;
-    }
-}