页面调用支付宝支付

 
  
1.config配置
public class AlipayConfig {
    // 商户appid
    public static String APPID = "";
    // 私钥 pkcs8格式的
    public static String RSA_PRIVATE_KEY = "";
    // 服务器异步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
    public static String notify_url = "";
    // 页面跳转同步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 商户可以自定义同步跳转地址
    public static String return_url = "";
    // 请求网关地址
    public static String URL = "https://openapi.alipay.com/gateway.do";
    // 编码
    public static String CHARSET = "UTF-8";
    // 返回格式
    public static String FORMAT = "json";
    // 支付宝公钥
    public static String ALIPAY_PUBLIC_KEY = "";
    // RSA2
    public static String SIGNTYPE = "RSA2";
}

2.接口
/**
 * 支付宝支付接入H5
 */
@Controller
@RequestMapping("/aliPay")
public class AliPayH5 {
    /**
     * 调用支付宝
     * @param request
     * @return
     */
    @RequestMapping("/toPay")
    public String pay(HttpServletRequest request, Model model){
        String rechargeNo = "";//订单号
        String body = "";//描述(可空)
        String subject = "";//订单名称
        String amount = "";//金额
        //rechargeNo = request.getParameter("rechargeNo");
        body = "";
        //subject = request.getParameter("subject");
        //amount = request.getParameter("amount");
        String timeout = "60m";//超时时间
        String productCode = "";//销售产品码
        //调用RSA签名方式
        AlipayClient client = new DefaultAlipayClient(
            AlipayConfig.gateWay,
            AlipayConfig.partner,
            AlipayConfig.private_key,
            AlipayConfig.format,
            AlipayConfig.input_charset,
            AlipayConfig.alipay_public_key,
            AlipayConfig.sign_type);


        AlipayTradeWapPayRequest aliPayRequest = new AlipayTradeWapPayRequest();
        // 封装请求支付信息
        AlipayTradeWapPayModel atw = new AlipayTradeWapPayModel();
        atw.setOutTradeNo(rechargeNo);
        atw.setSubject(subject);
        atw.setTotalAmount(amount);
        atw.setBody(body);
        atw.setTimeoutExpress(timeout);
        atw.setProductCode(productCode);
        aliPayRequest.setBizModel(atw);
        // 设置异步通知地址
        aliPayRequest.setNotifyUrl(AlipayConfig.notify_url);
        //设置同步地址
        aliPayRequest.setReturnUrl(AlipayConfig.return_url);
        // form表单生产
        String form = "";

        // 调用SDK生成表单
        try {
            form = client.pageExecute(aliPayRequest).getBody();
            model.addAttribute("form",form);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "alipay/pay";
    }

}


你可能感兴趣的:(页面调用支付宝支付)