| @@ -0,0 +1,107 @@ | |||||
| package com.simple.controller; | |||||
| import com.simple.enums.EnumPayWay; | |||||
| import com.simple.exception.BizMessageException; | |||||
| import com.simple.exception.MallinkException; | |||||
| import com.simple.pay.WxPayment; | |||||
| import com.simple.service.WxPayOrderService; | |||||
| import com.simple.service.WxRefundOrderService; | |||||
| import com.simple.utils.XmlUtil; | |||||
| import org.apache.commons.io.IOUtils; | |||||
| import org.apache.log4j.Logger; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import java.nio.charset.Charset; | |||||
| import java.util.LinkedHashMap; | |||||
| import java.util.Map; | |||||
| @RestController | |||||
| @RequestMapping("/WxPay/notify") | |||||
| public class WxPayController extends BaseController { | |||||
| private Logger logger = Logger.getLogger(WxPayController.class); | |||||
| @Autowired | |||||
| private WxPayOrderService wxPayOrderService; | |||||
| @Autowired | |||||
| private WxRefundOrderService wxRefundOrderService; | |||||
| /** | |||||
| * | |||||
| * @return 接收微信异步通知 | |||||
| * @throws Exception 可能产生的任何异常 | |||||
| */ | |||||
| @RequestMapping(value = "/pay", method = RequestMethod.POST) | |||||
| public String _payNotify(HttpServletRequest request) throws Exception { | |||||
| Map<String, String> paramMap = null; | |||||
| String response; | |||||
| try { | |||||
| String xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); | |||||
| paramMap = WxPayment.xmlToMap(xml); | |||||
| logger.info("payment wxpay, notify, param: " + paramMap.toString() ); | |||||
| response = wxPayOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||||
| logger.info("payment wxpay, notify success, req : " + paramMap.toString() + ", resp: " + response.toString()); | |||||
| return response; | |||||
| } catch (BizMessageException e) { | |||||
| logger.error("payment wxpay, notify error, req: " + paramMap.toString() + ", e:" + e.getLocalizedMessage()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", e.getMessage()); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } catch (MallinkException e) { | |||||
| logger.error("payment wxpay, notify error, req: " + paramMap.toString() + ", e:" +e.getLocalizedMessage()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", e.getMessage()); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } catch (Exception e) { | |||||
| logger.error("payment wxpay, order create error, req: " + paramMap.toString() + ", e: " + e.getMessage()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", e.getMessage()); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * | |||||
| * @return 接收微信退款异步通知 | |||||
| * @throws Exception 可能产生的任何异常 | |||||
| */ | |||||
| @RequestMapping(value = "/refund", method = RequestMethod.POST) | |||||
| public String __refundNotify(HttpServletRequest request) throws Exception { | |||||
| Map<String, String> paramMap = null; | |||||
| String response; | |||||
| try { | |||||
| String xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); | |||||
| paramMap = WxPayment.xmlToMap(xml); | |||||
| logger.info("refund wxpay, notify, param: " + paramMap.toString() ); | |||||
| response = wxRefundOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||||
| logger.info("refund wxpay, notify success, req : " + paramMap.toString() + ", resp: " + response.toString()); | |||||
| return response; | |||||
| } catch (BizMessageException e) { | |||||
| logger.error("refund wxpay, notify error, req: " + paramMap.toString() + ", e:" + e.getLocalizedMessage()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", e.getMessage()); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } catch (MallinkException e) { | |||||
| logger.error("refund wxpay, notify error, req: " + paramMap.toString() + ", e:" +e.getLocalizedMessage()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", e.getMessage()); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } catch (Exception e) { | |||||
| logger.error("refund wxpay, order create error, req: " + paramMap.toString() + ", e: " + e.getMessage()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", e.getMessage()); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -99,11 +99,16 @@ public enum ErrorCode{ | |||||
| PAY_ORDER_ERROR(12002, "支付订单异常"), | PAY_ORDER_ERROR(12002, "支付订单异常"), | ||||
| PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR(12003 , "支付验签失败"), | PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR(12003 , "支付验签失败"), | ||||
| REFUND_ORDER_EXIST(12004, "退款订单已存在"), | |||||
| REFUND_PAY_ORDER_IS_NOT_EXIST(12005, "退款支付订单不存在"), | |||||
| REFUND_PAY_ORDER_IS_ZERO(12006, "退款支付订单金额为0"), | |||||
| REFUND_ORDER_ERROR(12007, "退款订单异常"), | |||||
| REFUND_ORDER_NOTIFY_CHECK_SIGN_ERROR(12008, "退款验签失败"); | |||||
| REFUND_ORDER_EXIST(12010, "退款订单已存在"), | |||||
| REFUND_PAY_ORDER_IS_NOT_EXIST(12011, "退款支付订单不存在"), | |||||
| REFUND_PAY_ORDER_IS_ZERO(12012, "退款支付订单金额为0"), | |||||
| REFUND_ORDER_ERROR(12013, "退款订单异常"), | |||||
| REFUND_ORDER_NOTIFY_CHECK_SIGN_ERROR(12014, "退款验签失败"), | |||||
| APP_ID_NOT_FOUND(12020, "APPID没找到"), | |||||
| MCH_INFO_NOT_FOUND(12021, "商户信息没找到"), | |||||
| MCH_INFO_NOT_EQUAL(12022, "商户信息不对应"), | |||||
| ; | |||||
| @@ -19,8 +19,6 @@ public interface WxPayOrderService { | |||||
| */ | */ | ||||
| ResultData createPayOrder(WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay); | ResultData createPayOrder(WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay); | ||||
| void handleOrderPaySuccess(WxPayOrder record, String transactionId); | |||||
| /** | /** | ||||
| * 异步通知 | * 异步通知 | ||||
| * @param paramMap 异步通知参数 | * @param paramMap 异步通知参数 | ||||
| @@ -29,6 +27,13 @@ public interface WxPayOrderService { | |||||
| */ | */ | ||||
| String notify(Map<String, String> paramMap, EnumPayWay payWay); | String notify(Map<String, String> paramMap, EnumPayWay payWay); | ||||
| /** | |||||
| * 支付成功处理 | |||||
| * @param record | |||||
| * @param transactionId | |||||
| */ | |||||
| void handleOrderPaySuccess(WxPayOrder record, String transactionId); | |||||
| /** | /** | ||||
| * 页面回调 | * 页面回调 | ||||
| * @param paramMap 页面通知参数 | * @param paramMap 页面通知参数 | ||||
| @@ -4,7 +4,6 @@ import java.util.*; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.WxAppinfo; | import com.simple.domain.po.WxAppinfo; | ||||
| import com.simple.domain.po.WxCUser; | |||||
| import com.simple.domain.po.WxRefundOrder; | import com.simple.domain.po.WxRefundOrder; | ||||
| import com.simple.enums.EnumPayWay; | import com.simple.enums.EnumPayWay; | ||||
| @@ -26,6 +25,29 @@ public interface WxRefundOrderService { | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| ResultData queryRefundOrder(WxAppinfo appInfo, WxRefundOrder record); | ResultData queryRefundOrder(WxAppinfo appInfo, WxRefundOrder record); | ||||
| /** | |||||
| * 异步通知 | |||||
| * @param paramMap 异步通知参数 | |||||
| * @param payWay 支付方式 | |||||
| * @return | |||||
| */ | |||||
| String notify(Map<String, String> paramMap, EnumPayWay payWay); | |||||
| /** | |||||
| * 处理退款成功 | |||||
| * @param record | |||||
| * @param transactionId | |||||
| * @param refundId | |||||
| */ | |||||
| void handleRefundSuccess(WxRefundOrder record, String transactionId, String refundId); | |||||
| /** | |||||
| * 页面回调 | |||||
| * @param paramMap 页面通知参数 | |||||
| * @param payWay 支付方式 | |||||
| * @return | |||||
| */ | |||||
| void callback(Map<String, String> paramMap, EnumPayWay payWay); | |||||
| /** | /** | ||||
| * 根据实体查询分页列表 | * 根据实体查询分页列表 | ||||
| * | * | ||||
| @@ -1,9 +1,7 @@ | |||||
| package com.simple.service.impl; | package com.simple.service.impl; | ||||
| import java.math.BigDecimal; | |||||
| import java.util.*; | import java.util.*; | ||||
| import cn.binarywang.wx.miniapp.api.WxMaService; | |||||
| import com.alibaba.fastjson.JSON; | import com.alibaba.fastjson.JSON; | ||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| @@ -15,6 +13,7 @@ import com.simple.enums.EnumOrderStatus; | |||||
| import com.simple.enums.EnumPayStatus; | import com.simple.enums.EnumPayStatus; | ||||
| import com.simple.enums.EnumPayWay; | import com.simple.enums.EnumPayWay; | ||||
| import com.simple.exception.MallinkException; | import com.simple.exception.MallinkException; | ||||
| import com.simple.mapper.WxAppinfoMapper; | |||||
| import com.simple.mapper.WxOrderMapper; | import com.simple.mapper.WxOrderMapper; | ||||
| import com.simple.mapper.WxPayAccountMapper; | import com.simple.mapper.WxPayAccountMapper; | ||||
| import com.simple.mapper.WxPayOrderMapper; | import com.simple.mapper.WxPayOrderMapper; | ||||
| @@ -39,6 +38,9 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| private Logger logger = Logger.getLogger(getClass()); | private Logger logger = Logger.getLogger(getClass()); | ||||
| @Autowired | |||||
| WxAppinfoMapper wxAppinfoMapper; | |||||
| @Autowired | @Autowired | ||||
| WxPayAccountMapper wxPayAccountMapper; | WxPayAccountMapper wxPayAccountMapper; | ||||
| @@ -163,12 +165,26 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| // 微信订单查询 | // 微信订单查询 | ||||
| // 微信关闭订单 | // 微信关闭订单 | ||||
| /** | |||||
| * 提供微信支付回调调用 | |||||
| * @param paramMap 异步通知参数 | |||||
| * @param payWay 支付方式 | |||||
| * @return | |||||
| */ | |||||
| @Override | @Override | ||||
| public String notify(Map<String, String> paramMap, EnumPayWay payWay) { | public String notify(Map<String, String> paramMap, EnumPayWay payWay) { | ||||
| // how to get wechatAppId, wechatMchId, partnerKey | // how to get wechatAppId, wechatMchId, partnerKey | ||||
| String wechatAppId = paramMap.get("appId"); | |||||
| String wechatAppId = paramMap.get("appid"); | |||||
| String wechatMchId = paramMap.get("mch_id"); | String wechatMchId = paramMap.get("mch_id"); | ||||
| String partnerKey = ""; | |||||
| WxAppinfo appinfo = wxAppinfoMapper.findByAppId(wechatAppId); | |||||
| if (appinfo == null) { | |||||
| throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||||
| } | |||||
| WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appinfo.getPayId()); | |||||
| if (payAccount == null) { | |||||
| throw new MallinkException(ErrorCode.MCH_INFO_NOT_FOUND); | |||||
| } | |||||
| String partnerKey = payAccount.getApiKey(); | |||||
| try { | try { | ||||
| if (payWay == EnumPayWay.PAY_WAY_WEAPP) { | if (payWay == EnumPayWay.PAY_WAY_WEAPP) { | ||||
| boolean signVerified = false; | boolean signVerified = false; | ||||
| @@ -187,28 +203,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| resultMap.put("return_msg", "订单状态码非SUCCESS"); | resultMap.put("return_msg", "订单状态码非SUCCESS"); | ||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | return XmlUtil.parseDto2Xml(resultMap, ""); | ||||
| } | } | ||||
| if (!wechatAppId.equals(paramMap.get("appid"))) { | |||||
| logger.warn("notify order, wxpay appid is invalid, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", "非法请求appid"); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } | |||||
| if (!(wechatMchId.equals(paramMap.get("mch_id")))) { | |||||
| logger.warn("notify order, wxpay mch_id is invalid, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", "非法请求mch_id"); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } | |||||
| if (!"SUCCESS".equals(paramMap.get("result_code"))) { | |||||
| logger.warn("notify order, wxpay result_code is invalid, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", "result_code fail"); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } | |||||
| String payOrderNo = paramMap.get("out_trade_no"); | String payOrderNo = paramMap.get("out_trade_no"); | ||||
| Long payOrderId = Long.valueOf(payOrderNo); | Long payOrderId = Long.valueOf(payOrderNo); | ||||
| WxPayOrder payOrder = wxPayOrderMapper.selectByPrimaryKey(payOrderId); | WxPayOrder payOrder = wxPayOrderMapper.selectByPrimaryKey(payOrderId); | ||||
| @@ -264,18 +259,29 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | ||||
| } | } | ||||
| Date currentDate = new Date(); | |||||
| // 修改支付订单状态 | |||||
| try { | |||||
| WxPayOrder updatePayOrder = new WxPayOrder(); | |||||
| updatePayOrder.setId(record.getId()); | |||||
| updatePayOrder.setOrderId(record.getOrderId()); | |||||
| updatePayOrder.setUpdateTime(currentDate); | |||||
| updatePayOrder.setPayOrderStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); | |||||
| updatePayOrder.setTransactionId(transactionId); | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(updatePayOrder); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| // 修改订单状态 | // 修改订单状态 | ||||
| wxOrderService.updateOrderStatus(order.getId(), EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS); | |||||
| try { | |||||
| wxOrderService.updateOrderStatus(order.getId(), EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| // 修改支付订单状态 | |||||
| Date currentDate = new Date(); | |||||
| WxPayOrder updatePayOrder = new WxPayOrder(); | |||||
| updatePayOrder.setId(record.getId()); | |||||
| updatePayOrder.setOrderId(record.getOrderId()); | |||||
| updatePayOrder.setUpdateTime(currentDate); | |||||
| updatePayOrder.setPayOrderStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); | |||||
| updatePayOrder.setTransactionId(transactionId); | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(updatePayOrder); | |||||
| /* | /* | ||||
| Map<String, String> msgMap = new HashMap<>(); | Map<String, String> msgMap = new HashMap<>(); | ||||
| try { | try { | ||||
| @@ -9,31 +9,39 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.simple.common.ErrorCode; | import com.simple.common.ErrorCode; | ||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.*; | import com.simple.domain.po.*; | ||||
| import com.simple.enums.EnumOrderStatus; | |||||
| import com.simple.enums.EnumPayStatus; | import com.simple.enums.EnumPayStatus; | ||||
| import com.simple.enums.EnumPayWay; | import com.simple.enums.EnumPayWay; | ||||
| import com.simple.enums.EnumRefundStatus; | import com.simple.enums.EnumRefundStatus; | ||||
| import com.simple.exception.MallinkException; | import com.simple.exception.MallinkException; | ||||
| import com.simple.mapper.WxPayAccountMapper; | |||||
| import com.simple.mapper.WxPayOrderMapper; | |||||
| import com.simple.mapper.WxRefundOrderMapper; | |||||
| import com.simple.mapper.*; | |||||
| import com.simple.pay.WxPay; | import com.simple.pay.WxPay; | ||||
| import com.simple.pay.WxPayment; | import com.simple.pay.WxPayment; | ||||
| import com.simple.pay.WxRefundOrderP; | import com.simple.pay.WxRefundOrderP; | ||||
| import com.simple.service.WxRefundOrderService; | import com.simple.service.WxRefundOrderService; | ||||
| import com.simple.utils.BeanUtils; | import com.simple.utils.BeanUtils; | ||||
| import com.simple.utils.Utility; | import com.simple.utils.Utility; | ||||
| import com.simple.utils.XmlUtil; | |||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import com.simple.common.IdWorker; | import com.simple.common.IdWorker; | ||||
| import org.springframework.transaction.annotation.Propagation; | |||||
| import org.springframework.transaction.annotation.Transactional; | |||||
| @Service | @Service | ||||
| public class WxRefundOrderServiceImpl implements WxRefundOrderService { | public class WxRefundOrderServiceImpl implements WxRefundOrderService { | ||||
| private Logger logger = Logger.getLogger(getClass()); | private Logger logger = Logger.getLogger(getClass()); | ||||
| @Autowired | |||||
| WxAppinfoMapper wxAppinfoMapper; | |||||
| @Autowired | @Autowired | ||||
| WxRefundOrderMapper wxRefundOrderMapper; | WxRefundOrderMapper wxRefundOrderMapper; | ||||
| @Autowired | |||||
| WxOrderMapper wxOrderMapper; | |||||
| @Autowired | @Autowired | ||||
| WxPayOrderMapper wxPayOrderMapper; | WxPayOrderMapper wxPayOrderMapper; | ||||
| @@ -306,7 +314,169 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR.getCode(), errObj.toJSONString(), returnMap); | return new ResultData(ErrorCode.REFUND_ORDER_ERROR.getCode(), errObj.toJSONString(), returnMap); | ||||
| } | } | ||||
| } | } | ||||
| // 微信退款结果通知 | |||||
| /** | |||||
| * 微信退款结果通知 | |||||
| * @param paramMap 异步通知参数 | |||||
| * @param payWay 支付方式 | |||||
| * @return | |||||
| */ | |||||
| @Override | |||||
| public String notify(Map<String, String> paramMap, EnumPayWay payWay) { | |||||
| // how to get wechatAppId, wechatMchId, partnerKey | |||||
| String wechatAppId = paramMap.get("appid"); | |||||
| String wechatMchId = paramMap.get("mch_id"); | |||||
| WxAppinfo appinfo = wxAppinfoMapper.findByAppId(wechatAppId); | |||||
| if (appinfo == null) { | |||||
| logger.error("未找到appid信息:"+wechatAppId); | |||||
| throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||||
| } | |||||
| WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appinfo.getPayId()); | |||||
| if (payAccount == null) { | |||||
| logger.error("未找到mch_id信息:"+wechatMchId); | |||||
| throw new MallinkException(ErrorCode.MCH_INFO_NOT_FOUND); | |||||
| } | |||||
| if (wechatMchId != payAccount.getMchId()) { | |||||
| logger.error("mch_id不对应:"+wechatMchId + ",account:" + payAccount.getMchId()); | |||||
| throw new MallinkException(ErrorCode.MCH_INFO_NOT_EQUAL); | |||||
| } | |||||
| String partnerKey = payAccount.getApiKey(); | |||||
| try { | |||||
| if (payWay == EnumPayWay.PAY_WAY_WEAPP) { | |||||
| boolean signVerified = false; | |||||
| // 微信支付 | |||||
| signVerified = WxPayment.verifyNotify(paramMap, partnerKey); | |||||
| if (!signVerified) { | |||||
| logger.warn("notify order, wxpay checksign error, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); | |||||
| throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||||
| } | |||||
| if (!"SUCCESS".equals(paramMap.get("return_code"))) { | |||||
| logger.warn("notify order, wxpay status not success, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", "订单状态码非SUCCESS"); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } | |||||
| String payOrderNo = paramMap.get("out_trade_no"); | |||||
| Long payOrderId = Long.valueOf(payOrderNo); | |||||
| WxPayOrder payOrder = wxPayOrderMapper.selectByPrimaryKey(payOrderId); | |||||
| if (payOrder == null) { | |||||
| logger.warn("notify order, wxpay check pay order not exists, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", "订单不存在"); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } | |||||
| // 验证支付金额 | |||||
| if(!paramMap.get("total_fee").equals(payOrder.getPayAmount().toString())) { | |||||
| logger.warn("notify order, wxpay check total_fee is invalid, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", "订单总金额不一致"); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } | |||||
| String refundOrderNo = paramMap.get("out_refund_no"); | |||||
| Long refundOrderId = Long.valueOf(refundOrderNo); | |||||
| WxRefundOrder refundOrder = wxRefundOrderMapper.selectByPrimaryKey(refundOrderId); | |||||
| if (refundOrder == null) { | |||||
| logger.warn("notify order, wxpay check pay order not exists, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", "退款订单不存在"); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } | |||||
| // 验证支付金额 | |||||
| if(!paramMap.get("total_fee").equals(refundOrder.getTotalFee().toString())) { | |||||
| logger.warn("notify order, wxpay check total_fee is invalid, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", "订单总金额不一致"); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } | |||||
| // 验证退款金额 | |||||
| if(!paramMap.get("refund_fee").equals(refundOrder.getRefundFee().toString())) { | |||||
| logger.warn("notify order, wxpay check refund_fee is invalid, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "FAIL"); | |||||
| resultMap.put("return_msg", "退款总金额不一致"); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } | |||||
| // 处理支付成功 | |||||
| handleRefundSuccess(refundOrder, paramMap.get("transaction_id"), paramMap.get("refund_id")); | |||||
| logger.info("notify order, wxpay checksign success, paramMap:{}, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString()); | |||||
| Map<String, String> resultMap = new LinkedHashMap<>(); | |||||
| resultMap.put("return_code", "SUCCESS"); | |||||
| resultMap.put("return_msg", "OK"); | |||||
| return XmlUtil.parseDto2Xml(resultMap, ""); | |||||
| } | |||||
| } catch (RuntimeException e) { | |||||
| logger.warn("notify order, alipay checksign error, paramMap: "+paramMap.toString()+ ", payWay:" + payWay.toString() + ", e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); | |||||
| } | |||||
| return ""; | |||||
| } | |||||
| @Override | |||||
| public void callback(Map<String, String> paramMap, EnumPayWay payWay) { | |||||
| } | |||||
| @Override | |||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
| public void handleRefundSuccess(WxRefundOrder refundOrder, String transactionId, String refundId) { | |||||
| EnumRefundStatus refundStatus = EnumRefundStatus.getEnum(refundOrder.getRefundOrderStatus()); | |||||
| // 判断退款状态 | |||||
| if (refundStatus != EnumRefundStatus.REFUND_REQ_SUCCESS) { | |||||
| logger.error("refund success handle, refundOrder " + refundOrder.getRefundId() + | |||||
| "is paid success , orderId : " + refundOrder.getOrderId()); | |||||
| return; | |||||
| } | |||||
| /* | |||||
| WxOrder order = wxRefundOrderMapper.selectByPrimaryKey(record.getOrderId()); | |||||
| if (order == null) { | |||||
| logger.error("pay success handle, order " + record.getOrderId() +" not found , payOrderGid : " + record.getPayOrderNo()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | |||||
| } | |||||
| Date currentDate = new Date(); | |||||
| // 修改支付订单状态 | |||||
| try { | |||||
| WxPayOrder updatePayOrder = new WxPayOrder(); | |||||
| updatePayOrder.setId(record.getId()); | |||||
| updatePayOrder.setOrderId(record.getOrderId()); | |||||
| updatePayOrder.setUpdateTime(currentDate); | |||||
| updatePayOrder.setPayOrderStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); | |||||
| updatePayOrder.setTransactionId(transactionId); | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(updatePayOrder); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| // 修改订单状态 | |||||
| try { | |||||
| wxOrderService.updateOrderStatus(order.getId(), EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| */ | |||||
| /* | |||||
| Map<String, String> msgMap = new HashMap<>(); | |||||
| try { | |||||
| msgMap.put("name", String.valueOf(order.getCouponId())); | |||||
| msgMap.put("orderNo", String.valueOf(order.getId())); | |||||
| msgMap.put("createTime", Utility.getDataFormatString3(order.getCreateDate())); | |||||
| msgMap.put("standingTime", order.getCreateDate() + "-" + currentDate ); | |||||
| // 短信 通知 商户 | |||||
| //smsSenderHandler.sendSms("SMS_18195394", order.getMobile(), msgMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("pay success handle, sms send exception, payOrderi: " + updatePayOrder+ ", msgMap: " + msgMap.toString() + ", e: " + e.getMessage()); | |||||
| } | |||||
| */ | |||||
| } | |||||
| @Override | @Override | ||||