Merge branch 'main' of https://git.nuttyreading.com/zm/taimed-international-app
This commit is contained in:
@@ -6,6 +6,8 @@ import { createRequestClient } from '../request';
|
|||||||
import { SERVICE_MAP } from '../config';
|
import { SERVICE_MAP } from '../config';
|
||||||
|
|
||||||
export const paymentClient = createRequestClient({
|
export const paymentClient = createRequestClient({
|
||||||
baseURL: SERVICE_MAP.PAYMENT,
|
baseURL: SERVICE_MAP.MAIN,
|
||||||
|
// baseURL: SERVICE_MAP.PAYMENT,
|
||||||
|
loading: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// api/modules/user.ts
|
// api/modules/user.ts
|
||||||
import { mainClient } from '@/api/clients/main'
|
import { mainClient } from '@/api/clients/main'
|
||||||
|
import { paymentClient } from '@/api/clients/payment'
|
||||||
import type { IApiResponse } from '@/api/types'
|
import type { IApiResponse } from '@/api/types'
|
||||||
import type {
|
import type {
|
||||||
IUserInfo,
|
IUserInfo,
|
||||||
@@ -196,7 +197,7 @@ export async function submitFeedback(data: IFeedbackForm) {
|
|||||||
*/
|
*/
|
||||||
export async function verifyGooglePay(productId: number, purchaseToken: string, orderSn: string) {
|
export async function verifyGooglePay(productId: number, purchaseToken: string, orderSn: string) {
|
||||||
console.log(productId, purchaseToken, orderSn);
|
console.log(productId, purchaseToken, orderSn);
|
||||||
const res = await mainClient.request<IApiResponse>({
|
const res = await paymentClient.request<IApiResponse>({
|
||||||
url: 'pay/googlepay/googleVerify',
|
url: 'pay/googlepay/googleVerify',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: { productId, purchaseToken, orderSn }
|
data: { productId, purchaseToken, orderSn }
|
||||||
@@ -278,7 +279,7 @@ export async function getTransactionDetailsList(current : number, limit : number
|
|||||||
*/
|
*/
|
||||||
export async function getPlaceOrder(data: object) {
|
export async function getPlaceOrder(data: object) {
|
||||||
|
|
||||||
const res = await mainClient.request<IApiResponse>({
|
const res = await paymentClient.request<IApiResponse>({
|
||||||
url: '/book/buyOrder/placeOrder',
|
url: '/book/buyOrder/placeOrder',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: data
|
data: data
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export function createRequestClient(cfg: ICreateClientConfig) {
|
|||||||
const intercepted = requestInterceptor(final as IRequestOptions);
|
const intercepted = requestInterceptor(final as IRequestOptions);
|
||||||
|
|
||||||
// 全局处理请求 loading
|
// 全局处理请求 loading
|
||||||
const loading = !cfg.loading ? true : cfg.loading // 接口请求参数不传loading,默认显示loading
|
const loading = cfg.loading ?? true // 接口请求参数不传loading,默认显示loading
|
||||||
if (loading) {
|
if (loading) {
|
||||||
uni.showLoading({ mask: true })
|
uni.showLoading({ mask: true })
|
||||||
reqCount++
|
reqCount++
|
||||||
|
|||||||
@@ -212,7 +212,9 @@
|
|||||||
"yearCard": "Yearly",
|
"yearCard": "Yearly",
|
||||||
"days": "days",
|
"days": "days",
|
||||||
"selectPackage": "Please select a package",
|
"selectPackage": "Please select a package",
|
||||||
"consumptionRecord": "Consumption record"
|
"consumptionRecord": "Consumption record",
|
||||||
|
"returnMine": "I'm about to return to my page"
|
||||||
|
|
||||||
},
|
},
|
||||||
"book": {
|
"book": {
|
||||||
"title": "My Books",
|
"title": "My Books",
|
||||||
|
|||||||
@@ -213,7 +213,8 @@
|
|||||||
"yearCard": "年卡",
|
"yearCard": "年卡",
|
||||||
"days": "天",
|
"days": "天",
|
||||||
"selectPackage": "请选择套餐",
|
"selectPackage": "请选择套餐",
|
||||||
"consumptionRecord": "消费记录"
|
"consumptionRecord": "消费记录",
|
||||||
|
"returnMine": "即将返回我的页面"
|
||||||
},
|
},
|
||||||
"book": {
|
"book": {
|
||||||
"title": "我的书单",
|
"title": "我的书单",
|
||||||
|
|||||||
@@ -422,7 +422,7 @@
|
|||||||
border-radius: 50rpx;
|
border-radius: 50rpx;
|
||||||
color: #fffbf6;
|
color: #fffbf6;
|
||||||
padding: 10rpx 32rpx;
|
padding: 10rpx 32rpx;
|
||||||
background-image: linear-gradient(90deg, #3ab3ae 0%, #d5ecdd 200%);
|
background: #007bff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.assets {
|
.assets {
|
||||||
|
|||||||
@@ -117,6 +117,52 @@
|
|||||||
const orderSn = ref('')
|
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
|
productId: priceTypeId.value // 商品id
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
// uni.hideLoading()
|
||||||
const res = await getPlaceOrder(data)
|
const res = await getPlaceOrder(data)
|
||||||
orderSn.value = res.orderSn
|
orderSn.value = res.orderSn
|
||||||
console.log(orderSn.value, '获取订单号');
|
console.log(orderSn.value, '获取订单号');
|
||||||
|
uni.showLoading({ title: t('order.orderCreating') })
|
||||||
getGooglePay()
|
getGooglePay()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取订单号失败', 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) => {
|
const chosPric = (item : any) => {
|
||||||
console.log(item, '金额每项');
|
console.log(item, '金额每项');
|
||||||
@@ -177,17 +209,115 @@
|
|||||||
const showAgreement = () => {
|
const showAgreement = () => {
|
||||||
agreemenState.value = true
|
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 {
|
try {
|
||||||
rechargeList.value = await getBookBuyConfigList(type.value, qudao.value)
|
const obj = await verifyGooglePay(aloneItem.value.priceTypeId, purchaseToken.value, orderSn.value)
|
||||||
console.log(rechargeList.value.bookBuyConfigList, '充值列表');
|
uni.switchTab({
|
||||||
// 默认选择第一个金额
|
url: '/pages/user/index'
|
||||||
aloneItem.value = rechargeList.value.bookBuyConfigList[0]
|
})
|
||||||
|
console.log(obj, '校验订单');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取订单列表失败:', error)
|
console.error('校验订单失败:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,135 +357,6 @@
|
|||||||
// payType.value = val;
|
// 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(() => {
|
onMounted(() => {
|
||||||
getDevName();
|
getDevName();
|
||||||
getActivityDescriptionData()
|
getActivityDescriptionData()
|
||||||
|
|||||||
Reference in New Issue
Block a user