Skip to content

Commit 55a2d33

Browse files
committed
pay: 接入支付宝 PC 支付的表单
1 parent 8752ce7 commit 55a2d33

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

src/utils/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ export const PayDisplayModeEnum = {
160160
IFRAME: {
161161
"mode": "iframe",
162162
},
163+
FORM: {
164+
"mode": "form"
165+
}
163166
}
164167

165168
/**

src/views/pay/order/submit.vue

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@
4141
</div>
4242
</el-card>
4343

44-
<!-- 展示形式:二维码 -->
44+
<!-- 展示形式:二维码 URL -->
4545
<el-dialog :title="qrCode.title" :visible.sync="qrCode.visible" width="350px" append-to-body
4646
:close-on-press-escape="false">
4747
<qrcode-vue :value="qrCode.url" size="310" level="H" />
4848
</el-dialog>
4949

50-
<!-- 展示形式:iframe -->
50+
<!-- 展示形式:IFrame -->
5151
<el-dialog :title="iframe.title" :visible.sync="iframe.visible" width="800px" height="800px" append-to-body
5252
:close-on-press-escape="false">
5353
<iframe :src="iframe.url" width="100%" />
5454
</el-dialog>
5555

56-
<!-- 阿里支付 -->
57-
<div ref="alipayWap" v-html="alipayHtml.value" />
56+
<!-- 展示形式: -->
57+
<div ref="formRef" v-html="form.value" />
5858

5959
</div>
6060
</template>
@@ -88,6 +88,7 @@ export default {
8888
mock: require("@/assets/images/pay/icon/mock.svg"),
8989
},
9090
submitLoading: false, // 提交支付的 loading
91+
interval: undefined, // 定时任务,轮询是否完成支付
9192
qrCode: { // 展示形式:二维码
9293
url: '',
9394
title: '',
@@ -98,8 +99,9 @@ export default {
9899
title: '',
99100
visible: false
100101
},
101-
interval: undefined, // 定时任务,轮询是否完成支付
102-
alipayHtml: '' // 阿里支付的 HTML
102+
form: { // 展示形式:form
103+
html: '',
104+
},
103105
};
104106
},
105107
created() {
@@ -164,6 +166,8 @@ export default {
164166
this.displayIFrame(channelCode, data)
165167
} else if (data.displayMode === 'url') {
166168
this.displayUrl(channelCode, data)
169+
} else if (data.displayMode === 'form') {
170+
this.displayForm(channelCode, data)
167171
}
168172
// 不同的支付,调用不同的策略
169173
// if (channelCode === PayChannelEnum.ALIPAY_QR.code) {
@@ -203,7 +207,7 @@ export default {
203207
// 4:订单码-可定义宽度的嵌入式二维码,商户可根据需要设定二维码的大小
204208
// return {
205209
// "channelExtras": {
206-
// "qr_pay_mode": "2"
210+
// "qr_pay_mode": "4"
207211
// }
208212
// }
209213
// 情况【跳转模式】:跳转模式下,用户的扫码界面是由支付宝生成的,不在商户的域名下。支持传入的枚举值有
@@ -212,6 +216,10 @@ export default {
212216
"qr_pay_mode": "2"
213217
}
214218
}
219+
// 情况【表单模式】:直接提交当前页面到支付宝
220+
// return {
221+
// displayMode: PayDisplayModeEnum.FORM.mode
222+
// }
215223
}
216224
return {}
217225
},
@@ -224,33 +232,34 @@ export default {
224232
}
225233
this.submitLoading = false
226234
},
235+
/** 提交支付后,IFrame 内置 URL 的展示形式 */
227236
displayIFrame(channelCode, data) {
228-
// this.iframe = {
229-
// title: '支付窗口',
230-
// url: data.displayContent,
231-
// visible: true
232-
// }
233-
window.open(data.displayContent)
237+
// TODO 芋艿:目前有点奇怪,支付宝总是会显示“支付环境存在风险”
238+
this.iframe = {
239+
title: '支付窗口',
240+
url: data.displayContent,
241+
visible: true
242+
}
243+
this.submitLoading = false
234244
},
235245
/** 提交支付后,URL 的展示形式 */
236246
displayUrl(channelCode, data) {
237247
window.open(data.displayContent)
238248
this.submitLoading = false
239249
},
240-
/** 提交支付后(支付宝 PC 网站支付) */
241-
submitAfterAlipayPc(invokeResponse) {
250+
/** 提交支付后,Form 的展示形式 */
251+
displayForm(channelCode, data) {
242252
// 渲染支付页面
243-
this.alipayHtml = {
244-
value: invokeResponse.body,
245-
visible: true
253+
this.form = {
254+
value: data.displayContent
246255
}
247256
// 防抖避免重复支付
248257
this.$nextTick(() => {
249258
// 提交支付表单
250-
// this.$refs.alipayWap.children[0].submit();
251-
// setTimeout(() => {
252-
// this.submitLoading = false
253-
// }, 1000);
259+
this.$refs.formRef.children[0].submit();
260+
setTimeout(() => {
261+
this.submitLoading = false
262+
}, 1000);
254263
});
255264
},
256265
/** 轮询查询任务 */

0 commit comments

Comments
 (0)