Sfoglia il codice sorgente

修改微信支付

杨杰 5 anni fa
parent
commit
a47367e396

+ 10 - 4
src/main/java/com/llisoft/pay/controller/WxPayController.java

@@ -7,12 +7,15 @@ import javax.servlet.http.HttpServletRequest;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
+import com.llisoft.pay.service.WxPayService;
+
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 
@@ -22,22 +25,25 @@ import io.swagger.annotations.ApiOperation;
 public class WxPayController {
 	
 	private Logger logger = LoggerFactory.getLogger(WxPayController.class);
+
+	@Autowired
+	private WxPayService wxPayService;
 	
 
 	@ApiOperation(value="同步回调")
 	@GetMapping("/return")
-	public String retur(HttpServletRequest request) {
+	public String retur(HttpServletRequest request) throws Exception {
 		Map<String, String> resultMap = this.getParamMap(request);
 		logger.info("收到微信同步回调: {}", resultMap);
-		return null;
+		return wxPayService.dispose(resultMap) ? "success" : "";
 	}
 	
 	@ApiOperation(value="异步通知")
 	@PostMapping(value="/notify")
-	public @ResponseBody String notify(HttpServletRequest request) {
+	public @ResponseBody String notify(HttpServletRequest request) throws Exception {
 		Map<String, String> resultMap = this.getParamMap(request);
 		logger.info("收到微信异步通知: {}", resultMap);
-		return null;
+		return wxPayService.dispose(resultMap) ? "success" : "";
 	}
 	
 	

+ 2 - 58
src/main/java/com/llisoft/pay/service/OrderService.java

@@ -10,8 +10,6 @@ import org.springframework.stereotype.Service;
 import com.llisoft.common.exception.MtaException;
 import com.llisoft.common.util.BeanUtil;
 import com.llisoft.common.util.CodeUtil;
-import com.llisoft.common.util.HttpUtil;
-import com.llisoft.common.util.JsonUtil;
 import com.llisoft.pay.dao.OrderDao;
 import com.llisoft.pay.entity.App;
 import com.llisoft.pay.entity.Order;
@@ -80,7 +78,7 @@ public class OrderService {
 	 * @throws MtaException
 	 */
 	public OrderPayResponseVo pay(String orderNum, byte payType, boolean isMobile) throws MtaException{
-		Order order = this.getByOrderNum(orderNum);
+		Order order = orderDao.selectByOrderNum(orderNum);
 		if(order.getOrderStatus() == STATUS_PAYED){
 			throw new MtaException("订单已经支付过: " + orderNum);
 		}
@@ -100,64 +98,10 @@ public class OrderService {
 	 * @throws Exception 
 	 */
 	public OrderInfoResponseVo info(String orderNum) throws Exception {
-		Order order = this.getByOrderNum(orderNum);
+		Order order = orderDao.selectByOrderNum(orderNum);
 		OrderInfoResponseVo vo = BeanUtil.transformBean(order, OrderInfoResponseVo.class);
 		vo.setPayed(order.getOrderStatus() == STATUS_PAYED);
 		return vo;
 	}
 	
-	
-	/**
-	 * 获取
-	 * @param orderId
-	 * @return
-	 * @throws MtaException 
-	 */
-	public Order get(int orderId) throws MtaException{
-		Order order = orderDao.select(orderId);
-		if (Objects.isNull(order)) {
-			throw new MtaException("订单不存在: " + orderId);
-		}
-		return order;
-	}
-	
-	/**
-	 * 获取
-	 * @param orderNum
-	 * @return
-	 * @throws MtaException 
-	 */
-	public Order getByOrderNum(String orderNum) throws MtaException{
-		Order order = orderDao.selectByOrderNum(orderNum);
-		if (Objects.isNull(order)) {
-			throw new MtaException("订单不存在: " + orderNum);
-		}
-		return order;
-	}
-	
-	/**
-	 * 完成
-	 * @param orderNum
-	 * @return
-	 * @throws Exception 
-	 */
-	public boolean finish(int orderId) throws Exception{
-		Order order = this.get(orderId);
-		if (Objects.isNull(order)) {
-			throw new MtaException("订单不存在: " + orderId);
-		}
-		// 更新订单状态
-		orderDao.updatePay(order.getOrderId(), STATUS_PAYED);
-		// 发送支付成功异步通知
-		String notifyUrl = appService.getNotifyUrl(order.getAppId(), order.getOrderNum());
-		if(Objects.nonNull(notifyUrl)) {
-			logger.info("订单完成: 异步通知业务地址: {}, 参数: {}", notifyUrl, JsonUtil.toJson(order));
-			String result = HttpUtil.postJson(notifyUrl, JsonUtil.toJson(order));
-			logger.info("订单完成: 业务端返回信息: {}", result);
-			return "success".equals(result);
-		}
-		return true;
-	}
-
-	
 }

+ 22 - 7
src/main/java/com/llisoft/pay/service/PayService.java

@@ -10,7 +10,10 @@ import org.springframework.transaction.annotation.Transactional;
 
 import com.llisoft.common.exception.MtaException;
 import com.llisoft.common.util.CodeUtil;
+import com.llisoft.common.util.HttpUtil;
+import com.llisoft.common.util.JsonUtil;
 import com.llisoft.pay.dao.ItemDao;
+import com.llisoft.pay.dao.OrderDao;
 import com.llisoft.pay.entity.Item;
 import com.llisoft.pay.entity.Order;
 
@@ -42,9 +45,13 @@ public class PayService {
 	@Autowired
 	private ItemDao payDao;
 	@Autowired
-	private OrderService orderService;
+	private OrderDao orderDao;
 	@Autowired
 	private AliPayService aliPayService;
+	@Autowired
+	private WxPayService wxPayService;
+	@Autowired
+	private AppService appService;
 	
 	
 	/**
@@ -91,13 +98,12 @@ public class PayService {
 		if (Objects.isNull(item)) {
 			throw new MtaException("支付记录不存在: " + payNum);
 		}
-		Order order = orderService.get(item.getOrderId());
+		Order order = orderDao.select(item.getOrderId());
 		if (item.getPayType() == TYPE_ALI) { // 支付宝
 			return isMobile ? aliPayService.paym(payNum, order.getOrderMoney(), order.getOrderTitle()) : 
 				aliPayService.pay(payNum, order.getOrderMoney(), order.getOrderTitle());
 		}else if (item.getPayType() == TYPE_WX) { // 微信
-			return isMobile ? aliPayService.paym(payNum, order.getOrderMoney(), order.getOrderTitle()) : 
-				aliPayService.pay(payNum, order.getOrderMoney(), order.getOrderTitle());
+			return wxPayService.pay(payNum, order.getOrderMoney(), order.getOrderTitle());
 		}
 		return null;
 	}
@@ -115,15 +121,24 @@ public class PayService {
 	@Transactional
 	public boolean finish(String payNum, String tradeNum, int money, byte flag) throws Exception{
 		Item item = this.get(payNum);
-		Order order = orderService.get(item.getOrderId());
+		Order order = orderDao.select(item.getOrderId());
 		if (order.getOrderMoney() != money) { // 核对金额
 			throw new MtaException("支付金额异常: " + money);
 		}
 		// 更新支付状态
 		payDao.updatePay(item.getPayId(), tradeNum, STATUS_PAYED, flag);
 		logger.info("支付处理成功, 状态更新为已支付: {}", payNum);
-		// 更新订单
-		return orderService.finish(item.getOrderId());
+		// 更新订单状态
+		orderDao.updatePay(order.getOrderId(), STATUS_PAYED);
+		// 发送支付成功异步通知
+		String notifyUrl = appService.getNotifyUrl(order.getAppId(), order.getOrderNum());
+		if(Objects.nonNull(notifyUrl)) {
+			logger.info("订单完成: 异步通知业务地址: {}, 参数: {}", notifyUrl, JsonUtil.toJson(order));
+			String result = HttpUtil.postJson(notifyUrl, JsonUtil.toJson(order));
+			logger.info("订单完成: 业务端返回信息: {}", result);
+			return "success".equals(result);
+		}
+		return true;
 	}
 	
 	/**

+ 1 - 1
src/main/java/com/llisoft/pay/service/WxPayService.java

@@ -158,7 +158,7 @@ public class WxPayService {
 	 * @throws Throwable 
 	 * @createTime 2015年3月31日 下午5:36:27
 	 */
-	public boolean doResult(Map<String, String> resultMap, byte payFlag) throws Exception {
+	public boolean dispose(Map<String, String> resultMap) throws Exception {
 		// 判断通信标识
 		if (!"SUCCESS".equals(resultMap.get("return_code"))) {
 			logger.error("微信支付处理: 通信标识异常: {}", resultMap.get("return_code"));