andrew пре 4 година
родитељ
комит
fb34f308d1

src/main/java/com/huiju/estateagents/controller/WxPayController.java → src/main/java/com/huiju/estateagents/controller/WxPaypaypayController.java Прегледај датотеку

@@ -26,7 +26,7 @@ import java.util.Map;
26 26
 @Slf4j
27 27
 @RestController
28 28
 @RequestMapping("/api")
29
-public class WxPayController extends BaseController {
29
+public class WxPaypaypayController extends BaseController {
30 30
 
31 31
     @Autowired
32 32
     private IWxPayService wxPayService;

+ 1
- 0
src/main/java/com/huiju/estateagents/interceptor/AccessInterceptor.java Прегледај датотеку

@@ -79,6 +79,7 @@ public class AccessInterceptor implements HandlerInterceptor {
79 79
             "/clean/buttonrole",
80 80
             "/api/admin/taPersonFromRecord",
81 81
             "/api/notify",//微信支付所有回调放过
82
+            "/api/wxBillNotify",//微信支付所有回调放过
82 83
             "/api/refund/",//微信退款所有回调放过
83 84
             "/api/fadd/",//所有的法大大回调放过
84 85
             "/api/third",

+ 1
- 2
src/main/java/com/huiju/estateagents/property/controller/BillInvoiceController.java Прегледај датотеку

@@ -94,9 +94,8 @@ public class BillInvoiceController extends BaseController {
94 94
     @RequestMapping(value = "/bill/invoice/offlinePayment", method = RequestMethod.POST)
95 95
     public ResponseBean offlinePayment(HttpServletRequest request, @RequestBody List<Integer> ids) {
96 96
         ResponseBean responseBean = new ResponseBean();
97
-        TaUser userElement = getTaUser(request);
98 97
 
99
-        responseBean = iBillInvoiceService.offlinePayment(ids, userElement);
98
+        responseBean = iBillInvoiceService.offlinePayment(ids, getPersonId(request));
100 99
         return responseBean;
101 100
     }
102 101
 

+ 202
- 0
src/main/java/com/huiju/estateagents/property/controller/WxPayController.java Прегледај датотеку

@@ -0,0 +1,202 @@
1
+package com.huiju.estateagents.property.controller;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.google.common.collect.Maps;
5
+import com.huiju.estateagents.base.BaseController;
6
+import com.huiju.estateagents.base.ResponseBean;
7
+import com.huiju.estateagents.common.wxpay.WXPayConstants;
8
+import com.huiju.estateagents.common.wxpay.WXPayUtil;
9
+import com.huiju.estateagents.property.common.Constant;
10
+import com.huiju.estateagents.property.common.UserElement;
11
+import com.huiju.estateagents.property.service.WxPayServiceI;
12
+import io.swagger.annotations.Api;
13
+import io.swagger.annotations.ApiImplicitParam;
14
+import io.swagger.annotations.ApiImplicitParams;
15
+import io.swagger.annotations.ApiOperation;
16
+import org.slf4j.Logger;
17
+import org.slf4j.LoggerFactory;
18
+import org.springframework.beans.factory.annotation.Autowired;
19
+import org.springframework.web.bind.annotation.*;
20
+
21
+import javax.servlet.http.HttpServletRequest;
22
+import javax.servlet.http.HttpServletResponse;
23
+import javax.servlet.http.HttpSession;
24
+import java.io.ByteArrayOutputStream;
25
+import java.io.InputStream;
26
+import java.util.Arrays;
27
+import java.util.Map;
28
+
29
+/**
30
+ * @author FXF
31
+ * @date 2019-02-19
32
+ */
33
+@RestController
34
+@RequestMapping("/api")
35
+@Api(value = "微信支付 API", tags = "微信支付 API")
36
+public class WxPayController extends BaseController {
37
+	private Logger log = LoggerFactory.getLogger(WxPayController.class);
38
+	
39
+	@Autowired
40
+	private WxPayServiceI wxPayService;
41
+	
42
+	@ApiOperation(value = "统一下单", notes = "统一下单")
43
+	@ApiImplicitParams({
44
+			@ApiImplicitParam(paramType = "path", dataType = "Integer", name = "outTradeNo", value = "订单号"),
45
+			@ApiImplicitParam(paramType = "query", dataType = "String", name = "type", value = "订单类型: bill 表示订单,car 车缴费"),
46
+			@ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token")
47
+	})
48
+	@RequestMapping(value = "/wx/wxUnifiedOrder/{outTradeNo}",method = RequestMethod.GET)
49
+	public ResponseBean wxUnifiedOrder(@PathVariable("outTradeNo") String outTradeNo,
50
+									   @RequestParam("type") String type,
51
+									   HttpServletRequest request){
52
+		ResponseBean responseBean = new ResponseBean();
53
+
54
+		Map<String, String> resp = Maps.newHashMap();
55
+		try {
56
+			resp = wxPayService.wxUnifiedOrder(outTradeNo, type, getPersonId(request));
57
+		} catch (Exception e) {
58
+			e.printStackTrace();
59
+			responseBean.addError(e.getMessage());
60
+			return responseBean;
61
+		}
62
+		log.info("调用微信支付参数: {}",resp);
63
+		responseBean.addSuccess(resp);
64
+		return responseBean;
65
+	}
66
+	
67
+	@ApiOperation(value = "手机订单支付完成后回调 物业缴费", notes = "手机订单支付完成后回调 物业缴费")
68
+	@RequestMapping(value = "/wxBillNotify",method = RequestMethod.POST)
69
+	public String wxBillNotify(HttpServletRequest request, HttpServletResponse response){
70
+		return wxNotify(request, Constant.PAY_TYPE_BILL);
71
+	}
72
+
73
+
74
+//	@ApiOperation(value = "手机订单支付完成后回调 车缴费", notes = "手机订单支付完成后回调 车缴费")
75
+	@RequestMapping(value = "/wxCarNotify",method = RequestMethod.POST)
76
+	public String wxCarNotify(HttpServletRequest request, HttpServletResponse response){
77
+
78
+		return wxNotify(request, Constant.PAY_TYPE_CAR);
79
+	}
80
+
81
+	/**
82
+	 * 微信支付回调
83
+	 * @param request
84
+	 * @param type
85
+	 * @return
86
+	 */
87
+	private String wxNotify(HttpServletRequest request, String type) {
88
+		String failResult = "<xml>" + "<return_code><![CDATA[FAIL]]></return_code>" + "<return_msg><![CDATA[失败]]></return_msg>" + "</xml> ";
89
+		String successResult = "<xml>" + "<return_code><![CDATA[SUCCESS]]></return_code>" + "<return_msg><![CDATA[OK]]></return_msg>" + "</xml> ";
90
+		InputStream inStream;
91
+		try {
92
+
93
+			inStream = request.getInputStream();
94
+			ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
95
+			byte[] buffer = new byte[1024];
96
+			int len = 0;
97
+			while ((len = inStream.read(buffer)) != -1) {
98
+				outSteam.write(buffer, 0, len);
99
+			}
100
+
101
+			// 获取微信调用我们notify_url的返回信息
102
+			String result = new String(outSteam.toByteArray(), "utf-8");
103
+			WXPayUtil.getLogger().info("wxnotify:微信支付----result----=" + result);
104
+
105
+			// 关闭流
106
+			outSteam.close();
107
+			inStream.close();
108
+
109
+			// xml转换为map
110
+			Map<String, String> resultMap = WXPayUtil.xmlToMap(result);
111
+			if (WXPayConstants.SUCCESS.equalsIgnoreCase(resultMap.get("result_code"))) {
112
+				//处理业务逻辑 修改订单状态等
113
+				resultMap.put("pay_type","0");
114
+				String state = "";
115
+				if (Constant.PAY_TYPE_CAR.equals(type)) {
116
+					state = wxPayService.wxCarNotify(resultMap);
117
+				} else if (Constant.PAY_TYPE_BILL.equals(type)) {
118
+					state = wxPayService.wxBillNotify(resultMap);
119
+				}
120
+
121
+				if (state.equals("success")){
122
+					log.info("微信支付成功。。");
123
+					return successResult;
124
+				}
125
+			}else{
126
+				return failResult;
127
+			}
128
+
129
+		} catch (Exception e) {
130
+			log.error("手机支付回调通知失败",e);
131
+			return failResult;
132
+
133
+		}
134
+
135
+		return failResult;
136
+	}
137
+
138
+	
139
+	@ApiOperation(value = "订单查询", notes = "订单查询")
140
+	@ApiImplicitParams({
141
+			@ApiImplicitParam(paramType = "path", dataType = "Integer", name = "outTradeNo", value = "订单号")
142
+	})
143
+	@RequestMapping(value = "/wx/wxOrderQuery/{outTradeNo}",method = RequestMethod.GET)
144
+	public ResponseBean wxOrderQuery(@PathVariable("outTradeNo") String outTradeNo){
145
+		ResponseBean responseBean = new ResponseBean();
146
+		Map<String, String> resp = Maps.newHashMap();
147
+		try {
148
+			resp = wxPayService.wxOrderQuery(outTradeNo);
149
+		} catch (Exception e) {
150
+			e.printStackTrace();
151
+			responseBean.addError("查询失败");
152
+			return responseBean;
153
+		}
154
+		responseBean.addSuccess(resp);
155
+		return responseBean;
156
+	}
157
+	
158
+	@ApiOperation(value = "准备开始支付", notes = "准备开始支付")
159
+	@ApiImplicitParams({
160
+			@ApiImplicitParam(paramType = "body", dataType = "String", name = "parameter", value = "idArray:账单Id集合, type: 类型(car 车缴费, bill 物业缴费), extensionMonth: 延期月份,也就是延期几个月!只有在 车缴费的时候才有效"),
161
+			@ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token")
162
+	})
163
+	@RequestMapping(value = "/wx/wxStartPay",method = RequestMethod.POST)
164
+	public ResponseBean wxStartPay(@RequestBody String parameter, HttpServletRequest request){
165
+		ResponseBean responseBean = new ResponseBean();
166
+		try {
167
+			JSONObject jsonObject = JSONObject.parseObject(parameter);
168
+			Integer[] integers = jsonObject.getJSONArray("idArray").toArray(new Integer[]{});
169
+			String type = jsonObject.getString("type");
170
+			Integer extensionMonth = jsonObject.getInteger("extensionMonth");
171
+
172
+			String outTradeNo = wxPayService.wxStartPay(Arrays.asList(integers), type, extensionMonth,getPersonId(request));
173
+			Map<String,Object> resultMap = Maps.newHashMap();
174
+			resultMap.put("outTradeNo", outTradeNo);
175
+			responseBean.addSuccess(resultMap);
176
+		} catch (Exception e) {
177
+			e.printStackTrace();
178
+			responseBean.addError(e.getMessage());
179
+			return responseBean;
180
+		}
181
+		return responseBean;
182
+	}
183
+	
184
+	@ApiOperation(value = "取消支付", notes = "取消支付")
185
+	@ApiImplicitParams({
186
+			@ApiImplicitParam(paramType = "path", dataType = "String", name = "outTradeNo", value = "订单号"),
187
+			@ApiImplicitParam(paramType = "query", dataType = "String", name = "type", value = "type: 类型(car 车缴费, bill 物业缴费)"),
188
+			@ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token")
189
+	})
190
+	@RequestMapping(value = "/wx/wxCancelPay/{outTradeNo}",method = RequestMethod.GET)
191
+	public ResponseBean wxCancelPay(@PathVariable("outTradeNo") String outTradeNo, @RequestParam("type") String type, HttpServletRequest request){
192
+		ResponseBean responseBean = new ResponseBean();
193
+		try {
194
+			wxPayService.wxCancelPay(outTradeNo, type,getPersonId(request));
195
+		} catch (Exception e) {
196
+			e.printStackTrace();
197
+			responseBean.addError(e.getMessage());
198
+			return responseBean;
199
+		}
200
+		return responseBean;
201
+	}
202
+}

+ 2
- 2
src/main/java/com/huiju/estateagents/property/model/TpBillOrder.java Прегледај датотеку

@@ -54,7 +54,7 @@ public class TpBillOrder implements Serializable {
54 54
     /**
55 55
      * 创建人
56 56
      */
57
-    private Integer createUser;
57
+    private String createUser;
58 58
 
59 59
     /**
60 60
      * 创建时间
@@ -64,7 +64,7 @@ public class TpBillOrder implements Serializable {
64 64
     /**
65 65
      * 更新人
66 66
      */
67
-    private Integer updateUser;
67
+    private String updateUser;
68 68
 
69 69
     /**
70 70
      * 更新时间

+ 45
- 0
src/main/java/com/huiju/estateagents/property/perproties/PayNotifyPerproties.java Прегледај датотеку

@@ -0,0 +1,45 @@
1
+package com.huiju.estateagents.property.perproties;
2
+
3
+import lombok.Data;
4
+import org.springframework.boot.context.properties.ConfigurationProperties;
5
+import org.springframework.stereotype.Component;
6
+
7
+/**
8
+ * 支付回调地址配置
9
+ * @author weiximei
10
+ */
11
+@Component
12
+@ConfigurationProperties(prefix = "pay-new-notify")
13
+@Data
14
+public class PayNotifyPerproties {
15
+
16
+    /**
17
+     * 微信回调 物业缴费
18
+     */
19
+    private String wxBillNotify;
20
+
21
+    /**
22
+     * 支付宝回调 物业缴费
23
+     */
24
+    private String aliBillNotify;
25
+
26
+    /**
27
+     * 微信回调 车缴费
28
+     */
29
+    private String wxCarNotify;
30
+
31
+    /**
32
+     * 支付宝回调 车缴费
33
+     */
34
+    private String aliCarNotify;
35
+    
36
+    /**
37
+     * 微信临时车回调
38
+     */
39
+    private String wxTmpNotify;
40
+    
41
+    /**
42
+     * 支付宝临时车回调
43
+     */
44
+    private String aliTmpNotify;
45
+}

+ 2
- 2
src/main/java/com/huiju/estateagents/property/service/IBillInvoiceService.java Прегледај датотеку

@@ -38,10 +38,10 @@ public interface IBillInvoiceService extends IService<BillInvoice> {
38 38
     /**
39 39
      * 设置线下缴费
40 40
      * @param ids
41
-     * @param userElement
41
+     * @param personId
42 42
      * @return
43 43
      */
44
-    ResponseBean offlinePayment(List<Integer> ids, TaUser userElement);
44
+    ResponseBean offlinePayment(List<Integer> ids, String personId);
45 45
 
46 46
     /**
47 47
      * 由前台批量添加收费单, 默认定为 作废

+ 64
- 0
src/main/java/com/huiju/estateagents/property/service/WxPayServiceI.java Прегледај датотеку

@@ -0,0 +1,64 @@
1
+package com.huiju.estateagents.property.service;
2
+
3
+import java.util.List;
4
+import java.util.Map;
5
+
6
+public interface WxPayServiceI {
7
+	/**
8
+	 * 微信支付统一下单
9
+	 * @return
10
+	 * @param outTradeNo
11
+	 * @param type 订单类型  car 车缴费 , bill 物业缴费
12
+	 * @param personId
13
+	 */
14
+	Map<String, String> wxUnifiedOrder(String outTradeNo, String type, String personId) throws Exception;
15
+	
16
+	/**
17
+	 * 支付成功的回调 物业缴费
18
+	 * @return
19
+	 * @param resultMap
20
+	 */
21
+	String wxBillNotify(Map<String, String> resultMap) throws Exception;
22
+	
23
+	/**
24
+	 * 订单查询
25
+	 * @return
26
+	 */
27
+	Map<String, String> wxOrderQuery(String outTradeNo) throws Exception;
28
+	
29
+	/**
30
+	 * 准备支付
31
+	 * @param idArray 账单的id
32
+	 * @param personId
33
+	 * @param type 订单类型  car 车缴费 , bill 物业缴费
34
+	 * @param extensionMonth 延期月份,也就是延期几个月!
35
+	 *                        	只有在 车缴费的时候才有效
36
+	 * @throws Exception
37
+	 */
38
+	String wxStartPay(List<Integer> idArray, String type, Integer extensionMonth, String personId) throws Exception;
39
+	
40
+	/**
41
+	 * 取消支付
42
+	 * @param outTradeNo 订单号
43
+	 * @param type  订单类型  car 车缴费 , bill 物业缴费
44
+	 * @param personId
45
+	 */
46
+	void wxCancelPay(String outTradeNo, String type, String personId) throws Exception;
47
+
48
+	/**
49
+	 * 支付成功的回调 车缴费
50
+	 * @param resultMap
51
+	 * @return
52
+	 */
53
+	String wxCarNotify(Map<String, String> resultMap);
54
+
55
+	/**
56
+	 * 根据订单类型获取 金额 和 回调地址
57
+	 * @param type
58
+	 * @param orderNo
59
+	 * @param notifyType wx 微信, ali 支付宝
60
+	 * @return
61
+	 * @throws Exception
62
+	 */
63
+	Map<String,Object> getOrderPriceAndNotifyUrl(String type, String orderNo, String notifyType) throws Exception;
64
+}

+ 7
- 7
src/main/java/com/huiju/estateagents/property/service/impl/BillInvoiceServiceImpl.java Прегледај датотеку

@@ -161,9 +161,9 @@ public class BillInvoiceServiceImpl extends ServiceImpl<BillInvoiceMapper, BillI
161 161
 
162 162
     @Override
163 163
     @Transactional(rollbackFor = Exception.class)
164
-    public ResponseBean offlinePayment(List<Integer> ids, TaUser userElement) {
164
+    public ResponseBean offlinePayment(List<Integer> ids, String personId) {
165 165
         ResponseBean responseBean = new ResponseBean();
166
-        if (null == userElement) {
166
+        if (null == personId) {
167 167
             responseBean.addError("请登录后操作");
168 168
             return responseBean;
169 169
         }
@@ -182,7 +182,7 @@ public class BillInvoiceServiceImpl extends ServiceImpl<BillInvoiceMapper, BillI
182 182
 
183 183
                 // 插入流水
184 184
                 BillStatement billStatement = new BillStatement();
185
-                billStatement.setOrgId(userElement.getOrgId());
185
+                billStatement.setOrgId(1);
186 186
                 billStatement.setBillInvoiceId(billInvoice.getId());
187 187
                 billStatement.setTaUserId(billInvoice.getTaUserId());
188 188
                 billStatement.setPayPrice(billInvoice.getPayPrice());
@@ -212,7 +212,7 @@ public class BillInvoiceServiceImpl extends ServiceImpl<BillInvoiceMapper, BillI
212 212
 
213 213
                 // 生成订单
214 214
                 TpBillOrder tpBillOrder = new TpBillOrder();
215
-                tpBillOrder.setOrgId(userElement.getOrgId());
215
+                tpBillOrder.setOrgId(1);
216 216
                 tpBillOrder.setTpBillId(billInvoice.getBillId());
217 217
                 tpBillOrder.setTpBillInvoiceId(billInvoice.getId());
218 218
 
@@ -222,9 +222,9 @@ public class BillInvoiceServiceImpl extends ServiceImpl<BillInvoiceMapper, BillI
222 222
                 // 缴费状态  0:未支付  1: 已支付 2: 正在支付中
223 223
                 tpBillOrder.setOrderStatus("1");
224 224
                 tpBillOrder.setCreateDate(LocalDateTime.now());
225
-                tpBillOrder.setCreateUser(userElement.getUserId());
225
+                tpBillOrder.setCreateUser(personId);
226 226
                 tpBillOrder.setUpdateDate(LocalDateTime.now());
227
-                tpBillOrder.setUpdateUser(userElement.getUserId());
227
+                tpBillOrder.setUpdateUser(personId);
228 228
 
229 229
                 tpBillOrderMapper.insert(tpBillOrder);
230 230
 
@@ -232,7 +232,7 @@ public class BillInvoiceServiceImpl extends ServiceImpl<BillInvoiceMapper, BillI
232 232
 
233 233
                 // 把相对应的 APP端用户的代办消息进行设置为无效
234 234
                 QueryWrapper<Message> messageQueryWrapper = new QueryWrapper<>();
235
-                messageQueryWrapper.eq("org_id", userElement.getOrgId());
235
+                messageQueryWrapper.eq("org_id", 1);
236 236
                 messageQueryWrapper.eq("bill_id", billInvoice.getId());
237 237
                 messageQueryWrapper.eq("uuid_type", "1");
238 238
                 messageQueryWrapper.eq("uuid", billInvoice.getTaUserId());

+ 667
- 0
src/main/java/com/huiju/estateagents/property/service/impl/WxPayServiceImpl.java Прегледај датотеку

@@ -0,0 +1,667 @@
1
+package com.huiju.estateagents.property.service.impl;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5
+import com.google.common.collect.Lists;
6
+import com.google.common.collect.Maps;
7
+import com.huiju.estateagents.base.ResponseBean;
8
+import com.huiju.estateagents.center.taUser.entity.TaUser;
9
+import com.huiju.estateagents.center.taUser.mapper.TaUserMapper;
10
+import com.huiju.estateagents.common.wxpay.WXPay;
11
+import com.huiju.estateagents.common.wxpay.WXPayConstants;
12
+import com.huiju.estateagents.common.wxpay.WXPayUtil;
13
+import com.huiju.estateagents.common.wxpay.WxConfig;
14
+import com.huiju.estateagents.entity.TaPerson;
15
+import com.huiju.estateagents.entity.TaWxPayConfig;
16
+import com.huiju.estateagents.mapper.TaPersonMapper;
17
+import com.huiju.estateagents.mapper.TaWxPayConfigMapper;
18
+import com.huiju.estateagents.property.common.Constant;
19
+import com.huiju.estateagents.property.common.UserElement;
20
+import com.huiju.estateagents.property.dao.*;
21
+import com.huiju.estateagents.property.exception.WisdomException;
22
+import com.huiju.estateagents.property.model.*;
23
+import com.huiju.estateagents.property.perproties.PayNotifyPerproties;
24
+import com.huiju.estateagents.property.service.WxPayServiceI;
25
+import org.apache.commons.collections.CollectionUtils;
26
+import org.apache.commons.lang3.StringUtils;
27
+import org.slf4j.Logger;
28
+import org.slf4j.LoggerFactory;
29
+import org.springframework.beans.factory.annotation.Autowired;
30
+import org.springframework.context.ApplicationContext;
31
+import org.springframework.stereotype.Service;
32
+import org.springframework.transaction.annotation.Transactional;
33
+
34
+import java.io.ByteArrayOutputStream;
35
+import java.io.InputStream;
36
+import java.math.BigDecimal;
37
+import java.net.HttpURLConnection;
38
+import java.net.URL;
39
+import java.time.Instant;
40
+import java.time.LocalDateTime;
41
+import java.time.ZoneId;
42
+import java.time.ZoneOffset;
43
+import java.util.*;
44
+import java.util.stream.Collectors;
45
+
46
+/**
47
+ * @author FXF
48
+ * @date 2018-10-25
49
+ */
50
+@Service("wxPayService")
51
+@Transactional(rollbackFor = Exception.class)
52
+public class WxPayServiceImpl implements WxPayServiceI {
53
+	private Logger log = LoggerFactory.getLogger(WxPayServiceImpl.class);
54
+	
55
+	@Autowired
56
+	private BillInvoiceMapper tpBillInvoiceMapper;
57
+	
58
+	@Autowired
59
+	private BillStatementMapper tpBillStatementMapper;
60
+
61
+	@Autowired
62
+	private BillMapper tpBillMapper;
63
+
64
+	@Autowired
65
+	private TaPersonMapper taPersonMapper;
66
+
67
+	@Autowired
68
+	private TaSysRoleMapper taSysRoleMapper;
69
+
70
+	@Autowired
71
+	private MessageMapper tpMessageMapper;
72
+
73
+	@Autowired
74
+	private TpBillOrderMapper tpBillOrderMapper;
75
+
76
+	@Autowired
77
+	private TaUserVerifyMapper taUserVerifyMapper;
78
+
79
+	@Autowired
80
+	private TpBuildingOwnerInfoMapper tpBuildingOwnerInfoMapper;
81
+
82
+	@Autowired
83
+	private PayNotifyPerproties payNotifyPerproties;
84
+
85
+//	@Autowired
86
+//	private TaUserLicenseOrderMapper taUserLicenseOrderMapper;
87
+
88
+	@Autowired
89
+	private ApplicationContext applicationContext;
90
+
91
+	@Autowired
92
+	private TaWxPayConfigMapper taWxPayConfigMapper;
93
+
94
+//	@Autowired
95
+//	private IFuShiService iFuShiService;
96
+
97
+//	@Autowired
98
+//	private TaUserLicenseMapper taUserLicenseMapper;
99
+//
100
+//	@Autowired
101
+//	private ITaUserLicenseService iTaUserLicenseService;
102
+
103
+//	private IdGen idGen = IdGen.get();
104
+
105
+	/**
106
+	 * 微信支付统一下单
107
+	 *
108
+	 * @return
109
+	 * @param orderNo
110
+	 * @param
111
+	 */
112
+	@Override
113
+	@Transactional(rollbackFor = Exception.class)
114
+	public Map<String, String> wxUnifiedOrder(String orderNo, String type, String personId) throws Exception {
115
+		//构建微信配置
116
+		WxConfig config = getWxConfig(1);
117
+		WXPay wxpay = new WXPay(config);
118
+
119
+
120
+		Map<String, Object> orderPriceAndNotifyUrl = getOrderPriceAndNotifyUrl(type, orderNo, "wx");
121
+
122
+		String typeName = Constant.PAY_TYPE_BILL.equals(type) ? "物业缴费" : Constant.PAY_TYPE_CAR.equals(type) ? "车缴费" : "缴费";
123
+
124
+		//下单
125
+		Map<String, String> data = new HashMap<String, String>();
126
+		data.put("body", typeName);
127
+		//商品号唯一
128
+		data.put("out_trade_no", orderNo);
129
+		data.put("device_info", "");
130
+		data.put("fee_type", "CNY");
131
+		//金额 后台计算
132
+		data.put("total_fee", String.valueOf(orderPriceAndNotifyUrl.get("payPrice")));
133
+		//终端IP
134
+		data.put("spbill_create_ip", "123.12.12.123");
135
+		//回调地址
136
+		data.put("notify_url", String.valueOf(orderPriceAndNotifyUrl.get("notifyUrl")));
137
+		// 此处指定为APP支付
138
+		data.put("trade_type", "APP");
139
+		Map<String, String> resp = wxpay.unifiedOrder(data);
140
+		log.info("下单成功:{}", resp);
141
+		if (resp.get("result_code").equalsIgnoreCase(WXPayConstants.FAIL)){
142
+			throw new Exception(resp.get("err_code_des"));
143
+		}
144
+		//插入下单记录表
145
+		
146
+		//第二次重新生成签名
147
+		Map<String, String> secondSignData = new HashMap<String, String>();
148
+		long timestamp = Instant.now().getEpochSecond();
149
+		secondSignData.put("appid", config.getAppID());
150
+		secondSignData.put("partnerid", config.getMchID());
151
+		secondSignData.put("prepayid", resp.get("prepay_id"));
152
+		secondSignData.put("noncestr", resp.get("nonce_str"));
153
+		secondSignData.put("timestamp", String.valueOf(timestamp));
154
+		secondSignData.put("package", "Sign=WXPay");
155
+		secondSignData.put("sign", WXPayUtil.generateSignature(secondSignData, config.getKey(), WXPayConstants.SignType.MD5));
156
+
157
+		log.info("订单: {},订单类型: {}, 状态变更为正在支付", orderNo, type);
158
+
159
+		// 更改订单状态 为正在支付
160
+		updateOrderStatus(orderNo, type, "2");
161
+		return secondSignData;
162
+	}
163
+
164
+	/**
165
+	 * 根据订单类型获取 金额 和 回调地址
166
+	 * @param type
167
+	 * @param orderNo
168
+	 * @param notifyType wx 微信, ali 支付宝
169
+	 * @return
170
+	 * @throws Exception
171
+	 */
172
+	@Override
173
+	public Map<String,Object> getOrderPriceAndNotifyUrl(String type, String orderNo, String notifyType) throws Exception {
174
+		Map<String,Object> orderMap = Maps.newHashMap();
175
+
176
+		// 物业缴费
177
+		if (Constant.PAY_TYPE_BILL.equals(type)) {
178
+			//获取支付金额
179
+			List<TpBillOrder> billOrderList = tpBillOrderMapper.selectByOrderBumber(orderNo);
180
+			if (CollectionUtils.isEmpty(billOrderList)){
181
+				throw new Exception("订单不存在");
182
+			}
183
+			// 检测订单是否 已关闭
184
+			billOrderList.forEach(e-> {
185
+				if ("3".equals(e.getOrderStatus())) {
186
+					throw new WisdomException("无法支付已关闭的订单!");
187
+				}
188
+			});
189
+			// 计算金额
190
+			Long payPrice = billOrderList.stream().mapToLong(e -> tpBillInvoiceMapper.selectById(e.getTpBillInvoiceId()).getPayPrice()).sum();
191
+			orderMap.put("orderNo", orderNo);
192
+			orderMap.put("payPrice", String.valueOf(payPrice));
193
+			orderMap.put("notifyUrl", "wx".equals(notifyType) ? payNotifyPerproties.getWxBillNotify() : payNotifyPerproties.getAliBillNotify());
194
+
195
+		} else if (Constant.PAY_TYPE_CAR.equals(type)) { // 车缴费
196
+//			List<TaUserLicenseOrder> userLicenseOrders = taUserLicenseOrderMapper.selectByOrderNumber(orderNo);
197
+//			if (CollectionUtils.isEmpty(userLicenseOrders)) {
198
+//				throw new Exception("订单不存在");
199
+//			}
200
+//			// 检测订单是否 已关闭
201
+//			userLicenseOrders.forEach(e-> {
202
+//				if ("3".equals(e.getOrderStatus())) {
203
+//					throw new WisdomException("无法支付已关闭的订单!");
204
+//				}
205
+//			});
206
+//
207
+//			// 总额
208
+//			Long payPrice = userLicenseOrders.stream().map(e -> Long.parseLong(e.getExtensionPrice())).count();
209
+//			orderMap.put("orderNo", orderNo);
210
+//			orderMap.put("payPrice", String.valueOf(payPrice));
211
+//			orderMap.put("notifyUrl", "wx".equals(notifyType) ? payNotifyPerproties.getWxCarNotify() : payNotifyPerproties.getAliCarNotify());
212
+		}
213
+
214
+		return orderMap;
215
+	}
216
+
217
+
218
+
219
+
220
+	/**
221
+	 * 支付成功的回调
222
+	 *
223
+	 * @return
224
+	 * @param resultMap
225
+	 */
226
+	@Override
227
+	@Transactional(rollbackFor = Exception.class)
228
+	public String wxBillNotify(Map<String, String> resultMap) throws Exception {
229
+		String outTradeNo = resultMap.get("out_trade_no");
230
+		List<TpBillOrder> billOrderList = tpBillOrderMapper.selectByOrderBumber(outTradeNo);
231
+		if (CollectionUtils.isEmpty(billOrderList)){
232
+			return "不存在的订单";
233
+		}
234
+
235
+		// 缴费人在准备支付状态下更新, 这里是微信的回调所有没有 token
236
+
237
+		for ( TpBillOrder billOrder : billOrderList){
238
+			BillInvoice tpBillInvoice = tpBillInvoiceMapper.selectById(billOrder.getTpBillInvoiceId());
239
+
240
+			// 更新为正在支付状态
241
+			// 更改收费单的 缴费时间, 修改人, 修改时间
242
+			tpBillInvoice.setBillStatus("1");
243
+			tpBillInvoice.setPayDate(new Date());
244
+			tpBillInvoice.setUpdateDate(new Date());
245
+			// 缴费方式  0:微信支付  1:线下缴费 2.支付宝支付
246
+			tpBillInvoice.setPayType(resultMap.get("pay_type"));
247
+			tpBillInvoiceMapper.updateById(tpBillInvoice);
248
+
249
+			//插入流水账单表
250
+			BillStatement tpBillStatement = new BillStatement();
251
+			tpBillStatement.setBillInvoiceId(tpBillInvoice.getId());
252
+			tpBillStatement.setOrgId(1);
253
+			tpBillStatement.setTaUserId(tpBillInvoice.getTaUserId());
254
+			tpBillStatement.setPayPrice(tpBillInvoice.getPayPrice());
255
+			tpBillStatement.setPayName(tpBillInvoice.getPayName());
256
+			tpBillStatement.setPayRemark(tpBillInvoice.getBillInvoiceExplain());
257
+			tpBillStatement.setPayType(resultMap.get("pay_type"));
258
+			tpBillStatement.setCreateTime(new Date());
259
+			tpBillStatementMapper.insert(tpBillStatement);
260
+
261
+			// 更新 收费单流水id
262
+			tpBillInvoice.setBillStatementId(tpBillStatement.getId());
263
+			tpBillInvoiceMapper.updateById(tpBillInvoice);
264
+
265
+			// 更新收费组的 未交费用户数 和 已缴费用户数
266
+			Bill tpBill = tpBillMapper.selectById(tpBillInvoice.getBillId());
267
+			tpBill.setPayedNum(tpBill.getPayedNum() + 1);
268
+			tpBill.setUnpayedNum(tpBill.getUnpayedNum() - 1);
269
+			// 如果为零, 表示这个收费组收费完成
270
+			if (tpBill.getUnpayedNum() <= 0) {
271
+				tpBill.setBillStatus("1");
272
+				tpBill.setUnpayedNum(0);
273
+			}
274
+			tpBillMapper.updateById(tpBill);
275
+
276
+			// 把相对应的APP端, 代办消息设置为无效
277
+//			Map<String, Object> map = Maps.newHashMap();
278
+//			map.put("communityId", tpBillInvoice.getCommunityId());
279
+//			map.put("billInvoiceId", tpBillInvoice.getId());
280
+//			map.put("userId", tpBillInvoice.getTaUserId());
281
+//			TpMessage tpMessage = tpMessageMapper.selectBillinvoiceMessage(map);
282
+//			tpMessage.setStatus("0");
283
+//			tpMessageMapper.updateByPrimaryKeySelective(tpMessage);
284
+		}
285
+
286
+		log.info("订单: {},订单类型: {}, 状态变更为支付成功", outTradeNo, Constant.PAY_TYPE_BILL);
287
+
288
+		// 更改订单状态 为支付成功
289
+		updateOrderStatus(outTradeNo, Constant.PAY_TYPE_BILL, "1");
290
+
291
+		    // 只取第一条根据订单号去匹配列表
292
+		    TpBillOrder tpBillOrder = billOrderList.get(0);
293
+			BillInvoice tpBillInvoice = tpBillInvoiceMapper.selectById(tpBillOrder.getTpBillInvoiceId());
294
+//			List<TpUser> tpUserList= tpUserMapper.selectCommunityId(tpBillOrder.getCommunityId());
295
+//
296
+//			// 推物业端,推这个小区下的所有管理员
297
+//			TaUser taUser= taUserMapper.selectByPrimaryKey(tpBillOrder.getCreateUser());
298
+//			for (TpUser tpUser:tpUserList) {
299
+//				Map<String, Object> mapProp = new HashMap<>();
300
+//				mapProp.put("communityId", tpBillOrder.getCommunityId());
301
+//				mapProp.put("tpUserId", tpUser.getId());
302
+//				mapProp.put("createUserId", tpBillOrder.getCreateUser());
303
+//				mapProp.put("billInvoiceId", tpBillOrder.getId());
304
+//				mapProp.put("name", taUser.getUserName());
305
+//				applicationContext.publishEvent(new MessageEvent(mapProp, Constant.PAY_TYPE_SUCCEED, mapProp));
306
+//		}
307
+		return "success";
308
+	}
309
+	
310
+	/**
311
+	 * 订单查询
312
+	 *
313
+	 * @return
314
+	 */
315
+	@Override
316
+	public Map<String, String> wxOrderQuery(String outTradeNo) throws Exception {
317
+		WxConfig config = getWxConfig(1);
318
+		WXPay wxpay = new WXPay(config);
319
+		
320
+		Map<String, String> data = new HashMap<String, String>();
321
+		data.put("out_trade_no", outTradeNo);
322
+		return wxpay.orderQuery(data);
323
+	}
324
+	
325
+	@Override
326
+	@Transactional(rollbackFor = Exception.class)
327
+	public String wxStartPay(List<Integer> idArray, String type, Integer extensionMonth, String personId) throws Exception {
328
+		if (StringUtils.isBlank(type)) {
329
+			throw new WisdomException("type 不能为空!");
330
+		}
331
+
332
+		// 缴费的用户
333
+		TaPerson taPerson = taPersonMapper.selectById(personId);
334
+
335
+		Random random = new Random();
336
+		String orderNo = String.valueOf(System.currentTimeMillis()) + random.nextInt();
337
+
338
+		// 创建订单
339
+		createOrder(idArray, type, taPerson, personId, orderNo, extensionMonth, null);
340
+
341
+		return orderNo;
342
+	}
343
+
344
+	/**
345
+	 * 创建订单
346
+	 * @param idArray
347
+	 * @param type
348
+	 * @param orderNo
349
+	 * @param extensionMonth 延期月份,也就是延期几个月!
350
+	 *                       	只有在 车缴费的时候才有效
351
+	 * @param paymentType 缴费方式 1是支付宝 2是微信支付
352
+	 * @throws Exception
353
+	 */
354
+	private void createOrder(List<Integer> idArray, String type, TaPerson taPerson, String personId, String orderNo, Integer extensionMonth, String paymentType) throws Exception {
355
+		// 物业缴费
356
+		if (Constant.PAY_TYPE_BILL.equals(type)) {
357
+			//获取支付金额
358
+			for (Integer billInvoiceId : idArray) {
359
+				BillInvoice tpBillInvoice = tpBillInvoiceMapper.selectById(billInvoiceId);
360
+				if (null == tpBillInvoice){
361
+					throw new Exception("订单不存在");
362
+				}else if (!tpBillInvoice.getBillStatus().equals("0")){
363
+					throw new Exception("正在支付的订单");
364
+				}
365
+
366
+				TpBillOrder tpBillOrder = new TpBillOrder();
367
+				tpBillOrder.setOrgId(1);
368
+				tpBillOrder.setTpBillId(tpBillInvoice.getBillId());
369
+				tpBillOrder.setTpBillInvoiceId(tpBillInvoice.getId());
370
+				tpBillOrder.setCreateDate(LocalDateTime.now());
371
+				tpBillOrder.setCreateUser(personId);
372
+				tpBillOrder.setUpdateDate(LocalDateTime.now());
373
+				tpBillOrder.setUpdateUser(personId);
374
+				tpBillOrder.setOrderBumber(orderNo);
375
+				tpBillOrder.setPayPhone(taPerson.getPhone());
376
+				tpBillOrder.setOrderStatus("0");
377
+
378
+				tpBillOrderMapper.insert(tpBillOrder);
379
+
380
+			}
381
+			// 修改缴费人, 修改为正在缴费
382
+			updateBillInvoiceBillStatus(idArray, taPerson.getName(), "3");
383
+
384
+			// 车缴费
385
+		} else if (Constant.PAY_TYPE_CAR.equals(type)) {
386
+//			if (null == extensionMonth || extensionMonth <= 0) {
387
+//				throw new Exception("延期月份不能为空,并且要大于0!");
388
+//			}
389
+//
390
+//			for (Integer clicenseId : idArray) {
391
+//				// 根据车牌id,查询车牌
392
+//				TaUserLicense taUserLicense = taUserLicenseMapper.selectByPrimaryKey(clicenseId);
393
+//				// 获取车牌最新信息
394
+//				ResponseBean responseLicense = iTaUserLicenseService.getLicense(userElement, taUserLicense.getLicensePlate());
395
+//				Object licenseData = responseLicense.getData();
396
+//				if (null != licenseData && licenseData instanceof TaUserLicense) {
397
+//					taUserLicense = (TaUserLicense) licenseData;
398
+//				}
399
+//
400
+//				// 校验车状态
401
+//				if (taUserLicense.getLicenseType().intValue() != 1) {
402
+//					throw new WisdomException("异常状态,不能缴月租费!");
403
+//				}
404
+//
405
+//				// 校验是否,超出缴费有效期时间
406
+//				LocalDateTime expireDateLocalDateTime = LocalDateTime.ofInstant(taUserLicense.getExpireDate().toInstant(), ZoneId.systemDefault());
407
+//				expireDateLocalDateTime.plusDays(taUserLicense.getRenewTime());
408
+//				if (taUserLicense.getRenewTime().intValue() > 0 && System.currentTimeMillis() > expireDateLocalDateTime.toEpochSecond(ZoneOffset.of("+8"))) {
409
+//					throw new WisdomException("已超出续费时间,请找物业处理!");
410
+//				}
411
+//
412
+//				TaUserLicenseOrder taUserLicenseOrder = new TaUserLicenseOrder();
413
+//				taUserLicenseOrder.setCommunityId(userElement.getCommunityId());
414
+//				taUserLicenseOrder.setTaUserId(userElement.getId());
415
+//				taUserLicenseOrder.setOrderNumber(orderNo);
416
+//				taUserLicenseOrder.setOrderStatus("0");
417
+//				taUserLicenseOrder.setCreateDate(new Date());
418
+//				taUserLicenseOrder.setCreateUser(userElement.getId());
419
+//				taUserLicenseOrder.setExtensionMonth(extensionMonth);
420
+//
421
+//				// 费用
422
+//				String extensionPrice = BigDecimal.valueOf(Double.valueOf(taUserLicense.getUnitPrice()) / 100).multiply(BigDecimal.valueOf(extensionMonth)).toString();
423
+//				String price = String.valueOf(Double.valueOf(extensionPrice) * 100);
424
+//				taUserLicenseOrder.setExtensionPrice(price.substring(0, price.lastIndexOf(".")));
425
+//
426
+//				taUserLicenseOrder.setPaymentTel(taUser.getLoginName());
427
+//				taUserLicenseOrder.setPaymentName(taUser.getUserName());
428
+//				taUserLicenseOrder.setPaymentType(paymentType);
429
+//
430
+//				// 到期时间 (具体的到期时候,在支付回调里面以车辆管理系统为准)
431
+//				LocalDateTime localDateTime = LocalDateTime.ofInstant(taUserLicense.getExpireDate().toInstant(), ZoneId.systemDefault());
432
+//				localDateTime.plusMonths(extensionMonth);
433
+//				taUserLicenseOrder.setExpireDate(Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()));
434
+//				taUserLicenseOrder.setUnitPrice(taUserLicense.getUnitPrice());
435
+//				taUserLicenseOrder.setParkingLot(taUserLicense.getParkingLot());
436
+//				taUserLicenseOrder.setLicensePlate(taUserLicense.getLicensePlate());
437
+//
438
+//				// 插入数据
439
+//				taUserLicenseOrderMapper.insertSelective(taUserLicenseOrder);
440
+
441
+//			}
442
+
443
+		}
444
+	}
445
+
446
+
447
+
448
+	/**
449
+	 * 取消支付
450
+	 *
451
+	 * @param outTradeNo
452
+	 * @param
453
+	 */
454
+	@Override
455
+	@Transactional(rollbackFor = Exception.class)
456
+	public void wxCancelPay(String outTradeNo, String type, String personId) throws Exception {
457
+
458
+		/**
459
+		 * 如果是车缴费订单,就只直接更新 订单状态为关闭
460
+		 */
461
+		// 如果是车缴费
462
+//		if (Constant.PAY_TYPE_CAR.equals(type)) {
463
+//			// 更改订单状态 为订单已关闭
464
+//			updateOrderStatus(outTradeNo, type, "3");
465
+//			return;
466
+//		}
467
+
468
+		// --------------------------- 物业缴费 --------------------------------
469
+
470
+		//获取支付金额
471
+		List<TpBillOrder> billOrderList = tpBillOrderMapper.selectByOrderBumber(outTradeNo);
472
+		if (CollectionUtils.isEmpty(billOrderList)){
473
+			throw new Exception("订单不存在");
474
+		}
475
+
476
+		List<BillInvoice> billInvoiceList = Lists.newArrayList();
477
+		for (TpBillOrder tpBillOrder : billOrderList) {
478
+			BillInvoice billInvoice = tpBillInvoiceMapper.selectById(tpBillOrder.getTpBillInvoiceId());
479
+			if (!billInvoice.getBillStatus().equals("3")){
480
+				throw new Exception("不是正在支付的订单");
481
+			}
482
+			billInvoiceList.add(billInvoice);
483
+		}
484
+
485
+		// 缴费单id集合
486
+		List<Integer> billInvoiceIdList = billInvoiceList.stream().map(e -> e.getId()).collect(Collectors.toList());
487
+
488
+		//更新为 未支付状态
489
+		updateBillInvoiceBillStatus(billInvoiceIdList, "","0");
490
+		log.info("订单: {}, 订单类型: {}, 状态变更为取消支付", outTradeNo, type);
491
+
492
+		// 更改订单状态 为订单已关闭
493
+		updateOrderStatus(outTradeNo, type, "3");
494
+
495
+	}
496
+
497
+	@Override
498
+	public String wxCarNotify(Map<String, String> resultMap) {
499
+//
500
+//		String outTradeNo = resultMap.get("out_trade_no");
501
+//		String pay_type = resultMap.get("pay_type");
502
+//		String payTypeName = pay_type.equals("0") ? "微信支付" : pay_type.equals("2") ? "支付宝" : "未知";
503
+//
504
+//		List<TaUserLicenseOrder> userLicenseOrderList = taUserLicenseOrderMapper.selectByOrderNumber(outTradeNo);
505
+//		if (CollectionUtils.isEmpty(userLicenseOrderList)){
506
+//			return "不存在的订单";
507
+//		}
508
+//
509
+//		log.info("订单:{},订单类型: {} 开始推送到 车辆管理系统 ", outTradeNo, Constant.PAY_TYPE_CAR);
510
+//
511
+//		TaUserLicenseOrder taUserLicenseOrder = userLicenseOrderList.get(0);
512
+//		TaUser taUser = taUserMapper.selectByPrimaryKey(taUserLicenseOrder.getTaUserId());
513
+//
514
+//		ApiThirdPartyMonthCardPay apiThirdPartyMonthCardPay = new ApiThirdPartyMonthCardPay();
515
+//		apiThirdPartyMonthCardPay.setPhone(taUser.getLoginName());
516
+//		apiThirdPartyMonthCardPay.setRenewDayType("2");
517
+//		apiThirdPartyMonthCardPay.setRenewDay(String.valueOf(taUserLicenseOrder.getExtensionMonth()));
518
+//		apiThirdPartyMonthCardPay.setPayStyle(payTypeName);
519
+//		apiThirdPartyMonthCardPay.setCarNo(taUserLicenseOrder.getLicensePlate());
520
+//		apiThirdPartyMonthCardPay.setCardNo(null);
521
+//		apiThirdPartyMonthCardPay.setRechargeAmt(String.valueOf(Double.valueOf(taUserLicenseOrder.getExtensionPrice()) / 100));
522
+//		apiThirdPartyMonthCardPay.setDealNo(outTradeNo);
523
+//
524
+//		// 推送到车辆管理系统
525
+//		iFuShiServer.apiThirdPartyMonthCardPay(JSONObject.toJSONString(apiThirdPartyMonthCardPay));
526
+//
527
+//		// 推送到车辆管理系统
528
+////		iFuShiService.apiThirdPartyMonthCardPay(taUser.getLoginName(), "2",
529
+////				String.valueOf(taUserLicenseOrder.getExtensionMonth()),
530
+////				payTypeName, taUserLicenseOrder.getLicensePlate(),
531
+////				null, String.valueOf(Double.valueOf(taUserLicenseOrder.getExtensionPrice()) / 100));
532
+//
533
+//
534
+////		userLicenseOrderList.forEach(e-> {
535
+////			UserElement userElement = new UserElement();
536
+////			userElement.setCommunityId(e.getCommunityId());
537
+////			userElement.setId(e.getTaUserId());
538
+////			ResponseBean responseLicense = iTaUserLicenseService.getLicense(userElement, e.getLicensePlate());
539
+////			Object licenseData = responseLicense.getData();
540
+////			TaUserLicense taUserLicense = null;
541
+////			if (null != licenseData && licenseData instanceof TaUserLicense) {
542
+////				taUserLicense = (TaUserLicense) licenseData;
543
+////				e.setExpireDate(taUserLicense.getExpireDate());
544
+////			}
545
+////			e.setPaymentType(pay_type);
546
+////			e.setUpdateUser(e.getCreateUser());
547
+////			e.setUpdateDate(new Date());
548
+////			taUserLicenseOrderMapper.updateByPrimaryKeySelective(e);
549
+////
550
+////		});
551
+//
552
+//
553
+//		log.info("订单: {},订单类型: {}, 状态变更为支付成功", outTradeNo, Constant.PAY_TYPE_CAR);
554
+//
555
+//		// 更改订单状态 为支付成功
556
+//		updateOrderStatus(outTradeNo, Constant.PAY_TYPE_CAR, "1");
557
+//
558
+//		// 推物业端,推这个小区下的所有管理员
559
+//
560
+//		List<TpUser> tpUserList = tpUserMapper.selectCommunityId(taUserLicenseOrder.getCommunityId());
561
+//		for (TpUser tpUser : tpUserList) {
562
+//			Map<String, Object> mapProp = new HashMap<>();
563
+//			mapProp.put("communityId", taUserLicenseOrder.getCommunityId());
564
+//			mapProp.put("tpUserId", tpUser.getId());
565
+//			mapProp.put("createUserId", taUserLicenseOrder.getTaUserId());
566
+//			mapProp.put("licenseOrderId", taUserLicenseOrder.getId());
567
+//			mapProp.put("name", taUserLicenseOrder.getPaymentName());
568
+//			mapProp.put("number", taUserLicenseOrder.getLicensePlate());
569
+//			applicationContext.publishEvent(new MessageEvent(mapProp, Constant.PAY_MONTH_Bill_SUCCEED, mapProp));
570
+//		}
571
+
572
+		return "success";
573
+	}
574
+
575
+	/**
576
+	 * 更新支付状态
577
+	 * @param billInvoiceIdList
578
+	 * @param status
579
+	 */
580
+	private void updateBillInvoiceBillStatus(List<Integer> billInvoiceIdList, String status) {
581
+		billInvoiceIdList.forEach(e -> {
582
+			BillInvoice tpBillInvoiceUpdate = new BillInvoice();
583
+			tpBillInvoiceUpdate.setBillStatus(status);
584
+			tpBillInvoiceUpdate.setId(e);
585
+			tpBillInvoiceMapper.updateById(tpBillInvoiceUpdate);
586
+		});
587
+
588
+	}
589
+
590
+	/**
591
+	 * 更新支付状态
592
+	 * @param billInvoiceIdList
593
+	 * @param userName 缴费人
594
+	 * @param status
595
+	 */
596
+	private void updateBillInvoiceBillStatus(List<Integer> billInvoiceIdList, String userName, String status) {
597
+		billInvoiceIdList.forEach(e -> {
598
+			BillInvoice tpBillInvoiceUpdate = new BillInvoice();
599
+			tpBillInvoiceUpdate.setBillStatus(status);
600
+			tpBillInvoiceUpdate.setId(e);
601
+			tpBillInvoiceUpdate.setPayName(userName);
602
+			tpBillInvoiceMapper.updateById(tpBillInvoiceUpdate);
603
+		});
604
+	}
605
+
606
+	/**
607
+	 * 更改订单状态
608
+	 * @param orderNumber
609
+	 * @param type
610
+	 * @param status
611
+	 */
612
+	private void updateOrderStatus(String orderNumber, String type, String status){
613
+		// 物业缴费
614
+		if (Constant.PAY_TYPE_BILL.equals(type)) {
615
+			List<TpBillOrder> billOrders = tpBillOrderMapper.selectByOrderBumber(orderNumber);
616
+			billOrders.forEach(e-> {
617
+				e.setOrderStatus(status);
618
+				tpBillOrderMapper.updateById(e);
619
+			});
620
+
621
+			// 车缴费
622
+		} else if (Constant.PAY_TYPE_CAR.equals(type)) {
623
+//			List<TaUserLicenseOrder> taUserLicenseOrders = taUserLicenseOrderMapper.selectByOrderNumber(orderNumber);
624
+//			taUserLicenseOrders.forEach(e-> {
625
+//				e.setOrderStatus(status);
626
+//				taUserLicenseOrderMapper.updateByPrimaryKeySelective(e);
627
+//			});
628
+		}
629
+	}
630
+
631
+
632
+	/**
633
+	 * 获取每个小程序独立的微信账户
634
+	 * @param orgId
635
+	 * @return
636
+	 */
637
+	private WxConfig getWxConfig(Integer orgId) throws Exception {
638
+		//根据orgId获取支付配置
639
+		QueryWrapper<TaWxPayConfig> taWxPayConfigQueryWrapper = new QueryWrapper<>();
640
+		taWxPayConfigQueryWrapper.eq("org_id",orgId);
641
+		TaWxPayConfig taWxPayConfig = taWxPayConfigMapper.selectOne(taWxPayConfigQueryWrapper);
642
+		if (null == taWxPayConfig){
643
+			throw new Exception("请先完善支付信息");
644
+		}
645
+		log.info("正在配置orgId为{}的微信支付参数,商户号为{}",orgId,taWxPayConfig.getMchId());
646
+		//把库里的值赋值给微信
647
+		URL urlConet = new URL(taWxPayConfig.getApiPath());
648
+		HttpURLConnection con = (HttpURLConnection)urlConet.openConnection();
649
+		con.setRequestMethod("GET");
650
+		con.setConnectTimeout(4 * 1000);
651
+		InputStream inStream = con .getInputStream();
652
+		ByteArrayOutputStream outStream = new ByteArrayOutputStream();
653
+		byte[] buffer = new byte[2048];
654
+		int len = 0;
655
+		while( (len=inStream.read(buffer)) != -1 ){
656
+			outStream.write(buffer, 0, len);
657
+		}
658
+		inStream.close();
659
+
660
+		WxConfig config = new WxConfig();
661
+		config.setAppid(taWxPayConfig.getAppid());
662
+		config.setMachId(taWxPayConfig.getMchId());
663
+		config.setCertData(outStream.toByteArray());
664
+		config.setKey(taWxPayConfig.getMchKey());
665
+		return config;
666
+	}
667
+}

+ 9
- 0
src/main/resources/application-dev.yml Прегледај датотеку

@@ -78,6 +78,15 @@ pay-notify: https://dev.fangdeal.cn/api/notify/
78 78
 #退款回调
79 79
 pay-refund: https://dev.fangdeal.cn/api/refund/
80 80
 
81
+# 支付回调
82
+pay-new-notify:
83
+  wx-bill-notify: http://106.14.20.193:8086/api/wxBillNotify
84
+  ali-bill-notify: http://106.14.20.193:8086/api/aliPayBillNotify
85
+  wx-car-notify: http://106.14.20.193:8086/api/wxCarNotify
86
+  ali-car-notify: http://106.14.20.193:8086/api/aliPayCarNotify
87
+  wx-tmp-notify: http://106.14.20.193:8086/api/wxTmpNotify
88
+  ali-tmp-notify: http://106.14.20.193:8086/api/aliTmpNotify
89
+
81 90
 #法大大服务器地址
82 91
 fadada:
83 92
   appId: "403057"

+ 9
- 0
src/main/resources/application-prod.yml Прегледај датотеку

@@ -83,6 +83,15 @@ pay-notify: https://wx.fangdeal.cn/api/notify/
83 83
 #退款回调
84 84
 pay-refund: https://wx.fangdeal.cn/api/refund/
85 85
 
86
+# 支付回调
87
+pay-new-notify:
88
+  wx-bill-notify: http://106.14.20.193:8086/api/wxBillNotify
89
+  ali-bill-notify: http://106.14.20.193:8086/api/aliPayBillNotify
90
+  wx-car-notify: http://106.14.20.193:8086/api/wxCarNotify
91
+  ali-car-notify: http://106.14.20.193:8086/api/aliPayCarNotify
92
+  wx-tmp-notify: http://106.14.20.193:8086/api/wxTmpNotify
93
+  ali-tmp-notify: http://106.14.20.193:8086/api/aliTmpNotify
94
+
86 95
 #法大大服务器地址
87 96
 fadada:
88 97
   appId: "500261"