Helius
2021-03-11 a72aa4bb793ec765892406c842039a71b33215b1
zq-erp/src/main/java/com/matrix/system/shopXcx/api/action/WxCommonAction.java
@@ -1,13 +1,14 @@
package com.matrix.system.shopXcx.api.action;
import com.matrix.biz.dao.BizUserDao;
import com.matrix.component.rabbitmq.RabiitMqTemplate;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.LogUtil;
import com.matrix.component.wechat.externalInterface.common.Signature;
import com.matrix.component.wechat.externalInterface.common.Util;
import com.matrix.component.wechat.externalInterface.protocol.queryProtocol.NotifyData;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.LogUtil;
import com.matrix.system.common.bean.BusParameterSettings;
import com.matrix.system.common.constance.AppConstance;
import com.matrix.system.common.dao.BusParameterSettingsDao;
import com.matrix.system.hive.bean.SysVipInfo;
import com.matrix.system.hive.dao.SysVipInfoDao;
import com.matrix.system.shopXcx.bean.ShopActivitiesGroupJoin;
@@ -19,6 +20,7 @@
import com.matrix.system.shopXcx.dao.ShopOrderDao;
import com.matrix.system.shopXcx.dao.ShopPayLogDao;
import com.matrix.system.shopXcx.mqTask.MQTaskRouting;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
@@ -26,12 +28,10 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xml.sax.SAXException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -75,6 +75,11 @@
    @Autowired
    private SysVipInfoDao sysVipInfoDao;
    @Autowired
    BusParameterSettingsDao busParameterSettingsDao;
    @Value("${evn}")
    private String evn;
    /**
@@ -86,7 +91,7 @@
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    @RequestMapping(value = "/wxpayCallback")
    @RequestMapping(value = "/wxapi/wxpayCallback")
    public void payCallBack(HttpServletResponse response, HttpServletRequest request) throws IOException {
        LogUtil.info("微信支付回调start....");
@@ -102,16 +107,26 @@
                notityXml.append(inputLine);
            }
            request.getReader().close();
            // XMl转对象
            NotifyData data = (NotifyData) Util.getObjectFromXML(notityXml.toString(), NotifyData.class);
            LogUtil.info(data.toString());
            LogUtil.info("notityXml ---- :{} ", notityXml);
            // XMl转对象
            Object bb = Util.getObjectFromXML(notityXml.toString(), NotifyData.class);
            NotifyData    data = new NotifyData();
            BeanUtils.copyProperties(bb,data);
            LogUtil.info("----return_code = {}", data.getReturn_code());
            // 返回状态码 SUCCESS/FAIL
            if (AppConstance.CODE_SUCCESS.equals(data.getReturn_code())) {
                orderId = data.getAttach();
                // 检验订单状态
                ShopOrder order = shopOrderDao.selectById(Integer.valueOf(orderId));
                // 校验签名
                if (Signature.checkIsSignValidFromResponseString(notityXml.toString())) {
                BusParameterSettings paySecret = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.WECHARPAY_SECRET, order.getCompanyId());
                if (Signature.checkIsSignValidFromResponseString(notityXml.toString(),paySecret.getParamValue())) {
                    // 校验业务结果
                    if (AppConstance.CODE_SUCCESS.equals(data.getResult_code())) {
                        // 返回SUCCESS报文
@@ -120,14 +135,13 @@
                        Double total_fee = Double.parseDouble(data.getTotal_fee());
                        // 商户订单号
                        String payNum = data.getOut_trade_no();
                        orderId = data.getAttach();
                        LogUtil.info("支付回调关键信息---total_fee:{},payNum:{},orderId:{}", total_fee, payNum, orderId);
                        // 订单ID
                        BigDecimal payMoney = new BigDecimal(total_fee).divide(new BigDecimal(100), 2,
                                RoundingMode.HALF_UP);
                        // 检验订单状态
                        ShopOrder order = shopOrderDao.selectById(Integer.valueOf(orderId));
                        if (order != null && ShopOrder.ORDER_PAY_STATUS_WAIT == order.getPayStatus()) {
                            ShopPayLog payLog = new ShopPayLog();
                            // TODO 校验支付金额
@@ -210,7 +224,7 @@
                threadResult.putInMap("msg", "查询支付信息失败,请联系客服或者刷新支付信息(错误码:003)");
                resXml = AppConstance.RESULT_XML_FAIL.replace(ERRORMSG, "通信标识失败");
            }
        } catch (ParserConfigurationException | IOException | SAXException e) {
        } catch (Exception e) {
            LogUtil.error("支付回调签名错误", e);
            threadResult.putInMap("status", "err");
            threadResult.putInMap("msg", "查询支付信息失败,请联系客服或者刷新支付信息(错误码:004)");
@@ -262,4 +276,6 @@
        return null;
    }
}