Browse Source

ali 支付

mht 1 tháng trước cách đây
mục cha
commit
1976eb773d
5 tập tin đã thay đổi với 62 bổ sung130 xóa
  1. 12 0
      src/api/pay.js
  2. BIN
      src/assets/images/recharge_paypal.png
  3. 15 2
      src/utils/config.js
  4. 29 81
      src/views/Recharge.vue
  5. 6 47
      src/views/Search.vue

+ 12 - 0
src/api/pay.js

@@ -15,6 +15,18 @@ export function wechatPayCoin(data) {
   })
 } 
 
+// 支付宝支付接口
+export function aliPayCoin(data, platform) {
+  return request({
+    url: '/web/aliPayCoin',
+    method: 'post',
+    headers: {
+      'Content-Type': 'application/json',
+      'platform': platform
+    },
+    data
+  })
+}
 
 export const ahtuCodeApi = (code) =>{
   return requestPay({

BIN
src/assets/images/recharge_paypal.png


+ 15 - 2
src/utils/config.js

@@ -3,7 +3,7 @@ const isDev = process.env.NODE_ENV === 'development'
 
 // API基础URL配置
 export const API_BASE_URL = isDev 
-  ? 'https://gbyy91.com/api'
+  ? 'http://localhost:8082'
   : 'https://gbyy91.com/api' // 生产环境 
 
 // 支付方式ID
@@ -22,10 +22,23 @@ export function getDevicePayWayId() {
   return PAY_WAY_ID.ANDROID
 }
 
+// 获取平台类型
+export function getPlatformType() {
+  const ua = navigator.userAgent.toLowerCase()
+  if (/iphone|ipad|ipod|ios/.test(ua)) {
+    return 'ios'
+  } else if (/android/.test(ua)) {
+    return 'android'
+  }
+  // 默认返回web平台
+  return 'web'
+}
+
 // 其他全局配置可以在这里添加
 export default {
   API_BASE_URL,
   isDev,
   PAY_WAY_ID,
-  getDevicePayWayId
+  getDevicePayWayId,
+  getPlatformType
 } 

+ 29 - 81
src/views/Recharge.vue

@@ -60,9 +60,9 @@
     <div class="payment-section">
       <div class="payment-option">
         <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 class="payment-name">微信支付</div>
+        <div class="payment-name">支付宝支付</div>
         <div class="payment-selected">
           <img src="@/assets/images/duihao.png" alt="选中" class="check-icon" />
         </div>
@@ -114,16 +114,14 @@
 // eslint-disable-next-line no-undef
 import { getProductList } from '@/api/product'
 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 {
   name: 'RechargePage',
   data() {
     return {
       resultDataMess: {},
-      userCode: '',
       userInfo: {
         id: '',
         nickname: '',
@@ -131,7 +129,7 @@ export default {
       },
       rechargeOptions: [],
       selectedRecharge: 0,
-      paymentMethod: 'wechat',
+      paymentMethod: 'alipay',
       isLoading: false,
       agreementChecked: false,
       agreementVisible: false
@@ -148,30 +146,12 @@ export default {
     
     // 获取产品列表
     this.fetchProductList()
-        this.listenWeixinBridge() // 监听桥梁加载
-
   },
   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() {
       // 从路由参数获取用户信息
       const { id, nickname, avatar } = this.$route.query
-      this.userCode = this.$route.query.userCode
       if (id) {
         // 如果路由参数中有用户ID,直接使用
         this.userInfo.id = id
@@ -284,14 +264,14 @@ export default {
         allowHtml: true
       }).then(() => {
         // 调用支付接口
-        this.requestWechatPay(selectedOption)
+        this.requestAliPay(selectedOption)
       }).catch(() => {
         // 取消支付
       })
     },
     
-    // 请求微信支付
-    async requestWechatPay(product) {
+    // 请求支付宝支付
+    async requestAliPay(product) {
       // 显示加载提示
       this.isLoading = true
       this.$toast.loading({
@@ -301,42 +281,31 @@ export default {
       })
       
       try {
+        // 获取平台类型
+        const platform = getPlatformType()
+        
         // 构建支付参数
-        const payWayId = getDevicePayWayId() // 获取设备对应的支付方式ID
         const payData = {
-          "productName": "一号房间",
-          openId: localStorage.getItem('userOpenId'),
           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.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 {
-           this.$toast.fail(this.resultDataMess.returnMsg || '获取支付链接失败')
+          this.$toast.fail(res.message || '支付请求失败')
         }
       } catch (error) {
         this.$toast.clear()
@@ -345,39 +314,18 @@ export default {
         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('支付成功')
       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;
 }
 
-.wechat-icon {
+.alipay-icon {
   width: 28px;
   height: 28px;
   object-fit: contain;

+ 6 - 47
src/views/Search.vue

@@ -52,9 +52,9 @@
     <div class="payment-section">
       <div class="payment-option">
         <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 class="payment-name">微信支付</div>
+        <div class="payment-name">支付宝支付</div>
         <div class="payment-selected">
           <img src="@/assets/images/duihao.png" alt="选中" class="check-icon" />
         </div>
@@ -67,7 +67,7 @@
       <div class="tips-content">
         <div class="tip-item">1. 充值前请确定您已满18周岁并具有完全民事行为能力。</div>
         <div class="tip-item">2. 安全账号转账、理赔转账、刷单、代充均为骗局,请认真核实并确认</div>
-        <div class="tip-item">3. 大额充值,支付方式可选择"零钱通"</div>
+        <div class="tip-item">3. 大额充值,请确保支付宝账户余额充足</div>
         <div class="tip-item">4. 如有疑问,请联系服务号客服</div>
       </div>
       
@@ -105,8 +105,7 @@
 <script>
 import { getProductList } from '@/api/product'
 import { getUserInfo } from '@/api/user'
-import { ahtuCodeApi } from '@/api/pay'
-import { getDevicePayWayId } from '@/utils/config'
+import { getPlatformType, getDevicePayWayId } from '@/utils/config'
 
 export default {
   name: 'SearchPage',
@@ -118,7 +117,7 @@ export default {
       searchValue: '',
       coinOptions: [],
       selectedRecharge: 0,
-      paymentMethod: 'wechat',
+      paymentMethod: 'alipay',
       agreementChecked: false,
       agreementVisible: false
     }
@@ -126,47 +125,8 @@ export default {
   created() {
     // 获取产品列表
     this.fetchProductList()
-    this.getUserCode()
   },
   methods: {
-  getUserCode() {
-    let url = window.location.href
-    this.tianyongchao =  window.location.href
-  const strictMatch = url.match(/[?&]code=([^&]+)/);
-  const strictCode = strictMatch ? strictMatch[1] : null;
-  if (!strictCode) {
-    // 记录当前页面URL作为重定向目标
-    const redirectUrl = `https%3A%2F%2Fgbyy91.com%2Fpay`
-    
-    // 构建微信授权URL
-    const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa25eb9f7ebd39219&redirect_uri=${redirectUrl}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`
-    setTimeout(() =>{
-    window.location.href = authUrl
-    }, 300)
-
-  } else {
-      let url = window.location.href
-      const strictMatch = url.match(/[?&]code=([^&]+)/);
-      const strictCode = strictMatch ? strictMatch[1] : null;
-      this.userCode = strictCode
-       this.$toast.loading({
-          message: '加载中...',
-          forbidClick: true,
-          duration: 0
-        })
-      ahtuCodeApi(this.userCode).then((res) =>{
-        console.log(res,77777)
-        if (res.data.openid) {
-          localStorage.setItem('userOpenId', res.data.openid)
-        }
-      }).finally(() =>{
-        this.$toast.clear()
-      })
-  }
-},
-fetchUserInfo() {
-
-},
     // 获取产品列表
     async fetchProductList() {
       try {
@@ -212,7 +172,6 @@ fetchUserInfo() {
           this.$router.push({
             path: '/recharge',
             query: { 
-              userCode: this.userCode,
               id: res.data.userId,
               nickname: res.data.userName,
               avatar: res.data.avatar
@@ -510,7 +469,7 @@ fetchUserInfo() {
   margin-right: 12px;
 }
 
-.wechat-icon {
+.alipay-icon {
   width: 28px;
   height: 28px;
   object-fit: contain;