1 Star 0 Fork 3

黑白/tfyun

forked from afan/tfyun 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
wxpay.html 3.29 KB
一键复制 编辑 原始数据 按行查看 历史
afan 提交于 2023-11-12 00:13 . 1
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>微信支付</title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
</head>
<body>
</body>
<script>
(function (){
var url = new URL(window.location.href);
if(url.searchParams.get("code")){
//重定向到payUrl
var map = JSON.parse(localStorage.getItem("searchData"));
var str = "";
for (var key in map){
str += key+"="+encodeURIComponent(map[key])+"&";
}
window.location.href = "/webos/commercial?"+str+"code="+url.searchParams.get("code");
}else if(url.searchParams.get("prepayId")){
//执行支付
const appId = url.searchParams.get("appId");
const timeStamp = url.searchParams.get("timeStamp");
const prepayId = url.searchParams.get("prepayId");
const paySign = url.searchParams.get("paySign");
const nonceStr = url.searchParams.get("nonceStr");
function onBridgeReady() {
WeixinJSBridge.invoke('getBrandWCPayRequest', {
"appId": appId, //公众号ID,由商户传入
"timeStamp": timeStamp, //时间戳,自1970年以来的秒数
"nonceStr": nonceStr, //随机串
"package": "prepay_id="+prepayId,
"signType": "RSA", //微信签名方式:
"paySign": paySign //微信签名
},
function(res) {
if (res.err_msg == "get_brand_wcpay_request:ok") {
alert("支付成功");
}
});
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
}
} else {
onBridgeReady();
}
}else{
//获取code
var fields = ["id"];
var keys = url.searchParams.keys();
var map = {};
while (true){
var keyData = keys.next();
if(keyData.done){
break;
}
var key = keyData.value;
if(!fields.includes(key)){
continue;
}
var value = url.searchParams.get(key);
map[key] = decodeURIComponent(value);
}
localStorage.setItem("searchData",JSON.stringify(map));
var ru = window.location.origin+window.location.pathname;
var appid = url.searchParams.get("appid");
var nu = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+appid+"&redirect_uri="+encodeURIComponent(ru)+"&response_type=code&scope=snsapi_base&state=1#wechat_redirect";
window.location.href = nu;
}
})()
</script>
</html>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
HTML
1
https://gitee.com/hztv/tfyun.git
git@gitee.com:hztv/tfyun.git
hztv
tfyun
tfyun
master

搜索帮助