<dependency> <groupId>com.alipay.sdk</groupId> <artifactId>alipay-easysdk</artifactId> <version>2.1.0</version> </dependency>
cp.ali.pay.protocol = httpcp.ali.pay.gatewayHost = openapi.alipaydev.comcp.ali.pay.signType = RSA2cp.ali.pay.appId = 2016101300680499cp.ali.pay.merchantPrivateKey = ******cp.ali.pay.aliPayPublicKey = ******cp.ali.pay.notifyUrl = ""cp.ali.pay.encryptKey = ""
@Data@ConfigurationProperties(prefix = "cp.ali.pay")public class CpAliPayProperties { private String protocol; private String gatewayHost; private String signType; private String appId; private String merchantPrivateKey; private String aliPayPublicKey; private String notifyUrl; private String encryptKey;}
/** * 初始化支付 * 爪哇笔记 https://blog.52itstyle.vip * @author 小柒2012 */@Component@Configuration@EnableConfigurationProperties({CpAliPayProperties.class})public class CpPayUtils { private CpAliPayProperties aliPay; public CpPayUtils(CpAliPayProperties aliPay) { this.aliPay = aliPay; Config config = new Config(); config.protocol = aliPay.getProtocol(); config.gatewayHost = aliPay.getGatewayHost(); config.signType = aliPay.getSignType(); config.appId = aliPay.getAppId(); /** * 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中 */ config.merchantPrivateKey = aliPay.getMerchantPrivateKey(); config.alipayPublicKey = aliPay.getAliPayPublicKey(); config.notifyUrl = aliPay.getNotifyUrl(); config.encryptKey = aliPay.getEncryptKey(); Factory.setOptions(config); } public CpAliPayProperties getConfig(){ return aliPay; }}
AlipayTradePrecreateResponse response = Payment.FaceToFace() .preCreate("Apple iPhone13 128G", "202012108856987", "6999.00"); // 处理响应或异常 if (ResponseChecker.success(response)) { System.out.println("调用成功"); } else { System.err.println("调用失败,原因:" + response.msg + "," + response.subMsg); }
Factory.Payment.FaceToFace() // 此处设置的异步通知地址的优先级高于全局Config中配置的异步通知地址 .asyncNotify("https://blog.52itstyle.vip/callback") .preCreate("Apple iPhone13 256G", "202012108856987", "6999.00");
文章有问题?点此查看未经处理的缓存