uni-app 安卓、iOS App拉起微信h5支付

第一步在manifest->安卓/iOS常用其他设置

设置安卓、iOS的 UrlSchemes:

UrlSchemes: www.xxx.com

注意:

1、UrlSchemes最好和域名一致,UrlSchemes去掉https://   加上https:// 会定向到浏览器

2、设置完成后需要重新打包基座,再用新基座进行调试

3、设置完成UrlSchemes后,在浏览器输入:www.xxx.com:// 可以打开app,说明UrlSchemes设置成功

第二步在支付逻辑中实现跳转:

const HTTP_H5_HOST = 'https://www.xxx.com'
// #ifdef APP-PLUS
	uni.hideLoading();
    let goPages = '/pages/goods/order_pay_status/index';
	let androidRedictUrl = encodeURIComponent(HTTP_H5_HOST + goPages +
						'&status=1&from=wxpay&orderno'+orderNo)
	let scheme = "www.xxx.com"
	let iosRedictUrl = encodeURIComponent(scheme + "://" + goPages +
							'&status=1&from=wxpay&orderno'+orderNo)
	const androidPath = jsConfig.h5Url + '&redirect_url=' + androidRedictUrl;
	const iosPath = jsConfig.h5Url + '&redirect_url=' + iosRedictUrl;
	const platform = uni.getSystemInfoSync().platform;
	const webview = plus.webview.create('',HTTP_H5_HOST);
	switch(platform){
		case 'android':
			webview.loadURL(androidPath,{'Referer':HTTP_H5_HOST});
			 break;
		case 'ios':
			//iOS的referer需要用scheme方式,不然微信会返回到safari浏览器
			 webview.loadURL(iosPath,{'Referer':scheme});
			 break;
		default:
			 webview.loadURL(androidPath,{'Referer':HTTP_H5_HOST});
			break;
	}
    // 监听web
	webview.addEventListener('loaded',()=>{
		setTimeout(()=>{
			that.$refs.payPopup.open()
		},2000)
	},false)
			   
// #endif

第三步:弹窗样式:

<uni-popup ref="payPopup" type="center">
	<view class="payPopup">
		<view class="popup-title">
			请确认微信支付是否已完成
		</view>
		<view class="popup-subtext" @click="wechatPayFinish()" >
			已完成支付
		</view>
		<view class="popup-canceltext" @click="wechatPayCancel()">
			支付遇到问题,重新支付
		</view>
	</view>
</uni-popup>

第四步:点击‘已完成支付’检测订单状态

// 微信已完成支付
wechatPayFinish(){
	let that = this
	that.$refs.payPopup.close()
	wechatQueryPayResult(that.orderNo).then(res => {
		let url = '/pages/goods/order_pay_status/index?order_id=' + that.orderNo +
						'&msg=支付成功';
		uni.showToast({
			title: "支付成功"
		})
		setTimeout(res => {
			uni.redirectTo({
				url: url
			})
        }, 2000)
     }).catch(err => {
	    uni.hideLoading();
	    return that.$util.Tips({
		  title: err
	    });
     })
},

H5调起支付_H5支付|微信支付合作伙伴文档中心

https://juejin.cn/post/7383894869398388774

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值