feat: 优化代码
This commit is contained in:
+30
-30
@@ -2,15 +2,15 @@ import { feedback } from '@/api/payment.js';
|
||||
|
||||
|
||||
/**
|
||||
* 微信支付
|
||||
* 微信支付
|
||||
* @param {Object} alipay 微信支付的参数
|
||||
* @param {Object} orderId 支付的订单ID
|
||||
* @param {Object} orderNum 支付的订单编号
|
||||
*/
|
||||
export function appWxpayFun(alipay,orderId,orderNum){
|
||||
export function appWxpayFun(alipay, orderId, orderNum) {
|
||||
const type = alipay.type;
|
||||
const orderStr = alipay.orderStr;
|
||||
if(type === "app"){// app
|
||||
if (type === "app") {// app
|
||||
const orderInfo = {
|
||||
"appid": alipay.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
|
||||
"noncestr": alipay.nonceStr, // 随机字符串
|
||||
@@ -21,21 +21,21 @@ export function appWxpayFun(alipay,orderId,orderNum){
|
||||
"sign": alipay.sign // 签名,这里用的 MD5/RSA 签名
|
||||
};
|
||||
uni.requestPayment({
|
||||
provider:"wxpay",
|
||||
provider: "wxpay",
|
||||
orderInfo: orderInfo,
|
||||
success: function(res) {
|
||||
success: function (res) {
|
||||
console.log('success:' + res);
|
||||
payFeedbackFun(orderId,orderNum,1);
|
||||
payFeedbackFun(orderId, orderNum, 1);
|
||||
jumpWayOk();
|
||||
},
|
||||
fail: function(err) {
|
||||
console.log('fail:',err);
|
||||
fail: function (err) {
|
||||
console.log('fail:', err);
|
||||
jumpWayError();
|
||||
}
|
||||
});
|
||||
}else if(type === "h5"){// h5
|
||||
} else if (type === "h5") {// h5
|
||||
uni.navigateTo({
|
||||
url: `/pages/payment_processing/payment_processing?link=${encodeURIComponent(orderStr)}&orderNum=`+orderNum // 假设有一个专门的支付页面来处理支付链接
|
||||
url: `/pages/other_package/payment_processing/payment_processing?link=${encodeURIComponent(orderStr)}&orderNum=` + orderNum // 假设有一个专门的支付页面来处理支付链接
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -46,25 +46,25 @@ export function appWxpayFun(alipay,orderId,orderNum){
|
||||
* @param {Object} orderId 支付的订单ID
|
||||
* @param {Object} orderNum 支付的订单编号
|
||||
*/
|
||||
export function zfbPayFun(alipay,orderId,orderNum){
|
||||
console.log("alipay",alipay);
|
||||
export function zfbPayFun(alipay, orderId, orderNum) {
|
||||
console.log("alipay", alipay);
|
||||
const type = alipay.type;
|
||||
const orderStr = alipay.orderStr;
|
||||
if(type === "h5"){// h5
|
||||
if (type === "h5") {// h5
|
||||
uni.navigateTo({
|
||||
url: `/pages/payment_processing/payment_processing?link=${encodeURIComponent(orderStr)}&orderNum=`+orderNum // 假设有一个专门的支付页面来处理支付链接
|
||||
url: `/pages/other_package/payment_processing/payment_processing?link=${encodeURIComponent(orderStr)}&orderNum=` + orderNum // 假设有一个专门的支付页面来处理支付链接
|
||||
});
|
||||
}else if(type === "app"){ // app
|
||||
} else if (type === "app") { // app
|
||||
uni.requestPayment({
|
||||
provider: 'alipay',
|
||||
orderInfo: orderStr,
|
||||
success: function(res) {
|
||||
console.log("zfbPayFun res",res);
|
||||
payFeedbackFun(orderId,orderNum,1);
|
||||
success: function (res) {
|
||||
console.log("zfbPayFun res", res);
|
||||
payFeedbackFun(orderId, orderNum, 1);
|
||||
jumpWayOk();
|
||||
},
|
||||
fail: function(err) {
|
||||
console.error("支付宝支付error",err);
|
||||
fail: function (err) {
|
||||
console.error("支付宝支付error", err);
|
||||
jumpWayError();
|
||||
}
|
||||
});
|
||||
@@ -76,33 +76,33 @@ export function zfbPayFun(alipay,orderId,orderNum){
|
||||
};
|
||||
|
||||
// 跳转到支付成功页面
|
||||
export function jumpWayOk(){
|
||||
export function jumpWayOk() {
|
||||
uni.navigateTo({
|
||||
url:"/pages/order_submit_ok/order_submit_ok",
|
||||
url: "/pages/order_package/order_submit_ok/order_submit_ok",
|
||||
})
|
||||
}
|
||||
// 跳转到支付失败页面
|
||||
export function jumpWayError(){
|
||||
export function jumpWayError() {
|
||||
uni.navigateTo({
|
||||
url:"/pages/order_submit_error/order_submit_error",
|
||||
url: "/pages/order_package/order_submit_error/order_submit_error",
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 支付结果回调
|
||||
* 支付结果回调
|
||||
* @param {Object} orderId 支付订单ID
|
||||
* @param {Object} orderNum 支付订单编号
|
||||
* @param {Object} status 反馈结果【0:失败,1:成功】
|
||||
*/
|
||||
async function payFeedbackFun(orderId,orderNum,status){
|
||||
async function payFeedbackFun(orderId, orderNum, status) {
|
||||
const params = {
|
||||
orderId,
|
||||
orderNum,
|
||||
status,
|
||||
}
|
||||
console.log("params",params);
|
||||
console.log("params", params);
|
||||
const response = await feedback(params);
|
||||
console.log("payFeedbackFun response",response);
|
||||
if(response && response.bizcode !==100){
|
||||
console.error("反馈结果",response);
|
||||
console.log("payFeedbackFun response", response);
|
||||
if (response && response.bizcode !== 100) {
|
||||
console.error("反馈结果", response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user