演示沙箱环境下支付,沙箱环境和正式支付只不过一些参数不同 像AppId PrivateKey AlipayPublicKey gatewayUrl 这些参数会有不同。
代码配置
@Component @Data public class payConfig { private String PrivateKey = "应用私钥"; //Appid private String AppId = "*******"; // 支付宝网关地址 private String gatewayUrl = "https://openapi-sandbox.dl.alipaydev.com/gateway.do"; // 支付宝公钥 private String AlipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkel5XHyasYpwEFDQHGvV5+zun8WzGDkkSPwzqWxz84LlEUpmvvxTAke4RW6QyX6iQv7idKd949r+7nqoxZyAqJbicmtkQjm3SDhD5izyu37GLAB/CYxmCMrTfsV2+v2QtdAOgx0gJ71s3ForW2/ZjOKn2Orhahuf9AFw6crkJsgikU+PPPphu2GwQXspw5hB5PAyRbCENGHpzawKLqTdbBCaVAmzD/sYky6CLxd4xfEixQuLZu20qPXwrYaXHofm9R7OmXw6m17mDjuAXr2ZaYSAO4EDmMLhR9FMHQ5YY/ogNng3J7ap3n7yHJfrCydSB6OsPMZCclZ9JzcT1iJmswIDAQAB"; public String pay(PayVo payVo) throws AlipayApiException { AlipayConfig alipayConfig = new AlipayConfig(); //设置网关地址 alipayConfig.setServerUrl(gatewayUrl); //设置应用ID alipayConfig.setAppId(AppId); //设置应用私钥 alipayConfig.setPrivateKey(PrivateKey); //设置请求格式,固定值json alipayConfig.setFormat(FORMAT_JSON); //设置字符集 alipayConfig.setCharset(CHARSET_UTF8); //设置签名类型 alipayConfig.setSignType(SIGN_TYPE_RSA2); //设置支付宝公钥 alipayConfig.setAlipayPublicKey(AlipayPublicKey); AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig); String return_uri = "http://8j5704c509.goho.co/alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp"; String notify_url = "http://8j5704c509.goho.co/alipay.trade.page.pay-JAVA-UTF-8/notify_url.jsp"; String out_trade_no = payVo.getOut_trade_no(); //订单号 String total_amount = payVo.getTo