admin
2025-08-08 035edfa382d349ba66240fbfef68c14c7cfc95d1
src/main/java/com/taoke/autopay/utils/AlipayUtil.java
@@ -11,10 +11,12 @@
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
public class AlipayUtil {
    private final static Logger logger = org.slf4j.LoggerFactory.getLogger("alipayLogger");
    private static DefaultAlipayClient alipayClient = null;
@@ -27,16 +29,23 @@
        certAlipayRequest.setFormat("json");
        certAlipayRequest.setCharset("GBK");
        certAlipayRequest.setSignType("RSA2");
        certAlipayRequest.setCertPath(
                AlipayUtil.class.getClassLoader().getResource("alipay/appCertPublicKey_2021004141681244.crt").getPath());
        certAlipayRequest.setAlipayPublicCertPath(
                AlipayUtil.class.getClassLoader().getResource("alipay/alipayCertPublicKey_RSA2.crt").getPath());
        certAlipayRequest.setRootCertPath(
                AlipayUtil.class.getClassLoader().getResource("alipay/alipayRootCert.crt").getPath());
//        certAlipayRequest.setCertPath(
//                AlipayUtil.class.getClassLoader().getResource("alipay/appCertPublicKey_2021004141681244.crt").getPath());
//        certAlipayRequest.setAlipayPublicCertPath(
//                AlipayUtil.class.getClassLoader().getResource("alipay/alipayCertPublicKey_RSA2.crt").getPath());
//        certAlipayRequest.setRootCertPath(
//                AlipayUtil.class.getClassLoader().getResource("alipay/alipayRootCert.crt").getPath());
        certAlipayRequest.setCertPath("/www/wwwroot/alipay/appCertPublicKey_2021004141681244.crt");
        certAlipayRequest.setAlipayPublicCertPath("/www/wwwroot/alipay/alipayCertPublicKey_RSA2.crt");
        certAlipayRequest.setRootCertPath("/www/wwwroot/alipay/alipayRootCert.crt");
        logger.info("证书路径:{}", certAlipayRequest.getCertPath());
        try {
            alipayClient = new DefaultAlipayClient(certAlipayRequest);
        } catch (AlipayApiException e) {
            e.printStackTrace();
            logger.error("支付宝初始化失败", e);
        }
    }
@@ -63,9 +72,11 @@
        response = alipayClient.certificateExecute(request);
        // 成功转账
        if (response != null && response.isSuccess() && "10000".equals(response.getCode())) {
            logger.info("转账成功:{}-{}-{}-{}",outBizNo, name, account,money );
            return response;
        } else// 转账失败
        {
            logger.warn("转账失败:{}-{}",outBizNo, response!=null? response.getSubMsg():"未知原因");
            throw new AlipayTransferException(Integer.parseInt(response.getCode()), response.getSubCode(),
                    response.getSubMsg());
        }
@@ -138,4 +149,5 @@
    }
}