Procházet zdrojové kódy

订单支付宝支付

yxb
skx před 1 rokem
rodič
revize
771b72f072
1 změnil soubory, kde provedl 80 přidání a 1 odebrání
  1. 80
    1
      subpackage/orders/payment.vue

+ 80
- 1
subpackage/orders/payment.vue Zobrazit soubor

@@ -46,6 +46,19 @@
></image>
<view class="select-circle" v-else></view>
</view>
<view class="method-item border-line" @click="methodHandle('ali')">
<view class="method-name">
<image class="name-img" :src="`${$imgUrl}order/uni.png`"></image>
<text class="name-text">支付宝支付</text>
</view>
<image
class="name-img-selected"
:src="`${$imgUrl}order/selected.png`"
v-if="state.methodSelected == 'ali'"
></image>
<view class="select-circle" v-else></view>
</view>
<view class="method-item border-line" @click="methodHandle('ysf')">
<view class="method-name">
<image class="name-img" :src="`${$imgUrl}order/ysf.png`"></image>
@@ -105,6 +118,8 @@ import {
orderPay,
wechatAppID,
wechatPayConfigId,
aliPayConfigId,
obtainUserId,
wechatSecret,
} from "@/utils/network/api";
import { stringToJson } from "@/utils/network/encryption";
@@ -145,6 +160,8 @@ const toPayOrder = () => {
if (state.methodSelected == "wx") {
//微信支付
wxPayment();
} else if (state.methodSelected == "ali"){
aliPayment()
} else {
msg("目前只支持微信支付!");
}
@@ -192,6 +209,61 @@ const wxPayment = () => {
// #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: data.userId,
productId: state.orderData.productId, //产品id
orderId: state.orderData.orderId,
payConfigId: aliPayConfigId,
},
method: "POST",
showLoading: true,
};
request(orderPay, optionsali).then((res) => {
const data = stringToJson(res.bizContent);
state.orderData.orderId = data.orderId
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
};


//获取微信小程序openid
const getOpenID = () => {
uni.login({
@@ -209,11 +281,18 @@ const getOpenID = () => {

//支付成功改变订单状态
const checkOrder = () => {
let configId = ""
if (state.methodSelected == "wx") {
configId = wechatPayConfigId;
} else if (state.methodSelected == "ali") {
configId = aliPayConfigId
}

const options = {
type: 2,
data: {
orderId: state.orderData.orderId,
payConfigId: wechatPayConfigId,
payConfigId: configId,
},
method: "POST",
showLoading: true,

Načítá se…
Zrušit
Uložit