uniapp app端使用webview 跳转外部链接后,返回app端。(stripe pay 支付)

1 篇文章 0 订阅
1 篇文章 0 订阅

项目需求:app使用webview打开stripe pay支付页面,支付成功或失败的回调地址必须是网络地址,所以需要在回调的网络地址页面跳转回app。

1、在下单页面跳转到webview页面,携带stripe pay 支付链接

// #ifdef APP
uni.redirectTo({
	url: '/pages/payment/webview?stripeURL='+res.data.text
})
// #endif

2、新建webview页面,接收传递过来的stripeURL

<template>
	<view>
		<web-view :src="props.stripeURL"></web-view>
	</view>
</template>

<script setup>
	const props = defineProps({
		stripeURL: ''
	})
</script>

3、新建PayClosed.html,作为中间页跳回app

<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<!--强制浏览器以竖屏的布局来显示页面,缩放比例为1,最小缩放值为1,最大缩放值为1,用户缩放设置为不允许-->
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<!--<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />-->
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<!-- 删除苹果默认的工具栏和菜单栏 -->
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<!-- 设置苹果工具栏颜色 -->
		<meta name="format-detection" content="telephone=no, email=no" />
		<!-- 忽略页面中的数字识别为电话,忽略email识别 -->
		<!-- 启用360浏览器的极速模式(webkit) -->
		<meta name="renderer" content="webkit">
		<!-- 避免IE使用兼容模式 -->
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<!-- 针对手持设备优化,主要是针对一些老的不识别viewport的浏览器,比如黑莓 -->
		<meta name="HandheldFriendly" content="true">
		<!-- 微软的老式浏览器 -->
		<meta name="MobileOptimized" content="320">
		<!-- uc强制竖屏 -->
		<!--<meta name="screen-orientation" content="portrait">-->
		<!-- QQ强制竖屏 -->
		<meta name="x5-orientation" content="portrait">
		<!-- UC强制全屏 -->
		<!--<meta name="full-screen" content="yes">-->
		<!-- QQ强制全屏 -->
		<meta name="x5-fullscreen" content="true">
		<!-- UC应用模式 -->
		<meta name="browsermode" content="application">
		<!-- QQ应用模式 -->
		<meta name="x5-page-mode" content="app">
		<!-- windows phone 点击无高光 -->
		<meta name="msapplication-tap-highlight" content="no">
		<title>關閉支付頁面</title>
	</head>
	<body>
		<p class="test"><span id="num"></span>s后自動關閉頁面或</p>
		<p id="test">點擊關閉頁面</p>
	</body>
</html>

<!-- uni 的 SDK,必须引用。 -->
<script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.1.js">
</script>
<script>
	var num = 3;
	document.addEventListener('UniAppJSBridgeReady', function() {
		document.getElementById("num").innerHTML = num
		var timer = setInterval(() => {
			if (num <= 0) {
				clearInterval(timer)
				return uni.redirectTo({
					url: '/pages/payment/CheckOut'
				});
			}
			num--
			document.getElementById("num").innerHTML = num
		}, 1000);

		document.getElementById('test').addEventListener('click', function(evt) {
			uni.redirectTo({
				url: '/pages/payment/CheckOut'
			});
		});
	});
</script>

<style>
	#test,
	.test {
		text-align: center;
		color: #dcc69e;
		font-size: 22px;
	}

	.test {
		margin-top: 100px;
	}
</style>

4、将PayClosed.html放到服务器上,然后在stripe pay 后台的支付回调那里填上这条链接地址就可以了

扫码加q群
在这里插入图片描述

  • 9
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值