This commit is contained in:
2025-11-28 18:03:53 +08:00
7 changed files with 166 additions and 159 deletions

View File

@@ -422,7 +422,7 @@
border-radius: 50rpx;
color: #fffbf6;
padding: 10rpx 32rpx;
background-image: linear-gradient(90deg, #3ab3ae 0%, #d5ecdd 200%);
background: #007bff;
}
.assets {

View File

@@ -117,6 +117,52 @@
const orderSn = ref('')
/**
* 获取使用环境
*/
const getDevName = () => {
if (uni.getSystemInfoSync().platform === "android") {
qudao.value = 'Google'
isAndroid.value = true;
console.log('运行Android上')
} else {
qudao.value = 'Google'
console.log('运行iOS上')
}
getData()
}
/**
* 获取充值列表数据
*/
const getData = async () => {
try {
rechargeList.value = await getBookBuyConfigList(type.value, qudao.value)
console.log(rechargeList.value.bookBuyConfigList, '充值列表');
// 默认选择第一个金额
aloneItem.value = rechargeList.value.bookBuyConfigList[0]
} catch (error) {
console.error('获取订单列表失败:', error)
}
}
/**
* 点击支付按钮
*/
const paymentButton = async () => {
if (!state.value) {
uni.showToast({
title: t('order.readAgreeServices'),
icon: 'none'
})
return
}
getPlaceOrderObj()
}
// 节流支付按钮
const handleRecharge = useThrottle(paymentButton);
/**
* 获取订单编号
*/
@@ -132,31 +178,17 @@
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()
} catch (error) {
console.error('获取订单号失败', error)
}
}
/**
* 获取使用环境
*/
const getDevName = () => {
if (uni.getSystemInfoSync().platform === "android") {
qudao.value = 'Google'
isAndroid.value = true;
console.log('运行Android上')
} else {
qudao.value = 'Google'
console.log('运行iOS上')
}
getData()
}
// 点击金额
const chosPric = (item : any) => {
console.log(item, '金额每项');
@@ -177,17 +209,115 @@
const showAgreement = () => {
agreemenState.value = true
}
/**
* 获取充值列表数据
* 初始化
*/
const getData = async () => {
const getGooglePay = () => {
googlePay.init({
}, (e : any) => {
console.log('init', e);
if (e.code == 0) {
isConnected.value = true;
console.log('init成功了');
getQuerySku()
// 初始化成功
} else {
console.log('init失败了');
// 初始化失败
isConnected.value = false;
}
});
}
/**
* 查询sku
*/
const getQuerySku = () => {
const id = aloneItem.value.priceTypeId
console.log(id, '获取每项');
googlePay.querySku(
{
inapp: [id], // 与subs二选一, 参数为商品ID字符串数组
},
(e : any) => {
if (e.code == 0) {
// 查询成功.
console.log('querySku查询成功', e);
getPayAll()
uni.hideLoading()
} else {
console.log('查询失败', e);
uni.showToast({
title: t('global.networkConnectionError'),
icon: 'error'
})
}
}
)
}
/**
* 发起支付
*/
const getPayAll = () => {
console.log(aloneItem.value.priceTypeId, orderSn.value, '发起支付传入产品id,订单id');
googlePay.payAll(
{
productId: aloneItem.value.priceTypeId, // 产品id
accountId: orderSn.value // 订单编号
},
(e : any) => {
if (e.code == 0) {
purchaseToken.value = e.data[0].original.purchaseToken
// 支付成功
console.log(e, 'payAll方法成功返参');
getConsume()
} else {
uni.showToast({ title: t('user.paymentFailed'), icon: 'error' })
console.log(e, 'e');
// 支付失败
}
},
)
}
/**
* 消耗品 确认交易
*/
const getConsume = () => {
googlePay.consume(
{
purchaseToken: purchaseToken.value, // 来自支付结果的original.purchaseToken (或 original.token)
},
(e : any) => {
if (e.code == 0) {
console.log(e, '确认交易成功');
uni.showToast({ title: t('user.returnMine'), icon: 'none' })
// 确认成功
googleVerify()
} else {
console.log(e, '确认交易失败');
// 确认失败
}
},
);
}
/**
* 校验订单
*/
const googleVerify = async () => {
uni.hideLoading()
console.log(typeof aloneItem.value.priceTypeId, typeof purchaseToken.value, typeof orderSn.value);
try {
rechargeList.value = await getBookBuyConfigList(type.value, qudao.value)
console.log(rechargeList.value.bookBuyConfigList, '充值列表');
// 默认选择第一个金额
aloneItem.value = rechargeList.value.bookBuyConfigList[0]
const obj = await verifyGooglePay(aloneItem.value.priceTypeId, purchaseToken.value, orderSn.value)
uni.switchTab({
url: '/pages/user/index'
})
console.log(obj, '校验订单');
} catch (error) {
console.error('获取订单列表失败:', error)
console.error('校验订单失败:', error)
}
}
@@ -227,135 +357,6 @@
// payType.value = val;
}
/**
* 点击支付按钮
*/
const paymentButton = async () => {
if (!state.value) {
uni.showToast({
title: t('order.readAgreeServices'),
icon: 'none'
})
return
}
getPlaceOrderObj()
uni.showLoading({ title: '生成订单中...' })
}
// 节流支付按钮
const handleRecharge = useThrottle(paymentButton);
/**
* 初始化
*/
const getGooglePay = () => {
googlePay.init({
}, (e : any) => {
console.log('init', e);
if (e.code == 0) {
isConnected.value = true;
getQuerySku()
// 初始化成功
} else {
// 初始化失败
isConnected.value = false;
}
});
}
/**
* 查询sku
*/
const getQuerySku = () => {
const id = aloneItem.value.priceTypeId
console.log(id, '获取每项');
googlePay.querySku(
{
inapp: [id], // 与subs二选一, 参数为商品ID字符串数组
},
(e : any) => {
if (e.code == 0) {
// 查询成功.
console.log('querySku查询成功', e);
uni.hideLoading()
getPayAll()
} else {
console.log('查询失败', e);
uni.showToast({
title: 'No product found.',
icon: 'none',
duration: 2000
})
// 查询失败
}
}
)
}
/**
* 发起支付
*/
const getPayAll = () => {
console.log(aloneItem.value.priceTypeId, orderSn.value, '发起支付传入产品id,订单id');
googlePay.payAll(
{
productId: aloneItem.value.priceTypeId, // 产品id
accountId: orderSn.value // 订单编号
},
(e : any) => {
if (e.code == 0) {
purchaseToken.value = e.data[0].original.purchaseToken
// 支付成功
console.log(e, 'payAll方法成功返参');
getConsume()
} else {
uni.showToast({ title: '支付失败', icon: 'success' })
console.log(e, 'e');
// 支付失败
}
},
)
}
/**
* 消耗品 确认交易
*/
const getConsume = () => {
googlePay.consume(
{
purchaseToken: purchaseToken.value, // 来自支付结果的original.purchaseToken (或 original.token)
},
(e : any) => {
if (e.code == 0) {
console.log(e, '确认交易成功');
// 确认成功
googleVerify()
} else {
console.log(e, '确认交易失败');
// 确认失败
}
},
);
}
/**
* 校验订单
*/
const googleVerify = async () => {
console.log(typeof aloneItem.value.priceTypeId, typeof purchaseToken.value, typeof orderSn.value);
try {
const obj = await verifyGooglePay(aloneItem.value.priceTypeId, purchaseToken.value, orderSn.value)
uni.switchTab({
url: '/pages/user/index'
})
console.log(obj, '校验订单');
} catch (error) {
console.error('校验订单失败:', error)
}
}
onMounted(() => {
getDevName();
getActivityDescriptionData()