瀏覽代碼

支付宝适配

yxb
skx 1 年之前
父節點
當前提交
ab81144203
共有 3 個檔案被更改,包括 68 行新增4 行删除
  1. 66
    2
      pages/recharge/recharge.vue
  2. 1
    1
      subpackage/after-sale/arrears/arrears.vue
  3. 1
    1
      subpackage/orders/payment.vue

+ 66
- 2
pages/recharge/recharge.vue 查看文件

wechatAppID, wechatAppID,
wechatPayConfigId, wechatPayConfigId,
wechatSecret, wechatSecret,
aliPayConfigId,
obtainUserId,
} from "@/utils/network/api.js"; } from "@/utils/network/api.js";
import { import {
request request
// } // }
onLoad((option) => { onLoad((option) => {
/*获取openId 用途:(用户支付)*/ /*获取openId 用途:(用户支付)*/
getOpenID();
/*传参*/
// #ifdef MP-WEIXIN
getOpenID();/*传参*/
// #endif
state.cardId = option.cardId; state.cardId = option.cardId;
state.connectSuccess = option.connectSuccess; state.connectSuccess = option.connectSuccess;
state.orderNum = getItem("orderNum"); state.orderNum = getItem("orderNum");
if (applyResult.orderStatus === "ORDER_NOT_PAY") { if (applyResult.orderStatus === "ORDER_NOT_PAY") {
//走支付 //走支付
console.log("走支付"); console.log("走支付");
// #ifdef MP-WEIXIN
wxPayment(); wxPayment();
// #endif
// #ifdef MP-ALIPAY
aliPayment()
// #endif
} }
}); });
} }
}); });
// #endif // #endif
}; };
//掉起支付宝支付
const aliPayment = () => {
// #ifdef MP-ALIPAY
my.getAuthCode({
scopes: 'auth_user',
success: res => {
const optionsUser = {
type: 2,
data: {
payConfigId: aliPayConfigId,
code: res.authCode
},
method: "POST",
showLoading: true,
};
request(obtainUserId, optionsUser).then((res) => {
const data = stringToJson(res.bizContent);
const optionsali= {
type: 2,
data: {
openId: getItem(StorageKeys.OpenId),
wxOpenId: data.openId,
cardId: state.cardId,
orderNum: state.orderNum,
payConfigId: wechatPayConfigId,
body: "储值卡充值",
},
method: "POST",
showLoading: true,
};
request(cardCzPay, optionsali).then((res) => {
const data = stringToJson(res.bizContent);
my.tradePay ({
// 调用统一收单交易创建接口(alipay.trade.create),获得返回字段支付宝交易号 trade_no
tradeNO: data.prepayId,
success: res => {
console.log("支付成功", res);
checkOrder();
},
fail: res => {
confirm(res, () => {}, "支付失败", false);
},
});
});
});
},
fail: err => {
console.log('my.getAuthCode 调用失败', err)
}
});
// #endif
};
//支付成功改变订单状态 //支付成功改变订单状态
const checkOrder = () => { const checkOrder = () => {

+ 1
- 1
subpackage/after-sale/arrears/arrears.vue 查看文件

const optionsali = { const optionsali = {
type: 2, type: 2,
data: { data: {
openid: data.userId,
openid: data.openId,
suppleNoList: state.suppleNoList, suppleNoList: state.suppleNoList,
totalFee: allPrice.value * 100, totalFee: allPrice.value * 100,
payConfigId: aliPayConfigId, payConfigId: aliPayConfigId,

+ 1
- 1
subpackage/orders/payment.vue 查看文件

const optionsali= { const optionsali= {
type: 2, type: 2,
data: { data: {
openid: data.userId,
openid: data.openId,
productId: state.orderData.productId, //产品id productId: state.orderData.productId, //产品id
orderId: state.orderData.orderId, orderId: state.orderData.orderId,
payConfigId: aliPayConfigId, payConfigId: aliPayConfigId,

Loading…
取消
儲存