Skip to content

Commit 8752ce7

Browse files
committed
pay: 接入支付宝 PC 支付的跳转模式
1 parent 17ba74c commit 8752ce7

File tree

2 files changed

+94
-12
lines changed

2 files changed

+94
-12
lines changed

src/utils/constants.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ export const PayChannelEnum = {
150150
},
151151
}
152152

153+
/**
154+
* 支付的展示模式每局
155+
*/
156+
export const PayDisplayModeEnum = {
157+
URL: {
158+
"mode": "url",
159+
},
160+
IFRAME: {
161+
"mode": "iframe",
162+
},
163+
}
164+
153165
/**
154166
* 支付类型枚举
155167
*/

src/views/pay/order/submit.vue

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
</el-descriptions>
1313
</el-card>
1414

15-
1615
<!-- 支付选择框 -->
1716
<el-card style="margin-top: 10px" v-loading="submitLoading" element-loading-text="提交支付中...">
1817
<!-- 支付宝 -->
@@ -42,12 +41,18 @@
4241
</div>
4342
</el-card>
4443

45-
<!-- 支付二维码 -->
44+
<!-- 展示形式:二维码 -->
4645
<el-dialog :title="qrCode.title" :visible.sync="qrCode.visible" width="350px" append-to-body
4746
:close-on-press-escape="false">
4847
<qrcode-vue :value="qrCode.url" size="310" level="H" />
4948
</el-dialog>
5049

50+
<!-- 展示形式:iframe -->
51+
<el-dialog :title="iframe.title" :visible.sync="iframe.visible" width="800px" height="800px" append-to-body
52+
:close-on-press-escape="false">
53+
<iframe :src="iframe.url" width="100%" />
54+
</el-dialog>
55+
5156
<!-- 阿里支付 -->
5257
<div ref="alipayWap" v-html="alipayHtml.value" />
5358

@@ -57,7 +62,7 @@
5762
import QrcodeVue from 'qrcode.vue'
5863
import { DICT_TYPE, getDictDatas } from "@/utils/dict";
5964
import { getOrder, submitOrder } from '@/api/pay/order';
60-
import { PayChannelEnum, PayOrderStatusEnum } from "@/utils/constants";
65+
import {PayChannelEnum, PayDisplayModeEnum, PayOrderStatusEnum} from "@/utils/constants";
6166
6267
export default {
6368
name: "PayOrderSubmit",
@@ -83,11 +88,16 @@ export default {
8388
mock: require("@/assets/images/pay/icon/mock.svg"),
8489
},
8590
submitLoading: false, // 提交支付的 loading
86-
qrCode: { // 支付二维码
91+
qrCode: { // 展示形式:二维码
8792
url: '',
8893
title: '',
8994
visible: false,
9095
},
96+
iframe: { // 展示形式:iframe
97+
url: '',
98+
title: '',
99+
visible: false
100+
},
91101
interval: undefined, // 定时任务,轮询是否完成支付
92102
alipayHtml: '' // 阿里支付的 HTML
93103
};
@@ -146,21 +156,65 @@ export default {
146156
this.submitLoading = true
147157
submitOrder({
148158
id: this.id,
149-
channelCode: channelCode
159+
channelCode: channelCode,
160+
...this.buildSubmitParam(channelCode)
150161
}).then(response => {
151-
const invokeResponse = response.data.invokeResponse
152-
// 不同的支付,调用不同的策略
153-
if (channelCode === PayChannelEnum.ALIPAY_QR.code) {
154-
this.submitAfterAlipayQr(invokeResponse)
155-
} else if (channelCode === PayChannelEnum.ALIPAY_PC.code
156-
|| channelCode === PayChannelEnum.ALIPAY_WAP.code) {
157-
this.submitAfterAlipayPc(invokeResponse)
162+
const data = response.data
163+
if (data.displayMode === 'iframe') {
164+
this.displayIFrame(channelCode, data)
165+
} else if (data.displayMode === 'url') {
166+
this.displayUrl(channelCode, data)
158167
}
168+
// 不同的支付,调用不同的策略
169+
// if (channelCode === PayChannelEnum.ALIPAY_QR.code) {
170+
// this.submitAfterAlipayQr(invokeResponse)
171+
// } else if (channelCode === PayChannelEnum.ALIPAY_PC.code
172+
// || channelCode === PayChannelEnum.ALIPAY_WAP.code) {
173+
// this.submitAfterAlipayPc(invokeResponse)
174+
// }
159175
160176
// 打开轮询任务
161177
this.createQueryInterval()
162178
})
163179
},
180+
/** 构建提交支付的额外参数 */
181+
buildSubmitParam(channelCode) {
182+
// 支付宝网页支付时,有多种展示形态
183+
if (channelCode === PayChannelEnum.ALIPAY_PC.code) {
184+
// 情况【前置模式】:将二维码前置到商户的订单确认页的模式。需要商户在自己的页面中以 iframe 方式请求支付宝页面。具体支持的枚举值有以下几种:
185+
// 0:订单码-简约前置模式,对应 iframe 宽度不能小于 600px,高度不能小于 300px
186+
// return {
187+
// "channelExtras": {
188+
// "qr_pay_mode": "0"
189+
// }
190+
// }
191+
// 1:订单码-前置模式,对应iframe 宽度不能小于 300px,高度不能小于 600px
192+
// return {
193+
// "channelExtras": {
194+
// "qr_pay_mode": "1"
195+
// }
196+
// }
197+
// 3:订单码-迷你前置模式,对应 iframe 宽度不能小于 75px,高度不能小于 75px
198+
// return {
199+
// "channelExtras": {
200+
// "qr_pay_mode": "3"
201+
// }
202+
// }
203+
// 4:订单码-可定义宽度的嵌入式二维码,商户可根据需要设定二维码的大小
204+
// return {
205+
// "channelExtras": {
206+
// "qr_pay_mode": "2"
207+
// }
208+
// }
209+
// 情况【跳转模式】:跳转模式下,用户的扫码界面是由支付宝生成的,不在商户的域名下。支持传入的枚举值有
210+
return {
211+
"channelExtras": {
212+
"qr_pay_mode": "2"
213+
}
214+
}
215+
}
216+
return {}
217+
},
164218
/** 提交支付后(支付宝扫码支付) */
165219
submitAfterAlipayQr(invokeResponse) {
166220
this.qrCode = {
@@ -170,6 +224,19 @@ export default {
170224
}
171225
this.submitLoading = false
172226
},
227+
displayIFrame(channelCode, data) {
228+
// this.iframe = {
229+
// title: '支付窗口',
230+
// url: data.displayContent,
231+
// visible: true
232+
// }
233+
window.open(data.displayContent)
234+
},
235+
/** 提交支付后,URL 的展示形式 */
236+
displayUrl(channelCode, data) {
237+
window.open(data.displayContent)
238+
this.submitLoading = false
239+
},
173240
/** 提交支付后(支付宝 PC 网站支付) */
174241
submitAfterAlipayPc(invokeResponse) {
175242
// 渲染支付页面
@@ -188,6 +255,9 @@ export default {
188255
},
189256
/** 轮询查询任务 */
190257
createQueryInterval() {
258+
if (!this.interval) {
259+
return
260+
}
191261
this.interval = setInterval(() => {
192262
getOrder(this.id).then(response => {
193263
// 已支付

0 commit comments

Comments
 (0)