|
@@ -60,9 +60,9 @@
|
|
<div class="payment-section">
|
|
<div class="payment-section">
|
|
<div class="payment-option">
|
|
<div class="payment-option">
|
|
<div class="payment-icon">
|
|
<div class="payment-icon">
|
|
- <img src="@/assets/images/recharge_wechat.png" alt="微信支付" class="wechat-icon" />
|
|
|
|
|
|
+ <img src="@/assets/images/recharge_paypal.png" alt="支付宝支付" class="alipay-icon" />
|
|
</div>
|
|
</div>
|
|
- <div class="payment-name">微信支付</div>
|
|
|
|
|
|
+ <div class="payment-name">支付宝支付</div>
|
|
<div class="payment-selected">
|
|
<div class="payment-selected">
|
|
<img src="@/assets/images/duihao.png" alt="选中" class="check-icon" />
|
|
<img src="@/assets/images/duihao.png" alt="选中" class="check-icon" />
|
|
</div>
|
|
</div>
|
|
@@ -114,16 +114,14 @@
|
|
// eslint-disable-next-line no-undef
|
|
// eslint-disable-next-line no-undef
|
|
import { getProductList } from '@/api/product'
|
|
import { getProductList } from '@/api/product'
|
|
import { getUserInfo } from '@/api/user'
|
|
import { getUserInfo } from '@/api/user'
|
|
-import { wechatPayCoin, wxPay } from '@/api/pay'
|
|
|
|
-import { ahtuCodeApi } from '@/api/pay'
|
|
|
|
-import { getDevicePayWayId } from '@/utils/config'
|
|
|
|
|
|
+import { aliPayCoin } from '@/api/pay'
|
|
|
|
+import { getDevicePayWayId, getPlatformType } from '@/utils/config'
|
|
|
|
|
|
export default {
|
|
export default {
|
|
name: 'RechargePage',
|
|
name: 'RechargePage',
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
resultDataMess: {},
|
|
resultDataMess: {},
|
|
- userCode: '',
|
|
|
|
userInfo: {
|
|
userInfo: {
|
|
id: '',
|
|
id: '',
|
|
nickname: '',
|
|
nickname: '',
|
|
@@ -131,7 +129,7 @@ export default {
|
|
},
|
|
},
|
|
rechargeOptions: [],
|
|
rechargeOptions: [],
|
|
selectedRecharge: 0,
|
|
selectedRecharge: 0,
|
|
- paymentMethod: 'wechat',
|
|
|
|
|
|
+ paymentMethod: 'alipay',
|
|
isLoading: false,
|
|
isLoading: false,
|
|
agreementChecked: false,
|
|
agreementChecked: false,
|
|
agreementVisible: false
|
|
agreementVisible: false
|
|
@@ -148,30 +146,12 @@ export default {
|
|
|
|
|
|
// 获取产品列表
|
|
// 获取产品列表
|
|
this.fetchProductList()
|
|
this.fetchProductList()
|
|
- this.listenWeixinBridge() // 监听桥梁加载
|
|
|
|
-
|
|
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
- // 监听 weixinJSBridge 加载
|
|
|
|
- listenWeixinBridge() {
|
|
|
|
- if (window.WeixinJSBridge) {
|
|
|
|
- this.onWeixinBridgeReady()
|
|
|
|
- } else {
|
|
|
|
- const listener = () => this.onWeixinBridgeReady()
|
|
|
|
- document.addEventListener('WeixinJSBridgeReady', listener, false)
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
-
|
|
|
|
- // weixinJSBridge 加载成功回调
|
|
|
|
- onWeixinBridgeReady() {
|
|
|
|
- this.bridgeReady = true
|
|
|
|
- console.log('weixinJSBridge 加载成功')
|
|
|
|
- },
|
|
|
|
// 初始化用户信息
|
|
// 初始化用户信息
|
|
async initUserInfo() {
|
|
async initUserInfo() {
|
|
// 从路由参数获取用户信息
|
|
// 从路由参数获取用户信息
|
|
const { id, nickname, avatar } = this.$route.query
|
|
const { id, nickname, avatar } = this.$route.query
|
|
- this.userCode = this.$route.query.userCode
|
|
|
|
if (id) {
|
|
if (id) {
|
|
// 如果路由参数中有用户ID,直接使用
|
|
// 如果路由参数中有用户ID,直接使用
|
|
this.userInfo.id = id
|
|
this.userInfo.id = id
|
|
@@ -284,14 +264,14 @@ export default {
|
|
allowHtml: true
|
|
allowHtml: true
|
|
}).then(() => {
|
|
}).then(() => {
|
|
// 调用支付接口
|
|
// 调用支付接口
|
|
- this.requestWechatPay(selectedOption)
|
|
|
|
|
|
+ this.requestAliPay(selectedOption)
|
|
}).catch(() => {
|
|
}).catch(() => {
|
|
// 取消支付
|
|
// 取消支付
|
|
})
|
|
})
|
|
},
|
|
},
|
|
|
|
|
|
- // 请求微信支付
|
|
|
|
- async requestWechatPay(product) {
|
|
|
|
|
|
+ // 请求支付宝支付
|
|
|
|
+ async requestAliPay(product) {
|
|
// 显示加载提示
|
|
// 显示加载提示
|
|
this.isLoading = true
|
|
this.isLoading = true
|
|
this.$toast.loading({
|
|
this.$toast.loading({
|
|
@@ -301,42 +281,31 @@ export default {
|
|
})
|
|
})
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
+ // 获取平台类型
|
|
|
|
+ const platform = getPlatformType()
|
|
|
|
+
|
|
// 构建支付参数
|
|
// 构建支付参数
|
|
- const payWayId = getDevicePayWayId() // 获取设备对应的支付方式ID
|
|
|
|
const payData = {
|
|
const payData = {
|
|
- "productName": "一号房间",
|
|
|
|
- openId: localStorage.getItem('userOpenId'),
|
|
|
|
userId: this.userInfo.id,
|
|
userId: this.userInfo.id,
|
|
- productId: product.id,
|
|
|
|
- amount: product.price,
|
|
|
|
- orderNo: Date.now(),
|
|
|
|
- payWayId: payWayId // 添加支付方式ID
|
|
|
|
|
|
+ productId: product.id
|
|
}
|
|
}
|
|
|
|
|
|
- // 调用后端支付接口
|
|
|
|
- const res = await wxPay(payData)
|
|
|
|
- console.log(res, 9999)
|
|
|
|
|
|
+ // 调用支付宝支付接口
|
|
|
|
+ const res = await aliPayCoin(payData, platform)
|
|
this.$toast.clear()
|
|
this.$toast.clear()
|
|
this.isLoading = false
|
|
this.isLoading = false
|
|
|
|
|
|
// 处理支付结果
|
|
// 处理支付结果
|
|
- if (res.status == 200) {
|
|
|
|
- try {
|
|
|
|
- let signData = JSON.parse(res.data.outputJSON)
|
|
|
|
- this.resultDataMess = signData
|
|
|
|
- console.log(signData,'signData')
|
|
|
|
- let wxJsapiParam = signData.wxJsapiParam
|
|
|
|
- if (signData.returnCode == '0000') {
|
|
|
|
- // 5. 调用 weixinJSBridge 支付
|
|
|
|
- this.invokeWeixinBridgePayment(wxJsapiParam)
|
|
|
|
- } else {
|
|
|
|
- this.$toast.fail(this.resultDataMess.returnMsg|| '获取支付链接失败')
|
|
|
|
- }
|
|
|
|
- } catch {
|
|
|
|
- this.$toast.fail(this.resultDataMess.returnMsg || '获取支付链接失败')
|
|
|
|
- }
|
|
|
|
|
|
+ if (res.code === 200) {
|
|
|
|
+ // 支付宝支付成功,通常会返回一个支付链接或表单
|
|
|
|
+ if (res.data && res.data.payUrl) {
|
|
|
|
+ // 跳转到支付宝支付页面
|
|
|
|
+ window.location.href = res.data.payUrl
|
|
|
|
+ } else {
|
|
|
|
+ this.$toast.fail('获取支付链接失败')
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- this.$toast.fail(this.resultDataMess.returnMsg || '获取支付链接失败')
|
|
|
|
|
|
+ this.$toast.fail(res.message || '支付请求失败')
|
|
}
|
|
}
|
|
} catch (error) {
|
|
} catch (error) {
|
|
this.$toast.clear()
|
|
this.$toast.clear()
|
|
@@ -345,39 +314,18 @@ export default {
|
|
this.$toast.fail('支付请求失败,请重试')
|
|
this.$toast.fail('支付请求失败,请重试')
|
|
}
|
|
}
|
|
},
|
|
},
|
|
-// 调用 weixinJSBridge 支付
|
|
|
|
- invokeWeixinBridgePayment(payParams) {
|
|
|
|
- window.WeixinJSBridge.invoke(
|
|
|
|
- 'getBrandWCPayRequest',
|
|
|
|
- payParams,
|
|
|
|
- this.handleWeixinPayResult
|
|
|
|
- )
|
|
|
|
- },
|
|
|
|
- // 处理支付结果
|
|
|
|
- handleWeixinPayResult(res) {
|
|
|
|
- if (res.err_msg === "get_brand_wcpay_request:ok") {
|
|
|
|
- // 支付成功
|
|
|
|
- this.handlePaymentSuccess(res)
|
|
|
|
- } else if (res.err_msg === "get_brand_wcpay_request:cancel") {
|
|
|
|
- // 支付取消
|
|
|
|
- this.handlePaymentCancel()
|
|
|
|
- } else {
|
|
|
|
- // 支付失败
|
|
|
|
- this.handlePaymentFailure(res)
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
|
|
|
|
// 处理支付成功
|
|
// 处理支付成功
|
|
- handlePaymentSuccess(res) {
|
|
|
|
- console.log('支付成功:', res)
|
|
|
|
|
|
+ handlePaymentSuccess() {
|
|
|
|
+ console.log('支付成功')
|
|
this.$toast.success('支付成功')
|
|
this.$toast.success('支付成功')
|
|
window.location.href = 'https://gbyy91.com/pay'
|
|
window.location.href = 'https://gbyy91.com/pay'
|
|
},
|
|
},
|
|
|
|
|
|
// 处理支付失败
|
|
// 处理支付失败
|
|
- handlePaymentFailure(res) {
|
|
|
|
- console.error('支付失败:', res)
|
|
|
|
- this.$toast.fail(res.err_msg || '支付失败,请重试')
|
|
|
|
|
|
+ handlePaymentFailure(message) {
|
|
|
|
+ console.error('支付失败:', message)
|
|
|
|
+ this.$toast.fail(message || '支付失败,请重试')
|
|
},
|
|
},
|
|
|
|
|
|
// 处理支付取消
|
|
// 处理支付取消
|
|
@@ -626,7 +574,7 @@ export default {
|
|
margin-right: 12px;
|
|
margin-right: 12px;
|
|
}
|
|
}
|
|
|
|
|
|
-.wechat-icon {
|
|
|
|
|
|
+.alipay-icon {
|
|
width: 28px;
|
|
width: 28px;
|
|
height: 28px;
|
|
height: 28px;
|
|
object-fit: contain;
|
|
object-fit: contain;
|