| 
					
				 | 
			
			
				@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.exception.BusinessException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.service.doorCoach.PatientDoorCoachOrderService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.service.pay.PayService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.util.WxpayUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.util.XMLUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.order.BusinessOrderDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.order.BusinessOrderRefundDO; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -22,6 +23,7 @@ import io.swagger.annotations.ApiParam; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.web.bind.annotation.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -43,6 +45,8 @@ public class PayEndpoint extends EnvelopRestEndpoint { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private Logger log = LoggerFactory.getLogger(PatientDoorCoachOrderService.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${wechat.apiKey}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String apiKey; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PayService payService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -271,22 +275,31 @@ public class PayEndpoint extends EnvelopRestEndpoint { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 支付校验 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String returnCode = params.get("return_code"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (!"SUCCESS".equalsIgnoreCase(returnCode)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                log.info("【微信支付退款】订单失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                log.info("【微信支付退款1】订单失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return XMLUtil.setXML("FAIL", "退款失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String req_info = params.get("req_info"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //解密 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String desReqInfo = WxpayUtil.getRefundDecrypt(req_info,apiKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String, String> desParams = XMLUtil.doXMLParse(desReqInfo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(!"SUCCESS".equals(desParams.get("refund_status"))){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                log.info("【微信支付退款2】订单失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return XMLUtil.setXML("FAIL", "退款失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String outTradeNo = params.get("out_trade_no"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String outTradeNo = desParams.get("out_trade_no"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String payWaterId = outTradeNo.split("_")[0]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            payService.addHttpLog("2",payWaterId,paramsJson,null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            payService.addHttpLog("2",payWaterId,desReqInfo,null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            BusinessOrderRefundDO orderDO = orderRefundDao.selectByOrderNo(payWaterId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (orderDO == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                log.error("退款订单不存在"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return XMLUtil.setXML("SUCCESS", "OK"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            orderDO.setOutRefundNo(params.get("refund_id")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            orderDO.setOutRefundNo(desParams.get("refund_id")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            orderDO.setResponseParam(paramsJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String totalFee = params.get("refund_fee"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String totalFee = desParams.get("refund_fee"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            BigDecimal payTotalFee = new BigDecimal(totalFee); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            log.info("【微信支付退款】支付金额:{}", payTotalFee); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (new BigDecimal(orderDO.getRefundPrice()*100).compareTo(payTotalFee) != 0) { 
			 |