Search in sources :

Example 1 with WxPayServiceImpl

use of com.github.binarywang.wxpay.service.impl.WxPayServiceImpl in project weixin-java-pay-demo by binarywang.

the class WxPayConfiguration method wxPayService.

@Bean
public // @ConditionalOnMissingBean
WxPayService wxPayService(WxPayConfig payConfig) {
    WxPayService wxPayService = new WxPayServiceImpl();
    wxPayService.setConfig(payConfig);
    return wxPayService;
}
Also used : WxPayService(com.github.binarywang.wxpay.service.WxPayService) WxPayServiceImpl(com.github.binarywang.wxpay.service.impl.WxPayServiceImpl) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with WxPayServiceImpl

use of com.github.binarywang.wxpay.service.impl.WxPayServiceImpl in project leopard by tanhaichao.

the class WeixinPayClientImpl method init.

@PostConstruct
public void init() {
    WxPayConfig payConfig = new WxPayConfig();
    payConfig.setAppId(appId);
    payConfig.setMchId(mchId);
    payConfig.setMchKey(mchKey);
    wxPayService = new WxPayServiceImpl();
    wxPayService.setConfig(payConfig);
    this.weixinPayDao = new WeixinPayDaoMysqlImpl(jdbc);
}
Also used : WxPayServiceImpl(com.github.binarywang.wxpay.service.impl.WxPayServiceImpl) WxPayConfig(com.github.binarywang.wxpay.config.WxPayConfig) PostConstruct(javax.annotation.PostConstruct)

Example 3 with WxPayServiceImpl

use of com.github.binarywang.wxpay.service.impl.WxPayServiceImpl in project summer by foxsugar.

the class WechatPayConfig method wxPayService.

@Bean(name = "wxPayService")
@Primary
public WxPayService wxPayService() {
    WxPayService wxPayService = new WxPayServiceImpl();
    wxPayService.setConfig(wxPayConfig());
    return wxPayService;
}
Also used : WxPayService(com.github.binarywang.wxpay.service.WxPayService) WxPayServiceImpl(com.github.binarywang.wxpay.service.impl.WxPayServiceImpl) Primary(org.springframework.context.annotation.Primary) Bean(org.springframework.context.annotation.Bean)

Example 4 with WxPayServiceImpl

use of com.github.binarywang.wxpay.service.impl.WxPayServiceImpl in project summer by foxsugar.

the class WechatPayConfig method wxAppPayService.

@Bean(name = "wxAppPayService")
public WxPayService wxAppPayService() {
    WxPayService wxPayService = new WxPayServiceImpl();
    wxPayService.setConfig(wxAppPayConfig());
    return wxPayService;
}
Also used : WxPayService(com.github.binarywang.wxpay.service.WxPayService) WxPayServiceImpl(com.github.binarywang.wxpay.service.impl.WxPayServiceImpl) Bean(org.springframework.context.annotation.Bean)

Example 5 with WxPayServiceImpl

use of com.github.binarywang.wxpay.service.impl.WxPayServiceImpl in project fw-cloud-framework by liuweijw.

the class PayNotifyController method doNotifyResult.

public String doNotifyResult(HttpServletRequest request, HttpServletResponse response) {
    String logPrefix = "【微信支付回调通知】";
    log.info("====== 开始接收微信支付回调通知 ======");
    try {
        String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
        log.info("{}通知请求数据:reqStr={}", logPrefix, xmlResult);
        if (StringHelper.isBlank(xmlResult)) {
            return WxPayNotifyResponse.fail("FAIL");
        }
        WxPayServiceImpl wxPayService = new WxPayServiceImpl();
        WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlResult);
        // 验证业务数据是否正确
        if (!PayConstant.RETURN_VALUE_SUCCESS.equalsIgnoreCase(result.getResultCode()) || !PayConstant.RETURN_VALUE_SUCCESS.equalsIgnoreCase(result.getResultCode())) {
            log.error("returnCode={},resultCode={},errCode={},errCodeDes={}", result.getReturnCode(), result.getResultCode(), result.getErrCode(), result.getErrCodeDes());
            return WxPayNotifyResponse.fail("notify data failed");
        }
        // 总金额
        Integer total_fee = result.getTotalFee();
        // 商户系统订单号
        String out_trade_no = result.getOutTradeNo();
        // 查询payOrder记录
        String payOrderId = out_trade_no;
        PayOrder payOrder = payOrderService.findPayOrderByOrderId(payOrderId);
        if (null == payOrder) {
            log.error("Can't found payOrder form db. payOrderId={}, ", payOrderId);
            return WxPayNotifyResponse.fail("未查询到相应订单信息");
        }
        // 查询payChannel记录
        String mchId = payOrder.getMch_id();
        String channelId = payOrder.getChannelId();
        PayChannel payChannel = payChannelService.findPayChannel(channelId, mchId);
        if (null == payChannel) {
            log.error("Can't found payChannel form db. mchId={} channelId={}, ", payOrderId, mchId, channelId);
            return WxPayNotifyResponse.fail("未查询到订单相关渠道信息");
        }
        WxPayConfig wxPayConfig = WxPayUtil.getWxPayConfig(payChannel.getParam(), result.getTradeType(), wxPayProperties.getCertRootPath(), wxPayProperties.getNotifyUrl());
        wxPayService.setConfig(wxPayConfig);
        // 签名校验
        result.checkResult(wxPayService, null, false);
        // 核对金额
        long wxPayAmt = new BigDecimal(total_fee).longValue();
        long dbPayAmt = payOrder.getAmount().longValue();
        if (dbPayAmt != wxPayAmt) {
            log.error("db payOrder record payPrice not equals total_fee. total_fee={},payOrderId={}", total_fee, payOrderId);
            return WxPayNotifyResponse.fail("支付金额不正确");
        }
        // 处理订单
        // 0:订单生成,1:支付中,-1:支付失败,2:支付成功,3:业务处理完成,-2:订单过期
        int payStatus = payOrder.getStatus();
        if (payStatus == PayConstant.PAY_STATUS_COMPLETE) {
            // 处理完成
            log.info("====== 订单已经完成直接返回 ======");
            return WxPayNotifyResponse.success("OK");
        }
        if (payStatus != PayConstant.PAY_STATUS_SUCCESS) {
            boolean updatePayOrderRows = payOrderService.updatePayOrderStatus4Success(payOrder.getPayOrderId());
            if (!updatePayOrderRows) {
                log.error("{}更新支付状态失败,将payOrderId={},更新payStatus={}失败", logPrefix, payOrder.getPayOrderId(), PayConstant.PAY_STATUS_FAILED);
                return WxPayNotifyResponse.fail("处理订单失败");
            }
            log.error("{}更新支付状态成功,将payOrderId={},更新payStatus={}成功", logPrefix, payOrder.getPayOrderId(), PayConstant.PAY_STATUS_SUCCESS);
            payOrder.setStatus(PayConstant.PAY_STATUS_SUCCESS);
        }
        // 业务系统后端通知
        this.notifyService.notifyPayOrder(payOrder);
        log.info("====== 完成接收微信支付回调通知 ======");
        return WxPayNotifyResponse.success("OK");
    } catch (WxPayException e) {
        // 出现业务错误
        log.error("微信回调结果异常,异常原因" + e);
        log.info("{}请求数据result_code=FAIL", logPrefix);
        log.info("err_code:", e.getErrCode());
        log.info("err_code_des:", e.getErrCodeDes());
        return WxPayNotifyResponse.fail(e.getMessage());
    } catch (Exception e) {
        log.error("微信回调结果异常,异常原因" + e);
        return WxPayNotifyResponse.fail(e.getMessage());
    }
}
Also used : WxPayOrderNotifyResult(com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult) WxPayServiceImpl(com.github.binarywang.wxpay.service.impl.WxPayServiceImpl) PayOrder(com.github.liuweijw.business.pay.domain.PayOrder) WxPayException(com.github.binarywang.wxpay.exception.WxPayException) PayChannel(com.github.liuweijw.business.pay.domain.PayChannel) BigDecimal(java.math.BigDecimal) WxPayException(com.github.binarywang.wxpay.exception.WxPayException) WxPayConfig(com.github.binarywang.wxpay.config.WxPayConfig)

Aggregations

WxPayServiceImpl (com.github.binarywang.wxpay.service.impl.WxPayServiceImpl)9 WxPayService (com.github.binarywang.wxpay.service.WxPayService)7 Bean (org.springframework.context.annotation.Bean)5 WxPayConfig (com.github.binarywang.wxpay.config.WxPayConfig)4 WxPayException (com.github.binarywang.wxpay.exception.WxPayException)3 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)3 R (com.github.liuweijw.commons.base.R)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JSONObject (com.alibaba.fastjson.JSONObject)1 WxPayOrderNotifyResult (com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult)1 WxPayUnifiedOrderRequest (com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest)1 WxPaySendRedpackResult (com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult)1 WxPayUnifiedOrderResult (com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult)1 PayChannel (com.github.liuweijw.business.pay.domain.PayChannel)1 PayOrder (com.github.liuweijw.business.pay.domain.PayOrder)1 BigDecimal (java.math.BigDecimal)1 PostConstruct (javax.annotation.PostConstruct)1 Primary (org.springframework.context.annotation.Primary)1