支付宝支付后端开发

2018-06-28 14:39:00    admin    628    原创
摘要:支付宝支付后端开发

1、支付宝支付后端开发

 @RequestMapping(value ="/payMoney",method = RequestMethod.GET)
    @ResponseBody
    public void payMoney(HttpServletResponse httpResponse, @RequestParam("orderNo") String orderNo) throws Exception {
        SysAomaoTrade sysAomaoTrade=sysAomaoTradeService.queryObjectByOrderNo(orderNo);
        if(null==sysAomaoTrade){
            logger.info("订单号不存在:"+orderNo);
            return;
        }
        AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
        //设置请求参数
        AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
        alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
        //商户订单号,商户网站订单系统中唯一订单号,必填
        String out_trade_no = sysAomaoTrade.getOrderNo();
        //付款金额,必填
        String total_amount = "0.01";
        //订单名称,必填
        String subject = "abc";
        //商品描述,可空
        String body = "abc";
        alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
                + "\"total_amount\":\""+ total_amount +"\","
                + "\"subject\":\""+ subject +"\","
                + "\"body\":\""+ body +"\","
                + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
        //请求
        String form="";
        try {
            //调用SDK生成表单
            form = alipayClient.pageExecute(alipayRequest).getBody();
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
        //输出
        httpResponse.setContentType("text/html;charset=" + AlipayConfig.charset);
        //直接将完整的表单html输出到页面
        httpResponse.getWriter().write(form);
        httpResponse.getWriter().flush();
        httpResponse.getWriter().close();
    }
2、会打开一个新窗口,该窗口是支付宝的支付窗口



豫ICP备15006410号
蝉知 蝉知4.5.2