Kaynağa Gözat

联调安卓支付及优化·

bayi 1 yıl önce
ebeveyn
işleme
e6cc47ce5e
4 değiştirilmiş dosya ile 38 ekleme ve 16 silme
  1. 2 0
      api/user.js
  2. 31 2
      pages/my/index.js
  3. 4 13
      pages/my/index.wxml
  4. 1 1
      utils/request.js

+ 2 - 0
api/user.js

@@ -17,6 +17,8 @@ module.exports = {
     getLearnCard: data => request('/v3/learnCard/exchange', 'get', data, false, false),
     // 购买vip
     buyVip: data => request('/order', 'post', data, true),
+    // 安卓购买vip
+    androidbuyVip: data => request('/order/appCreate', 'post', data, true),
     //获取是否vip及过期时间
     getVipInfo: data => request('/auth', 'get', data),
     //获取自己朗读的作品

+ 31 - 2
pages/my/index.js

@@ -1,6 +1,6 @@
 import {
     getMyInfo,
-    buyVip,
+    androidbuyVip,
     getVipInfo,
     getWxQrcode,
     getLearnCard
@@ -76,6 +76,7 @@ Page({
             productList: products,
             isPreferential
         } = await getProducts()
+        console.log(products);
         this.setData({
             products,
             isPreferential
@@ -142,11 +143,39 @@ Page({
             title: '提交中',
             mask: true
         })
-        let res = await buyVip({
+        let res = await androidbuyVip({
             productId: currentTarget.dataset.id
         }).finally(() => {
             wx.hideLoading()
         })
+        wx.miniapp.requestPayment({
+            timeStamp: res.timestamp,
+            mchId: res.partnerid,
+            prepayId: res.prepayid,
+            package: res.package,
+            nonceStr: res.noncestr,
+            sign: res.sign,
+            success: async (res) => {
+                setTimeout(() => {
+                    this.setUserInfo()
+                    this.selectComponent('#vipModal').open()
+                }, 1500)
+                userEvent({
+                    action: 'ANDROID_PAY_SUCCESS',
+                })
+            },
+            fail(res) {
+                wx.showToast({
+                    title: "支付失败",
+                    icon: "none",
+                    duration: 3000
+                })
+            },
+            complete: (res) => {
+                console.error('wx.miniapp.requestPayment complete:', res)
+            }
+        })
+        return
         userEvent({
             action: 'ANDROID_PAY_ACTIVITY',
         })

+ 4 - 13
pages/my/index.wxml

@@ -40,17 +40,7 @@
     <!-- 安卓 -->
     <view class="scrollViewBox" wx:if="{{vipTime!='1'&&!isIos}}">
         <scroll-view class="goodsList" scroll-x="true" enhanced show-scrollbar="{{false}}">
-            <view class="payBox pbbg2" bindtap="toBuy" data-id="{{products[0].id}}">
-                <view class="pay">
-                    {{isPreferential?'立即续费':'立即开通'}}
-                </view>
-            </view>
-            <view class="payBox pbbg1" bindtap="toBuy" data-id="{{products[2].id}}">
-                <view class="pay">
-                    {{isPreferential?'立即续费':'立即开通'}}
-                </view>
-            </view>
-            <view class="payBox pbbg3" bindtap="toBuy" data-id="{{products[1].id}}">
+            <view wx:for="{{products}}" wx:key="id" class="payBox {{item.payType=='LIFELONG'?'pbbg2':item.payType=='YEAR'?'pbbg1':'pbbg3'}}" bindtap="toBuy" data-id="{{item.id}}">
                 <view class="pay">
                     {{isPreferential?'立即续费':'立即开通'}}
                 </view>
@@ -89,9 +79,10 @@
             </view>
             <image class='black' src='/static/black.png'></image>
         </view>
-        <view class="activation" bindtap="jump" data-url="/pages/rankIntro/index?img=https://reader-wx.ai160.com/images/reader/v3/jghz.jpg">
+        <view class="activation" bindtap="jump"
+            data-url="/pages/rankIntro/index?img=https://reader-wx.ai160.com/images/reader/v3/jghz.jpg">
             <view class="tips">
-                <image src="/static/fs.png" class="tipsImg" style="height: 34rpx;"/>机构合作
+                <image src="/static/fs.png" class="tipsImg" style="height: 34rpx;" />机构合作
             </view>
             <image class='black' src='/static/black.png'></image>
         </view>

+ 1 - 1
utils/request.js

@@ -18,7 +18,7 @@ function request(url, method, data, oldBaseUrl = false, intercept = true) {
 
     let header = {
         'uid': wx.getStorageSync('uid') || '',
-        'channelCode': wx.getStorageSync('user').channel == '4001' ? '4001' : '3001'
+        'channelCode': wx.getStorageSync('user').channel == '4001' ? '4001' : '3006'
     }
     return new Promise((reslove, reject) => {
         wx.request({