Commit 6b286309f323d735bc1f75cb7609c9f6c7ace0b6
1 parent
3c184204
支付方式 -- 微信
Showing
4 changed files
with
179 additions
and
30 deletions
src/api/orderPay/orderPay.js
1 | 1 | import request from '@/utils/request' |
2 | 2 | |
3 | -export function aliPay(params) { | |
3 | +export function aliPay(params) { // 支付宝 | |
4 | 4 | return request({ |
5 | 5 | url: '/api/alipay/aliH5Pay', |
6 | 6 | method: 'post', |
... | ... | @@ -8,3 +8,22 @@ export function aliPay(params) { |
8 | 8 | }) |
9 | 9 | } |
10 | 10 | |
11 | + | |
12 | +export function getOpenId(params) { // 获取OpenId | |
13 | + return request({ | |
14 | + url: '/api//weixinPublicPay/getOpenIdByCode', | |
15 | + method: 'post', | |
16 | + data: params | |
17 | + }) | |
18 | +} | |
19 | + | |
20 | +export function vxPayQuery(params) { // 微信 | |
21 | + return request({ | |
22 | + url: '/api//weixinpay/publicUnifiedOrder', | |
23 | + method: 'post', | |
24 | + data: params | |
25 | + }) | |
26 | +} | |
27 | + | |
28 | + | |
29 | + | ... | ... |
src/components/orderPay.vue
... | ... | @@ -38,7 +38,8 @@ |
38 | 38 | </template> |
39 | 39 | |
40 | 40 | <script> |
41 | -import { aliPay } from '@/api/orderPay/orderPay' | |
41 | +import {aliPay, getOpenId, vxPayQuery} from '@/api/orderPay/orderPay' | |
42 | + | |
42 | 43 | export default { |
43 | 44 | name: 'orderPay', |
44 | 45 | data() { |
... | ... | @@ -46,9 +47,12 @@ export default { |
46 | 47 | carWrapBG: 0, |
47 | 48 | carNumber: '京A12312', |
48 | 49 | arrearageActFee: 0, |
49 | - arrearageDiscFee:0, | |
50 | - arrearageActFee:0, | |
51 | - clientBrowser:'', // 客户端 | |
50 | + arrearageDiscFee: 0, | |
51 | + arrearageActFee: 0, | |
52 | + clientBrowser: '', // 客户端 | |
53 | + paySrcType: '', //支付的类型 101 是本次 103是历史欠费 | |
54 | + orderId: '', //支付的订单 | |
55 | + webAppCode: '', // 微信code | |
52 | 56 | } |
53 | 57 | }, |
54 | 58 | created() { |
... | ... | @@ -58,32 +62,147 @@ export default { |
58 | 62 | this.arrearageDiscFee = this.$route.query.arrearageDiscFee // 优惠 |
59 | 63 | this.arrearageActFee = this.$route.query.arrearageActFee // 实收 |
60 | 64 | this.clientBrowser = this.$utils.clientBrowser() //支付方式 |
65 | + this.paySrcType = this.$route.query.paySrcType // 实收 | |
66 | + this.orderId = this.$route.query.ordeID | |
67 | + | |
68 | + if (this.clientBrowser == "微信") { | |
69 | + this.webAppCode = this.getCode(); | |
70 | + } | |
61 | 71 | }, |
62 | - methods:{ | |
63 | - toPay(){ | |
64 | - if(this.clientBrowser == '支付宝') { | |
72 | + methods: { | |
73 | + getCode() { | |
74 | + var appID = this.$utils.myVxAppId; | |
75 | + var code = this.$route.query.code | |
76 | + var local = window.location.href; | |
77 | + if (code == null || code === '') { | |
78 | + window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + appID + '&redirect_uri=' + encodeURIComponent(local) + '&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect' | |
79 | + } else { | |
80 | + return code; | |
81 | + } | |
82 | + }, | |
83 | + toPay() { | |
84 | + let me = this | |
85 | + let _order = [] | |
86 | + this.orderId = JSON.parse(this.orderId) | |
87 | + console.log(this.orderId) | |
88 | + if (this.paySrcType == 103) { | |
89 | + this.orderId.forEach(item => { | |
90 | + _order.push({ | |
91 | + orderId: item | |
92 | + }) | |
93 | + }) | |
94 | + this.orderId = [] | |
95 | + this.orderId = _order | |
96 | + } | |
97 | + | |
98 | + if (this.clientBrowser == '支付宝') { // 支付宝支付 | |
65 | 99 | var aliParams = {}; |
66 | - aliParams.orderId = orderID; | |
100 | + aliParams.orderId = this.orderId; | |
67 | 101 | aliParams.carNumber = this.carNumber; |
68 | 102 | aliParams.payType = 1;// 1:支付宝 2:微信 3:银联 10:H5 4微信公众号 |
69 | 103 | aliParams.terminalSource = 7;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 |
70 | - aliParams.paySrcType = _paySrcType;//101停车支付 | |
71 | - aliParams.orgId = '10003', | |
72 | - aliParams.backType=2, | |
73 | - // aliParams.recordArreaInfos = JSON.stringify([{ | |
74 | - // "orderId": webAppParams.orderId, | |
75 | - // "orderNotPayFee": _mon * 100, | |
76 | - // "parkId": getQueryString(window.location).parkCode | |
77 | - // }]); | |
78 | - | |
79 | - aliParams.recordArreaInfos = JSON.stringify(orderID); | |
104 | + aliParams.paySrcType = this.paySrcType;//101停车支付 | |
105 | + aliParams.orgId = this.$utils.myOrgId, | |
106 | + aliParams.backType = 2, | |
107 | + aliParams.recordArreaInfos = JSON.stringify(this.orderId); | |
108 | + | |
109 | + aliPay(aliParams).then(response => { | |
110 | + console.log(response) | |
111 | + if (response.code == 0) {//进场 | |
112 | + document.write(response.data);//打开支付表单 | |
113 | + } else {//其他情况如【该卡号场内已存在】 | |
114 | + console.log(response.message); | |
115 | + } | |
116 | + | |
117 | + }) | |
80 | 118 | } |
81 | 119 | |
120 | + if (this.clientBrowser == '微信') { // 微信支付 | |
121 | + //第一步获取openid | |
122 | + var codeParams = { | |
123 | + code: this.webAppCode, | |
124 | + appId: this.$utils.myVxAppId | |
125 | + }; | |
126 | + getOpenId(codeParams).then(res => { | |
127 | + if (res.code == 0) { | |
128 | + me.vxPay(res.data, this.orderId) | |
129 | + } else if (res.code == 40163) { //code been used, hints[重复code问题] | |
130 | + alert(res.message) | |
131 | + console.log(res.message); | |
132 | + } else { | |
133 | + alert(res.message) | |
134 | + } | |
135 | + }) | |
82 | 136 | |
83 | - } | |
137 | + } | |
138 | + | |
139 | + }, | |
140 | + vxPay(openIdData, orderIdData) { | |
141 | + var wxParams = {}; | |
142 | + wxParams.orderId = orderIdData; | |
143 | + wxParams.backType = 2, | |
144 | + wxParams.orgId = this.$utils.myOrgId, | |
145 | + wxParams.payType = 4;// 1:支付宝 2:微信 3:银联 10:H5 4微信公众号 | |
146 | + wxParams.terminalSource = 7;//请求端来源 1: 任你停 2:pda 3:微信公共号 7:H5扫码 10页面支付 | |
147 | + wxParams.carNumber = this.carNumber; | |
148 | + wxParams.paySrcType = this.paySrcType;//101停车支付 | |
149 | + wxParams.recordArreaInfos = JSON.stringify(orderIdData); | |
150 | + wxParams.openId = openIdData; | |
151 | + wxParams.appId = this.$utils.myVxAppId; | |
152 | + vxPayQuery(wxParams).then( res => { | |
153 | + if (res.code == 0) { // | |
154 | + //alertMsg("出场成功"); | |
155 | + if (res.data) { | |
156 | + var data = res.data; | |
157 | + console.log(JSON.stringify(data)); | |
158 | + if (typeof WeixinJSBridge === 'undefined') { // 微信浏览器内置对象。参考微信官方文档 | |
159 | + if (document.addEventListener) { | |
160 | + document.addEventListener('WeixinJSBridgeReady', vm.onBridgeReady(data), false) | |
161 | + } else if (document.attachEvent) { | |
162 | + document.attachEvent('WeixinJSBridgeReady', vm.onBridgeReady(data)) | |
163 | + document.attachEvent('onWeixinJSBridgeReady', vm.onBridgeReady(data)) | |
164 | + } | |
165 | + } else { | |
166 | + console.log('准备调用微信支付') | |
167 | + vm.onBridgeReady(data) | |
168 | + } | |
169 | + } else { | |
170 | + alert("没有找到返回值"); | |
171 | + } | |
172 | + } else { | |
173 | + console.log(res.message); | |
174 | + alert(res.message); | |
175 | + } | |
176 | + }) | |
177 | + }, | |
178 | + onBridgeReady (data) { | |
179 | + console.log('调用微信支付WeixinJSBridge') | |
180 | + var vm = this | |
181 | + WeixinJSBridge.invoke( | |
182 | + 'getBrandWCPayRequest', params, | |
183 | + // | |
184 | + // 'getBrandWCPayRequest', { // 下面参数内容都是后台返回的 | |
185 | + // 'appId': data.appId, // 公众号名称,由商户传入 | |
186 | + // 'timeStamp': data.timeStamp, // 时间戳 | |
187 | + // 'nonceStr': data.nonceStr, // 随机串 | |
188 | + // 'package': data.package, // 预支付id | |
189 | + // 'signType': data.signType, // 微信签名方式 | |
190 | + // 'paySign': data.paySign // 微信签名 | |
191 | + // }, | |
192 | + function (res) { | |
193 | + // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。 | |
194 | + if (res.err_msg === 'get_brand_wcpay_request:ok') { | |
195 | + console.log('成功') | |
196 | + } else { | |
197 | + console.log('失败') | |
198 | + alert('支付失败') | |
199 | + } | |
200 | + } | |
201 | + ) | |
202 | + }, | |
84 | 203 | }, |
85 | - filters:{ | |
86 | - formateColor(val){ | |
204 | + filters: { | |
205 | + formateColor(val) { | |
87 | 206 | switch (val) { |
88 | 207 | case '0': |
89 | 208 | return 'carBlue' |
... | ... | @@ -116,23 +235,28 @@ export default { |
116 | 235 | width: 100%; |
117 | 236 | height: 130px; |
118 | 237 | } |
119 | - .carBlue{ | |
238 | + | |
239 | + .carBlue { | |
120 | 240 | background: url("../assets/images/blueBG.png") no-repeat; |
121 | 241 | background-size: 100% 100%; |
122 | 242 | } |
123 | - .carYellow{ | |
243 | + | |
244 | + .carYellow { | |
124 | 245 | background: url("../assets/images/yellowBG.png") no-repeat; |
125 | 246 | background-size: 100% 100%; |
126 | 247 | } |
127 | - .carGreen{ | |
248 | + | |
249 | + .carGreen { | |
128 | 250 | background: url("../assets/images/greenBG.png") no-repeat; |
129 | 251 | background-size: 100% 100%; |
130 | 252 | } |
131 | - .carWhite{ | |
253 | + | |
254 | + .carWhite { | |
132 | 255 | background: url("../assets/images/whiteBG.png") no-repeat; |
133 | 256 | background-size: 100% 100%; |
134 | 257 | } |
135 | - .carBlack{ | |
258 | + | |
259 | + .carBlack { | |
136 | 260 | background: url("../assets/images/blackBG.png") no-repeat; |
137 | 261 | background-size: 100% 100%; |
138 | 262 | } |
... | ... | @@ -179,7 +303,8 @@ export default { |
179 | 303 | color: #FFF; |
180 | 304 | cursor: pointer; |
181 | 305 | } |
182 | - .tip{ | |
306 | + | |
307 | + .tip { | |
183 | 308 | padding-left: 40px; |
184 | 309 | background: url("../assets/images/free-tip.png") no-repeat 18px center; |
185 | 310 | background-size: 16px 16px; | ... | ... |
src/components/parkRecord.vue
... | ... | @@ -269,6 +269,7 @@ export default { |
269 | 269 | var salt = this.$utils.myCommonSalt(32); |
270 | 270 | |
271 | 271 | var list = "[" + this.orderIds + "]" |
272 | + | |
272 | 273 | // var orderlist = this.orderIds |
273 | 274 | // var codes = "[" + fun.parkCodes + "]" |
274 | 275 | // |
... | ... | @@ -305,6 +306,7 @@ export default { |
305 | 306 | console.log(response) |
306 | 307 | let res = response.data.carArrearages[0] |
307 | 308 | console.log(res) |
309 | + this.orderIds = JSON.stringify(this.orderIds) | |
308 | 310 | this.$router.push( |
309 | 311 | { |
310 | 312 | path:'orderPay', |
... | ... | @@ -313,7 +315,9 @@ export default { |
313 | 315 | arrearageTotalFee: res.arrearageTotalFee,// 应收 |
314 | 316 | arrearageDiscFee: res.arrearageDiscFee,// 优惠 |
315 | 317 | arrearageActFee: res.arrearageActFee,// 实收 |
316 | - carNumber: this.carNumber // 车牌 | |
318 | + carNumber: this.carNumber, // 车牌 | |
319 | + paySrcType: 103, //支付的类型 101 是本次 103是历史欠费 | |
320 | + ordeID: this.orderIds, //支付的订单号 | |
317 | 321 | } |
318 | 322 | } |
319 | 323 | ) | ... | ... |
src/utils/utils.js
... | ... | @@ -109,7 +109,8 @@ export default { |
109 | 109 | return '支付宝' |
110 | 110 | } |
111 | 111 | }, |
112 | - | |
112 | + // 0eca8f5373ca4866aec2f8e9d9367104 老的id | |
113 | + // 14318527b13840c2a4af63fef52c2d6e 老的签名 | |
113 | 114 | myVarAppid:'ud8yq5tv0inxupc05xfeau39jywlqoj2',// 公共请求Appid |
114 | 115 | |
115 | 116 | myDeviceInfo: 'BC0703A4-AFB0-4B51-9089-9B7487C0CC6E', // 公共请求设备信息 | ... | ... |