hookehuyr

模拟支付流程代码更新

1 /* 1 /*
2 * @Date: 2023-12-22 10:29:37 2 * @Date: 2023-12-22 10:29:37
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-12-27 14:08:21 4 + * @LastEditTime: 2023-12-27 17:27:31
5 * @FilePath: /meihuaApp/src/api/index.js 5 * @FilePath: /meihuaApp/src/api/index.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
...@@ -16,6 +16,8 @@ const Api = { ...@@ -16,6 +16,8 @@ const Api = {
16 GET_LIST: '/srv/?a=room_data&t=get_list', 16 GET_LIST: '/srv/?a=room_data&t=get_list',
17 GET_ROOM: '/srv/?a=room_data&t=get_room', 17 GET_ROOM: '/srv/?a=room_data&t=get_room',
18 ADD_ORDER: '/srv/?a=room_data&t=add_order', 18 ADD_ORDER: '/srv/?a=room_data&t=add_order',
19 + PAY: '/srv/?a=pay',
20 + PAY_CHECK: '/srv/?a=pay_check',
19 } 21 }
20 22
21 /** 23 /**
...@@ -84,3 +86,17 @@ export const getRoomAPI = (params) => fn(fetch.get(Api.GET_ROOM, params)); ...@@ -84,3 +86,17 @@ export const getRoomAPI = (params) => fn(fetch.get(Api.GET_ROOM, params));
84 * @returns 86 * @returns
85 */ 87 */
86 export const addOrderAPI = (params) => fn(fetch.post(Api.ADD_ORDER, params)); 88 export const addOrderAPI = (params) => fn(fetch.post(Api.ADD_ORDER, params));
89 +
90 +/**
91 + * @description: 支付
92 + * @param order_id 订单ID
93 + * @returns
94 + */
95 +export const payAPI = (params) => fn(fetch.post(Api.PAY, params));
96 +
97 +/**
98 + * @description: 检查是否支付成功
99 + * @param order_id 订单ID
100 + * @returns
101 + */
102 +export const payCheckAPI = (params) => fn(fetch.post(Api.PAY_CHECK, params));
......
1 <!-- 1 <!--
2 * @Date: 2023-12-20 14:11:11 2 * @Date: 2023-12-20 14:11:11
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2023-12-27 11:47:33 4 + * @LastEditTime: 2023-12-27 17:37:35
5 * @FilePath: /meihuaApp/src/components/payCard.vue 5 * @FilePath: /meihuaApp/src/components/payCard.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
22 import Taro from '@tarojs/taro' 22 import Taro from '@tarojs/taro'
23 import { ref, watch, onMounted, onUnmounted } from 'vue' 23 import { ref, watch, onMounted, onUnmounted } from 'vue'
24 import { getCurrentPageUrl } from "@/utils/weapp"; 24 import { getCurrentPageUrl } from "@/utils/weapp";
25 +import { payAPI, payCheckAPI } from '@/api/index'
25 26
26 /** 27 /**
27 * 格式化时间 28 * 格式化时间
...@@ -98,8 +99,8 @@ onUnmounted(() => { ...@@ -98,8 +99,8 @@ onUnmounted(() => {
98 timeId && clearInterval(timeId); 99 timeId && clearInterval(timeId);
99 }) 100 })
100 101
101 -const goToPay = () => { 102 +const goToPay = async () => {
102 - // TODO:支付成功后的操作 103 + // TODO:模拟代码
103 emit('close'); // 关闭支付弹框 104 emit('close'); // 关闭支付弹框
104 // 105 //
105 Taro.showToast({ 106 Taro.showToast({
...@@ -122,35 +123,45 @@ const goToPay = () => { ...@@ -122,35 +123,45 @@ const goToPay = () => {
122 }); 123 });
123 } 124 }
124 }, 1000); 125 }, 1000);
125 - // this.$parent.sdk.post('c/app/prepay', { 126 + // TODO:实际操作代码等待接口放上去
126 - // id: this.params.id 127 + // // 获取支付参数
127 - // }).then(res => { 128 + // const pay = await payAPI({ order_id: id.value });
128 - // if (res.data.ret === 'OK') { 129 + // if (pay.code) {
129 - // let pay = res.data.content.payargs; 130 + // let pay = pay.data.payargs;
130 - // wx.requestPayment({ 131 + // // 触发微信支付操作
131 - // timeStamp: pay.timeStamp, 132 + // wx.requestPayment({
132 - // nonceStr: pay.nonceStr, 133 + // timeStamp: pay.timeStamp,
133 - // package: pay.package, 134 + // nonceStr: pay.nonceStr,
134 - // signType: pay.signType, 135 + // package: pay.package,
135 - // paySign: pay.paySign, 136 + // signType: pay.signType,
136 - // success: (result) => { 137 + // paySign: pay.paySign,
137 - // that.$parent.sdk.post('c/order/paySuccess', { 138 + // success: async (result) => {
138 - // id: that.params.id 139 + // emit('close'); // 关闭支付弹框
139 - // }).then(pRes => { 140 + // Taro.showToast({
140 - // if (pRes.data.ret === 'OK') { 141 + // title: '支付成功',
141 - // that.Toast('success', '感谢您的捐赠', 3000) 142 + // icon: 'success',
142 - // } else { 143 + // duration: 1000
143 - // that.Toast('fail', pRes.data.err, 3000); 144 + // });
144 - // } 145 + // // 支付成功后,调用检查接口
145 - // }).catch(err => { 146 + // const pay_success = await payCheckAPI({ order_id: id.value });
146 - // console.error(err) 147 + // if (pay_success.code) {
147 - // }) 148 + // let current_page = getCurrentPageUrl();
148 - // } 149 + // if (current_page === 'pages/my/index') { // 我的页面打开
149 - // }); 150 + // // 刷新当前页面
150 - // } else { 151 + // Taro.reLaunch({
151 - // this.Toast('fail', res.data.msg, 3000); 152 + // url: '/pages/my/index?tab_index=1'
153 + // });
154 + // }
155 + // if (current_page === 'pages/detail/index') { // 订房确认页打开
156 + // // 跳转订单成功页
157 + // Taro.navigateTo({
158 + // url: '/pages/payInfo/index',
159 + // });
160 + // }
152 // } 161 // }
153 - // }) 162 + // }
163 + // });
164 + // }
154 } 165 }
155 </script> 166 </script>
156 167
......