Search in sources :

Example 1 with WxPayConfig

use of com.github.binarywang.wxpay.config.WxPayConfig in project weixin-java-pay-demo by binarywang.

the class WxPayConfiguration method payConfig.

@Bean
@ConditionalOnMissingBean
public WxPayConfig payConfig() {
    WxPayConfig payConfig = new WxPayConfig();
    payConfig.setAppId(this.properties.getAppId());
    payConfig.setMchId(this.properties.getMchId());
    payConfig.setMchKey(this.properties.getMchKey());
    payConfig.setSubAppId(StringUtils.trimToNull(this.properties.getSubAppId()));
    payConfig.setSubMchId(StringUtils.trimToNull(this.properties.getSubMchId()));
    payConfig.setKeyPath(this.properties.getKeyPath());
    return payConfig;
}
Also used : WxPayConfig(com.github.binarywang.wxpay.config.WxPayConfig) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with WxPayConfig

use of com.github.binarywang.wxpay.config.WxPayConfig 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 WxPayConfig

use of com.github.binarywang.wxpay.config.WxPayConfig in project summer by foxsugar.

the class WechatPayConfig method wxAppPayConfig.

@Bean
public WxPayConfig wxAppPayConfig() {
    // WxMpInMemoryConfigStorage wxMpConfigStorage = new WxMpInMemoryConfigStorage();
    WxPayConfig wxPayConfig = new WxPayConfig();
    wxPayConfig.setAppId(serverConfig.getAppId());
    wxPayConfig.setMchId(serverConfig.getMchId());
    wxPayConfig.setMchKey(serverConfig.getKey());
    // wxPayConfig.setSubAppId(accountConfig.getsubAppId);
    // wxPayConfig.setSubMchId(this.subMchId);
    wxPayConfig.setKeyPath(accountConfig.getKeyPath());
    return wxPayConfig;
}
Also used : WxPayConfig(com.github.binarywang.wxpay.config.WxPayConfig) Bean(org.springframework.context.annotation.Bean)

Example 4 with WxPayConfig

use of com.github.binarywang.wxpay.config.WxPayConfig in project fw-cloud-framework by liuweijw.

the class WxPayUtil method getWxPayConfig.

/**
 * 获取微信支付配置
 */
public static WxPayConfig getWxPayConfig(String configParam, String tradeType, String certRootPath, String notifyUrl) {
    WxPayConfig wxPayConfig = new WxPayConfig();
    JSONObject paramObj = JSON.parseObject(configParam);
    wxPayConfig.setMchId(paramObj.getString("mchId"));
    if (null != tradeType && tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_APP)) {
        wxPayConfig.setAppId(paramObj.getString("openAppId"));
    } else {
        wxPayConfig.setAppId(paramObj.getString("appId"));
    }
    wxPayConfig.setMchKey(paramObj.getString("key"));
    if (!PublicHelper.isEmpty(certRootPath))
        wxPayConfig.setKeyPath(certRootPath + File.separator + paramObj.getString("certLocalPath"));
    if (!PublicHelper.isEmpty(notifyUrl))
        wxPayConfig.setNotifyUrl(notifyUrl);
    if (!PublicHelper.isEmpty(tradeType))
        wxPayConfig.setTradeType(tradeType);
    return wxPayConfig;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) WxPayConfig(com.github.binarywang.wxpay.config.WxPayConfig)

Example 5 with WxPayConfig

use of com.github.binarywang.wxpay.config.WxPayConfig 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

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