Commit ce8571e313aa2de3f209b965cbfdfff077e76adf

Authored by YunaiV
1 parent b34801f3

pay: 接入支付宝 PC 支付的表单

yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClient.java
@@ -69,10 +69,6 @@ public class AlipayPcPayClient extends AbstractAlipayClient { @@ -69,10 +69,6 @@ public class AlipayPcPayClient extends AbstractAlipayClient {
69 log.error("[unifiedOrder][request({}) 发起支付失败]", JsonUtils.toJsonString(reqDTO), e); 69 log.error("[unifiedOrder][request({}) 发起支付失败]", JsonUtils.toJsonString(reqDTO), e);
70 return PayCommonResult.build(e.getErrCode(), e.getErrMsg(), null, codeMapping); 70 return PayCommonResult.build(e.getErrCode(), e.getErrMsg(), null, codeMapping);
71 } 71 }
72 - // 1. form  
73 - // 2. url  
74 - // 3. code  
75 - // 4. code url  
76 72
77 // 2.2 处理结果 73 // 2.2 处理结果
78 System.out.println(response.getBody()); 74 System.out.println(response.getBody());
yudao-ui-admin/src/utils/constants.js
@@ -160,6 +160,9 @@ export const PayDisplayModeEnum = { @@ -160,6 +160,9 @@ export const PayDisplayModeEnum = {
160 IFRAME: { 160 IFRAME: {
161 "mode": "iframe", 161 "mode": "iframe",
162 }, 162 },
  163 + FORM: {
  164 + "mode": "form"
  165 + }
163 } 166 }
164 167
165 /** 168 /**
yudao-ui-admin/src/views/pay/order/submit.vue
@@ -41,20 +41,20 @@ @@ -41,20 +41,20 @@
41 </div> 41 </div>
42 </el-card> 42 </el-card>
43 43
44 - <!-- 展示形式:二维码 --> 44 + <!-- 展示形式:二维码 URL -->
45 <el-dialog :title="qrCode.title" :visible.sync="qrCode.visible" width="350px" append-to-body 45 <el-dialog :title="qrCode.title" :visible.sync="qrCode.visible" width="350px" append-to-body
46 :close-on-press-escape="false"> 46 :close-on-press-escape="false">
47 <qrcode-vue :value="qrCode.url" size="310" level="H" /> 47 <qrcode-vue :value="qrCode.url" size="310" level="H" />
48 </el-dialog> 48 </el-dialog>
49 49
50 - <!-- 展示形式:iframe --> 50 + <!-- 展示形式:IFrame -->
51 <el-dialog :title="iframe.title" :visible.sync="iframe.visible" width="800px" height="800px" append-to-body 51 <el-dialog :title="iframe.title" :visible.sync="iframe.visible" width="800px" height="800px" append-to-body
52 :close-on-press-escape="false"> 52 :close-on-press-escape="false">
53 <iframe :src="iframe.url" width="100%" /> 53 <iframe :src="iframe.url" width="100%" />
54 </el-dialog> 54 </el-dialog>
55 55
56 - <!-- 阿里支付 -->  
57 - <div ref="alipayWap" v-html="alipayHtml.value" /> 56 + <!-- 展示形式: -->
  57 + <div ref="formRef" v-html="form.value" />
58 58
59 </div> 59 </div>
60 </template> 60 </template>
@@ -88,6 +88,7 @@ export default { @@ -88,6 +88,7 @@ export default {
88 mock: require("@/assets/images/pay/icon/mock.svg"), 88 mock: require("@/assets/images/pay/icon/mock.svg"),
89 }, 89 },
90 submitLoading: false, // 提交支付的 loading 90 submitLoading: false, // 提交支付的 loading
  91 + interval: undefined, // 定时任务,轮询是否完成支付
91 qrCode: { // 展示形式:二维码 92 qrCode: { // 展示形式:二维码
92 url: '', 93 url: '',
93 title: '', 94 title: '',
@@ -98,8 +99,9 @@ export default { @@ -98,8 +99,9 @@ export default {
98 title: '', 99 title: '',
99 visible: false 100 visible: false
100 }, 101 },
101 - interval: undefined, // 定时任务,轮询是否完成支付  
102 - alipayHtml: '' // 阿里支付的 HTML 102 + form: { // 展示形式:form
  103 + html: '',
  104 + },
103 }; 105 };
104 }, 106 },
105 created() { 107 created() {
@@ -164,6 +166,8 @@ export default { @@ -164,6 +166,8 @@ export default {
164 this.displayIFrame(channelCode, data) 166 this.displayIFrame(channelCode, data)
165 } else if (data.displayMode === 'url') { 167 } else if (data.displayMode === 'url') {
166 this.displayUrl(channelCode, data) 168 this.displayUrl(channelCode, data)
  169 + } else if (data.displayMode === 'form') {
  170 + this.displayForm(channelCode, data)
167 } 171 }
168 // 不同的支付,调用不同的策略 172 // 不同的支付,调用不同的策略
169 // if (channelCode === PayChannelEnum.ALIPAY_QR.code) { 173 // if (channelCode === PayChannelEnum.ALIPAY_QR.code) {
@@ -203,7 +207,7 @@ export default { @@ -203,7 +207,7 @@ export default {
203 // 4:订单码-可定义宽度的嵌入式二维码,商户可根据需要设定二维码的大小 207 // 4:订单码-可定义宽度的嵌入式二维码,商户可根据需要设定二维码的大小
204 // return { 208 // return {
205 // "channelExtras": { 209 // "channelExtras": {
206 - // "qr_pay_mode": "2" 210 + // "qr_pay_mode": "4"
207 // } 211 // }
208 // } 212 // }
209 // 情况【跳转模式】:跳转模式下,用户的扫码界面是由支付宝生成的,不在商户的域名下。支持传入的枚举值有 213 // 情况【跳转模式】:跳转模式下,用户的扫码界面是由支付宝生成的,不在商户的域名下。支持传入的枚举值有
@@ -212,6 +216,10 @@ export default { @@ -212,6 +216,10 @@ export default {
212 "qr_pay_mode": "2" 216 "qr_pay_mode": "2"
213 } 217 }
214 } 218 }
  219 + // 情况【表单模式】:直接提交当前页面到支付宝
  220 + // return {
  221 + // displayMode: PayDisplayModeEnum.FORM.mode
  222 + // }
215 } 223 }
216 return {} 224 return {}
217 }, 225 },
@@ -224,33 +232,34 @@ export default { @@ -224,33 +232,34 @@ export default {
224 } 232 }
225 this.submitLoading = false 233 this.submitLoading = false
226 }, 234 },
  235 + /** 提交支付后,IFrame 内置 URL 的展示形式 */
227 displayIFrame(channelCode, data) { 236 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
234 }, 244 },
235 /** 提交支付后,URL 的展示形式 */ 245 /** 提交支付后,URL 的展示形式 */
236 displayUrl(channelCode, data) { 246 displayUrl(channelCode, data) {
237 window.open(data.displayContent) 247 window.open(data.displayContent)
238 this.submitLoading = false 248 this.submitLoading = false
239 }, 249 },
240 - /** 提交支付后(支付宝 PC 网站支付) */  
241 - submitAfterAlipayPc(invokeResponse) { 250 + /** 提交支付后,Form 的展示形式 */
  251 + displayForm(channelCode, data) {
242 // 渲染支付页面 252 // 渲染支付页面
243 - this.alipayHtml = {  
244 - value: invokeResponse.body,  
245 - visible: true 253 + this.form = {
  254 + value: data.displayContent
246 } 255 }
247 // 防抖避免重复支付 256 // 防抖避免重复支付
248 this.$nextTick(() => { 257 this.$nextTick(() => {
249 // 提交支付表单 258 // 提交支付表单
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);
254 }); 263 });
255 }, 264 },
256 /** 轮询查询任务 */ 265 /** 轮询查询任务 */