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