mirror of
https://gitee.com/bootx/dax-pay-h5
synced 2026-08-11 15:15:34 +08:00
feat 添加聚合支付接口, 收银台支持自动升级为聚合支付
This commit is contained in:
@@ -27,7 +27,7 @@ export const DaxPayRoute: RouteRecordRaw = {
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/cashier/:code',
|
||||
path: '/cashier/:orderNo',
|
||||
name: 'CashierCode',
|
||||
component: () => import('@/views/daxpay/cashier/Cashier.vue'),
|
||||
meta: {
|
||||
@@ -35,7 +35,7 @@ export const DaxPayRoute: RouteRecordRaw = {
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/aggregate/:code',
|
||||
path: '/aggregate/:orderNo',
|
||||
name: 'CheckAggregate',
|
||||
component: () => import('@/views/daxpay/aggregate/Aggregate.vue'),
|
||||
meta: {
|
||||
@@ -43,7 +43,7 @@ export const DaxPayRoute: RouteRecordRaw = {
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/aggregate/alipay/:code',
|
||||
path: '/aggregate/alipay/:orderNo',
|
||||
name: 'AliCheckout',
|
||||
component: () => import('@/views/daxpay/aggregate/alipay/AlipayAggregate.vue'),
|
||||
meta: {
|
||||
@@ -51,7 +51,7 @@ export const DaxPayRoute: RouteRecordRaw = {
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/aggregate/wechat/:code',
|
||||
path: '/aggregate/wechat/:orderNo',
|
||||
name: 'WechatCheckout',
|
||||
component: () => import('@/views/daxpay/aggregate/wechat/WechatAggregate.vue'),
|
||||
meta: {
|
||||
|
||||
15
src/utils/uaUtil.ts
Normal file
15
src/utils/uaUtil.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 获取浏览器UA类型
|
||||
*/
|
||||
export function getBrowserUA() {
|
||||
const ua = navigator.userAgent
|
||||
if (ua.includes('MicroMessenger')) {
|
||||
return 'wechat'
|
||||
}
|
||||
else if (ua.includes('Alipay')) {
|
||||
return 'alipay'
|
||||
}
|
||||
else {
|
||||
return 'browser'
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,25 @@
|
||||
import type { AuthResult } from '../auth/ChannelAuth.api'
|
||||
import { http } from '@/utils/http/axios'
|
||||
import type { Result } from '#/axios'
|
||||
import type { GatewayOrder, GatewayPayConfig } from '@/views/daxpay/cashier/Cashier.api'
|
||||
|
||||
/**
|
||||
* 获取收银台配置信息
|
||||
* 获取聚合支付相关订单和配置信息
|
||||
*/
|
||||
export function getCashierTypeConfig(cashierType: string, cashierCode: string) {
|
||||
return http.request<Result<CashierTypeConfigResult>>({
|
||||
url: '/unipay/cashier/code/findByCashierType',
|
||||
export function getAggregateConfig(orderNo, aggregateType) {
|
||||
return http.request<Result<AggregateOrderAndConfig>>({
|
||||
url: '/unipay/gateway/getAggregateConfig',
|
||||
method: 'GET',
|
||||
params: { cashierType, cashierCode },
|
||||
params: { orderNo, aggregateType },
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取收银台所需授权链接, 用于获取OpenId一类的信息
|
||||
*/
|
||||
export function generateAuthUrl(param: CashierAuthUrlParam) {
|
||||
export function generateAuthUrl(param: GatewayAuthUrlParam) {
|
||||
return http.request<Result<string>>({
|
||||
url: '/unipay/cashier/code/generateAuthUrl',
|
||||
url: '/unipay/gateway/generateAuthUrl',
|
||||
method: 'POST',
|
||||
data: param,
|
||||
})
|
||||
@@ -27,9 +28,9 @@ export function generateAuthUrl(param: CashierAuthUrlParam) {
|
||||
/**
|
||||
* 获取授权信息
|
||||
*/
|
||||
export function auth(param: CashierAuthParam) {
|
||||
export function auth(param: GatewayAuthCodeParam) {
|
||||
return http.request<Result<AuthResult>>({
|
||||
url: '/unipay/cashier/code/auth',
|
||||
url: '/unipay/gateway/auth',
|
||||
method: 'POST',
|
||||
data: param,
|
||||
})
|
||||
@@ -38,7 +39,7 @@ export function auth(param: CashierAuthParam) {
|
||||
/**
|
||||
* 发起支付
|
||||
*/
|
||||
export function cashierPay(param: CashierPayParam) {
|
||||
export function aggregatePay(param: AggregatePayParam) {
|
||||
return http.request<Result<PayResult>>({
|
||||
url: '/unipay/cashier/code/pay',
|
||||
method: 'POST',
|
||||
@@ -46,24 +47,54 @@ export function cashierPay(param: CashierPayParam) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 网关聚合支付订单和配置信息
|
||||
*/
|
||||
export interface AggregateOrderAndConfig {
|
||||
/** 订单信息 */
|
||||
order: GatewayOrder
|
||||
/** 收银台配置信息 */
|
||||
config: GatewayPayConfig
|
||||
/** 聚合支付配置信息 */
|
||||
aggregateConfig: AggregateConfig
|
||||
}
|
||||
|
||||
/**
|
||||
* 收银台聚合配置信息
|
||||
*/
|
||||
export interface AggregateConfig {
|
||||
/** 支付类型 */
|
||||
aggregateType?: string
|
||||
/** 通道 */
|
||||
channel?: string
|
||||
/** 支付方式 */
|
||||
payMethod?: string
|
||||
/** 其他支付方式 */
|
||||
otherMethod?: string
|
||||
/** 自动拉起支付 */
|
||||
autoLaunch?: boolean
|
||||
/** 需要获取OpenId */
|
||||
needOpenId?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取认证URL参数
|
||||
*/
|
||||
export interface CashierAuthUrlParam {
|
||||
// 应用号
|
||||
cashierCode?: string
|
||||
// 收银台类型
|
||||
cashierType?: string
|
||||
export interface GatewayAuthUrlParam {
|
||||
// 订单号
|
||||
orderNo?: string
|
||||
// 聚合支付类型
|
||||
aggregateType?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 认证参数
|
||||
*/
|
||||
export interface CashierAuthParam {
|
||||
// 应用号
|
||||
cashierCode?: string
|
||||
// 收银台类型
|
||||
cashierType?: string
|
||||
export interface GatewayAuthCodeParam {
|
||||
// 订单号
|
||||
orderNo?: string
|
||||
// 聚合支付类型
|
||||
aggregateType?: string
|
||||
// 授权码
|
||||
authCode?: string
|
||||
}
|
||||
@@ -71,17 +102,13 @@ export interface CashierAuthParam {
|
||||
/**
|
||||
* 通道收银支付参数
|
||||
*/
|
||||
export interface CashierPayParam {
|
||||
// 应用号
|
||||
cashierCode?: string
|
||||
// 收银台类型
|
||||
cashierType?: string
|
||||
// 支付金额
|
||||
amount?: number
|
||||
export interface AggregatePayParam {
|
||||
// 订单
|
||||
orderNo?: string
|
||||
// 聚合支付类型
|
||||
aggregateType?: string
|
||||
// 唯一标识
|
||||
openId?: string
|
||||
// 支付描述
|
||||
description?: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,19 +142,3 @@ export interface WxJsapiSignResult {
|
||||
// 微信签名
|
||||
paySign?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 收银码牌配置信息
|
||||
*/
|
||||
export interface CashierTypeConfigResult {
|
||||
// 应用号
|
||||
appId?: string
|
||||
// 码牌名称
|
||||
name?: string
|
||||
// 支付通道
|
||||
channel?: string
|
||||
// 支付方式
|
||||
payMethod?: string
|
||||
// 是否开启分账
|
||||
allocation?: boolean
|
||||
}
|
||||
|
||||
@@ -4,16 +4,17 @@
|
||||
<script setup lang="ts">
|
||||
import { useRoute } from 'vue-router'
|
||||
import router from '@/router'
|
||||
import { getBrowserUA } from '@/utils/uaUtil'
|
||||
|
||||
const route = useRoute()
|
||||
const { code } = route.params
|
||||
const { orderNo } = route.params
|
||||
|
||||
const ua = navigator.userAgent
|
||||
if (ua.includes('MicroMessenger')) {
|
||||
router.push({ path: `/aggregate/wechat/${code}`, replace: true })
|
||||
const ua = getBrowserUA()
|
||||
if (ua === 'wechat') {
|
||||
router.push({ path: `/aggregate/wechat/${orderNo}`, replace: true })
|
||||
}
|
||||
else if (ua.includes('Alipay')) {
|
||||
router.push({ path: `/aggregate/alipay/${code}`, replace: true })
|
||||
else if (ua === 'alipay') {
|
||||
router.push({ path: `/aggregate/alipay/${orderNo}`, replace: true })
|
||||
}
|
||||
else {
|
||||
router.push({ name: 'ErrorResult', query: { msg: '请使用支付宝、微信等软件进行扫码支付' }, replace: true })
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<div class="payPrice">
|
||||
<span class="unit">¥</span>
|
||||
<div class="price">
|
||||
1288
|
||||
{{ 1288 }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="excessTime">
|
||||
@@ -38,7 +38,17 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useRoute } from 'vue-router'
|
||||
import { getAggregateConfig } from '@/views/daxpay/aggregate/Aggregate.api'
|
||||
|
||||
const route = useRoute()
|
||||
const { orderNo } = route.params
|
||||
|
||||
onMounted(() => {
|
||||
getAggregateConfig(orderNo, 'alipay').then(({ data, code, msg }) => {
|
||||
console.log(data)
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div class="aggeegateWeixin">
|
||||
<div v-if="orderAndConfig" class="aggeegateWeixin">
|
||||
<div class="aggBox">
|
||||
<img src="@/assets/images/bill_logo.png" alt="">
|
||||
<div class="payPrice">
|
||||
@@ -38,7 +38,25 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useRoute } from 'vue-router'
|
||||
import { ref } from 'vue'
|
||||
import type { AggregateOrderAndConfig } from '@/views/daxpay/aggregate/Aggregate.api'
|
||||
import { getAggregateConfig } from '@/views/daxpay/aggregate/Aggregate.api'
|
||||
|
||||
const route = useRoute()
|
||||
const { orderNo } = route.params
|
||||
|
||||
const orderAndConfig = ref<AggregateOrderAndConfig>()
|
||||
|
||||
onMounted(() => {
|
||||
getAggregateConfig(orderNo, 'wechat_pay').then(({ data, code, msg }) => {
|
||||
// 判断是否需要获取OpenId
|
||||
if (data.aggregateConfig.needOpenId){
|
||||
|
||||
}
|
||||
orderAndConfig.value = data
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
|
||||
@@ -112,14 +112,15 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, onUnmounted, reactive, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import type { OrderAndConfig, payConfig } from '@/views/daxpay/cashier/Cashier.api'
|
||||
import type { OrderAndConfig } from '@/views/daxpay/cashier/Cashier.api'
|
||||
import { getOrderAndConfig, payOrder } from '@/views/daxpay/cashier/Cashier.api'
|
||||
import { getBrowserUA } from '@/utils/uaUtil'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
// 获取传入的参数
|
||||
const { code: orderNo } = route.params
|
||||
const { orderNo } = route.params
|
||||
// 储存初始化的数据
|
||||
const orderAndConfig = ref<OrderAndConfig>()
|
||||
|
||||
@@ -279,7 +280,15 @@ function init() {
|
||||
})
|
||||
return
|
||||
}
|
||||
// 如果自动升级聚合支付, 判断是否在对应环境中, 自动进行升级
|
||||
if (data.config.h5AutoUpgrade) {
|
||||
if (getBrowserUA() !== 'browser') {
|
||||
router.replace({ path: `/aggregate/${orderNo}`, replace: true })
|
||||
return;
|
||||
}
|
||||
}
|
||||
orderAndConfig.value = data // 赋值初始化数据
|
||||
|
||||
getDownTotalTime(data.order.expiredTime) // 计算倒计时
|
||||
getMinter() // 先执行一下 解决进入页面一秒后才显示倒计时
|
||||
resume() // 开启倒计时
|
||||
|
||||
Reference in New Issue
Block a user