Skip to content

Commit b76193c

Browse files
committed
pay: 接入支付宝 Wap 支付
1 parent ec12298 commit b76193c

File tree

2 files changed

+35
-23
lines changed

2 files changed

+35
-23
lines changed

src/utils/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@ export const PayDisplayModeEnum = {
162162
},
163163
FORM: {
164164
"mode": "form"
165+
},
166+
QR_CODE: {
167+
"mode": "qr_code"
165168
}
166169
}
167170

src/views/pay/order/submit.vue

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<!-- 展示形式:二维码 URL -->
4545
<el-dialog :title="qrCode.title" :visible.sync="qrCode.visible" width="350px" append-to-body
4646
:close-on-press-escape="false">
47-
<qrcode-vue :value="qrCode.url" size="310" level="H" />
47+
<qrcode-vue :value="qrCode.url" size="310" level="L" />
4848
</el-dialog>
4949

5050
<!-- 展示形式:IFrame -->
@@ -53,7 +53,7 @@
5353
<iframe :src="iframe.url" width="100%" />
5454
</el-dialog>
5555

56-
<!-- 展示形式: -->
56+
<!-- 展示形式:Form -->
5757
<div ref="formRef" v-html="form.value" />
5858

5959
</div>
@@ -162,28 +162,23 @@ export default {
162162
...this.buildSubmitParam(channelCode)
163163
}).then(response => {
164164
const data = response.data
165-
if (data.displayMode === 'iframe') {
165+
if (data.displayMode === PayDisplayModeEnum.IFRAME.mode) {
166166
this.displayIFrame(channelCode, data)
167-
} else if (data.displayMode === 'url') {
167+
} else if (data.displayMode === PayDisplayModeEnum.URL.mode) {
168168
this.displayUrl(channelCode, data)
169-
} else if (data.displayMode === 'form') {
169+
} else if (data.displayMode === PayDisplayModeEnum.FORM.mode) {
170170
this.displayForm(channelCode, data)
171+
} else if (data.displayMode === PayDisplayModeEnum.QR_CODE.mode) {
172+
this.displayQrCode(channelCode, data)
171173
}
172-
// 不同的支付,调用不同的策略
173-
// if (channelCode === PayChannelEnum.ALIPAY_QR.code) {
174-
// this.submitAfterAlipayQr(invokeResponse)
175-
// } else if (channelCode === PayChannelEnum.ALIPAY_PC.code
176-
// || channelCode === PayChannelEnum.ALIPAY_WAP.code) {
177-
// this.submitAfterAlipayPc(invokeResponse)
178-
// }
179174
180175
// 打开轮询任务
181176
this.createQueryInterval()
182177
})
183178
},
184179
/** 构建提交支付的额外参数 */
185180
buildSubmitParam(channelCode) {
186-
// 支付宝网页支付时,有多种展示形态
181+
// ① 支付宝 PC 支付时,有多种展示形态
187182
if (channelCode === PayChannelEnum.ALIPAY_PC.code) {
188183
// 情况【前置模式】:将二维码前置到商户的订单确认页的模式。需要商户在自己的页面中以 iframe 方式请求支付宝页面。具体支持的枚举值有以下几种:
189184
// 0:订单码-简约前置模式,对应 iframe 宽度不能小于 600px,高度不能小于 300px
@@ -221,16 +216,13 @@ export default {
221216
// displayMode: PayDisplayModeEnum.FORM.mode
222217
// }
223218
}
224-
return {}
225-
},
226-
/** 提交支付后(支付宝扫码支付) */
227-
submitAfterAlipayQr(invokeResponse) {
228-
this.qrCode = {
229-
title: '请使用支付宝“扫一扫”扫码支付',
230-
url: invokeResponse.qrCode,
231-
visible: true
219+
// ② 支付宝 Wap 支付时,引导手机扫码支付
220+
if (channelCode === PayChannelEnum.ALIPAY_WAP.code) {
221+
return {
222+
displayMode: PayDisplayModeEnum.QR_CODE.mode
223+
}
232224
}
233-
this.submitLoading = false
225+
return {}
234226
},
235227
/** 提交支付后,IFrame 内置 URL 的展示形式 */
236228
displayIFrame(channelCode, data) {
@@ -262,9 +254,26 @@ export default {
262254
}, 1000);
263255
});
264256
},
257+
/** 提交支付后(支付宝扫码支付) */
258+
displayQrCode(channelCode, data) {
259+
let title = '请使用手机浏览器“扫一扫”';
260+
if (channelCode === PayChannelEnum.ALIPAY_WAP.code) {
261+
// 考虑到 WAP 测试,所以引导手机浏览器搞
262+
} else if (channelCode.indexOf('alipay_') === 0) {
263+
title = '请使用支付宝“扫一扫”扫码支付';
264+
} else if (channelCode.indexOf('wx_') === 0) {
265+
title = '请使用微信“扫一扫”扫码支付';
266+
}
267+
this.qrCode = {
268+
title: title,
269+
url: data.displayContent,
270+
visible: true
271+
}
272+
this.submitLoading = false
273+
},
265274
/** 轮询查询任务 */
266275
createQueryInterval() {
267-
if (!this.interval) {
276+
if (this.interval) {
268277
return
269278
}
270279
this.interval = setInterval(() => {

0 commit comments

Comments
 (0)