| | |
| | | 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; |
| | | |
| | |
| | | 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); |
| | | } |
| | | |
| | | } |
| | |
| | | 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()); |
| | | } |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | } |