2025-08-05 15:25:23 +08:00
|
|
|
import { feedback } from '@/api/payment.js';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2025-08-06 20:25:41 +08:00
|
|
|
* 微信支付
|
2025-08-05 15:25:23 +08:00
|
|
|
* @param {Object} alipay 微信支付的参数
|
|
|
|
|
* @param {Object} orderId 支付的订单ID
|
|
|
|
|
* @param {Object} orderNum 支付的订单编号
|
|
|
|
|
*/
|
2025-08-06 20:25:41 +08:00
|
|
|
export function appWxpayFun(alipay, orderId, orderNum) {
|
2025-08-05 15:25:23 +08:00
|
|
|
const type = alipay.type;
|
|
|
|
|
const orderStr = alipay.orderStr;
|
2025-09-05 23:52:22 +08:00
|
|
|
console.log("微信支付---",alipay)
|
2025-08-06 20:25:41 +08:00
|
|
|
if (type === "app") {// app
|
2025-08-05 15:25:23 +08:00
|
|
|
const orderInfo = {
|
|
|
|
|
"appid": alipay.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
|
|
|
|
|
"noncestr": alipay.nonceStr, // 随机字符串
|
|
|
|
|
"package": "Sign=WXPay", // 固定值
|
|
|
|
|
"partnerid": alipay.partnerId, // 微信支付商户号
|
|
|
|
|
"prepayid": alipay.prepayId, // 统一下单订单号
|
|
|
|
|
"timestamp": alipay.timeStamp, // 时间戳(单位:秒)
|
|
|
|
|
"sign": alipay.sign // 签名,这里用的 MD5/RSA 签名
|
|
|
|
|
};
|
|
|
|
|
uni.requestPayment({
|
2025-08-06 20:25:41 +08:00
|
|
|
provider: "wxpay",
|
2025-08-05 15:25:23 +08:00
|
|
|
orderInfo: orderInfo,
|
2025-08-06 20:25:41 +08:00
|
|
|
success: function (res) {
|
2025-08-05 15:25:23 +08:00
|
|
|
console.log('success:' + res);
|
2025-08-06 20:25:41 +08:00
|
|
|
payFeedbackFun(orderId, orderNum, 1);
|
2025-08-05 15:25:23 +08:00
|
|
|
jumpWayOk();
|
|
|
|
|
},
|
2025-08-06 20:25:41 +08:00
|
|
|
fail: function (err) {
|
|
|
|
|
console.log('fail:', err);
|
2025-08-05 15:25:23 +08:00
|
|
|
jumpWayError();
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-08-06 20:25:41 +08:00
|
|
|
} else if (type === "h5") {// h5
|
2025-08-05 15:25:23 +08:00
|
|
|
uni.navigateTo({
|
2025-08-06 20:25:41 +08:00
|
|
|
url: `/pages/other_package/payment_processing/payment_processing?link=${encodeURIComponent(orderStr)}&orderNum=` + orderNum // 假设有一个专门的支付页面来处理支付链接
|
2025-08-05 15:25:23 +08:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 支付宝支付
|
|
|
|
|
* @param {Object} alipay 微信支付的参数
|
|
|
|
|
* @param {Object} orderId 支付的订单ID
|
|
|
|
|
* @param {Object} orderNum 支付的订单编号
|
|
|
|
|
*/
|
2025-08-06 20:25:41 +08:00
|
|
|
export function zfbPayFun(alipay, orderId, orderNum) {
|
|
|
|
|
console.log("alipay", alipay);
|
2025-08-05 15:25:23 +08:00
|
|
|
const type = alipay.type;
|
|
|
|
|
const orderStr = alipay.orderStr;
|
2025-08-06 20:25:41 +08:00
|
|
|
if (type === "h5") {// h5
|
2025-08-05 15:25:23 +08:00
|
|
|
uni.navigateTo({
|
2025-08-06 20:25:41 +08:00
|
|
|
url: `/pages/other_package/payment_processing/payment_processing?link=${encodeURIComponent(orderStr)}&orderNum=` + orderNum // 假设有一个专门的支付页面来处理支付链接
|
2025-08-05 15:25:23 +08:00
|
|
|
});
|
2025-08-06 20:25:41 +08:00
|
|
|
} else if (type === "app") { // app
|
2025-08-05 15:25:23 +08:00
|
|
|
uni.requestPayment({
|
|
|
|
|
provider: 'alipay',
|
|
|
|
|
orderInfo: orderStr,
|
2025-08-06 20:25:41 +08:00
|
|
|
success: function (res) {
|
|
|
|
|
console.log("zfbPayFun res", res);
|
|
|
|
|
payFeedbackFun(orderId, orderNum, 1);
|
2025-08-05 15:25:23 +08:00
|
|
|
jumpWayOk();
|
|
|
|
|
},
|
2025-08-06 20:25:41 +08:00
|
|
|
fail: function (err) {
|
|
|
|
|
console.error("支付宝支付error", err);
|
2025-08-05 15:25:23 +08:00
|
|
|
jumpWayError();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// return new Promise((resolve, reject) => {
|
|
|
|
|
// resolve(res);
|
|
|
|
|
// // reject(err);
|
|
|
|
|
// });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 跳转到支付成功页面
|
2025-08-06 20:25:41 +08:00
|
|
|
export function jumpWayOk() {
|
2025-08-05 15:25:23 +08:00
|
|
|
uni.navigateTo({
|
2025-08-06 20:25:41 +08:00
|
|
|
url: "/pages/order_package/order_submit_ok/order_submit_ok",
|
2025-08-05 15:25:23 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
// 跳转到支付失败页面
|
2025-08-06 20:25:41 +08:00
|
|
|
export function jumpWayError() {
|
2025-08-05 15:25:23 +08:00
|
|
|
uni.navigateTo({
|
2025-08-06 20:25:41 +08:00
|
|
|
url: "/pages/order_package/order_submit_error/order_submit_error",
|
2025-08-05 15:25:23 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/**
|
2025-08-06 20:25:41 +08:00
|
|
|
* 支付结果回调
|
2025-08-05 15:25:23 +08:00
|
|
|
* @param {Object} orderId 支付订单ID
|
|
|
|
|
* @param {Object} orderNum 支付订单编号
|
|
|
|
|
* @param {Object} status 反馈结果【0:失败,1:成功】
|
|
|
|
|
*/
|
2025-08-06 20:25:41 +08:00
|
|
|
async function payFeedbackFun(orderId, orderNum, status) {
|
2025-08-05 15:25:23 +08:00
|
|
|
const params = {
|
|
|
|
|
orderId,
|
|
|
|
|
orderNum,
|
|
|
|
|
status,
|
|
|
|
|
}
|
2025-08-06 20:25:41 +08:00
|
|
|
console.log("params", params);
|
2025-08-05 15:25:23 +08:00
|
|
|
const response = await feedback(params);
|
2025-08-06 20:25:41 +08:00
|
|
|
console.log("payFeedbackFun response", response);
|
|
|
|
|
if (response && response.bizcode !== 100) {
|
|
|
|
|
console.error("反馈结果", response);
|
2025-08-05 15:25:23 +08:00
|
|
|
}
|
2025-05-07 10:09:55 +08:00
|
|
|
}
|