| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.lang.Snowflake; |
| | | import cn.hutool.core.util.XmlUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse; |
| | | import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; |
| | | import com.github.binarywang.wxpay.config.WxPayConfig; |
| | | import com.github.binarywang.wxpay.constant.WxPayConstants; |
| | | import com.github.binarywang.wxpay.service.WxPayService; |
| | | import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5C3HeartbeatReportInnerFrame; |
| | | import com.sandu.ximon.admin.manager.iot.rrpc.enums.C3mRedisConstant; |
| | | import com.sandu.ximon.admin.pay.OrderStatusEnums; |
| | | import com.sandu.ximon.admin.pay.wx.WxFastPayService; |
| | | import com.sandu.ximon.admin.pay.wxpay.UsrWxPayConfigService; |
| | | import com.sandu.ximon.admin.security.SecurityUtils; |
| | | import com.sandu.ximon.admin.security.order.OrderQueryListener; |
| | | import com.sandu.ximon.admin.utils.AliPayUtils; |
| | |
| | | import com.sandu.ximon.dao.domain.C3mCharging; |
| | | import com.sandu.ximon.dao.domain.C3mOrder; |
| | | import com.sandu.ximon.dao.domain.Pole; |
| | | import com.sandu.ximon.dao.domain.WxConfigEntity; |
| | | import com.sandu.ximon.dao.enums.OrderStatus; |
| | | import com.sandu.ximon.dao.enums.OrderType; |
| | | import com.sandu.ximon.dao.mapper.C3mOrderMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @Author liuhaonan |
| | |
| | | private final Snowflake snowflake; |
| | | |
| | | private final C3ChargingService c3ChargingService; |
| | | private final UsrWxPayConfigService usrWxPayConfigService; |
| | | |
| | | /** |
| | | * 退款 |
| | |
| | | .eq(C3mOrder::getC3Udid, c3m.getMcuUdid()).last("limit 1")); |
| | | |
| | | //充电桩正在充电中 |
| | | if (c3mOrder != null && c3mOrder.getChargingStates() == 0) { |
| | | if (c3mOrder != null && c3mOrder.getChargingStates() != null && c3mOrder.getChargingStates() == 0) { |
| | | throw new BusinessException("充电桩正在被占用!"); |
| | | } |
| | | |
| | |
| | | c3mOrderEntity.setUserCode(wxCode); |
| | | c3mOrderEntity.setC3Udid(c3m.getMcuUdid()); |
| | | |
| | | // |
| | | c3mOrderEntity.setC3Name("创建订单"); |
| | | |
| | | |
| | | if (save(c3mOrderEntity)) { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 微信支付回调 |
| | | * 微信支付回调 小程序 |
| | | */ |
| | | public Object payWechatNotify(String xmlData) { |
| | | WxPayOrderNotifyResult wxPayOrderNotifyResult = fastPayService.parseOrderNotifyResult(xmlData); |
| | | public Object payOrderInstoreNotify(HttpServletRequest request, HttpServletResponse httpResponse) { |
| | | log.error("[-----------------微信支付回调开始-----------------]"); |
| | | String xmlResult = null; |
| | | try { |
| | | xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding()); |
| | | } catch (IOException e) { |
| | | throw new BusinessException(e.getMessage()); |
| | | } |
| | | log.error("request: " + xmlResult); |
| | | |
| | | if (xmlResult == null) { |
| | | return null; |
| | | } |
| | | Map<String, Object> stringObjectMap = XmlUtil.xmlToMap(xmlResult); |
| | | String appId = (String) stringObjectMap.get("appid"); |
| | | WxConfigEntity configByAppId = usrWxPayConfigService.getConfigByAppId(appId); |
| | | WxPayConfig config = new WxPayConfig(); |
| | | config.setAppId(configByAppId.getAppappid()); |
| | | config.setMchId(configByAppId.getMchId()); |
| | | config.setMchKey(configByAppId.getPrivateKey()); |
| | | |
| | | WxPayService wxPayService = new WxPayServiceImpl(); |
| | | wxPayService.setConfig(config); |
| | | |
| | | |
| | | WxPayOrderNotifyResult wxPayOrderNotifyResult = fastPayService.parseOrderNotifyResult(wxPayService, xmlResult); |
| | | if (!WxPayConstants.ResultCode.SUCCESS.equals(wxPayOrderNotifyResult.getResultCode()) |
| | | || !WxPayConstants.ResultCode.SUCCESS.equals(wxPayOrderNotifyResult.getReturnCode())) { |
| | | log.error(xmlResult); |
| | | return WxPayNotifyResponse.fail("微信通知支付失败!"); |
| | | } |
| | | |
| | | String orderSn = wxPayOrderNotifyResult.getOutTradeNo(); |
| | | String transactionId = wxPayOrderNotifyResult.getOutTradeNo(); |
| | | C3mOrder userOrder = getByOrderSn(orderSn); |
| | | userOrder.setC3Name("回调成功"); |
| | | updateById(userOrder); |
| | | if (userOrder == null) { |
| | | return WxPayNotifyResponse.fail("订单不存在 sn=" + orderSn); |
| | |
| | | */ |
| | | String s = c3ChargingService.startCharging(userOrder.getC3Mac(), userOrder.getSubscribeChargingCapacity(), userOrder.getTotalAmount()); |
| | | if (s.isEmpty() || s == null) { |
| | | log.error("[-----------------开启充电失败-----------------]"); |
| | | throw new BusinessException("开启充电失败"); |
| | | } |
| | | //开启充电成功后,更新订单状态为充电中 |
| | | userOrder.setChargingStates(0); |
| | | log.error("[-----------------微信支付回调结束-----------------]"); |
| | | if (!updateById(userOrder)) { |
| | | return WxPayNotifyResponse.fail("更新数据已失效"); |
| | | } |
| | |
| | | return WxPayNotifyResponse.success("更新数据成功"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 订单详情 by orderSn |
| | | * |