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