230921整合支付宝支付

整合支付宝支付

  • 1. 官网
  • 支付宝支付

1. 官网

电脑网站支付
电脑网站支付文档
230921整合支付宝支付_第1张图片

支付宝支付

电商平台参考: 整合微信支付

web接口

	/**
	 *
	 * @Description: 前往支付宝进行支付
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="/goAlipay")
	public IMOOCJSONResult goAlipay(String merchantOrderId, String merchantUserId) throws Exception{

		// 查询订单详情
		Orders waitPayOrder = paymentOrderService.queryOrderByStatus(merchantUserId, merchantOrderId, PaymentStatus.WAIT_PAY.type);

		//获得初始化的AlipayClient
		AlipayClient alipayClient = new DefaultAlipayClient(aliPayResource.getGatewayUrl(),
															aliPayResource.getAppId(),
															aliPayResource.getMerchantPrivateKey(),
															"json",
															aliPayResource.getCharset(),
															aliPayResource.getAlipayPublicKey(),
															aliPayResource.getSignType());

		//设置请求参数
		AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
		alipayRequest.setReturnUrl(aliPayResource.getReturnUrl());
		alipayRequest.setNotifyUrl(aliPayResource.getNotifyUrl());

		// 商户订单号, 商户网站订单系统中唯一订单号, 必填
		String out_trade_no = merchantOrderId;
		// 付款金额, 必填 单位元
		String total_amount = CurrencyUtils.getFen2YuanWithPoint(waitPayOrder.getAmount());
//    	String total_amount = "0.01";	// 测试用 1分钱
		// 订单名称, 必填
		String subject = "天天吃货-付款用户[" + merchantUserId + "]";
		// 商品描述, 可空, 目前先用订单名称
		String body = subject;

		// 该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m。
		String timeout_express = "1d";

		alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
				+ "\"total_amount\":\""+ total_amount +"\","
				+ "\"subject\":\""+ subject +"\","
				+ "\"body\":\""+ body +"\","
				+ "\"timeout_express\":\""+ timeout_express +"\","
				+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");

		//若想给BizContent增加其他可选请求参数, 以增加自定义超时时间参数timeout_express来举例说明
		//alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
		//		+ "\"total_amount\":\""+ total_amount +"\","
		//		+ "\"subject\":\""+ subject +"\","
		//		+ "\"body\":\""+ body +"\","
		//		+ "\"timeout_express\":\"10m\","
		//		+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
		//请求参数可查阅【电脑网站支付的API文档-alipay.trade.page.pay-请求参数】章节

		//请求
		String alipayForm = "";
		try {
			alipayForm = alipayClient.pageExecute(alipayRequest).getBody();
		} catch (AlipayApiException e) {
			e.printStackTrace();
		}

		log.info("支付宝支付 - 前往支付页面, alipayForm: \n{}", alipayForm);

		return IMOOCJSONResult.ok(alipayForm);
	}

你可能感兴趣的:(Java架构师0到1(mkw),java,阿里云)