feat: 支付

This commit is contained in:
黄泽群
2026-07-23 14:00:22 +08:00
committed by charles
parent 15dd3d7b5b
commit 3629555911
8 changed files with 1098 additions and 1018 deletions
@@ -46,191 +46,221 @@
</template>
<script>
import Header from '@/components/header.vue';
import { getRechargeSupportPay, recharge } from '@/api/finance.js';
import { feedback } from '@/api/payment.js';
import { appWxpayFun, zfbPayFun } from '@/utils/payUtils.js'
import Header from '@/components/header.vue';
import {
getRechargeSupportPay,
recharge
} from '@/api/finance.js';
import {
feedback
} from '@/api/payment.js';
import {
appWxpayFun,
zfbPayFun
} from '@/utils/payUtils.js'
export default {
components: { Header },
data() {
return {
form: {
category: null,
amount: null,//充值金额
payway: null,// 支付当时
},
wayOption: [],
proAmount: 0,
leftPath: '/pages/mine_package/mine_purse/mine_purse',
}
},
onLoad(option) {
const category = option.category;
if (category && category !== 'null') {
this.form.category = category;
}
const amount = option.amount;
if (amount && amount !== 'null') {
this.proAmount = amount;
}
const back = option.back;
if (back && back !== 'null') {
if (back === "submit") {
const id = option.id;
this.leftPath = "/pages/order_package/order_submit/order_submit?payOpen=true&ids=" + id;
}
if (back === "orderInfo") {
const id = option.id;
this.leftPath = "/pages/mine_package/mine_order_info/mine_order_info?payOpen=true&id=" + id;
}
}
},
mounted() {
this.getWayOption();
},
methods: {
async getWayOption() {
const result = await getRechargeSupportPay();
if (result && result.bizcode === 100) {
this.wayOption = result.data;
export default {
components: {
Header
},
data() {
return {
form: {
category: null,
amount: null, //充值金额
payway: null, // 支付当时
},
wayOption: [],
proAmount: 0,
leftPath: '/pages/mine_package/mine_purse/mine_purse',
}
},
// 立即充值
async rechargeOk() {
console.log('aaaaa',this.form);
const params = this.form;
if (!params.amount) {
this.$refs.uToastRef.show({
type: 'error',
message: "请输入需要充值的金额",
});
return;
onLoad(option) {
const category = option.category;
if (category && category !== 'null') {
this.form.category = category;
}
if (!params.payway) {
this.$refs.uToastRef.show({
type: 'error',
message: "请选择支付方式",
});
return;
const amount = option.amount;
if (amount && amount !== 'null') {
this.proAmount = amount;
}
console.log("params---", params);
const result = await recharge(params);
console.log("result", result);
if (result && result.bizcode === 100) {
const item = result.data;
console.log("item", item);
if (item.wechat && Object.keys(item.wechat).length !== 0) {
this.appWxpay(item.wechat, item.orderId, item.orderNum);
} else if (item.alipay && Object.keys(item.alipay).length !== 0 && item.alipay) {
this.zfbPay(item.alipay, item.orderId, item.orderNum);
} else {
this.$refs.uToastRef.show({
type: 'error',
message: "充值失败",
});
const back = option.back;
if (back && back !== 'null') {
if (back === "submit") {
const id = option.id;
this.leftPath = "/pages/order_package/order_submit/order_submit?payOpen=true&ids=" + id;
}
if (back === "orderInfo") {
const id = option.id;
this.leftPath = "/pages/mine_package/mine_order_info/mine_order_info?payOpen=true&id=" + id;
}
}
},
// app 微信支付
async appWxpay(alipay, orderId, orderNum) {
try {
const result = await appWxpayFun(alipay, orderId, orderNum);
console.log('支付成功', result);
// 处理支付成功后的逻辑,如更新订单状态等
} catch (error) {
console.error('支付失败', error);
// 处理支付失败后的逻辑,如提示用户等
}
// const newThis = this;
// const orderInfo = {
// "appid": item.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
// "noncestr": item.nonceStr, // 随机字符串
// "package": "Sign=WXPay", // 固定值
// "partnerid": item.partnerId, // 微信支付商户号
// "prepayid": item.prepayId, // 统一下单订单号
// "timestamp": item.timeStamp, // 时间戳(单位:秒)
// "sign": item.sign // 签名,这里用的 MD5/RSA 签名
// };
// uni.requestPayment({
// provider:"wxpay",
// orderInfo: orderInfo,
// success: function(res) {
// console.log('success:' + res);
// newThis.payFeedbackFun(orderId,orderNum,1);
// newThis.jumpWayOk();
// },
// fail: function(err) {
// console.log('fail:',err);
// newThis.$refs.uToastRef.show({
// type: 'error',
// message: "充值失败",
// });
// setTimeout(()=>{
// newThis.jumpWayError()
// },2000)
// }
// });
mounted() {
this.getWayOption();
},
// 支付宝支付
async zfbPay(alipay, orderId, orderNum) {
try {
const result = await zfbPayFun(alipay, orderId, orderNum);
console.log('支付成功', result);
// 处理支付成功后的逻辑,如更新订单状态等
} catch (error) {
console.error('支付失败', error);
// 处理支付失败后的逻辑,如提示用户等
}
// const that = this;
// uni.requestPayment({
// provider: 'alipay',
// orderInfo: item,
// success(res) {
// that.payFeedbackFun(orderId,orderNum,1);
// that.jumpWayOk();
// },
// //调用失败的回调
// fail(err) {
// that.$refs.uToastRef.show({
// type: 'error',
// message: "充值失败",
// });
// setTimeout(()=>{
// that.jumpWayError()
// },2000)
// }
// })
},
// 跳转到支付成功页面
jumpWayOk() {
this.$refs.uToastRef.show({
type: 'success',
message: "充值成功",
});
setTimeout(() => {
uni.navigateTo({
url: '/pages/mine_package/mine_purse/mine_purse'
});
}, 1500)
},
// 支付结果回调
async payFeedbackFun(orderId, orderNum, status) {
const params = {
orderId,
orderNum,
status,
}
const response = await feedback(params);
console.log("response", response);
if (response && response.bizcode !== 100) {
console.error("反馈结果", response);
}
methods: {
async getWayOption() {
const result = await getRechargeSupportPay();
if (result && result.bizcode === 100) {
this.wayOption = result.data;
}
},
// 立即充值
async rechargeOk() {
console.log('aaaaa', this.form);
const params = this.form;
if (!params.amount) {
this.$refs.uToastRef.show({
type: 'error',
message: "请输入需要充值的金额",
});
return;
}
if (!params.payway) {
this.$refs.uToastRef.show({
type: 'error',
message: "请选择支付方式",
});
return;
}
},
if (params.payway == "wechat") {
// #ifdef MP-WEIXIN
params["payway"] = "wechatMiniProgram";
params["code"] = await new Promise((resolve) => {
uni.login({
provider: "weixin",
onlyAuthorize: true,
success: function(loginRes) {
resolve(loginRes.code);
},
fail: (err) => {
resolve(""); // 登录失败时返回空字符串,避免后续流程中断
},
});
});
// #endif
}
console.log("params---", params);
const result = await recharge(params);
console.log("result", result);
if (result && result.bizcode === 100) {
const item = result.data;
console.log("item", item);
if (item.wechat && Object.keys(item.wechat).length !== 0) {
this.appWxpay(item.wechat, item.orderId, item.orderNum);
} else if (item.alipay && Object.keys(item.alipay).length !== 0 && item.alipay) {
this.zfbPay(item.alipay, item.orderId, item.orderNum);
} else {
this.$refs.uToastRef.show({
type: 'error',
message: "充值失败",
});
}
}
},
// app 微信支付
async appWxpay(alipay, orderId, orderNum) {
try {
const result = await appWxpayFun(alipay, orderId, orderNum);
console.log('支付成功', result);
// 处理支付成功后的逻辑,如更新订单状态等
} catch (error) {
console.error('支付失败', error);
// 处理支付失败后的逻辑,如提示用户等
}
// const newThis = this;
// const orderInfo = {
// "appid": item.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
// "noncestr": item.nonceStr, // 随机字符串
// "package": "Sign=WXPay", // 固定值
// "partnerid": item.partnerId, // 微信支付商户号
// "prepayid": item.prepayId, // 统一下单订单号
// "timestamp": item.timeStamp, // 时间戳(单位:秒)
// "sign": item.sign // 签名,这里用的 MD5/RSA 签名
// };
// uni.requestPayment({
// provider:"wxpay",
// orderInfo: orderInfo,
// success: function(res) {
// console.log('success:' + res);
// newThis.payFeedbackFun(orderId,orderNum,1);
// newThis.jumpWayOk();
// },
// fail: function(err) {
// console.log('fail:',err);
// newThis.$refs.uToastRef.show({
// type: 'error',
// message: "充值失败",
// });
// setTimeout(()=>{
// newThis.jumpWayError()
// },2000)
// }
// });
},
// 支付宝支付
async zfbPay(alipay, orderId, orderNum) {
try {
const result = await zfbPayFun(alipay, orderId, orderNum);
console.log('支付成功', result);
// 处理支付成功后的逻辑,如更新订单状态等
} catch (error) {
console.error('支付失败', error);
// 处理支付失败后的逻辑,如提示用户等
}
// const that = this;
// uni.requestPayment({
// provider: 'alipay',
// orderInfo: item,
// success(res) {
// that.payFeedbackFun(orderId,orderNum,1);
// that.jumpWayOk();
// },
// //调用失败的回调
// fail(err) {
// that.$refs.uToastRef.show({
// type: 'error',
// message: "充值失败",
// });
// setTimeout(()=>{
// that.jumpWayError()
// },2000)
// }
// })
},
// 跳转到支付成功页面
jumpWayOk() {
this.$refs.uToastRef.show({
type: 'success',
message: "充值成功",
});
setTimeout(() => {
uni.navigateTo({
url: '/pages/mine_package/mine_purse/mine_purse'
});
}, 1500)
},
// 支付结果回调
async payFeedbackFun(orderId, orderNum, status) {
const params = {
orderId,
orderNum,
status,
}
const response = await feedback(params);
console.log("response", response);
if (response && response.bizcode !== 100) {
console.error("反馈结果", response);
}
},
}
}
}
</script>
<style lang="scss" scoped></style>
<style lang="scss" scoped></style>