import com.alipay.easysdk.factory.factory;
import com.alipay.easysdk.factory.factory.payment;
import com.alipay.easysdk.kernel.config;
import com.alipay.easysdk.kernel.util.responsechecker;
import com.alipay.easysdk.payment.facetoface.models.alipaytradeprecreateresponse;
public class main {
public static void main(string[] args) throws exception {
// 1. 设置参数(全局只需设置一次)
factory.setoptions(getoptions());
try {
// 2. 发起api调用(以创建当面付收款二维码为例)
alipaytradeprecreateresponse response = payment.facetoface()
.precreate("apple iphone11 128g", "2234567890", "5799.00");
// 3. 处理响应或异常
if (responsechecker.success(response)) {
system.out.println("调用成功");
} else {
system.err.println("调用失败,原因:" response.msg "," response.submsg);
}
} catch (exception e) {
system.err.println("调用遭遇异常,原因:" e.getmessage());
throw new runtimeexception(e.getmessage(), e);
}
}
private static config getoptions() {
config config = new config();
config.protocol = "https";
config.gatewayhost = "openapi.alipay.com";
config.signtype = "rsa2";
config.appid = "<-- 请填写您的appid,例如:2019091767145019 -->";
// 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
config.merchantprivatekey = "<-- 请填写您的应用私钥,例如:miievqibadanb ... ... -->";
//注:证书文件路径支持设置为文件系统中的路径或class_path中的路径,优先从文件系统中加载,加载失败后会继续尝试从class_path中加载
config.merchantcertpath = "<-- 请填写您的应用公钥证书文件路径,例如:/foo/appcertpublickey_2019051064521003.crt -->";
config.alipaycertpath = "<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipaycertpublickey_rsa2.crt -->";
config.alipayrootcertpath = "<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayrootcert.crt -->";