Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
project-online-fi
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
EzijingWeb
project-online-fi
Commits
2e01098e
提交
2e01098e
authored
11月 22, 2022
作者:
matian
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
h5支付开发
上级
1da8c191
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
99 行增加
和
47 行删除
+99
-47
Index.vue
src/components/layout/Index.vue
+4
-1
Confirm.vue
src/modules/pay/components/Confirm.vue
+95
-46
没有找到文件。
src/components/layout/Index.vue
浏览文件 @
2e01098e
...
@@ -19,7 +19,10 @@ const props = defineProps<Props>()
...
@@ -19,7 +19,10 @@ const props = defineProps<Props>()
<router-view
:key=
"$route.fullPath"
></router-view>
<router-view
:key=
"$route.fullPath"
></router-view>
</section>
</section>
<template
<template
v-if=
"(!mobile && route.path !== '/shop/pay') || route.path !== '/shop'"
v-if=
"
(!mobile && !route.path.includes('/shop/pay')) ||
(!mobile && route.path !== '/shop')
"
>
>
<AppFooter></AppFooter>
<AppFooter></AppFooter>
</
template
>
</
template
>
...
...
src/modules/pay/components/Confirm.vue
浏览文件 @
2e01098e
...
@@ -3,10 +3,11 @@ import { ElMessage } from 'element-plus'
...
@@ -3,10 +3,11 @@ import { ElMessage } from 'element-plus'
import
{
Check
}
from
'@element-plus/icons-vue'
import
{
Check
}
from
'@element-plus/icons-vue'
import
{
useUserStore
}
from
'@/stores/user'
import
{
useUserStore
}
from
'@/stores/user'
import
{
useDevice
}
from
'@/composables/useDevice'
import
{
useDevice
}
from
'@/composables/useDevice'
import
queryString
from
'query-string'
import
{
wxJSPay
}
from
'@/utils/wxpay'
import
{
getOpenId
,
wxJSPay
}
from
'@/utils/wxpay'
import
{
createOrder
,
getOrderList
}
from
'../api'
import
{
createOrder
,
getOrderList
}
from
'../api'
import
{
getOpenId
}
from
'@/api/base'
const
router
=
useRouter
()
const
router
=
useRouter
()
const
route
=
useRoute
()
const
{
mobile
,
wechat
,
alipay
}
=
useDevice
()
const
{
mobile
,
wechat
,
alipay
}
=
useDevice
()
const
user
=
useUserStore
()
const
user
=
useUserStore
()
const
props
=
defineProps
({
const
props
=
defineProps
({
...
@@ -14,14 +15,14 @@ const props = defineProps({
...
@@ -14,14 +15,14 @@ const props = defineProps({
type
:
Object
type
:
Object
}
}
})
})
const
orderInfo
:
any
=
ref
([])
// const defaultParams: any = ref({})
const
openId
:
any
=
ref
(
window
.
localStorage
.
getItem
(
'openId'
))
const
payment_method
=
ref
(
''
)
const
orderInfoDetail
:
any
=
ref
([])
const
orderInfoDetail
:
any
=
ref
([])
const
payMode
=
ref
(
1
)
const
payMode
=
ref
(
1
)
const
isAgree
=
ref
(
false
)
const
isAgree
=
ref
(
false
)
const
currentCheck
=
ref
(
'12'
)
const
currentCheck
=
ref
(
'12'
)
const
query
=
$computed
(()
=>
{
const
timer
=
ref
()
return
queryString
.
parse
(
location
.
search
,
{
parseBooleans
:
true
})
})
function
getDateTime
(
dayNum
:
any
)
{
function
getDateTime
(
dayNum
:
any
)
{
const
dateDay
=
new
Date
()
const
dateDay
=
new
Date
()
dateDay
.
setDate
(
dateDay
.
getDate
()
+
dayNum
)
//获取dayNum天后的日期
dateDay
.
setDate
(
dateDay
.
getDate
()
+
dayNum
)
//获取dayNum天后的日期
...
@@ -39,22 +40,26 @@ const end_time = getDateTime(90)
...
@@ -39,22 +40,26 @@ const end_time = getDateTime(90)
const
emit
=
defineEmits
<
{
const
emit
=
defineEmits
<
{
(
e
:
'success'
,
params
:
object
):
void
(
e
:
'success'
,
params
:
object
):
void
}
>
()
}
>
()
const
checkdChange
=
(
val
:
string
)
=>
{
currentCheck
.
value
=
val
}
// 创建订单
// 获取订单
const
handleCreateOrder
=
()
=>
{
const
getOrder
=
(
val
:
any
)
=>
{
if
(
wechat
)
{
getOrderList
({
order_detail_id
:
val
}).
then
((
resp
)
=>
{
const
openId
=
localStorage
.
getItem
(
'openId'
)
orderInfoDetail
.
value
=
resp
.
data
[
0
]
if
(
!
openId
)
{
const
params
=
{
getOpenId
(
query
.
code
,
pay
)
status
:
'success'
,
return
Promise
.
reject
(
'openId不存在'
)
orderId
:
orderInfoDetail
.
value
.
order_id
,
}
payPrice
:
orderInfoDetail
.
value
.
payment_money
,
pay
()
payStatus
:
orderInfoDetail
.
value
.
order_status
}
else
if
(
alipay
)
{
pay
()
}
}
clearInterval
(
timer
.
value
)
emit
(
'success'
,
params
)
})
}
}
//
去支付
//
创建订单
function
pay
()
{
const
handleCreateOrder
=
()
=>
{
const
params
:
any
=
{
const
params
:
any
=
{
shop_id
:
'6998523899570814976'
,
shop_id
:
'6998523899570814976'
,
spu_id
:
'6998525810348916736'
,
spu_id
:
'6998525810348916736'
,
...
@@ -63,37 +68,52 @@ function pay() {
...
@@ -63,37 +68,52 @@ function pay() {
buy_count
:
'1'
,
buy_count
:
'1'
,
notify_url
:
`https://ep-lms-api.ezijing.com/v2/student/push?tenant=paa&sso_id=
${
user
.
user
?.
id
}
&
class_id
=
$
{
props
.
shopItem
?.
class_id
}
&
course_flag
=
1
&
course_id
=
$
{
props
.
shopItem
?.
course_id
}
`
notify_url
:
`https://ep-lms-api.ezijing.com/v2/student/push?tenant=paa&sso_id=
${
user
.
user
?.
id
}
&
class_id
=
$
{
props
.
shopItem
?.
class_id
}
&
course_flag
=
1
&
course_id
=
$
{
props
.
shopItem
?.
course_id
}
`
}
}
if (payMode.value === 4 && wechat) {
params.payment_method = '4'
// 微信扫码支付
} else if (payMode.value === 12 && alipay) {
params.payment_method = '12'
}
createOrder(params).then((order) => {
orderInfo.value = order
if (wechat) {
if (wechat) {
wxJSPay(order, getOrder())
if (openId.value) {
params.open_id = openId.value
params.payment_method = '3'
fetchPlaceOrder(params)
}
} else if (alipay) {
} else if (alipay) {
location.href = orderInfo.value[0]?.payment_url
params.payment_method = '12'
fetchPlaceOrder(params)
}
}
}
const fetchPlaceOrder = (params: any) => {
createOrder(params).then((res) => {
placeOrderCallback(res)
})
})
}
}
const placeOrderCallback = (res: any) => {
// 获取订单
const payType = payment_method.value
function getOrder() {
if (payType === '3') {
return getOrderList({
// 微信内支付
order_detail_id: orderInfo.value[0].order_detail_id
if (typeof res.payment_more_info === 'string') {
}).then((resp) => {
const payInfo = JSON.parse(res.payment_more_info)
orderInfoDetail.value = resp.data[0]
if (payInfo.appId) {
const params = {
wxJSPay(res, getOrder)
status: 'success',
}
orderId: orderInfoDetail.value.order_id,
}
payPrice: orderInfoDetail.value.payment_money,
} else if (payType === '4') {
payStatus: orderInfoDetail.value.order_status
// 微信外微信h5支付
window.location.href =
res.payment_url +
'&redirect_url=' +
encodeURIComponent(res.order_details_url)
timer.value = setInterval(() => {
// 通过定时器每间隔一会去请求查询微信支付状态(具体参数根据项目需要而定)
getOrder(res.order_detail_id)
}, 2000)
} else if (payType === '12') {
// 支付宝网页支付
window.location.href = res.payment_url
timer.value = setInterval(() => {
// 通过定时器每间隔一会去请求查询微信支付状态(具体参数根据项目需要而定)
getOrder(res.order_detail_id)
}, 2000)
}
}
emit('success', params)
})
}
}
// 点击立即购买
const handlePay = () => {
const handlePay = () => {
if (isAgree.value === false) {
if (isAgree.value === false) {
ElMessage.warning('请先勾选紫荆金保服务协议')
ElMessage.warning('请先勾选紫荆金保服务协议')
...
@@ -106,6 +126,7 @@ const handlePay = () => {
...
@@ -106,6 +126,7 @@ const handlePay = () => {
}
}
emit('success', params)
emit('success', params)
} else {
} else {
// H5创建订单
handleCreateOrder()
handleCreateOrder()
}
}
} else {
} else {
...
@@ -115,9 +136,7 @@ const handlePay = () => {
...
@@ -115,9 +136,7 @@ const handlePay = () => {
}
}
}
}
}
}
const checkdChange = (val: string) => {
currentCheck.value = val
}
const handlePrev = () => {
const handlePrev = () => {
router.push({
router.push({
path: `
/
shop
/
detail
/
$
{
props
.
shopItem
?.
id
}
`,
path: `
/
shop
/
detail
/
$
{
props
.
shopItem
?.
id
}
`,
...
@@ -126,6 +145,36 @@ const handlePrev = () => {
...
@@ -126,6 +145,36 @@ const handlePrev = () => {
}
}
})
})
}
}
const fetchOpenId = (code: any) => {
getOpenId({ code, identity: 'ezijing' }).then((res: any) => {
if (res.openid) {
openId.value = res.openid || ''
window.localStorage.setItem('openId', res.openid || '')
} else {
window.localStorage.removeItem('openId')
getCode()
}
})
}
const getCode = () => {
const redirectURI = `
https
:
//pages.ezijing.com/given/auth.html?redirect_uri=${encodeURIComponent(
window
.
location
.
href
)}
`
window.location.href = `
https
:
//open.weixin.qq.com/connect/oauth2/authorize?appid=wx451c01d40d090d7a&redirect_uri=${redirectURI}&response_type=code&scope=snsapi_base#wechat_redirect`
}
if
(
(
openId
.
value
===
''
||
openId
.
value
===
null
||
openId
.
value
===
undefined
)
&&
wechat
)
{
const
{
code
}
=
route
.
query
if
(
code
)
{
fetchOpenId
(
code
)
}
else
{
getCode
()
}
}
</
script
>
</
script
>
<
template
>
<
template
>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论