Showing
1 changed file
with
38 additions
and
28 deletions
@@ -146,42 +146,52 @@ if ($aliPayEL && $aliPayEL.length > 0 && $aliPayEL.data('href')) { | @@ -146,42 +146,52 @@ if ($aliPayEL && $aliPayEL.length > 0 && $aliPayEL.data('href')) { | ||
146 | }); | 146 | }); |
147 | } | 147 | } |
148 | 148 | ||
149 | -// 微信支付 | ||
150 | -function callpay(orderCode) { | 149 | +function getWechatPayData(orderCode) { |
151 | let jsApiParameters; | 150 | let jsApiParameters; |
152 | 151 | ||
152 | + $.ajax({ | ||
153 | + type: 'GET', | ||
154 | + url: '/cart/index/new/pay', | ||
155 | + data: { | ||
156 | + order_code: orderCode, | ||
157 | + payment: '22_platform', | ||
158 | + }, | ||
159 | + dataType: 'json', | ||
160 | + success: function(res) { | ||
161 | + if (res.code === 200) { | ||
162 | + jsApiParameters = res.data.jsApiParameters; | ||
163 | + jsApiCall(orderCode, jsApiParameters); | ||
164 | + } else { | ||
165 | + tip.show('微信支付调取失败'); | ||
166 | + } | ||
167 | + }, | ||
168 | + error: function() { | ||
169 | + tip.show('请刷新本页面,完成微信支付'); | ||
170 | + }, | ||
171 | + complete: function() { | ||
172 | + $loadingToast.addClass('hide'); | ||
173 | + } | ||
174 | + }); | ||
175 | +} | ||
176 | + | ||
177 | +// 微信支付 | ||
178 | +function callpay(orderCode) { | ||
153 | $loadingToast.removeClass('hide'); | 179 | $loadingToast.removeClass('hide'); |
154 | if (typeof WeixinJSBridge === 'undefined') { | 180 | if (typeof WeixinJSBridge === 'undefined') { |
155 | if (document.addEventListener) { | 181 | if (document.addEventListener) { |
156 | - document.addEventListener('WeixinJSBridgeReady', jsApiCall, false); | 182 | + document.addEventListener('WeixinJSBridgeReady', function() { |
183 | + getWechatPayData(orderCode); | ||
184 | + }, false); | ||
157 | } else if (document.attachEvent) { | 185 | } else if (document.attachEvent) { |
158 | - document.attachEvent('WeixinJSBridgeReady', jsApiCall); | ||
159 | - document.attachEvent('onWeixinJSBridgeReady', jsApiCall); | 186 | + document.attachEvent('WeixinJSBridgeReady', function() { |
187 | + getWechatPayData(orderCode); | ||
188 | + }); | ||
189 | + document.attachEvent('onWeixinJSBridgeReady', function() { | ||
190 | + getWechatPayData(orderCode); | ||
191 | + }); | ||
160 | } | 192 | } |
161 | } else { | 193 | } else { |
162 | - $.ajax({ | ||
163 | - type: 'GET', | ||
164 | - url: '/cart/index/new/pay', | ||
165 | - data: { | ||
166 | - order_code: orderCode, | ||
167 | - payment: '22_platform', | ||
168 | - }, | ||
169 | - dataType: 'json', | ||
170 | - success: function(res) { | ||
171 | - if (res.code === 200) { | ||
172 | - jsApiParameters = res.data.jsApiParameters; | ||
173 | - jsApiCall(orderCode, jsApiParameters); | ||
174 | - } else { | ||
175 | - tip.show('微信支付调取失败'); | ||
176 | - } | ||
177 | - }, | ||
178 | - error: function() { | ||
179 | - tip.show('请刷新本页面,完成微信支付'); | ||
180 | - }, | ||
181 | - complete: function() { | ||
182 | - $loadingToast.addClass('hide'); | ||
183 | - } | ||
184 | - }); | 194 | + getWechatPayData(orderCode); |
185 | } | 195 | } |
186 | } | 196 | } |
187 | 197 |
-
Please register or login to post a comment