admin
2021-06-23 b47f8a03db79bb1f6356479cd8a5cf190d7d9694
service-vip/src/main/java/com/ks/vip/service/remote/VipOrderPayServiceImpl.java
@@ -17,8 +17,8 @@
import com.ks.vip.util.Constant;
import com.ks.vip.util.PayUtil;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.transaction.annotation.Transactional;
import org.yeshi.utils.StringUtil;
import org.yeshi.utils.alipay.AlipayH5PayUtil;
@@ -31,10 +31,11 @@
import java.util.Date;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@Service(version = "1.0")
public class VipOrderPayServiceImpl implements VipOrederPayService {
    Logger logger = LoggerFactory.getLogger(VipOrederPayService.class);
    @Resource
    private VipOrderMapper vipOrderMapper;
@@ -133,6 +134,7 @@
                    String payUrl = PayUtil.createWXOrder(ip, orderId, order.getPayMoney(), goodsTitle, notifyUrl, returnUrl);
                    return new PayWayInfoDTO(PayWayEnum.weChat, payUrl, null);
                } catch (Exception e) {
                    logger.error("创建微信支付出错", e);
                    throw new OrderPayException(OrderPayException.CODE_CREATE_PAY_ORDER_FAIL, e.getMessage());
                }
        }
@@ -152,9 +154,12 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public VipOrder checkOrderPayState(Long id) {
    public VipOrder checkOrderPayState(Long id) throws VipOrderException, OrderPayException {
        VipOrder order = vipOrderMapper.selectByPrimaryKey(id);
        if (order == null || order.getState() == VipOrder.STATE_PAY) {
        if (order == null) {
            throw new VipOrderException(VipOrderException.CODE_NOT_EXIST, "订单不存在");
        }
        if (order.getState() == VipOrder.STATE_PAY) {
            return order;
        }
        switch (order.getPayWay()) {
@@ -162,31 +167,33 @@
            case "alipay":
                AlipayTradeQueryResponse res = null;
                try {
                    res = AlipayH5PayUtil.queryOrder(PayUtil.getAlipayApp(), id + "", null);
                    res = AlipayH5PayUtil.queryOrder(PayUtil.getAlipayApp(), order.getThreeOrderId(), null);
                    //支付成功
                    if (res.isSuccess() && "TRADE_SUCCESS".equalsIgnoreCase(res.getTradeStatus())) {
                        try {
                            return paySuccess(order);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return paySuccess(order);
                    } else {
                        throw new OrderPayException(OrderPayException.CODE_PAY_FAIL, "支付宝付款未成功");
                    }
                } catch (AlipayApiException e) {
                    e.printStackTrace();
                    throw new OrderPayException(OrderPayException.CODE_API_ERROR, "支付宝接口请求出错:" + e.getErrMsg());
                }
                //微信
            case "weChat":
                WXPayOrderInfoV3 info = null;
                try {
                    WXPayOrderInfoV3 info = WXPayV3Util.getPayOrderInfo(id + "", PayUtil.getWXAPP());
                    if (info != null && info.getTrade_state().equalsIgnoreCase("SUCCESS")) {
                        paySuccess(order);
                        return order;
                    }
                    info = WXPayV3Util.getPayOrderInfo(order.getThreeOrderId(), PayUtil.getWXAPP());
                } catch (Exception e) {
                    e.printStackTrace();
                    throw new OrderPayException(OrderPayException.CODE_API_ERROR, "微信支付接口请求出错:" + e.getMessage());
                }
                if (info != null && info.getTrade_state().equalsIgnoreCase("SUCCESS")) {
                    paySuccess(order);
                    return order;
                } else {
                    throw new OrderPayException(OrderPayException.CODE_PAY_FAIL, "微信付款未成功");
                }
            default:
                throw new OrderPayException(OrderPayException.CODE_PAY_WAY_NOT_EXIST, "付款方式不存在");
        }
        return null;
    }
    @Override