提交 0c683568 authored 作者: 王鹏飞's avatar 王鹏飞

chore: 修改h5微信支付

上级 08936e03
...@@ -18,6 +18,10 @@ export function usePay() { ...@@ -18,6 +18,10 @@ export function usePay() {
const openId = useStorage('openId', '') const openId = useStorage('openId', '')
const redirectURL = computed(() => {
return `${location.origin}/shop/order/${shopStore.shopItem?.id}`
})
// 支付 // 支付
async function pay(options = {}) { async function pay(options = {}) {
// 默认参数 // 默认参数
...@@ -26,7 +30,7 @@ export function usePay() { ...@@ -26,7 +30,7 @@ export function usePay() {
spu_id: shopStore.shopItem?.spu_id || '6998525810348916736', spu_id: shopStore.shopItem?.spu_id || '6998525810348916736',
sku_id: shopStore.shopItem?.sku_id || '6998525810365693952', sku_id: shopStore.shopItem?.sku_id || '6998525810365693952',
buy_count: '1', buy_count: '1',
redirect_url: `${location.origin}/shop/order/${shopStore.shopItem?.id}`, redirect_url: redirectURL.value,
notify_url: `https://ep-lms-api.ezijing.com/v2/student/push?tenant=paa&sso_id=${userStore.user?.id}&class_id=${shopStore.shopItem?.class_id}&course_flag=1&course_id=${shopStore.shopItem?.course_id}` notify_url: `https://ep-lms-api.ezijing.com/v2/student/push?tenant=paa&sso_id=${userStore.user?.id}&class_id=${shopStore.shopItem?.class_id}&course_flag=1&course_id=${shopStore.shopItem?.course_id}`
}) })
const params = Object.assign(defaultParams, options) const params = Object.assign(defaultParams, options)
...@@ -42,10 +46,20 @@ export function usePay() { ...@@ -42,10 +46,20 @@ export function usePay() {
if (!payOrder.value) return if (!payOrder.value) return
// 网页支付,直接唤起对应支付网页 // 网页支付,直接唤起对应支付网页
if (params.payment_method === '4' || params.payment_method === '12') { if (params.payment_method === '12') {
location.href = payOrder.value.payment_url location.href = payOrder.value.payment_url
return return
} }
// 微信h5支付
if (params.payment_method === '4') {
const paymentUrl = `${payOrder.value.payment_url}&redirect_url=${encodeURIComponent(
`https://pages.ezijing.com/base/auth.html?redirect_uri=${encodeURIComponent(redirectURL.value)}`
)}`
location.href = `https://pages.ezijing.com/base/pay.html?payment_url=${encodeURIComponent(
paymentUrl
)}&redirect_url=${redirectURL.value}`
return
}
// 微信JS支付 // 微信JS支付
if (params.payment_method === '3') { if (params.payment_method === '3') {
wxJSPay() wxJSPay()
...@@ -91,7 +105,7 @@ export function usePay() { ...@@ -91,7 +105,7 @@ export function usePay() {
// 获取code // 获取code
function getCode() { function getCode() {
const href = location.href.includes('?') ? `${location.href}&is_pay=true` : `${location.href}?is_pay=true` const href = location.href.includes('?') ? `${location.href}&is_pay=true` : `${location.href}?is_pay=true`
const redirectURI = `https://pages.ezijing.com/given/auth.html?redirect_uri=${encodeURIComponent(href)}` const redirectURI = `https://pages.ezijing.com/base/auth.html?redirect_uri=${encodeURIComponent(href)}`
location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx451c01d40d090d7a&redirect_uri=${redirectURI}&response_type=code&scope=snsapi_base` location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx451c01d40d090d7a&redirect_uri=${redirectURI}&response_type=code&scope=snsapi_base`
} }
...@@ -113,10 +127,11 @@ export function usePay() { ...@@ -113,10 +127,11 @@ export function usePay() {
alert('订单创建错误') alert('订单创建错误')
return return
} }
const payInfo: any = JSON.parse(payOrder.value.payment_more_info) location.href = `https://pages.ezijing.com/base/pay.html?payment_more_info=${payOrder.value.payment_more_info}&redirect_url=${redirectURL.value}`
;(window as any).WeixinJSBridge?.invoke('getBrandWCPayRequest', payInfo, (res: any) => { // const payInfo: any = JSON.parse(payOrder.value.payment_more_info)
console.log(res) // ;(window as any).WeixinJSBridge?.invoke('getBrandWCPayRequest', payInfo, (res: any) => {
}) // console.log(res)
// })
} }
return { order, payOrder, pay } return { order, payOrder, pay }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论