Bladeren bron

订单支付宝支付

yxb
skx 1 jaar geleden
bovenliggende
commit
771b72f072
1 gewijzigde bestanden met toevoegingen van 80 en 1 verwijderingen
  1. 80
    1
      subpackage/orders/payment.vue

+ 80
- 1
subpackage/orders/payment.vue Bestand weergeven

></image> ></image>
<view class="select-circle" v-else></view> <view class="select-circle" v-else></view>
</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-item border-line" @click="methodHandle('ysf')">
<view class="method-name"> <view class="method-name">
<image class="name-img" :src="`${$imgUrl}order/ysf.png`"></image> <image class="name-img" :src="`${$imgUrl}order/ysf.png`"></image>
orderPay, orderPay,
wechatAppID, wechatAppID,
wechatPayConfigId, wechatPayConfigId,
aliPayConfigId,
obtainUserId,
wechatSecret, wechatSecret,
} from "@/utils/network/api"; } from "@/utils/network/api";
import { stringToJson } from "@/utils/network/encryption"; import { stringToJson } from "@/utils/network/encryption";
if (state.methodSelected == "wx") { if (state.methodSelected == "wx") {
//微信支付 //微信支付
wxPayment(); wxPayment();
} else if (state.methodSelected == "ali"){
aliPayment()
} else { } else {
msg("目前只支持微信支付!"); msg("目前只支持微信支付!");
} }
// #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: 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 //获取微信小程序openid
const getOpenID = () => { const getOpenID = () => {
uni.login({ uni.login({


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

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

Laden…
Annuleren
Opslaan