第一步在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
});
})
},
https://juejin.cn/post/7383894869398388774