-
Notifications
You must be signed in to change notification settings - Fork 5
/
wxpay.html
207 lines (193 loc) · 8.61 KB
/
wxpay.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!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/[email protected]/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="img/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" v-if="paymentInfo.total_fee">
<i>¥</i>{{paymentInfo.total_fee / 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="paymentInfo.qrcode" 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>
</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() {
// 通过cookie判断用户是否登录
app.judgeUserLoginStatus(this);
// 获得订单号
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 + '/pay/getPaidOrderInfo?payjsOrderId=' + this.paymentInfo.payjs_order_id,
{},
{
headers: {
'headerUserId': userInfo.id,
'headerUserToken': userInfo.userUniqueToken
}
})
.then(res => {
if (res.data.status == 200) {
var orderStatus = res.data.data;
// console.log(orderStatus);
if (orderStatus.status == 1) {
window.location.href = "success.html?orderId=" + orderId + "&orderAmount=" + this.paymentInfo.total_fee;
}
} else {
alert(res.data.msg);
window.location.href = "index.html"
}
});
},
getWXPayQRCodeUrl(orderId) {
var userInfo = this.userInfo;
// 发起请求获得微信支付扫描二维码
var serverUrl = app.serverUrl;
axios.defaults.withCredentials = true;
axios.post(
serverUrl + '/pay/getWXPayQRCode?userId=' + userInfo.id + "&orderId=" + orderId,
{},
{
headers: {
'imoocUserId': "imooc",
'password': "imooc"
}
})
.then(res => {
if (res.data.status == 200) {
var paymentInfo = res.data.data;
this.paymentInfo = paymentInfo;
} else {
alert(res.data.msg);
}
});
},
}
});
</script>
</body>
</html>