Pārlūkot izejas kodu

Merge branch 'dev' of http://git.ycjcjy.com/zhiyuxing/estateagents into dev

张延森 5 gadus atpakaļ
vecāks
revīzija
bd872bd367

+ 2
- 21
src/main/java/com/huiju/estateagents/common/wxpay/WxConfig.java Parādīt failu

@@ -17,25 +17,6 @@ public class WxConfig extends WXPayConfig {
17 17
 
18 18
 	private byte[] certData;
19 19
 
20
-	//api文件放在oss里所以是个http地址
21
-	private String apiPath;
22
-
23
-	public WxConfig() throws Exception {
24
-		URL urlConet = new URL(apiPath);
25
-		HttpURLConnection con = (HttpURLConnection)urlConet.openConnection();
26
-		con.setRequestMethod("GET");
27
-		con.setConnectTimeout(4 * 1000);
28
-		InputStream inStream = con .getInputStream();
29
-		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
30
-		byte[] buffer = new byte[2048];
31
-		int len = 0;
32
-		while( (len=inStream.read(buffer)) != -1 ){
33
-			outStream.write(buffer, 0, len);
34
-		}
35
-		inStream.close();
36
-		this.certData =  outStream.toByteArray();
37
-	}
38
-
39 20
 	/**
40 21
 	 * 获取 App ID
41 22
 	 *
@@ -119,8 +100,8 @@ public class WxConfig extends WXPayConfig {
119 100
 		this.key = key;
120 101
 	}
121 102
 
122
-	public void setApiPath(String apiPath) {
123
-		this.apiPath = apiPath;
103
+	public void setCertData(byte[] certData) {
104
+		this.certData = certData;
124 105
 	}
125 106
 }
126 107
 

+ 26
- 1
src/main/java/com/huiju/estateagents/service/impl/WxPayServiceImpl.java Parādīt failu

@@ -17,6 +17,10 @@ import org.springframework.stereotype.Service;
17 17
 import org.springframework.transaction.annotation.Transactional;
18 18
 
19 19
 import javax.xml.ws.soap.Addressing;
20
+import java.io.ByteArrayOutputStream;
21
+import java.io.InputStream;
22
+import java.net.HttpURLConnection;
23
+import java.net.URL;
20 24
 import java.time.Instant;
21 25
 import java.time.LocalDateTime;
22 26
 import java.util.HashMap;
@@ -51,6 +55,9 @@ public class WxPayServiceImpl implements IWxPayService {
51 55
     @Autowired
52 56
     private TaOrderMapper taOrderMapper;
53 57
 
58
+    @Autowired
59
+    private TaPersonMapper taPersonMapper;
60
+
54 61
     /**
55 62
      * 微信支付-统一下单
56 63
      *
@@ -76,6 +83,9 @@ public class WxPayServiceImpl implements IWxPayService {
76 83
         String tradeNo = prefix + System.currentTimeMillis() + taOrder.getTargetId();
77 84
         taOrder.setTradeNo(tradeNo);
78 85
 
86
+        //获取personxinx
87
+        TaPerson person = taPersonMapper.getById(taOrder.getPersonId());
88
+
79 89
         //下单
80 90
         Map<String, String> data = new HashMap<String, String>();
81 91
         data.put("body", taOrder.getTargetType().equals(CommConstant.ORDER_TARGET_TYPE_HOUSE) ? "房源认筹" : "微信支付");
@@ -91,6 +101,8 @@ public class WxPayServiceImpl implements IWxPayService {
91 101
         data.put("notify_url", payNotify+taOrder.getTargetType());
92 102
         // 此处指定为APP支付
93 103
         data.put("trade_type", "JSAPI");
104
+        //openid
105
+        data.put("openid", person.getMiniOpenid());
94 106
         Map<String, String> resp = wxpay.unifiedOrder(data);
95 107
         log.info("下单成功:{}", resp);
96 108
         if (resp.get("result_code").equalsIgnoreCase(WXPayConstants.FAIL)){
@@ -394,10 +406,23 @@ public class WxPayServiceImpl implements IWxPayService {
394 406
         }
395 407
         log.info("正在配置orgId为{}的微信支付参数,商户号为{}",orgId,taWxPayConfig.getMchId());
396 408
         //把库里的值赋值给微信
409
+        URL urlConet = new URL(taWxPayConfig.getApiPath());
410
+        HttpURLConnection con = (HttpURLConnection)urlConet.openConnection();
411
+        con.setRequestMethod("GET");
412
+        con.setConnectTimeout(4 * 1000);
413
+        InputStream inStream = con .getInputStream();
414
+        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
415
+        byte[] buffer = new byte[2048];
416
+        int len = 0;
417
+        while( (len=inStream.read(buffer)) != -1 ){
418
+            outStream.write(buffer, 0, len);
419
+        }
420
+        inStream.close();
421
+
397 422
         WxConfig config = new WxConfig();
398 423
         config.setAppid(taWxPayConfig.getAppid());
399 424
         config.setMachId(taWxPayConfig.getMchId());
400
-        config.setApiPath(taWxPayConfig.getApiPath());
425
+        config.setCertData(outStream.toByteArray());
401 426
         config.setKey(taWxPayConfig.getMchKey());
402 427
         return config;
403 428
     }