第三方支付

h5
wangdong 4 months ago
parent cc67bbd14f
commit dc51c18fbb
  1. 5
      App.vue
  2. 2
      common/enum/payment/Method.js
  3. 1
      manifest.json
  4. 75
      pages/checkout/cashier/index.vue

@ -26,13 +26,12 @@
}, },
onShow(options) { onShow(options) {
console.log('app onShow', options); console.log('app onShow', options);
let extraData = options.referrerInfo.extraData; if (options.referrerInfo) {
if (extraData) {
// wx.showToast({ // wx.showToast({
// title: params.errStr, // title: params.errStr,
// icon: 'none', // icon: 'none',
// }); // });
uni.$emit('appShow', extraData); uni.$emit('appShow', options.referrerInfo);
} }
}, },

@ -8,5 +8,5 @@ export default new Enum([
{ key: 'WECHAT', name: '微信支付', value: 'wechat' }, { key: 'WECHAT', name: '微信支付', value: 'wechat' },
{ key: 'ALIPAY', name: '支付宝支付', value: 'alipay' }, { key: 'ALIPAY', name: '支付宝支付', value: 'alipay' },
{ key: 'BALANCE', name: '余额支付', value: 'balance' }, { key: 'BALANCE', name: '余额支付', value: 'balance' },
{ key: 'HUIFU', name: '支付', value: 'huifu' } { key: 'HUIFU', name: '银联支付', value: 'huifu' }
]) ])

@ -123,6 +123,7 @@
"optimization" : { "optimization" : {
"subPackages" : true "subPackages" : true
}, },
"embeddedAppIdList": ["wx014ad2ef80a147a7"],
"requiredPrivateInfos" : [ "chooseAddress", "getLocation" ] "requiredPrivateInfos" : [ "chooseAddress", "getLocation" ]
}, },
"mp-alipay" : { "mp-alipay" : {

@ -19,9 +19,12 @@
<view v-for="(item, index) in methods" :key="index" class="pay-item dis-flex flex-x-between" <view v-for="(item, index) in methods" :key="index" class="pay-item dis-flex flex-x-between"
@click="handleSelectPayType(index)"> @click="handleSelectPayType(index)">
<view class="item-left dis-flex flex-y-center"> <view class="item-left dis-flex flex-y-center">
<view class="item-left_icon" :class="[item.method]"> <view v-if="item.method!=='huifu'" class="item-left_icon" :class="[item.method]">
<text class="iconfont" :class="[PayMethodIconEnum[item.method]]"></text> <text class="iconfont" :class="[PayMethodIconEnum[item.method]]"></text>
</view> </view>
<view v-else class="huifu-box">
<image :src="`${$picUrl}/static/yinlian.png`" mode="heightFix" class="huifu"></image>
</view>
<view class="item-left_text"> <view class="item-left_text">
<text>{{ PayMethodEnum[item.method].name }}</text> <text>{{ PayMethodEnum[item.method].name }}</text>
</view> </view>
@ -137,15 +140,14 @@
// //
this.getCashierInfo(); this.getCashierInfo();
uni.$on('appShow', this.solveShowMsg); uni.$on('appShow', this.solveShowMsg);
uni.onAppShow()
}, },
methods: { methods: {
solveShowMsg(msgData) { solveShowMsg(info) {
console.log(msgData); console.log(info);
if (msgData.errCode === '0000') { if (this.miniPayRequest && Object.keys(this.miniPayRequest).length > 0 && info.appId === this.miniPayRequest.miniuser) {
this.onShowSuccess({ message: msgData.errStr }); this.onTradeQuery(this.miniPayRequest.out_trade_no, this.curPaymentItem.method);
} else {
this.onPayFail({ message: msgData.errStr });
} }
}, },
// //
@ -194,7 +196,11 @@
// this.$toast('') // this.$toast('')
// return // return
// } // }
this.curPaymentItem = this.methods[index] this.curPaymentItem = this.methods[index];
console.log(this.curPaymentItem);
if (this.curPaymentItem.method === 'huifu') {
this.createOrder();
}
}, },
// //
@ -238,7 +244,34 @@
// //
if (app.disabled) return if (app.disabled) return
app.disabled = true app.disabled = true
if (app.curPaymentItem.method === 'huifu') {
if (!app.miniPayRequest || Object.keys(app.miniPayRequest).length === 0) {
app.$toast(`暂无${app.PayMethodEnum[app.curPaymentItem.method].name}支付信息`);
return
}
let appPayRequest = '';
appPayRequest = encodeURIComponent(JSON.stringify({
sign: app.miniPayRequest.sign,
prepayid: app.miniPayRequest.prepayid,
}));
uni.openEmbeddedMiniProgram({
appId: app.miniPayRequest.miniuser,
path: `${app.miniPayRequest.minipath}?appPayRequest=${appPayRequest}`,
success(res) {
console.log('success', res)
},
fail(e) {
console.log('fail', e);
}
});
} else {
// API // API
this.createOrder();
}
},
createOrder() {
const app = this;
CashierApi.orderPay(app.orderId, { CashierApi.orderPay(app.orderId, {
method: app.curPaymentItem.method, method: app.curPaymentItem.method,
client: app.platform, client: app.platform,
@ -247,16 +280,9 @@
.then(result => { .then(result => {
console.log(result); console.log(result);
if (app.curPaymentItem.method === 'huifu') { if (app.curPaymentItem.method === 'huifu') {
const { miniPayRequest } = result.data.payment; const { miniPayRequest, out_trade_no } = result.data.payment;
let appPayRequest = ''; app.miniPayRequest = miniPayRequest;
appPayRequest = encodeURIComponent(JSON.stringify({ app.miniPayRequest.out_trade_no = out_trade_no;
sign: miniPayRequest.sign,
prepayid: miniPayRequest.prepayid,
}));
uni.navigateToMiniProgram({
appId: miniPayRequest.miniuser,
path: `${miniPayRequest.minipath}?appPayRequest=${appPayRequest}`,
});
} else { } else {
app.onSubmitCallback(result) app.onSubmitCallback(result)
} }
@ -422,7 +448,7 @@
.payment-method { .payment-method {
width: 94%; width: 94%;
margin: 0 auto 20rpx auto; margin: 0 auto 20rpx auto;
padding: 0 40rpx; padding: 0 40rpx 0 20rpx;
background-color: #ffffff; background-color: #ffffff;
border-radius: 20rpx; border-radius: 20rpx;
@ -436,7 +462,8 @@
} }
.item-left_icon { .item-left_icon {
margin-right: 20rpx; width: 100rpx;
text-align: center;
font-size: 44rpx; font-size: 44rpx;
&.wechat { &.wechat {
@ -455,6 +482,14 @@
color: #009fe8; color: #009fe8;
} }
} }
.huifu-box {
width: 100rpx;
display: flex;
justify-content: center;
.huifu {
height: 44rpx;
}
}
.item-left_text { .item-left_text {
font-size: 28rpx; font-size: 28rpx;

Loading…
Cancel
Save