微信h5 支付,已经获得weixin://wap/pay?prepayid,但是无法调起微信客户端支付
程序员文章站
2024-03-22 23:05:04
...
结果几个接口,最终获得到到一直包含调起微信客户端的支付链接
但是直接打开这个页面,却不能调起微信客户端支付,原因是,在打开新页面的时候,需要设置 a.rel = "noreferrer";
<body>
<a href="javascript:void(0)" onclick="openNewWindowNoreferrer(this)">点击支付</a>
</body>
<script src="https://libs.cdnjs.net/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/aaa@qq.com/qrcode.js"></script>
<script type="text/javascript">
//判断是否是IE
function isIE() {
if (!!window.ActiveXObject || "ActiveXObject" in window)
return true;
else
return false;
}
//ie不带referer打开url,url要打开的链接,blankurl指向一个空页面
function ieNorefererOpen(url, blankurl) {
if (blankurl === undefined) {
//blankurl = null;
blankurl = "https://www.alipay.com/";
}
var win = window.open(blankurl, '_blank');
var doc = win.document;
doc.body.innerHTML='';
//doc.clear();
doc.write('<html><head><meta http-equiv="Refresh" content="0; URL=' + url + '"/><meta name="__hash__" content="a7f55f8c2998c0e892ee07994c6c48a6_7dc297b550c20b088c34f63cad13fea8" /></head><body></body></html>');
doc.close();
}
var full_link = "weixin:\/\/wap\/pay?prepayid%3Dwx021611457196396d56be1d871710454700\u0026package=328998914\u0026noncestr=1585815194\u0026sign=2144fbd3bd301771d574f2d5cb9aee89";
//在新的窗口不带referer打开链接,a超链接对象,full_link要打开的链掿
function openNewWindowNoreferrer(a) {
if (isIE()) {
a.rel = "noreferrer";
a.target = "_self";
ieNorefererOpen(full_link);
} else {
a.rel = "noreferrer";
a.target = "_blank";
a.href = full_link;
}
}
</script>
点击支付 链接会打开full_link 中的支付链接
上一篇: 【计算机视觉】Opencv编译采坑记录
下一篇: Shiro安全框架的使用