diff --git a/mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayController.java b/mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayController.java index ba679d8ed..075aafbce 100644 --- a/mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayController.java +++ b/mallinkCallback/src/main/java/com/iformall/controller/callback/WxPayController.java @@ -180,7 +180,7 @@ public class WxPayController extends BaseController { xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); paramMap = WxPayment.xmlToMap(xml); logger.info("share wxpay, notify, param: " + xml ); - response = wxPayOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WECHAT); + response = wxPayOrderService.shareNotify(paramMap, EnumPayWay.PAY_WAY_WECHAT); logger.info("share wxpay, notify success, req : " + xml + ", resp: " + response.toString()); return response; } catch (BizMessageException e) { diff --git a/mallinkMQConsumer/src/main/java/com/iformall/mq/MqBaseConsumer.java b/mallinkMQConsumer/src/main/java/com/iformall/mq/MqBaseConsumer.java index 390debf64..fde9eb603 100644 --- a/mallinkMQConsumer/src/main/java/com/iformall/mq/MqBaseConsumer.java +++ b/mallinkMQConsumer/src/main/java/com/iformall/mq/MqBaseConsumer.java @@ -37,8 +37,8 @@ public class MqBaseConsumer { @Autowired private MqBaseProducer mqBaseProducer; - @Autowired - private FmInsideNotifyPaySuccessMsgServiceImpl fmInsideNotifyPaySuccessMsgService; + //@Autowired + //private FmInsideNotifyPaySuccessMsgServiceImpl fmInsideNotifyPaySuccessMsgService; @Autowired private FmInsideNotifyRefundSuccessMsgServiceImpl fmInsideNotifyRefundSuccessMsgService; @Autowired @@ -89,11 +89,13 @@ public class MqBaseConsumer { // 内部消息 - c端登录 FmInsideCLoginMsg msg = (FmInsideCLoginMsg)JsonUtil.readValue(message,FmInsideCLoginMsg.class); fmInsideCouponVerifyMsgService.send(msg); - } else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(baseMsg.getMsgType())) { + } + //else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(baseMsg.getMsgType())) { // 内部消息 - 微信支付通知 - FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)JsonUtil.readValue(message,FmInsideNotifyPaySuccessMsg.class); - fmInsideNotifyPaySuccessMsgService.send(msg); - } else if(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode().equals(baseMsg.getMsgType())) { + //FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)JsonUtil.readValue(message,FmInsideNotifyPaySuccessMsg.class); + //fmInsideNotifyPaySuccessMsgService.send(msg); + //} + else if(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode().equals(baseMsg.getMsgType())) { // 内部消息 - 微信退款通知 FmInsideNotifyRefundSuccessMsg msg = (FmInsideNotifyRefundSuccessMsg)JsonUtil.readValue(message,FmInsideNotifyRefundSuccessMsg.class); fmInsideNotifyRefundSuccessMsgService.send(msg); diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/MsgReSendSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/MsgReSendSchedule.java index 776e8d00f..7701fc425 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/MsgReSendSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/MsgReSendSchedule.java @@ -25,56 +25,56 @@ public class MsgReSendSchedule { @Autowired private MqBaseProducer mqBaseProducer; - @Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次 + //@Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次 //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 public void msgReSend() { - logger.info("消息重发开始..."); - //消息重发 - WxMsgRecord msgRecord = new WxMsgRecord(); - msgRecord.setMsgStatus(EnumMsgRecordStatus.SEND_FAIL.getCode()); - List recordList = wxMsgRecordService.findList(msgRecord); - for (WxMsgRecord wxMsgRecord:recordList) { - logger.info("消息重发:{}",wxMsgRecord.getMsgJson()); - TenantEntity tenantEntity = wxMsgRecord.getTenantInfo(); - try { - if(EnumMsgRecordType.INSIDE_ORDER_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){ - //内部消息 - 下订单成功 - FmInsideOrderSuccessMsg msg = (FmInsideOrderSuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideOrderSuccessMsg.class); - msg.setMsgType(wxMsgRecord.getMsgType()); - msg.setReceiver(wxMsgRecord.getReceiver()); - msg.updateTenantInfo(tenantEntity); - mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); - }else if(EnumMsgRecordType.INSIDE_COUPON_VERIFY.getCode().equals(wxMsgRecord.getMsgType())){ - FmInsideCouponVerifyMsg msg = (FmInsideCouponVerifyMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideCouponVerifyMsg.class); - msg.setMsgType(wxMsgRecord.getMsgType()); - msg.setReceiver(wxMsgRecord.getReceiver()); - msg.updateTenantInfo(tenantEntity); - mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); - }else if(EnumMsgRecordType.INSIDE_C_LOGIN.getCode().equals(wxMsgRecord.getMsgType())){ - FmInsideCLoginMsg msg = (FmInsideCLoginMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideCLoginMsg.class); - msg.setMsgType(wxMsgRecord.getMsgType()); - msg.setReceiver(wxMsgRecord.getReceiver()); - msg.updateTenantInfo(tenantEntity); - mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); - }else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){ - FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideNotifyPaySuccessMsg.class); - msg.setMsgType(wxMsgRecord.getMsgType()); - msg.setReceiver(wxMsgRecord.getReceiver()); - msg.updateTenantInfo(tenantEntity); - mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); - }else if(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){ - FmInsideNotifyRefundSuccessMsg msg = (FmInsideNotifyRefundSuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideNotifyRefundSuccessMsg.class); - msg.setMsgType(wxMsgRecord.getMsgType()); - msg.setReceiver(wxMsgRecord.getReceiver()); - msg.updateTenantInfo(tenantEntity); - mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); - } - } catch (Exception e) { - e.printStackTrace(); - logger.error("消息重发错误:" + e.getMessage()); - } - } - logger.info("消息重发结束..."); +// logger.info("消息重发开始..."); +// //消息重发 +// WxMsgRecord msgRecord = new WxMsgRecord(); +// msgRecord.setMsgStatus(EnumMsgRecordStatus.SEND_FAIL.getCode()); +// List recordList = wxMsgRecordService.findList(msgRecord); +// for (WxMsgRecord wxMsgRecord:recordList) { +// logger.info("消息重发:{}",wxMsgRecord.getMsgJson()); +// TenantEntity tenantEntity = wxMsgRecord.getTenantInfo(); +// try { +// if(EnumMsgRecordType.INSIDE_ORDER_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){ +// //内部消息 - 下订单成功 +// FmInsideOrderSuccessMsg msg = (FmInsideOrderSuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideOrderSuccessMsg.class); +// msg.setMsgType(wxMsgRecord.getMsgType()); +// msg.setReceiver(wxMsgRecord.getReceiver()); +// msg.updateTenantInfo(tenantEntity); +// mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); +// }else if(EnumMsgRecordType.INSIDE_COUPON_VERIFY.getCode().equals(wxMsgRecord.getMsgType())){ +// FmInsideCouponVerifyMsg msg = (FmInsideCouponVerifyMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideCouponVerifyMsg.class); +// msg.setMsgType(wxMsgRecord.getMsgType()); +// msg.setReceiver(wxMsgRecord.getReceiver()); +// msg.updateTenantInfo(tenantEntity); +// mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); +// }else if(EnumMsgRecordType.INSIDE_C_LOGIN.getCode().equals(wxMsgRecord.getMsgType())){ +// FmInsideCLoginMsg msg = (FmInsideCLoginMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideCLoginMsg.class); +// msg.setMsgType(wxMsgRecord.getMsgType()); +// msg.setReceiver(wxMsgRecord.getReceiver()); +// msg.updateTenantInfo(tenantEntity); +// mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); +// }else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){ +// FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideNotifyPaySuccessMsg.class); +// msg.setMsgType(wxMsgRecord.getMsgType()); +// msg.setReceiver(wxMsgRecord.getReceiver()); +// msg.updateTenantInfo(tenantEntity); +// mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); +// }else if(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode().equals(wxMsgRecord.getMsgType())){ +// FmInsideNotifyRefundSuccessMsg msg = (FmInsideNotifyRefundSuccessMsg) JsonUtil.readValue(wxMsgRecord.getMsgJson(),FmInsideNotifyRefundSuccessMsg.class); +// msg.setMsgType(wxMsgRecord.getMsgType()); +// msg.setReceiver(wxMsgRecord.getReceiver()); +// msg.updateTenantInfo(tenantEntity); +// mqBaseProducer.sendMessage(msg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); +// } +// } catch (Exception e) { +// e.printStackTrace(); +// logger.error("消息重发错误:" + e.getMessage()); +// } +// } +// logger.info("消息重发结束..."); } diff --git a/mallinkSchedule/src/main/java/com/iformall/schedule/OrderExpiringSchedule.java b/mallinkSchedule/src/main/java/com/iformall/schedule/OrderExpiringSchedule.java index 5af6020dd..74f5f8051 100644 --- a/mallinkSchedule/src/main/java/com/iformall/schedule/OrderExpiringSchedule.java +++ b/mallinkSchedule/src/main/java/com/iformall/schedule/OrderExpiringSchedule.java @@ -30,7 +30,7 @@ import com.iformall.service.WxPayOrderService; import com.iformall.service.WxRefundOrderService; import com.iformall.service.helper.WxPayOrderServiceHelper; import com.iformall.service.pay.PayServiceFactory; -import com.iformall.service.pay.entity.PayQueryAdapterResult; +import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; import com.iformall.utils.DateUtils; @Component diff --git a/mallinkService/src/main/java/com/iformall/enums/EnumMsgRecordType.java b/mallinkService/src/main/java/com/iformall/enums/EnumMsgRecordType.java index 95b4583da..3db9a9338 100644 --- a/mallinkService/src/main/java/com/iformall/enums/EnumMsgRecordType.java +++ b/mallinkService/src/main/java/com/iformall/enums/EnumMsgRecordType.java @@ -15,7 +15,7 @@ public enum EnumMsgRecordType { INSIDE_ORDER_SUCCESS(100, "下订单成功"), INSIDE_COUPON_VERIFY(101, "券核销"), INSIDE_C_LOGIN(102, "C端用户登录"), - INSIDE_NOTIFY_PAY_SUCCESS(103, "微信支付回调"), + //INSIDE_NOTIFY_PAY_SUCCESS(103, "微信支付回调"), INSIDE_NOTIFY_REFUND_SUCCESS(104, "微信退款回调"), COUPON_STOCK(105, "券库存更新"), ; diff --git a/mallinkService/src/main/java/com/iformall/service/WxPayOrderService.java b/mallinkService/src/main/java/com/iformall/service/WxPayOrderService.java index 389b08e7e..52a285df0 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxPayOrderService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxPayOrderService.java @@ -14,9 +14,9 @@ import com.iformall.domain.po.WxPayAccount; import com.iformall.domain.po.WxPayOrder; import com.iformall.enums.EnumPayShare; import com.iformall.enums.EnumPayWay; -import com.iformall.service.pay.entity.PayAdapterResult; import com.iformall.service.pay.entity.PayExtraParam; -import com.iformall.service.pay.entity.PayQueryAdapterResult; +import com.iformall.service.pay.service.pay.entity.PayAdapterResult; +import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; public interface WxPayOrderService { @@ -68,7 +68,7 @@ public interface WxPayOrderService { * @param payWay 支付方式 * @return */ - String notify(Map paramMap, EnumPayWay payWay); + String shareNotify(Map paramMap, EnumPayWay payWay); /** * 支付成功处理 diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java index 07da5ffaf..5ba207a74 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java @@ -19,13 +19,14 @@ import com.iformall.pay.*; import com.iformall.service.*; import com.iformall.service.helper.WxPayOrderServiceHelper; import com.iformall.service.pay.PayServiceFactory; -import com.iformall.service.pay.entity.CreateCUser; -import com.iformall.service.pay.entity.PayAdapterResult; import com.iformall.service.pay.entity.PayExtraParam; -import com.iformall.service.pay.entity.PayQueryAdapterResult; import com.iformall.service.pay.service.pay.CDrivingPayService; import com.iformall.service.pay.service.pay.CPassivePayService; import com.iformall.service.pay.service.pay.PayAdapterService; +import com.iformall.service.pay.service.pay.entity.CreateCUser; +import com.iformall.service.pay.service.pay.entity.PayAdapterResult; +import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; +import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; import com.iformall.utils.*; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; @@ -877,119 +878,23 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { /** - * 提供微信支付回调调用 + * 提供微信支付回调调用 --- 分账通知 * * @param paramMap 异步通知参数 * @param payWay 支付方式 * @return */ @Override - public String notify(Map paramMap, EnumPayWay payWay) { - // how to get wechatAppId, wechatMchId, partnerKey - String appId = paramMap.get("appid"); - String subAppId = paramMap.get("sub_appid"); - String mchId = paramMap.get("mch_id"); - String subMchId = paramMap.get("sub_mch_id"); - WxAppinfo appinfo = null; - boolean isNormal = true; - if (StringUtils.isBlank(subAppId) && StringUtils.isBlank(subMchId)) { - // 普通商户号 - appinfo = wxAppinfoMapper.findByAppId(appId); - if (appinfo == null) { - logger.error("appid not found: " + appId); - throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); - } - isNormal = true; - } else { - // 服务号 现在用hmac-sha256 - appinfo = wxAppinfoMapper.findByAppId(subAppId); - if (appinfo == null) { - logger.error("subappid not found: " + subAppId); - throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); - } - isNormal = false; - } - - WxPayAccount payAccount = wxPayAccountMapper.selectById(appinfo.getPayId()); - if (payAccount == null) { - throw new MallinkException(ErrorCode.MCH_INFO_NOT_FOUND); - } - String partnerKey = payAccount.getApiKey(); - try { - if (payWay == EnumPayWay.PAY_WAY_WECHAT) { - boolean signVerified = false; - if (isNormal) { - // 普通商户号支付 - 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); - } - } else { - // 服务号 现在用hmac-sha256 - signVerified = WxPayment.verifyNotifyHMAC(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()); - SortedMap resultMap = new TreeMap(); - resultMap.put("return_code", "FAIL"); - resultMap.put("return_msg", "订单状态码非SUCCESS"); - return XmlUtil.getRequestXml(resultMap); - } - - String payOrderNo = paramMap.get("out_trade_no"); - String timEndStr = paramMap.get("time_end"); - Long payOrderId = Long.valueOf(payOrderNo); - WxPayOrder payOrder = wxPayOrderMapper.selectById(payOrderId); - if (payOrder == null) { - logger.warn("notify order, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); - SortedMap resultMap = new TreeMap(); - resultMap.put("return_code", "FAIL"); - resultMap.put("return_msg", "订单不存在"); - return XmlUtil.getRequestXml(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()); - SortedMap resultMap = new TreeMap(); - resultMap.put("return_code", "FAIL"); - resultMap.put("return_msg", "订单总金额不一致"); - return XmlUtil.getRequestXml(resultMap); - } - - Date timeEnd = null; - - try { - timeEnd = Utility.getDateFromString(timEndStr); - } catch (ParseException e) { - logger.error("解析timeEnd失败"); - timeEnd = new Date(); - } - payOrder.setPayTimeEnd(timeEnd); - payOrder.setPayEndFrom(EnumPayEndFrom.CALLBACK.getCode()); - - // 处理支付成功 - handleOrderPaySuccess(payOrder, paramMap.get("transaction_id")); - logger.info("notify order, wxpay checksign success, paramMap:{}, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); - SortedMap resultMap = new TreeMap(); - resultMap.put("return_code", "SUCCESS"); - resultMap.put("return_msg", "OK"); - return XmlUtil.getRequestXml(resultMap); - } - } catch (RuntimeException e) { - logger.warn("notify order, checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString() + ", e:" + e.getMessage()); - throw new MallinkException(ErrorCode.PAY_ORDER_ERROR); - } - - SortedMap resultMap = new TreeMap(); - resultMap.put("return_code", "FAIL"); - resultMap.put("return_msg", "FAILED"); - return XmlUtil.getRequestXml(resultMap); + public String shareNotify(Map paramMap, EnumPayWay payWay) { + ShareNotifyAdapterResult shareResult = payServiceFactory.getPayShareAdapterService(payWay.getCode()).notify(paramMap,payWay); + if (shareResult.isSuccess()) { + // 处理支付成功 + shareResult.getPayOrder().setPayEndFrom(EnumPayEndFrom.CALLBACK.getCode()); + handleOrderPaySuccess(shareResult.getPayOrder(), shareResult.getTranscationId()); + return shareResult.getReturnJson(); + }else { + return shareResult.getReturnJson(); + } } @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java index e2db1f825..45cf4890d 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxProfitSharingOrderServiceImpl.java @@ -21,7 +21,7 @@ import com.iformall.mapper.*; import com.iformall.pay.*; import com.iformall.service.WxProfitSharingOrderService; import com.iformall.service.pay.PayServiceFactory; -import com.iformall.service.pay.entity.PayShareResult; +import com.iformall.service.pay.service.share.entity.PayShareResult; import com.iformall.utils.BeanUtils; import com.iformall.utils.DateUtils; import com.iformall.utils.Utility; diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxRefundOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxRefundOrderServiceImpl.java index 13575e4f8..ba869e12b 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxRefundOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxRefundOrderServiceImpl.java @@ -21,8 +21,8 @@ import com.iformall.service.WxOrderService; import com.iformall.service.WxRefundOrderService; import com.iformall.service.helper.WxPayOrderServiceHelper; import com.iformall.service.pay.PayServiceFactory; -import com.iformall.service.pay.entity.RefundAdapterResult; -import com.iformall.service.pay.entity.RefundNotifyAdapterResult; +import com.iformall.service.pay.service.refund.entity.RefundAdapterResult; +import com.iformall.service.pay.service.refund.entity.RefundNotifyAdapterResult; import com.iformall.utils.BeanUtils; import com.iformall.utils.CipherUtil; import com.iformall.utils.Utility; diff --git a/mallinkService/src/main/java/com/iformall/service/msg/impl/FmInsideNotifyPaySuccessMsgServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/msg/impl/FmInsideNotifyPaySuccessMsgServiceImpl.java index 77f73e33b..d68dbd5a6 100644 --- a/mallinkService/src/main/java/com/iformall/service/msg/impl/FmInsideNotifyPaySuccessMsgServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/msg/impl/FmInsideNotifyPaySuccessMsgServiceImpl.java @@ -18,17 +18,17 @@ import java.util.Map; * @author Stormeye Wu * @date 2019/5/10 */ -@Service -public class FmInsideNotifyPaySuccessMsgServiceImpl implements MsgSendService { - private final Logger logger = LoggerFactory.getLogger(this.getClass()); - - @Autowired - private WxPayOrderService wxPayOrderService; - - @Override - public void send(BaseMsg baseMsg) throws Exception { - FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)baseMsg; - Map paramMap = JSON.parseObject(msg.getJsonMsg(), Map.class); - wxPayOrderService.notify(paramMap, EnumPayWay.getEnum(msg.getPayWay())); - } -} +//@Service +//public class FmInsideNotifyPaySuccessMsgServiceImpl implements MsgSendService { +// private final Logger logger = LoggerFactory.getLogger(this.getClass()); +// +// @Autowired +// private WxPayOrderService wxPayOrderService; +// +// @Override +// public void send(BaseMsg baseMsg) throws Exception { +// FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)baseMsg; +// Map paramMap = JSON.parseObject(msg.getJsonMsg(), Map.class); +// wxPayOrderService.notify(paramMap, EnumPayWay.getEnum(msg.getPayWay())); +// } +//} diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/CPassivePayService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/CPassivePayService.java index f218d7d09..33e736907 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/CPassivePayService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/CPassivePayService.java @@ -7,9 +7,9 @@ import com.iformall.domain.po.WxOrder; import com.iformall.domain.po.WxPayAccount; import com.iformall.domain.po.WxPayOrder; import com.iformall.enums.EnumPayShare; -import com.iformall.service.pay.entity.CreateCUser; -import com.iformall.service.pay.entity.PayAdapterResult; import com.iformall.service.pay.entity.PayExtraParam; +import com.iformall.service.pay.service.pay.entity.CreateCUser; +import com.iformall.service.pay.service.pay.entity.PayAdapterResult; /** * C端被动发起的支付 diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/PayAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/PayAdapterService.java index 450bb3d70..e74f5c071 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/PayAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/PayAdapterService.java @@ -6,9 +6,9 @@ import com.iformall.domain.po.WxOrder; import com.iformall.domain.po.WxPayAccount; import com.iformall.domain.po.WxPayOrder; import com.iformall.enums.EnumPayShare; -import com.iformall.service.pay.entity.PayAdapterResult; import com.iformall.service.pay.entity.PayExtraParam; -import com.iformall.service.pay.entity.PayQueryAdapterResult; +import com.iformall.service.pay.service.pay.entity.PayAdapterResult; +import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; public interface PayAdapterService { diff --git a/mallinkService/src/main/java/com/iformall/service/pay/entity/CreateCUser.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/CreateCUser.java similarity index 88% rename from mallinkService/src/main/java/com/iformall/service/pay/entity/CreateCUser.java rename to mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/CreateCUser.java index ec7f7bb25..344609316 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/entity/CreateCUser.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/CreateCUser.java @@ -1,4 +1,4 @@ -package com.iformall.service.pay.entity; +package com.iformall.service.pay.service.pay.entity; import java.io.Serializable; diff --git a/mallinkService/src/main/java/com/iformall/service/pay/entity/PayAdapterResult.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/PayAdapterResult.java similarity index 94% rename from mallinkService/src/main/java/com/iformall/service/pay/entity/PayAdapterResult.java rename to mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/PayAdapterResult.java index 53b8c339f..eebaac236 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/entity/PayAdapterResult.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/PayAdapterResult.java @@ -1,4 +1,4 @@ -package com.iformall.service.pay.entity; +package com.iformall.service.pay.service.pay.entity; import java.io.Serializable; diff --git a/mallinkService/src/main/java/com/iformall/service/pay/entity/PayQueryAdapterResult.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/PayQueryAdapterResult.java similarity index 90% rename from mallinkService/src/main/java/com/iformall/service/pay/entity/PayQueryAdapterResult.java rename to mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/PayQueryAdapterResult.java index 1d577a805..ebc8bcea8 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/entity/PayQueryAdapterResult.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/entity/PayQueryAdapterResult.java @@ -1,4 +1,4 @@ -package com.iformall.service.pay.entity; +package com.iformall.service.pay.service.pay.entity; import java.io.Serializable; diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/BaseWxPayAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/BaseWxPayAdapterService.java index 508efe8e0..84d50fc68 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/BaseWxPayAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/BaseWxPayAdapterService.java @@ -7,8 +7,8 @@ import com.iformall.domain.po.WxOrder; import com.iformall.domain.po.WxPayAccount; import com.iformall.domain.po.WxPayOrder; import com.iformall.service.helper.WxPayOrderServiceHelper; -import com.iformall.service.pay.entity.PayQueryAdapterResult; import com.iformall.service.pay.service.pay.PayAdapterService; +import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; public class BaseWxPayAdapterService { diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/h5/WxH5PayService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/h5/WxH5PayService.java index 5c7ad931c..1a115b642 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/h5/WxH5PayService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/h5/WxH5PayService.java @@ -9,10 +9,10 @@ import com.iformall.domain.po.WxOrder; import com.iformall.domain.po.WxPayAccount; import com.iformall.domain.po.WxPayOrder; import com.iformall.enums.EnumPayShare; -import com.iformall.service.pay.entity.PayAdapterResult; import com.iformall.service.pay.entity.PayExtraParam; -import com.iformall.service.pay.entity.PayQueryAdapterResult; import com.iformall.service.pay.service.pay.CDrivingPayService; +import com.iformall.service.pay.service.pay.entity.PayAdapterResult; +import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; import com.iformall.service.pay.service.pay.wx.BaseWxPayAdapterService; @Service diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/miniApp/appPay/WxMiniAppPayAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/miniApp/appPay/WxMiniAppPayAdapterService.java index 2b53ae516..c974f2886 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/miniApp/appPay/WxMiniAppPayAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/miniApp/appPay/WxMiniAppPayAdapterService.java @@ -22,10 +22,10 @@ import com.iformall.pay.WxPay; import com.iformall.pay.WxPayOrderP; import com.iformall.pay.WxPayOrderSP; import com.iformall.pay.WxPayment; -import com.iformall.service.pay.entity.PayAdapterResult; import com.iformall.service.pay.entity.PayExtraParam; -import com.iformall.service.pay.entity.PayQueryAdapterResult; import com.iformall.service.pay.service.pay.CDrivingPayService; +import com.iformall.service.pay.service.pay.entity.PayAdapterResult; +import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; import com.iformall.service.pay.service.pay.wx.BaseWxPayAdapterService; import com.iformall.utils.BeanUtils; import com.iformall.utils.MapUtil; diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/miniApp/maPay/WxMiniMaPayAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/miniApp/maPay/WxMiniMaPayAdapterService.java index 71524ae60..0a70ca203 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/miniApp/maPay/WxMiniMaPayAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/pay/wx/miniApp/maPay/WxMiniMaPayAdapterService.java @@ -22,11 +22,11 @@ import com.iformall.pay.WxMicroPayOrderSP; import com.iformall.pay.WxPay; import com.iformall.pay.WxPayment; import com.iformall.service.WxCUserService; -import com.iformall.service.pay.entity.CreateCUser; -import com.iformall.service.pay.entity.PayAdapterResult; import com.iformall.service.pay.entity.PayExtraParam; -import com.iformall.service.pay.entity.PayQueryAdapterResult; import com.iformall.service.pay.service.pay.CPassivePayService; +import com.iformall.service.pay.service.pay.entity.CreateCUser; +import com.iformall.service.pay.service.pay.entity.PayAdapterResult; +import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; import com.iformall.service.pay.service.pay.wx.BaseWxPayAdapterService; import com.iformall.utils.BeanUtils; import com.iformall.utils.Utility; diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/refund/RefundPayAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/RefundPayAdapterService.java index 8fa71dfc7..5c748f6f3 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/refund/RefundPayAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/RefundPayAdapterService.java @@ -8,8 +8,8 @@ import com.iformall.domain.po.WxPayOrder; import com.iformall.domain.po.WxRefundOrder; import com.iformall.enums.EnumPayType; import com.iformall.enums.EnumPayWay; -import com.iformall.service.pay.entity.RefundAdapterResult; -import com.iformall.service.pay.entity.RefundNotifyAdapterResult; +import com.iformall.service.pay.service.refund.entity.RefundAdapterResult; +import com.iformall.service.pay.service.refund.entity.RefundNotifyAdapterResult; public interface RefundPayAdapterService { diff --git a/mallinkService/src/main/java/com/iformall/service/pay/entity/RefundAdapterResult.java b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/entity/RefundAdapterResult.java similarity index 94% rename from mallinkService/src/main/java/com/iformall/service/pay/entity/RefundAdapterResult.java rename to mallinkService/src/main/java/com/iformall/service/pay/service/refund/entity/RefundAdapterResult.java index 826832bc4..a5cf2e720 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/entity/RefundAdapterResult.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/entity/RefundAdapterResult.java @@ -1,4 +1,4 @@ -package com.iformall.service.pay.entity; +package com.iformall.service.pay.service.refund.entity; import java.io.Serializable; diff --git a/mallinkService/src/main/java/com/iformall/service/pay/entity/RefundNotifyAdapterResult.java b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/entity/RefundNotifyAdapterResult.java similarity index 97% rename from mallinkService/src/main/java/com/iformall/service/pay/entity/RefundNotifyAdapterResult.java rename to mallinkService/src/main/java/com/iformall/service/pay/service/refund/entity/RefundNotifyAdapterResult.java index 131fe95aa..fbadd80a9 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/entity/RefundNotifyAdapterResult.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/entity/RefundNotifyAdapterResult.java @@ -1,4 +1,4 @@ -package com.iformall.service.pay.entity; +package com.iformall.service.pay.service.refund.entity; import java.io.Serializable; diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/WxRefundAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/WxRefundAdapterService.java index e497be7d8..f85bca4d3 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/WxRefundAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/refund/wx/WxRefundAdapterService.java @@ -31,9 +31,9 @@ import com.iformall.pay.WxPay; import com.iformall.pay.WxPayment; import com.iformall.pay.WxRefundOrderP; import com.iformall.pay.WxRefundOrderSP; -import com.iformall.service.pay.entity.RefundAdapterResult; -import com.iformall.service.pay.entity.RefundNotifyAdapterResult; import com.iformall.service.pay.service.refund.RefundPayAdapterService; +import com.iformall.service.pay.service.refund.entity.RefundAdapterResult; +import com.iformall.service.pay.service.refund.entity.RefundNotifyAdapterResult; import com.iformall.utils.BeanUtils; import com.iformall.utils.CipherUtil; import com.iformall.utils.Utility; diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java index b33e63e1c..a579cef9f 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/PayShareAdapterService.java @@ -1,13 +1,17 @@ package com.iformall.service.pay.service.share; +import java.util.Map; + import com.alibaba.fastjson.JSONArray; import com.iformall.domain.po.WxAppinfo; import com.iformall.domain.po.WxPayAccount; import com.iformall.domain.po.WxProfitSharingOrder; +import com.iformall.enums.EnumPayWay; import com.iformall.enums.EnumProfitSharingOrderType; import com.iformall.enums.EnumProfitSharingReceiverType; import com.iformall.exception.MallinkException; -import com.iformall.service.pay.entity.PayShareResult; +import com.iformall.service.pay.service.share.entity.PayShareResult; +import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; /** * 分账接口 @@ -58,4 +62,7 @@ public interface PayShareAdapterService { */ public EnumProfitSharingReceiverType getShareAccount(Integer accountType); + + public ShareNotifyAdapterResult notify(Map paramMap,EnumPayWay payWay); + } diff --git a/mallinkService/src/main/java/com/iformall/service/pay/entity/PayShareResult.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareResult.java similarity index 86% rename from mallinkService/src/main/java/com/iformall/service/pay/entity/PayShareResult.java rename to mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareResult.java index 0bff92338..4d76cd443 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/entity/PayShareResult.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/PayShareResult.java @@ -1,4 +1,4 @@ -package com.iformall.service.pay.entity; +package com.iformall.service.pay.service.share.entity; import java.io.Serializable; diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/ShareNotifyAdapterResult.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/ShareNotifyAdapterResult.java new file mode 100644 index 000000000..86eb5bbf6 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/entity/ShareNotifyAdapterResult.java @@ -0,0 +1,76 @@ +package com.iformall.service.pay.service.share.entity; + +import java.io.Serializable; +import com.iformall.domain.po.WxPayOrder; + +public class ShareNotifyAdapterResult implements Serializable{ + private static final long serialVersionUID = -6647306162758854293L; + private boolean isSuccess; + private Integer code; + private String msg; + private String returnJson; + private String transcationId; + private WxPayOrder payOrder; + + + public ShareNotifyAdapterResult() { + + } + + public ShareNotifyAdapterResult(boolean isSuccess,Integer code,String msg,String returnJson) { + this.isSuccess = isSuccess; + this.msg = msg; + this.returnJson = returnJson; + } + + public ShareNotifyAdapterResult(String transcationId,WxPayOrder payOrder,String returnJson) { + this.isSuccess = true; + this.transcationId = transcationId; + this.payOrder = payOrder; + this.returnJson = returnJson; + } + + public boolean isSuccess() { + return isSuccess; + } + public void setSuccess(boolean isSuccess) { + this.isSuccess = isSuccess; + } + public String getMsg() { + return msg; + } + public void setMsg(String msg) { + this.msg = msg; + } + public Integer getCode() { + return code; + } + + public void setCode(Integer code) { + this.code = code; + } + + public String getTranscationId() { + return transcationId; + } + + public void setTranscationId(String transcationId) { + this.transcationId = transcationId; + } + + public String getReturnJson() { + return returnJson; + } + + public void setReturnJson(String returnJson) { + this.returnJson = returnJson; + } + + public WxPayOrder getPayOrder() { + return payOrder; + } + + public void setPayOrder(WxPayOrder payOrder) { + this.payOrder = payOrder; + } +} diff --git a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java index 623e5f7db..e95a3c052 100644 --- a/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java +++ b/mallinkService/src/main/java/com/iformall/service/pay/service/share/wx/WxPayShareService.java @@ -1,28 +1,44 @@ package com.iformall.service.pay.service.share.wx; +import java.text.ParseException; +import java.util.Date; import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.alibaba.fastjson.JSONArray; import com.iformall.common.ErrorCode; import com.iformall.domain.po.WxAppinfo; import com.iformall.domain.po.WxPayAccount; +import com.iformall.domain.po.WxPayOrder; import com.iformall.domain.po.WxProfitSharingOrder; import com.iformall.enums.EnumMerchantSubsidyType; +import com.iformall.enums.EnumPayEndFrom; +import com.iformall.enums.EnumPayWay; import com.iformall.enums.EnumProfitSharingOrderStatus; import com.iformall.enums.EnumProfitSharingOrderType; import com.iformall.enums.EnumProfitSharingReceiverType; import com.iformall.enums.EnumProfitSharingType; import com.iformall.exception.MallinkException; +import com.iformall.mapper.WxAppinfoMapper; +import com.iformall.mapper.WxPayAccountMapper; +import com.iformall.mapper.WxPayOrderMapper; import com.iformall.pay.WxPayment; import com.iformall.pay.WxProfitSharing; import com.iformall.pay.WxProfitSharingFinishP; import com.iformall.pay.WxProfitSharingP; -import com.iformall.service.pay.entity.PayShareResult; import com.iformall.service.pay.service.share.PayShareAdapterService; import com.iformall.service.pay.service.share.PayShareBaseAdapterService; +import com.iformall.service.pay.service.share.entity.PayShareResult; +import com.iformall.service.pay.service.share.entity.ShareNotifyAdapterResult; import com.iformall.utils.BeanUtils; import com.iformall.utils.Utility; +import com.iformall.utils.XmlUtil; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -130,4 +146,117 @@ public class WxPayShareService extends PayShareBaseAdapterService{ return new PayShareResult(true, null, "success",returnMap, returnMap.get("order_id")); } + + + @Autowired + WxAppinfoMapper wxAppinfoMapper; + @Autowired + WxPayAccountMapper wxPayAccountMapper; + @Autowired + WxPayOrderMapper wxPayOrderMapper; + + private ShareNotifyAdapterResult getErrorResult(String msg) { + SortedMap resultMap = new TreeMap(); + resultMap.put("return_code", "FAIL"); + resultMap.put("return_msg", msg); + return new ShareNotifyAdapterResult(false,ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR.getCode(),msg,XmlUtil.getRequestXml(resultMap)); + } + + private ShareNotifyAdapterResult getSuccessResult(WxPayOrder payOrder, String transcationId){ + SortedMap resultMap = new TreeMap(); + resultMap.put("return_code", "SUCCESS"); + resultMap.put("return_msg", "OK"); + return new ShareNotifyAdapterResult(transcationId, payOrder, XmlUtil.getRequestXml(resultMap)); + } + + @Override + public ShareNotifyAdapterResult notify(Map paramMap,EnumPayWay payWay) { + // how to get wechatAppId, wechatMchId, partnerKey + String appId = paramMap.get("appid"); + String subAppId = paramMap.get("sub_appid"); + String mchId = paramMap.get("mch_id"); + String subMchId = paramMap.get("sub_mch_id"); + WxAppinfo appinfo = null; + boolean isNormal = true; + if (StringUtils.isBlank(subAppId) && StringUtils.isBlank(subMchId)) { + // 普通商户号 + appinfo = wxAppinfoMapper.findByAppId(appId); + if (appinfo == null) { + log.error("appid not found: " + appId); + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + isNormal = true; + } else { + // 服务号 现在用hmac-sha256 + appinfo = wxAppinfoMapper.findByAppId(subAppId); + if (appinfo == null) { + log.error("subappid not found: " + subAppId); + throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); + } + isNormal = false; + } + + WxPayAccount payAccount = wxPayAccountMapper.selectById(appinfo.getPayId()); + if (payAccount == null) { + throw new MallinkException(ErrorCode.MCH_INFO_NOT_FOUND); + } + String partnerKey = payAccount.getApiKey(); + try { + if (payWay == EnumPayWay.PAY_WAY_WECHAT) { + boolean signVerified = false; + if (isNormal) { + // 普通商户号支付 + signVerified = WxPayment.verifyNotify(paramMap, partnerKey); + if (!signVerified) { + log.warn("notify order, wxpay checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); + throw new MallinkException(ErrorCode.PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR); + } + } else { + // 服务号 现在用hmac-sha256 + signVerified = WxPayment.verifyNotifyHMAC(paramMap, partnerKey); + if (!signVerified) { + log.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"))) { + log.warn("notify order, wxpay status not success, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); + return getErrorResult("订单状态码非SUCCESS"); + } + + String payOrderNo = paramMap.get("out_trade_no"); + String timEndStr = paramMap.get("time_end"); + Long payOrderId = Long.valueOf(payOrderNo); + WxPayOrder payOrder = wxPayOrderMapper.selectById(payOrderId); + if (payOrder == null) { + log.warn("notify order, wxpay check pay order not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); + return getErrorResult("订单不存在"); + } + // 验证支付金额 + if (!paramMap.get("total_fee").equals(payOrder.getPayAmount().toString())) { + log.warn("notify order, wxpay check total_fee is invalid, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); + return getErrorResult("订单总金额不一致"); + } + + Date timeEnd = null; + + try { + timeEnd = Utility.getDateFromString(timEndStr); + } catch (ParseException e) { + log.error("解析timeEnd失败"); + timeEnd = new Date(); + } + payOrder.setPayTimeEnd(timeEnd); + + log.info("notify order, wxpay checksign success, paramMap:{}, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString()); + return getSuccessResult(payOrder, paramMap.get("transaction_id")); + } + } catch (RuntimeException e) { + log.warn("notify order, checksign error, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString() + ", e:" + e.getMessage()); + throw new MallinkException(ErrorCode.PAY_ORDER_ERROR); + } + + return getErrorResult("FAILED"); + } }