首页 > 其他分享 >支付宝网页端 调用沙箱 支付环境

支付宝网页端 调用沙箱 支付环境

时间:2022-08-14 23:23:47浏览次数:61  
标签:支付宝 网页 request bizContent public alipayConfig 沙箱 response out

<dependency>
  <groupId>com.alipay.sdk</groupId>
  <artifactId>alipay-sdk-java</artifactId>
  <version>4.33.1.ALL</version>
</dependency>
@Data
public class aliOrderPayConfig {
    public static final String PRIVATE_KEY ="MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCmpGnxsyra+uvAByKWsC9s9mc6zPDFJUY4N6/JBbEOQ1/I5fcrPyCB3czOhyXwodeo0PEVvV9+Tlwfatg/B4reYeeXVHGrB9rWSyM0cB23CEDOhO9uslalOUCD6XB1Pf2buZYofIQgc5Q6goUI7PgkEYzh/O4c+XYj10+tR2SENTRvXitOUcKeSSuCKXQlviUsuNPaFZw+ujwblY+CjnAYHLvDTMkVmpl/hg39o5AwE3IV21GCsbXLal0KCKNvLMw9SJeEIsXbfuQG5NsA1EMTK98/2dbcYoAt3NO4dazw2zZksIs4OzCQ8DwcgOegvA7Ddo3EzZC2NNl+vgWrNpQPAgMBAAECggEASC16feferg50wi3U+3PAdu+a8ssFlj541ay5BNbkQ4tHF5sTnbWv/M/2/5VmB33yDPrDEWl+zRRfrnP2ygYYTg4V42P9/9hdHuhYjUPqevamK01E76trABF2MiyQOxfomuSdd1fHWs706wrRWHZbXDQF03RcJkyesRN3PVRo4yH9Ej5nCOS/ef4q9zQ9J9+FC/WkvHXWiPa6wUssTgsc0cVe6YvRxZaxy/ANj7M4vR+YxE+uvO/QNazQE5QrsqWrFMITi3lryatXMFcbJflqqDtODXaIYiWLnsq8CQWvd5B2am7FAiXx5sehZVYbRw1dsUwllhFt0r677k2M2FMOEQKBgQDcUslj2mK1ShhZ5YamOU55268mtPn8YI6TuKyCAVuzYgCaMm8JIZi7ujOMNiaplcjjnAzQQKvP0NE/o9uVreVpvcXi0jo01A7gvVm9eW2jUf66xCqB6booLFv4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08oVE+gq5i5ADMm721JoLEKsxQmuYfdc9guqTHaz5CCWbWD2AUKEAvWT40Y0sWsV2uoG9OhNBWypR9QIDAQAB";

    public static final  String RETURN_URL="http://localhost:100/aliPayRetrunUrl";
    
}
 public String sendRequestToAlipay(Integer orderId, BigDecimal amount)  {
        AlipayConfig alipayConfig = new AlipayConfig();
        /*沙箱配置*/
        alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
        alipayConfig.setAppId("2021000121603247");
        alipayConfig.setPrivateKey(aliOrderPayConfig.PRIVATE_KEY);
        alipayConfig.setFormat("json");
        alipayConfig.setCharset("GBK");
        alipayConfig.setAlipayPublicKey(aliOrderPayConfig.ALIPAY_PUBLIC_KEY);
        alipayConfig.setSignType("RSA2");
        AlipayTradeAppPayResponse response = null;

        try {
            //构造client
            AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);
            AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
            /*设置通知地址*/
            request.setNotifyUrl("");
            /*设置回调地址*/
            request.setReturnUrl(aliOrderPayConfig.RETURN_URL);
            JSONObject bizContent = new JSONObject();
            /*设置自定义的值*/
            bizContent.put("out_trade_no",orderId);//商户网站唯一订单号  out_trade_no
            bizContent.put("total_amount",amount);//该笔订单的资金总额,单位为人民币(元),取值范围为 0.01~100000000.00,精确到小数点后两位
            bizContent.put("subject", "后台系统调用支付宝网页接口");//订单标题
            request.setBizContent(bizContent.toString());
            response = alipayClient.sdkExecute(request);
        } catch (AlipayApiException e) {
            log.error("调用支付宝失败");
        }

        if(response.isSuccess()){
            System.out.println("调用成功"+response);
            System.out.println(response.getBody());

        } else {
            System.out.println("调用失败");
        }

        return response.getBody();
    }
    }

 

标签:支付宝,网页,request,bizContent,public,alipayConfig,沙箱,response,out
From: https://www.cnblogs.com/Lcch/p/16586678.html

相关文章