傅行帆 6 gadus atpakaļ
vecāks
revīzija
b3146083f0

+ 38
- 11
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/WxPayController.java Parādīt failu

@@ -6,6 +6,8 @@ import com.community.commom.redis.RedisTemplate;
6 6
 import com.community.commom.session.UserElement;
7 7
 import com.community.huiju.common.wxpay.HfWxConfig;
8 8
 import com.community.huiju.common.wxpay.WXPay;
9
+import com.community.huiju.common.wxpay.WXPayConstants;
10
+import com.community.huiju.common.wxpay.WXPayUtil;
9 11
 import com.community.huiju.service.TaVistorServiceI;
10 12
 import com.community.huiju.service.WxPayServiceI;
11 13
 import com.google.common.collect.Maps;
@@ -22,7 +24,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
22 24
 import org.springframework.web.bind.annotation.RequestMethod;
23 25
 import org.springframework.web.bind.annotation.RestController;
24 26
 
27
+import javax.servlet.http.HttpServletRequest;
28
+import javax.servlet.http.HttpServletResponse;
25 29
 import javax.servlet.http.HttpSession;
30
+import java.io.ByteArrayOutputStream;
31
+import java.io.InputStream;
26 32
 import java.util.HashMap;
27 33
 import java.util.Map;
28 34
 
@@ -61,20 +67,41 @@ public class WxPayController {
61 67
 		return responseBean;
62 68
 	}
63 69
 	
64
-	@ApiOperation(value = "下载对账单", notes = "下载对账单")
65
-	@RequestMapping(value = "/wxDownloadBill",method = RequestMethod.POST)
66
-	public ResponseBean wxDownloadBill(){
67
-		ResponseBean responseBean = new ResponseBean();
68
-		
69
-		Map<String, String> resp = Maps.newHashMap();
70
+	@ApiOperation(value = "手机订单支付完成后回调", notes = "手机订单支付完成后回调")
71
+	@RequestMapping(value = "/wxNotify",method = RequestMethod.POST)
72
+	public String wxNotify(HttpServletRequest request, HttpServletResponse response){
73
+		String resXml = "";
74
+		InputStream inStream;
70 75
 		try {
71
-			resp = wxPayService.wxDownloadBill();
72
-			log.info("支付成功的回调参数: {}",resp);
76
+			
77
+			inStream = request.getInputStream();
78
+			ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
79
+			byte[] buffer = new byte[1024];
80
+			int len = 0;
81
+			while ((len = inStream.read(buffer)) != -1) {
82
+				outSteam.write(buffer, 0, len);
83
+			}
84
+			
85
+			// 获取微信调用我们notify_url的返回信息
86
+			String result = new String(outSteam.toByteArray(), "utf-8");
87
+			WXPayUtil.getLogger().info("wxnotify:微信支付----result----=" + result);
88
+			
89
+			// 关闭流
90
+			outSteam.close();
91
+			inStream.close();
92
+			
93
+			// xml转换为map
94
+			Map<String, String> resultMap = WXPayUtil.xmlToMap(result);
95
+			System.out.println("返回结果是:" + resultMap);
96
+			//处理业务逻辑 修改订单状态等
97
+			String state = wxPayService.wxNotify(resultMap);
73 98
 		} catch (Exception e) {
74
-			e.printStackTrace();
99
+			log.error("手机支付回调通知失败",e);
100
+			String result = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[失败]]></return_msg>" + "</xml> ";
101
+			return result;
102
+			
75 103
 		}
76
-		responseBean.addSuccess(resp);
77
-		return responseBean;
104
+		return "";
78 105
 	}
79 106
 	
80 107
 	@ApiOperation(value = "订单查询", notes = "订单查询")

+ 3
- 2
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/WxPayServiceI.java Parādīt failu

@@ -14,10 +14,11 @@ public interface WxPayServiceI {
14 14
 	Map<String, String> wxUnifiedOrder(Integer billInvoiceId, UserElement userElement) throws Exception;
15 15
 	
16 16
 	/**
17
-	 * 下载对账单
17
+	 * 支付成功的回调
18 18
 	 * @return
19
+	 * @param resultMap
19 20
 	 */
20
-	Map<String, String> wxDownloadBill() throws Exception;
21
+	String wxNotify(Map<String, String> resultMap) throws Exception;
21 22
 	
22 23
 	/**
23 24
 	 * 订单查询

+ 5
- 13
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/WxPayServiceImpl.java Parādīt failu

@@ -5,7 +5,6 @@ import com.community.huiju.common.wxpay.HfWxConfig;
5 5
 import com.community.huiju.common.wxpay.WXPay;
6 6
 import com.community.huiju.common.wxpay.WXPayConstants;
7 7
 import com.community.huiju.common.wxpay.WXPayUtil;
8
-import com.community.huiju.controller.WxPayController;
9 8
 import com.community.huiju.dao.TpBillInvoiceMapper;
10 9
 import com.community.huiju.model.TpBillInvoice;
11 10
 import com.community.huiju.service.WxPayServiceI;
@@ -14,9 +13,7 @@ import org.slf4j.LoggerFactory;
14 13
 import org.springframework.beans.factory.annotation.Autowired;
15 14
 import org.springframework.stereotype.Service;
16 15
 
17
-import java.text.SimpleDateFormat;
18 16
 import java.time.Instant;
19
-import java.util.Date;
20 17
 import java.util.HashMap;
21 18
 import java.util.Map;
22 19
 
@@ -61,7 +58,7 @@ public class WxPayServiceImpl implements WxPayServiceI {
61 58
 		//终端IP
62 59
 		data.put("spbill_create_ip", "123.12.12.123");
63 60
 		//回调地址
64
-		data.put("notify_url", "http://106.14.20.193:8086/app-api/wxDownloadBill");
61
+		data.put("notify_url", "http://106.14.20.193:8086/app-api/wxNotify");
65 62
 		// 此处指定为APP支付
66 63
 		data.put("trade_type", "APP");
67 64
 		Map<String, String> resp = wxpay.unifiedOrder(data);
@@ -81,19 +78,14 @@ public class WxPayServiceImpl implements WxPayServiceI {
81 78
 	}
82 79
 	
83 80
 	/**
84
-	 * 下载对账单
81
+	 * 支付成功的回调
85 82
 	 *
86 83
 	 * @return
84
+	 * @param resultMap
87 85
 	 */
88 86
 	@Override
89
-	public Map<String, String> wxDownloadBill() throws Exception {
90
-		HfWxConfig config = new HfWxConfig();
91
-		WXPay wxpay = new WXPay(config);
92
-		
93
-		Map<String, String> data = new HashMap<String, String>();
94
-		data.put("bill_date", new SimpleDateFormat("yyyyMMdd").format(new Date()));
95
-		data.put("bill_type", "ALL");
96
-		return wxpay.downloadBill(data);
87
+	public String wxNotify(Map<String, String> resultMap) throws Exception {
88
+		return null;
97 89
 	}
98 90
 	
99 91
 	/**