com.alipay.api.request.AlipayTradePagePayRequest Java Examples

The following examples show how to use com.alipay.api.request.AlipayTradePagePayRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AlipayPagePayController.java    From springboot-pay-example with Apache License 2.0 6 votes vote down vote up
@PostMapping("/gotoPayPage")
public void gotoPayPage(HttpServletResponse response) throws AlipayApiException, IOException {
    // 订单模型
    String productCode = "FAST_INSTANT_TRADE_PAY";
    AlipayTradePagePayModel model = new AlipayTradePagePayModel();
    model.setOutTradeNo(UUID.randomUUID().toString());
    model.setSubject("支付测试");
    model.setTotalAmount("0.01");
    model.setBody("支付测试,共0.01元");
    model.setProductCode(productCode);

    AlipayTradePagePayRequest pagePayRequest =new AlipayTradePagePayRequest();
    pagePayRequest.setReturnUrl("http://s9v2cw.natappfree.cc/alipay/page/returnUrl");
    pagePayRequest.setNotifyUrl(alipayProperties.getNotifyUrl());
    pagePayRequest.setBizModel(model);

    // 调用SDK生成表单, 并直接将完整的表单html输出到页面
    String form = alipayClient.pageExecute(pagePayRequest).getBody();
    response.setContentType("text/html;charset=" + alipayProperties.getCharset());
    response.getWriter().write(form);
    response.getWriter().flush();
    response.getWriter().close();
}
 
Example #2
Source File: AlipayConfigServiceImpl.java    From yshopmall with Apache License 2.0 5 votes vote down vote up
@Override
public String toPayAsPc(AlipayConfig alipay, TradeVo trade) throws Exception {

    if(alipay.getId() == null){
        throw new BadRequestException("请先添加相应配置,再操作");
    }
    AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppId(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());

    // 创建API对应的request(电脑网页版)
    AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

    // 订单完成后返回的页面和异步通知地址
    request.setReturnUrl(alipay.getReturnUrl());
    request.setNotifyUrl(alipay.getNotifyUrl());
    // 填充订单参数
    request.setBizContent("{" +
            "    \"out_trade_no\":\""+trade.getOutTradeNo()+"\"," +
            "    \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," +
            "    \"total_amount\":"+trade.getTotalAmount()+"," +
            "    \"subject\":\""+trade.getSubject()+"\"," +
            "    \"body\":\""+trade.getBody()+"\"," +
            "    \"extend_params\":{" +
            "    \"sys_service_provider_id\":\""+alipay.getSysServiceProviderId()+"\"" +
            "    }"+
            "  }");//填充业务参数
    // 调用SDK生成表单, 通过GET方式,口可以获取url
    return alipayClient.pageExecute(request, "GET").getBody();

}
 
Example #3
Source File: AliPayServiceImpl.java    From eladmin with Apache License 2.0 5 votes vote down vote up
@Override
public String toPayAsPc(AlipayConfig alipay, TradeVo trade) throws Exception {

    if(alipay.getId() == null){
        throw new BadRequestException("请先添加相应配置,再操作");
    }
    AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppId(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());

    // 创建API对应的request(电脑网页版)
    AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

    // 订单完成后返回的页面和异步通知地址
    request.setReturnUrl(alipay.getReturnUrl());
    request.setNotifyUrl(alipay.getNotifyUrl());
    // 填充订单参数
    request.setBizContent("{" +
            "    \"out_trade_no\":\""+trade.getOutTradeNo()+"\"," +
            "    \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," +
            "    \"total_amount\":"+trade.getTotalAmount()+"," +
            "    \"subject\":\""+trade.getSubject()+"\"," +
            "    \"body\":\""+trade.getBody()+"\"," +
            "    \"extend_params\":{" +
            "    \"sys_service_provider_id\":\""+alipay.getSysServiceProviderId()+"\"" +
            "    }"+
            "  }");//填充业务参数
    // 调用SDK生成表单, 通过GET方式,口可以获取url
    return alipayClient.pageExecute(request, "GET").getBody();

}
 
Example #4
Source File: AliPayServiceImpl.java    From albedo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String toPayAsPc(AlipayConfig alipay, TradeVo trade) throws Exception {

	if (alipay.getId() == null) {
		throw new BadRequestException("请先添加相应配置,再操作");
	}
	AlipayClient alipayClient = new DefaultAlipayClient(alipay.getGatewayUrl(), alipay.getAppId(), alipay.getPrivateKey(), alipay.getFormat(), alipay.getCharset(), alipay.getPublicKey(), alipay.getSignType());

	// 创建API对应的request(电脑网页版)
	AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();

	// 订单完成后返回的页面和异步通知地址
	request.setReturnUrl(alipay.getReturnUrl());
	request.setNotifyUrl(alipay.getNotifyUrl());
	// 填充订单参数
	request.setBizContent("{" +
		"    \"out_trade_no\":\"" + trade.getOutTradeNo() + "\"," +
		"    \"product_code\":\"FAST_INSTANT_TRADE_PAY\"," +
		"    \"total_amount\":" + trade.getTotalAmount() + "," +
		"    \"subject\":\"" + trade.getSubject() + "\"," +
		"    \"body\":\"" + trade.getBody() + "\"," +
		"    \"extend_params\":{" +
		"    \"sys_service_provider_id\":\"" + alipay.getSysServiceProviderId() + "\"" +
		"    }" +
		"  }");//填充业务参数
	// 调用SDK生成表单, 通过GET方式,口可以获取url
	return alipayClient.pageExecute(request, "GET").getBody();

}
 
Example #5
Source File: PaymentController.java    From express-ssm with Apache License 2.0 4 votes vote down vote up
/**
 * 支付宝支付方式
 * @param money 支付金额
 * @author jitwxs
 * @since 2018/5/14 8:53
 */
@PostMapping("/alipay")
public void paymentAlipay(Double money, HttpSession session, HttpServletResponse response) throws IOException {
    Express express = (Express)session.getAttribute(SESSION_LATEST_EXPRESS);

    if(express == null || money == null) {
        response.getWriter().write("参数错误,请重新下单");
    }

    // 金额保留两位
    money = (double) (Math.round(money * 100)) / 100;

    // 生成订单
    String expressId = expressService.createExpress(express);
    // 生成订单支付
    expressPaymentService.createAliPayment(expressId, money, aliPaySetting.getSellerId());

    // 1、设置请求参数
    AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
    // 页面跳转同步通知页面路径
    alipayRequest.setReturnUrl(aliPaySetting.getReturnUrl());
    // 服务器异步通知页面路径
    alipayRequest.setNotifyUrl(aliPaySetting.getNotifyUrl());

    // 2、SDK已经封装掉了公共参数,这里只需要传入业务参数,请求参数查阅开头Wiki
    Map<String,String> map = new HashMap<>(16);
    map.put("out_trade_no", expressId);
    map.put("total_amount", String.valueOf(money));
    map.put("subject", "快递代拿");
    map.put("body", "快递代拿在线支付");
    // 销售产品码
    map.put("product_code","FAST_INSTANT_TRADE_PAY");

    alipayRequest.setBizContent(JsonUtils.objectToJson(map));

    response.setContentType("text/html;charset=utf-8");
    try{
        // 3、生成支付表单
        AlipayTradePagePayResponse alipayResponse = alipayClient.pageExecute(alipayRequest);
        if(alipayResponse.isSuccess()) {
            String result = alipayResponse.getBody();
            response.getWriter().write(result);
        } else {
            response.getWriter().write("error");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #6
Source File: PayController.java    From blog-sample with Apache License 2.0 4 votes vote down vote up
/**
 * 支付宝支付
 * 该方法无返回值,执行成功后response回写结果即可
 * @param subject 订单名称
 * @param body 订单描述
 * @param money 支付金额
 * @author jitwxs
 * @since 2018/6/4 14:00
 */
@PostMapping("/alipay/payment")
public void payment(String subject, String body, float money, HttpServletResponse response) {
    // 金额保留两位
    money = (float) (Math.round(money * 100)) / 100;

    // 生成订单
    OrderInfo orderInfo = orderInfoService.createOrder(subject, body, money, aliPayConfig.getSellerId());

    // 1、设置请求参数
    AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
    // 页面跳转同步通知页面路径
    alipayRequest.setReturnUrl(aliPayConfig.getReturnUrl());
    // 服务器异步通知页面路径
    alipayRequest.setNotifyUrl(aliPayConfig.getNotifyUrl());

    // 2、SDK已经封装掉了公共参数,这里只需要传入业务参数,请求参数查阅开头Wiki
    Map<String,String> map = new HashMap<>(16);
    map.put("out_trade_no", orderInfo.getOrderId());
    map.put("total_amount", String.valueOf(money));
    map.put("subject", subject);
    map.put("body",body);
    // 销售产品码
    map.put("product_code","FAST_INSTANT_TRADE_PAY");

    alipayRequest.setBizContent(JsonUtils.objectToJson(map));

    response.setContentType("text/html;charset=utf-8");
    try{
        // 3、生成支付表单
        AlipayTradePagePayResponse alipayResponse = alipayClient.pageExecute(alipayRequest);
        if(alipayResponse.isSuccess()) {
            String result = alipayResponse.getBody();
            response.getWriter().write(result);
        } else {
            log.error("【支付表单生成】失败,错误信息:{}", alipayResponse.getSubMsg());
            response.getWriter().write("error");
        }
    } catch (Exception e) {
        log.error("【支付表单生成】异常,异常信息:{}", e.getMessage());
        e.printStackTrace();
    }
}
 
Example #7
Source File: PagePayChain.java    From alipay with Apache License 2.0 3 votes vote down vote up
/**
 * Generate Payment Page
 * <p>
 * 生成支付页面
 *
 * @param returnUrl After the transaction is completed, the page will take the initiative to jump to the HTTP / HTTPS path specified in the merchant server
 *                  交易完成后页面主动跳转,商户服务器里指定的页面http/https路径
 * @param notifyUrl AliPay Server Initiatively Tells The Http/Https Path Specified In The Merchant Server.
 *                  支付宝服务器主动通知商户服务器里指定的页面http/https路径
 * @return pay
 * @throws AlipayApiException AlipayApiException
 */
public String pay(String returnUrl, String notifyUrl) throws AlipayApiException {
    AlipayTradePagePayRequest pagePayRequest = new AlipayTradePagePayRequest ();
    pagePayRequest.setReturnUrl (returnUrl);
    pagePayRequest.setNotifyUrl (notifyUrl);
    pagePayRequest.setBizModel (alipayTradePagePayModel);
    return alipayClient.pageExecute (pagePayRequest).getBody ();
}
 
Example #8
Source File: PagePayChain.java    From alipay with Apache License 2.0 2 votes vote down vote up
/**
 * Custom Build PayRequest
 * <p>
 * 自定义构建PayRequest
 *
 * @param pagePayRequest pagePayRequest
 * @return String
 * @throws AlipayApiException AlipayApiException
 */
public String pay(AlipayTradePagePayRequest pagePayRequest) throws AlipayApiException {
    pagePayRequest.setBizModel (alipayTradePagePayModel);
    return alipayClient.pageExecute (pagePayRequest).getBody ();
}