电脑支付宝支付 vue.js+java

1.前台请求后台获得相应的地址参数,跳转URL 前台跳转支付页面

(1)前台   

window.document.location = "${ctxPath}/api/alipay.html?_batch=true&_type=alipayPay&_c="+_this.id;

(2)后台

	/**
	 * 生成跳转支付宝页面
	 */
	public String _$indexBatchAlipayPay() {
		Map<String, String> map = alipayPay();
		String from = map.get("form");
		if ("200".equals(map.get("status"))) {
			renderHtml(from);//返回渲染HTML页面
		} else {
			try {
				String path = request.getContextPath();
				String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
				basePath = basePath + "/member/order?type=route&key=123#/order/unpaid?_c=" + map.get("_c") + "&text=" + URLEncoder.encode(from, "UTF-8");
				response.sendRedirect(basePath);
				attr("text", from);
			} catch (Exception e) {
				e.printStackTrace();
				logger.error("[{}] [{}] [{}]", "生成跳转支付宝页面失败   请求消息-->" + map.toString(), "<异常-->", e);
			}
		}
		return null;
	}

	/**
	 * 生成跳转支付宝页面
	 * 
	 * @author: hjj
	 * @date: 2018年1月30日 上午11:52:28
	 * @param: @return:
	 *             void @throws
	 */
	public Map<String, String> alipayPay() {
		Map<String, String> map = new HashMap<>();
		map.put("status", "404");
		map.put("_c", _c);
		if (!StringUtils.isBlank(_c)) {
			Members members = getMembers();
			OrderForm orderForm = orderFormService.queryCodeObject(_c);
			if (orderForm == null || isDel(orderForm) || !Constants.ORDER_FORM_STATUS_BUY_UNPAID.equals(orderForm.getStatus())) {//
				map.put("form", "未找到未支付订单");
				return map;
			}
			if (orderForm.getMembersId() == null || !members.getId().equals(orderForm.getMembersId().getId())) {
				map.put("form", "未找到用户未支付订单");
				return map;
			}
			RouteInfor routeId = routeInforService.getById(orderForm.getRouteId().getId());
			RLock lock = null;
			// 锁库存
			try {
				lock = CacheFactory.build(CacheFactory.REDIS).getRLock(Constants.ROUTE_QUOTA_RLOCK + orderForm.getRouteId().getId());
				if (Constants.IS_TRUE.equals(routeId.getIsScareBuying())) {// 抢购活动
					Boolean boo = routeInforService.judgeScareBuying(routeId.getBuyingStartDate(), routeId.getBuyingEndDate(), new Date());
					if (!boo) {// 不在抢购时间内
						map.put("form", "抢购时间已过!");
						return map;
					}
				}

				int quota = routeId.getQuota() == null ? 0 : routeId.getQuota();
				int pendingQuota = routeId.getPendingQuota() == null ? 0 : routeId.getPe
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的Spring Boot和Vue.js应用程序中的支付宝沙箱支付代码示例: 在Spring Boot项目中: 1. 添加以下依赖: ``` <dependency> <groupId>com.alipay.sdk</groupId> <artifactId>alipay-sdk-java</artifactId> <version>4.3.0.ALL</version> </dependency> ``` 2. 创建一个支付宝配置信息的类,例如: ``` @Configuration public class AlipayConfig { private String appId; private String privateKey; private String publicKey; private String notifyUrl; private String returnUrl; private String gatewayUrl; // getters and setters } ``` 3. 创建一个返回AlipayClient的方法: ``` @Bean public AlipayClient getAlipayClient() { return new DefaultAlipayClient( alipayConfig.getGatewayUrl(), alipayConfig.getAppId(), alipayConfig.getPrivateKey(), "json", "UTF-8", alipayConfig.getPublicKey(), "RSA2" ); } ``` 4. 在控制器中创建支付接口,例如: ``` @Autowired private AlipayClient alipayClient; @Autowired private AlipayConfig alipayConfig; @PostMapping("/pay") public String pay(@RequestParam String orderNo, @RequestParam String amount) throws AlipayApiException { AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest(); alipayRequest.setReturnUrl(alipayConfig.getReturnUrl()); alipayRequest.setNotifyUrl(alipayConfig.getNotifyUrl()); alipayRequest.setBizContent("{\"out_trade_no\":\"" + orderNo + "\"," + "\"total_amount\":\"" + amount + "\"," + "\"subject\":\"" + "测试订单" + "\"," + "\"body\":\"" + "测试订单" + "\"," + "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}"); String form = alipayClient.pageExecute(alipayRequest).getBody(); return form; } ``` 在Vue.js中: 1. 创建一个按钮来启动支付流程: ``` <template> <div> <button @click="pay">Pay Now</button> </div> </template> ``` 2. 在脚本部分中创建一个调用支付接口的方法: ``` <script> export default { methods: { pay() { axios.post('/api/pay', { orderNo: '123456', amount: '0.01' }) .then(response => { let form = response.data; document.write(form); // 打开支付页面 }) .catch(error => { console.log(error); }); } } } </script> ``` 请注意,以上示例只适用于测试环境,如果您想在生产环境中使用支付宝支付,您需要进行更多的测试和配置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值