anderx 4 gadi atpakaļ
vecāks
revīzija
c95c857efc

+ 1 - 0
pom.xml

@@ -36,6 +36,7 @@
 	</profiles> 
 
 	<dependencies>
+	
 		<!-- spring -->
 		<dependency>
 			<groupId>org.springframework</groupId>

+ 3 - 0
src/main/java/com/kede/admin/controller/AdminLoginController.java

@@ -113,6 +113,7 @@ public class AdminLoginController extends BaseController {
 		Calendar now = Calendar.getInstance();
 		now.set(Calendar.MILLISECOND, 0);
 		JSONObject jsonObject=getUserOpenId(request, code);
+		String sessionKey =jsonObject.getString("session_key");
 		String openId=jsonObject.getString("openid");
 		if (StringUtils.isBlank(openId)) {
 			res.getError().add(buildError(ErrorConstants.PARAM_ERROR,"openId","openId"));
@@ -131,6 +132,8 @@ public class AdminLoginController extends BaseController {
 		}
 		u.setPassword("123456");
 		WebUtils.getAndClearSavedRequest(request);
+		TokenManager.setVal2Session("openId", openId);
+		TokenManager.setVal2Session("sessionKey", sessionKey);
 		res.data(TokenManager.login(u, remember,openId));
 		return res;
 	}

+ 2 - 0
src/main/java/com/kede/common/controller/PublicApiController.java

@@ -8,6 +8,7 @@ import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RestController;
@@ -139,6 +140,7 @@ public class PublicApiController extends BaseController {
 	}
 	
 	@RequestMapping(value = "/selectProject", method = RequestMethod.GET)
+	@CrossOrigin(origins="*",allowCredentials="true")
 	public Result selectProject(Integer id) {
 		Result res =new Result();
 		if (id==null) {

+ 50 - 4
src/main/java/com/kede/wxsdk/service/WxService.java

@@ -5,21 +5,28 @@ import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.math.BigDecimal;
 import java.net.InetAddress;
+import java.security.AlgorithmParameters;
+import java.util.Arrays;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
 
+import javax.crypto.Cipher;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.SecretKeySpec;
 import javax.servlet.http.HttpServletRequest;
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 
+import org.apache.commons.codec.binary.Base64;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import com.alibaba.fastjson.JSONObject;
 import com.kede.common.dao.OrderMapper;
 import com.kede.common.error.BusinessException;
 import com.kede.common.model.Order;
@@ -35,7 +42,6 @@ import com.kede.wxsdk.WXPayUtil;
 @Service
 public class WxService {
 	
-	
 	@Value(value = "${wx.appId}")
 	private String appId;
 	@Value(value = "${wx.appSecret}")
@@ -68,7 +74,7 @@ public class WxService {
 				Map<String, String> map=new HashMap<>();
 				try {
 					IWxPayConfig iWxPayConfig=new IWxPayConfig(appId,mchId,apiKiy,certPath);
-				    wxpay = new WXPay(iWxPayConfig,null, true, false); // *** 注入自己实现的微信配置类, 创建WXPay核心类, WXPay 包括统一下单接口
+				    wxpay = new WXPay(iWxPayConfig); // *** 注入自己实现的微信配置类, 创建WXPay核心类, WXPay 包括统一下单接口
 					InetAddress addr = InetAddress.getLocalHost();
 					String ip = addr.getHostAddress();
 				    Map<String, String> data = new HashMap<String, String>();
@@ -149,7 +155,7 @@ public class WxService {
 				Map<String, String> map=new HashMap<>();
 				try {
 					IWxPayConfig iWxPayConfig=new IWxPayConfig(appId,mchId,apiKiy,certPath);
-				    wxpay = new WXPay(iWxPayConfig,null, true, false); // *** 注入自己实现的微信配置类, 创建WXPay核心类, WXPay 包括统一下单接口
+				    wxpay = new WXPay(iWxPayConfig); // *** 注入自己实现的微信配置类, 创建WXPay核心类, WXPay 包括统一下单接口
 					Map<String, String> data = new HashMap<String, String>();
 					data.put("out_trade_no", orderNo);
 					data.put("mchid", mchId); 
@@ -191,7 +197,7 @@ public class WxService {
 				Map<String, String> map=new HashMap<>();
 				try {
 					IWxPayConfig iWxPayConfig=new IWxPayConfig(appId,mchId,apiKiy,certPath);
-				    wxpay = new WXPay(iWxPayConfig,null, true, false); // *** 注入自己实现的微信配置类, 创建WXPay核心类, WXPay 包括统一下单接口
+				    wxpay = new WXPay(iWxPayConfig); // *** 注入自己实现的微信配置类, 创建WXPay核心类, WXPay 包括统一下单接口
 					Map<String, String> data = new HashMap<String, String>();
 					data.put("out_trade_no", o.getOrderNo());
 					data.put("mchid", mchId); 
@@ -318,6 +324,46 @@ public class WxService {
         return xmlString;
     }
 
+    public JSONObject decryptData(String sessionKey,String encryptedData, String iv) throws Exception{
+        byte[] dataByte = Base64.decodeBase64(encryptedData);
+        // 加密秘钥
+        byte[] keyByte = Base64.decodeBase64(sessionKey);
+        // 偏移量
+        byte[] ivByte = Base64.decodeBase64(iv);
+        try {
+            // 如果密钥不足16位,那么就补足.  这个if 中的内容很重要
+            int base = 16;
+            if (keyByte.length % base != 0) {
+                int groups = keyByte.length / base + (keyByte.length % base != 0 ? 1 : 0);
+                byte[] temp = new byte[groups * base];
+                Arrays.fill(temp, (byte) 0);
+                System.arraycopy(keyByte, 0, temp, 0, keyByte.length);
+                keyByte = temp;
+            }
+            // 初始化
+//            Security.addProvider(new BouncyCastleProvider());
+            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding","BC");
+            SecretKeySpec spec = new SecretKeySpec(keyByte, "AES");
+            AlgorithmParameters parameters = AlgorithmParameters.getInstance("AES");
+            parameters.init(new IvParameterSpec(ivByte));
+            cipher.init(Cipher.DECRYPT_MODE, spec, parameters);// 初始化
+            byte[] resultByte = cipher.doFinal(dataByte);
+            if (null != resultByte && resultByte.length > 0) {
+                String result = new String(resultByte, "UTF-8");
+                return JSONObject.parseObject(result);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+    
+    
+    
+    
+   
+
+
 	
 	
 }