NotifyPaymentV1InnerServiceSMOImpl.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright 2017-2020 吴学文 and java110 team.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.java110.acct.smo.impl;
  17. import com.alibaba.fastjson.JSONObject;
  18. import com.java110.acct.dao.IOnlinePayV1ServiceDao;
  19. import com.java110.acct.payment.IPaymentBusiness;
  20. import com.java110.acct.payment.IPaymentFactoryAdapt;
  21. import com.java110.core.annotation.Java110Transactional;
  22. import com.java110.core.base.smo.BaseServiceSMO;
  23. import com.java110.core.log.LoggerFactory;
  24. import com.java110.dto.PageDto;
  25. import com.java110.dto.onlinePay.OnlinePayDto;
  26. import com.java110.dto.payment.NotifyPaymentOrderDto;
  27. import com.java110.dto.payment.PaymentOrderDto;
  28. import com.java110.intf.acct.INotifyPaymentV1InnerServiceSMO;
  29. import com.java110.intf.acct.IOnlinePayV1InnerServiceSMO;
  30. import com.java110.po.onlinePay.OnlinePayPo;
  31. import com.java110.utils.cache.CommonCache;
  32. import com.java110.utils.cache.MappingCache;
  33. import com.java110.utils.constant.WechatConstant;
  34. import com.java110.utils.exception.CmdException;
  35. import com.java110.utils.factory.ApplicationContextFactory;
  36. import com.java110.utils.util.BeanConvertUtil;
  37. import com.java110.utils.util.StringUtil;
  38. import org.slf4j.Logger;
  39. import org.springframework.beans.factory.annotation.Autowired;
  40. import org.springframework.http.ResponseEntity;
  41. import org.springframework.web.bind.annotation.RequestBody;
  42. import org.springframework.web.bind.annotation.RestController;
  43. import java.util.List;
  44. /**
  45. * 类表述: 服务之前调用的接口实现类,不对外提供接口能力 只用于接口建调用
  46. * add by 吴学文 at 2021-12-21 13:05:25 mail: 928255095@qq.com
  47. * open source address: https://gitee.com/wuxw7/MicroCommunity
  48. * 官网:http://www.homecommunity.cn
  49. * 温馨提示:如果您对此文件进行修改 请不要删除原有作者及注释信息,请补充您的 修改的原因以及联系邮箱如下
  50. * // modify by 张三 at 2021-09-12 第10行在某种场景下存在某种bug 需要修复,注释10至20行 加入 20行至30行
  51. */
  52. @RestController
  53. public class NotifyPaymentV1InnerServiceSMOImpl extends BaseServiceSMO implements INotifyPaymentV1InnerServiceSMO {
  54. private static final Logger logger = LoggerFactory.getLogger(NotifyPaymentV1InnerServiceSMOImpl.class);
  55. private static final String DEFAULT_PAYMENT_NOTIFY_ADAPT = "wechatPaymentFactory";// 默认微信通用支付
  56. /**
  57. * 通知类
  58. *
  59. * @param notifyPaymentOrderDto 数据对象分享
  60. * @return
  61. */
  62. @Override
  63. public ResponseEntity<String> notifyPayment(@RequestBody NotifyPaymentOrderDto notifyPaymentOrderDto) {
  64. try {
  65. String payNotifyAdapt = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAYMENT_ADAPT);
  66. payNotifyAdapt = StringUtil.isEmpty(payNotifyAdapt) ? DEFAULT_PAYMENT_NOTIFY_ADAPT : payNotifyAdapt;
  67. //支付适配器IPayNotifyAdapt
  68. logger.debug("适配器:" + payNotifyAdapt);
  69. IPaymentFactoryAdapt tPayNotifyAdapt = ApplicationContextFactory.getBean(payNotifyAdapt, IPaymentFactoryAdapt.class);
  70. PaymentOrderDto paymentOrderDto = tPayNotifyAdapt.java110NotifyPayment(notifyPaymentOrderDto.getParam());
  71. logger.info("【支付回调响应】 响应内容:\n" + paymentOrderDto.getResponseEntity());
  72. if (StringUtil.isEmpty(paymentOrderDto.getOrderId())) {
  73. return paymentOrderDto.getResponseEntity();
  74. }
  75. String paramIn = CommonCache.getAndRemoveValue("unifiedPayment_" + paymentOrderDto.getOrderId());
  76. JSONObject reqJson = JSONObject.parseObject(paramIn);
  77. IPaymentBusiness paymentBusiness = ApplicationContextFactory.getBean(reqJson.getString("business"), IPaymentBusiness.class);
  78. if (paymentBusiness == null) {
  79. throw new CmdException("当前支付业务不支持");
  80. }
  81. paymentOrderDto.setAppId(notifyPaymentOrderDto.getAppId());
  82. //2.0 相应业务 下单 返回 单号 ,金额,
  83. paymentBusiness.notifyPayment(paymentOrderDto, reqJson);
  84. return paymentOrderDto.getResponseEntity();
  85. }catch (Exception e){
  86. logger.error("通知是配置异常",e);
  87. throw e;
  88. }
  89. }
  90. }