xujunwei 2 rokov pred
rodič
commit
dfb64eaa2d

+ 3 - 4
framework-common/src/main/java/com/mrxu/framework/common/util/HttpUtil.java

@@ -404,7 +404,7 @@ public class HttpUtil {
         return isAjax(request) || uri.endsWith(".aj") || uri.endsWith(".json");
     }
 
-    public static String httpsRequest(String requestUrl, String requestMethod, String outputStr,InputStream certInputStream) {
+    public static String httpsRequest(String requestUrl, String requestMethod, String outputStr,InputStream certInputStream,String keyPassword) {
         SSLContext sslContext = null;
         HttpsURLConnection conn = null;
         InputStream inputStream = null;
@@ -412,10 +412,9 @@ public class HttpUtil {
         BufferedReader bufferedReader = null;
         try {
             if(certInputStream != null) {
-                String certName = "cert.p12";
                 KeyStore keyStore = KeyStore.getInstance("PKCS12");
-                keyStore.load(certInputStream, certName.toCharArray());
-                sslContext = SSLContexts.custom().loadKeyMaterial(keyStore, certName.toCharArray()).build();
+                keyStore.load(certInputStream, keyPassword.toCharArray());
+                sslContext = SSLContexts.custom().loadKeyMaterial(keyStore, keyPassword.toCharArray()).build();
             }
             else {
                 // 创建SSLContext对象,并使用我们指定的信任管理器初始化

+ 7 - 7
framework-common/src/main/java/com/mrxu/framework/common/xcx/api/PayService.java

@@ -25,25 +25,25 @@ public class PayService {
 
     // https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_1
     public static UnifiedorderResponse unifiedorder(UnifiedorderRequest request,String apiKey) {
-        return request(UnifiedorderResponse.class,unifiedorder,"POST",request,apiKey,null);
+        return request(UnifiedorderResponse.class,unifiedorder,"POST",request,apiKey,null,null);
     }
 
     // https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_2
     public static OrderqueryResponse orderquery(OrderqueryRequest request, String apiKey) {
-        return request(OrderqueryResponse.class,orderquery,"POST",request,apiKey,null);
+        return request(OrderqueryResponse.class,orderquery,"POST",request,apiKey,null,null);
     }
 
     // https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_3
     public static CloseorderResponse closeorder(CloseorderRequest request, String apiKey) {
-        return request(CloseorderResponse.class,closeorder,"POST",request,apiKey,null);
+        return request(CloseorderResponse.class,closeorder,"POST",request,apiKey,null,null);
     }
 
     // https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_4
-    public static RefundResponse refund(RefundRequest request, String apiKey,InputStream certInputStream) {
-        return request(RefundResponse.class,refund,"POST",request,apiKey,certInputStream);
+    public static RefundResponse refund(RefundRequest request, String apiKey,InputStream certInputStream,String keyPassword) {
+        return request(RefundResponse.class,refund,"POST",request,apiKey,certInputStream,keyPassword);
     }
 
-    private static <T extends PayBaseResponse> T request(Class<T> clazz, String requestUrl, String requestMethod, Object requestBean, String apiKey,InputStream certInputStream) {
+    private static <T extends PayBaseResponse> T request(Class<T> clazz, String requestUrl, String requestMethod, Object requestBean, String apiKey,InputStream certInputStream,String keyPassword) {
         MrxuAssert.validateBean(requestBean);
         String jsonStr = JSONUtil.toJsonStr(requestBean);
         TreeMap<String, Object> parameters = JSONUtil.toBean(jsonStr,new TreeMap<String, String>().getClass());
@@ -51,7 +51,7 @@ public class PayService {
         String sign = WeixinUtil.createSign(parameters,apiKey);
         parameters.put("sign", sign);
         String requestXML = WeixinUtil.getRequestXml(parameters);
-        String resultStr =  HttpUtil.httpsRequest(requestUrl,requestMethod,requestXML,certInputStream);
+        String resultStr =  HttpUtil.httpsRequest(requestUrl,requestMethod,requestXML,certInputStream,keyPassword);
         MrxuAssert.isNotEmpty(resultStr,"微信未响应");
         System.out.println(resultStr);
         JSONObject resultJson = WeixinUtil.doXMLParse(resultStr);