更新:ios支付
This commit is contained in:
@@ -8,8 +8,8 @@
|
||||
<view class="text">活动充值金额</view>
|
||||
<view class="recharge">
|
||||
<view class="recharge_block" @click="chosPric(item)"
|
||||
:class="aloneItem.priceTypeId === item.priceTypeId ? 'selected' : ''"
|
||||
v-for="item in eventAmountList" :key="item.priceTypeId">
|
||||
:class="aloneItem.priceTypeId === item.priceTypeId ? 'selected' : ''" v-for="item in eventAmountList"
|
||||
:key="item.priceTypeId">
|
||||
<view class="recharge_money">NZ${{item.realMoney}}</view>
|
||||
<view style="font-size: 26rpx;">{{item.money}}{{ $t('global.coin') }}</view>
|
||||
<span class="activity-label" v-if="item.givejf >0">{{item.description}}</span>
|
||||
@@ -23,8 +23,8 @@
|
||||
<view class="text">{{$t('order.rechargeAmount')}}</view>
|
||||
<view class="recharge">
|
||||
<view class="recharge_block" @click="chosPric(item)"
|
||||
:class="aloneItem.priceTypeId === item.priceTypeId ? 'selected' : ''"
|
||||
v-for="item in standardAmountList" :key="item.priceTypeId">
|
||||
:class="aloneItem.priceTypeId === item.priceTypeId ? 'selected' : ''" v-for="item in standardAmountList"
|
||||
:key="item.priceTypeId">
|
||||
<view class="recharge_money">NZ${{item.realMoney}}</view>
|
||||
<view style="font-size: 26rpx;">{{item.money}}{{ $t('global.coin') }}</view>
|
||||
<span class="activity-label" v-if="item.givejf >0">{{item.description}}</span>
|
||||
@@ -80,7 +80,7 @@
|
||||
import { ref, computed, onMounted, toRefs, reactive } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useMessage } from '@/uni_modules/wot-design-uni'
|
||||
import { getBookBuyConfigList, getAgreement, getActivityDescription, verifyGooglePay, getPlaceOrder } from '@/api/modules/user'
|
||||
import { getBookBuyConfigList, getAgreement, getActivityDescription, verifyGooglePay, getPlaceOrder, getIosPayment } from '@/api/modules/user'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { useThrottle } from '@/hooks/useThrottle';
|
||||
|
||||
@@ -136,6 +136,8 @@
|
||||
//正常金额数据
|
||||
const standardAmountList = ref([])
|
||||
|
||||
const iapChannel = ref(null)
|
||||
|
||||
/**
|
||||
* 获取使用环境
|
||||
*/
|
||||
@@ -145,6 +147,7 @@
|
||||
isAndroid.value = true;
|
||||
console.log('运行Android上')
|
||||
} else {
|
||||
isAndroid.value = false;
|
||||
qudao.value = 'Google'
|
||||
console.log('运行iOS上')
|
||||
}
|
||||
@@ -189,10 +192,11 @@
|
||||
* 获取订单编号
|
||||
*/
|
||||
const getPlaceOrderObj = async () => {
|
||||
console.log(isAndroid.value);
|
||||
const { priceTypeId, realMoney, money } = toRefs(aloneItem.value)
|
||||
const data = {
|
||||
userId: userStore.userInfo.id, // 用户di
|
||||
paymentMethod: '5', //支付方式4point 5google
|
||||
paymentMethod: isAndroid.value ? '5' : '3', //支付方式3ios 5google
|
||||
orderMoney: money.value, //订单金额
|
||||
realMoney: realMoney.value, //实际金额
|
||||
come: '10', //订单来源 2医学吴门医述 10海外读书
|
||||
@@ -200,12 +204,12 @@
|
||||
productId: priceTypeId.value // 商品id
|
||||
}
|
||||
try {
|
||||
// uni.hideLoading()
|
||||
const res = await getPlaceOrder(data)
|
||||
orderSn.value = res.orderSn
|
||||
console.log(orderSn.value, '获取订单号');
|
||||
uni.showLoading({ title: t('order.orderCreating') })
|
||||
getGooglePay()
|
||||
isAndroid.value ? getGooglePay() : checkProvider()
|
||||
// getGooglePay()
|
||||
} catch (error) {
|
||||
console.error('获取订单号失败', error)
|
||||
}
|
||||
@@ -233,7 +237,121 @@
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
* 检测支付提供商(判断是否支持applepay)
|
||||
*/
|
||||
const checkProvider = () => {
|
||||
uni.getProvider({
|
||||
service: 'payment',
|
||||
success: (res) => {
|
||||
console.log('getProvider返回结果:', res); // 关键日志:看是否包含applepay
|
||||
iapChannel.value = res.providers.find((channel) => {
|
||||
return (channel.id === 'appleiap')
|
||||
})
|
||||
getProductInfo()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询后台配置的商品信息
|
||||
*/
|
||||
const getProductInfo = () => {
|
||||
const id = String(aloneItem.value.priceTypeId)
|
||||
iapChannel.value.requestProduct([id], (res: any) => {
|
||||
console.log(res, '查询苹果后台配置的商品id');
|
||||
topay(id)
|
||||
}, (err: any) => {
|
||||
uni.showToast({ title: '未获取到产品信息,请联系管理员', icon: 'none' });
|
||||
console.error('失败', err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 准备支付-调出支付窗口
|
||||
*/
|
||||
const topay = (id: string) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.hideLoading()
|
||||
uni.requestPayment({
|
||||
provider: 'appleiap',
|
||||
orderInfo: {
|
||||
productid: id,
|
||||
username: orderSn.value, // 订单id
|
||||
quantity: 1,
|
||||
manualFinishTransaction: true
|
||||
},
|
||||
success: (res) => {
|
||||
console.log(res, 'res-topay');
|
||||
iapCheck(res);
|
||||
resolve(res);
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log('支付错误', err);
|
||||
restoreComplateRequest()
|
||||
uni.showToast({
|
||||
title: '关闭支付弹窗',
|
||||
icon: 'none'
|
||||
})
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用后台支付-ios
|
||||
*/
|
||||
const iapCheck = async (res : { transactionIdentifier : string; transactionReceipt : string }) => {
|
||||
// console.log(res.transactionIdentifier,res.payment.productid,res.payment.username,res.transactionReceipt,userStore.userInfo.id);
|
||||
try {
|
||||
const obj = await getIosPayment(res.transactionIdentifier, res.payment.productid, res.payment.username, res.transactionReceipt, userStore.userInfo.id)
|
||||
console.log(obj, '校验订单')
|
||||
finishTransaction(res)
|
||||
} catch (error) {
|
||||
console.error('校验订单失败:', error)
|
||||
// 也需要释放订单,防止再次提交支付窗口拉不起来
|
||||
finishTransaction(res)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否存在未关闭的订单
|
||||
*/
|
||||
const restoreComplateRequest = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
iapChannel.value.restoreCompletedTransactions({
|
||||
manualFinishTransaction: true,
|
||||
}, (res: unknown) => {
|
||||
console.log(res, '成功-restoreCompletedTransactions');
|
||||
res.map((item: any) => {
|
||||
finishTransaction(item)
|
||||
})
|
||||
resolve(res);
|
||||
}, (err : any) => {
|
||||
console.log(err, '失败-restoreCompletedTransactions');
|
||||
reject(err);
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭订单
|
||||
*/
|
||||
const finishTransaction = (trans : any) => {
|
||||
iapChannel.value.finishTransaction(
|
||||
trans,
|
||||
(success : any) => {
|
||||
console.log("关闭订单成功", success);
|
||||
},
|
||||
(fail : any) => {
|
||||
console.log("关闭订单失败", fail);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 谷歌初始化
|
||||
*/
|
||||
const getGooglePay = () => {
|
||||
googlePay.init({
|
||||
@@ -403,7 +521,7 @@
|
||||
color: #007bff;
|
||||
padding: 30rpx 0 20rpx 30rpx;
|
||||
}
|
||||
|
||||
|
||||
.recharge {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
|
||||
Reference in New Issue
Block a user