foodie-shop/wxpay.html

246 lines
10 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport"
content="width=device-width, initial-scale=1.0 ,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>天天吃货 - 微信支付</title>
<link rel="shortcut icon" href="img/foodie.ico" />
<link rel="stylesheet" href="css/wxpay.css" />
<script src="AmazeUI-2.4.2/assets/js/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.9/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body class="body">
<div id="wxpay" class="container">
<div class="hd">
<div class="hd-main">
<div class="ep-hd-info">
<div class="ep-logo">
<img src="images/logobig.png" alt="慕课网 - 天天吃货" />
</div>
<div class="ep-order-status">
<!-- <h1>订单支付</h1> -->
<span class="page-title">订单支付</span>
</div>
</div>
<div class="user-info">
<p>账号:{{ userInfo.nickname }}</p>
</div>
</div>
</div>
<div class="bd">
<div class="bd-main">
<div class="ep-wrapper">
<div class="ep-pay-step ep-step-channel bd-main-container" style="display: block;">
<div class="ep-order-detail">
<div>
<div class="ep-order-tit">
<dl>
<dt>商品订单:</dt>
<dd>{{orderId}}</dd>
</dl>
</div>
<div class="ep-order-tit">
<span>支付金额:<em class="rmb"><i>¥</i>{{paymentInfo.amount / 100}}</em></span>
</div>
</div>
</div>
<div class="ep-pay-method ep-pay-methods">
<dl>
<span class="pay-method">
<dt class="pay-words">支付方式:</dt>
<div class="ep-pay-method-list-tit">
<ul>
<li class="selected" data-type="wechat" title="微信支付">
<span class="ep-icon ep-icon-wxpay"></span>
<span class="ep-pay-method-name">微信支付</span>
<i class="ep-icon ep-icon-selected"></i>
</li>
</ul>
</div>
</span>
<dd class="pay-channel ">
<div class="ep-pay-method-list-con">
<div class="con channel-wechat show">
<div class="clearfix">
<div class="fl">
<div class="ep-wxpay-qrcode-wrap">
<div id="wxqrcode-display" style="margin-bottom: 10px;"></div>
<!-- <img src="" height="200" width="200" class="ep-wxpay-qrcode" /> -->
</div>
<div class="ep-wxpay-qrcode-notice">
请打开手机微信,扫一扫完成支付
</div>
</div>
<div class="fl ep-wxpay-qrcode-tip">
<img src="img/ep_sys_wx_tip.jpg" />
</div>
</div>
</div>
</div>
</dd>
</dl>
</div>
</div>
</div>
</div>
</div>
<div class="ft">
<div class="ft-main">
<div class="copyright">
<p>
© 2019 imooc.com 京ICP备12003892号-11 北京奥鹏文化传媒有限公司
版权所有
</p>
<p>本服务由慕课网 - 天天吃货提供</p>
</div>
</div>
</div>
</div>
<script type="text/javascript " src="js/app.js"></script>
<script src="js/jquery.qrcode.min.js" type="text/javascript"></script>
<script type="text/javascript">
var index = new Vue({
el: "#wxpay",
data: {
userIsLogin: false,
userInfo: {},
orderId: null,
paymentInfo: [],
},
created() {
// var me = this;
// 通过cookie判断用户是否登录
this.judgeUserLoginStatus();
// 获得订单号
var orderId = app.getUrlParam("orderId");
// 如果orderId为空跳转到错误页面
if (orderId == null || orderId == undefined || orderId == '') {
app.goErrorPage();
return;
}
this.orderId = orderId;
this.getWXPayQRCodeUrl(orderId);
// 每隔3秒调用后台方法查看订单是否已经支付成功
this.setTimer();
},
methods: {
setTimer() {
return setInterval(()=>{
this.checkPayResult()
}, 3000)
},
// 查询是否支付成功
checkPayResult() {
var orderId = this.orderId;
// console.log(orderId);
// 查询订单是否成功
var userInfo = this.userInfo;
// 发起请求获得微信支付扫描二维码
var serverUrl = app.serverUrl;
axios.defaults.withCredentials = true;
axios.post(
serverUrl + '/orders/getPaidOrderInfo?orderId=' + orderId,
{},
{
headers: {
'headerUserId': userInfo.id,
'headerUserToken': userInfo.userUniqueToken
}
})
.then(res => {
if (res.data.status == 200) {
var orderStatus = res.data.data;
// console.log(orderStatus);
if (orderStatus.orderStatus == 20) {
window.location.href = "success.html?orderId=" + orderId + "&orderAmount=" + this.paymentInfo.amount;
}
} else {
alert(res.data.msg);
}
});
},
getWXPayQRCodeUrl(orderId) {
var userInfo = this.userInfo;
// 发起请求获得微信支付扫描二维码
var paymentServerUrl = app.paymentServerUrl;
axios.defaults.withCredentials = true;
axios.post(
paymentServerUrl + '/payment/getWXPayQRCode?merchantUserId=' + userInfo.id + "&merchantOrderId=" + orderId,
{},
{
headers: {
'imoocUserId': "imooc",
'password': "imooc"
}
})
.then(res => {
if (res.data.status == 200) {
var paymentInfo = res.data.data;
this.paymentInfo = paymentInfo;
// qrCodeUrl
// console.log(paymentInfo);
$('#wxqrcode-display').qrcode({
width: 200,
height:200,
text: paymentInfo.qrCodeUrl
});
} else {
alert(res.data.msg);
}
});
},
// 通过cookie判断用户是否登录
judgeUserLoginStatus() {
var userCookie = app.getCookie("user");
if (
userCookie != null &&
userCookie != undefined &&
userCookie != ""
) {
var userInfoStr = decodeURIComponent(userCookie);
// console.log(userInfo);
if (
userInfoStr != null &&
userInfoStr != undefined &&
userInfoStr != ""
) {
var userInfo = JSON.parse(userInfoStr);
// 判断是否是一个对象
if ( typeof(userInfo) == "object" ) {
this.userIsLogin = true;
// console.log(userInfo);
this.userInfo = userInfo;
} else {
this.userIsLogin = false;
this.userInfo = {};
}
}
} else {
this.userIsLogin = false;
this.userInfo = {};
}
}
}
});
</script>
</body>
</html>