Browse Source

开发联调vip及充值项配置接口,处理苹果充值配置

sunxf 2 years ago
parent
commit
9188a19395

+ 7 - 0
api/global.js

@@ -0,0 +1,7 @@
+import {
+    request
+} from "../utils/request";
+module.exports = {
+    //获取充值配置信息
+    getProducts: data => request('/v3/product', 'get', data),
+}

+ 3 - 1
api/user.js

@@ -5,8 +5,10 @@ import {
 module.exports = {
     //获取用户信息
     getUserInfo: data => request('/v3/user/my', 'get', data),
+    //获取是否vip及过期时间
+    getVipInfo: data => request('/auth', 'get', data),
     //获取自己朗读的作品
     getSelfRead: data => request('/userRead/my', 'get', data),
-    //获取用户朗读的作品
+    //获取其他用户朗读的作品
     getUserRead: data => request('/userRead', 'get', data),
 }

+ 38 - 5
pages/my/index.js

@@ -1,18 +1,28 @@
 import {
-    getUserInfo
+    getUserInfo,
+    getVipInfo
 } from '~/api/user'
 import {
+    getProducts
+} from '~/api/global'
+import {
     getOpenidNoLogin
 } from '~/utils/httpUtilNoLogin';
 import httpRequestApi from '~/utils/APIClient';
+
 let app = getApp()
 Page({
     data: {
         userInfo: {},
-        isIos: false
-        // isIos: app.globalData.isIOS
+        vipTime: '',
+        isIos: false,
+        // isIos: app.globalData.isIOS,
+        productNum: {},
+        productVip: {}
+    },
+    onLoad() {
+        this.getProducts()
     },
-    onLoad() {},
     async onShow() {
         let uid = wx.getStorageSync('uid') || ''
         // 没登陆先走静默登录,登录后直接获取用户信息
@@ -26,8 +36,11 @@ Page({
     },
     async setUserInfo() {
         let userInfo = await getUserInfo()
+        let vipTime = await getVipInfo()
+
         this.setData({
-            userInfo
+            userInfo,
+            vipTime
         })
         console.log(userInfo);
         // 如果用户没有头像及昵称的话就提醒获取
@@ -37,6 +50,26 @@ Page({
             });
         }
     },
+    async getProducts() {
+        let products = await getProducts()
+        let productVip = products.find(item => {
+            return item.type == 1
+        })
+        let productNum = products.find(item => {
+            return item.type == 2
+        })
+        console.log(productNum, productVip);
+        this.setData({
+            productNum,
+            productVip
+        })
+    },
+    // 支付
+    toPay({
+        currentTarget
+    }) {
+        let type = currentTarget.dataset.type
+    },
     jump({
         currentTarget
     }) {

+ 1 - 1
pages/my/index.less

@@ -127,7 +127,7 @@
 
     .iosVip {
         margin: 4rpx 0px 0px 6rpx;
-        font-size: 18rpx;
+        font-size: 20rpx;
         color: #333;
     }
 

+ 9 - 9
pages/my/index.wxml

@@ -44,8 +44,8 @@
         </view>
     </view>
     <!-- ios会员展示到期时间 -->
-    <view class="iosVip" wx:if="{{isIos}}">
-        会员至:2023年12月11日
+    <view class="iosVip" wx:if="{{isIos&&vipTime}}">
+        会员至:{{filters.formatDate(vipTime)}}
     </view>
     <!-- 跳转菜单 -->
     <view class="sectionBoxs">
@@ -80,22 +80,22 @@
         <view class="pay vipPay">
             <view class="payLeft">
                 <view class="pLTitle vipTitle">
-                    99元/12个月VIP
+                    {{productVip.title}}
                 </view>
                 <view class="pLcontent vipContent">
-                    购买VIP会员,即可畅读全部资源
+                    {{vipTime?filters.formatDate(vipTime)+'过期':'购买VIP会员,即可畅读全部资源'}}
                 </view>
             </view>
-            <view class="payRight vipBtn">
-                立即开通
+            <view class="payRight vipBtn" bindtap="toPay" data-type='1'>
+                {{vipTime?'立即续费':'立即开通'}}
             </view>
         </view>
         <view class="pay buyPay">
             <view class="payLeft">
-                10元/10次体验
+                {{productNum.title}}
             </view>
-            <view class="payRight buyBtn">
-                立即开通
+            <view class="payRight buyBtn" bindtap="toPay" data-type='2'>
+                立即购买
             </view>
         </view>
     </view>

+ 1 - 1
pages/my/index.wxss

@@ -107,7 +107,7 @@
 }
 .container .iosVip {
   margin: 4rpx 0px 0px 6rpx;
-  font-size: 18rpx;
+  font-size: 20rpx;
   color: #333;
 }
 .container .sectionBoxs {

+ 3 - 3
pages/reading/reading.js

@@ -516,7 +516,7 @@ Page({
         } else {
             const recordSource = this.data.recordSource
             wx.uploadFile({
-                url: 'https://reader-api.ai160.com//file/upload',
+                url: 'https://reader-api.efunbox.cn/file/upload',
                 filePath: recordSource,
                 name: '朗读录音',
                 header: {
@@ -589,8 +589,8 @@ Page({
         })
         const recordSource = this.data.recordSource;
         wx.uploadFile({
-            // url: 'https://reader-api.ai160.com//file/upload',
-            url: 'https://reader-api.ai160.com///file/upload',
+            // url: 'https://reader-api.efunbox.cn/file/upload',
+            url: 'https://reader-api.efunbox.cn//file/upload',
             filePath: recordSource,
             name: '朗读录音',
             header: {

+ 1 - 1
pages/user/myEdit/myEdit.js

@@ -79,7 +79,7 @@ Page({
         // tempFilePath可以作为img标签的src属性显示图片
         const localImage = res.tempFilePaths[0];
         wx.uploadFile({
-          url: 'https://reader-api.ai160.com//file/upload',
+          url: 'https://reader-api.efunbox.cn/file/upload',
           filePath: localImage,
           name: '头像',
           header: {

+ 68 - 68
pages/vipPage/vip/vip.js

@@ -4,76 +4,76 @@ import APIClient from '../../../utils/APIClient.js'
 import utils from '../../../utils/util'
 Page({
 
-  data: {
-    buyBtnText: '立即开通',
-    price: '29',
-    bottomText: '原价99元/年',
-    productId: 0,
-    modalType: 'image',
-    isModalShow: false,
-    isVIP: false
-  },
-  onLoad: function (options) {
-    if (options.title) {
-      wx.setNavigationBarTitle({
-        title: VIP购买
-      });
-    }
-    APIClient.getProductData().success(res => {
-      this.setData({
-        price: res.data.data.price,
-        productId: res.data.data.id
-      })
-    }).fail(err => {
-      console.log(err);
-    });
-    APIClient.getUserAuth().success(res => {
-      if (res.data.data) {
-        this.setData({
-          isVIP: true,
-          bottomText: `有效期:${utils.formatDate(res.data.data.endTime,2)}`
+    data: {
+        buyBtnText: '立即开通',
+        price: '29',
+        bottomText: '原价99元/年',
+        productId: 0,
+        modalType: 'image',
+        isModalShow: false,
+        isVIP: false
+    },
+    onLoad: function (options) {
+        if (options.title) {
+            wx.setNavigationBarTitle({
+                title: VIP购买
+            });
+        }
+        APIClient.getProductData().success(res => {
+            this.setData({
+                price: res.data.data.price,
+                productId: res.data.data.id
+            })
+        }).fail(err => {
+            console.log(err);
+        });
+        APIClient.getUserAuth().success(res => {
+            if (res.data.data) {
+                this.setData({
+                    isVIP: true,
+                    bottomText: `有效期:${utils.formatDate(res.data.data.endTime,2)}`
+                })
+            } else {
+                this.setData({
+                    isVIP: false
+                })
+            }
         })
-      } else {
+    },
+
+    createOrder() {
+        APIClient.postOrder(this.data.productId).success(res => {
+            this.prePayMap(res.data.data)
+        }).fail(err => {
+            console.log(err);
+        });
+    },
+    prePayMap(prePayMap) {
+        const that = this;
+        wx.requestPayment({
+            'appId': prePayMap.appId,
+            'timeStamp': prePayMap.timeStamp,
+            'nonceStr': prePayMap.nonceStr,
+            'package': prePayMap.package,
+            'signType': 'MD5',
+            'paySign': prePayMap.sign,
+            'success': function (res) {
+                that.setData({
+                    isModalShow: true,
+                })
+            },
+            'fail': function (res) {
+                console.log('支付失败', res)
+
+            }
+        })
+    },
+    modalConfirmHandler() {
         this.setData({
-          isVIP: false
+            isModalShow: false
         })
-      }
-    })
-  },
-
-  createOrder() {
-    APIClient.postOrder(this.data.productId).success(res => {
-      this.prePayMap(res.data.data)
-    }).fail(err => {
-      console.log(err);
-    });
-  },
-  prePayMap(prePayMap) {
-    const that = this;
-    wx.requestPayment({
-      'appId': prePayMap.appId,
-      'timeStamp': prePayMap.timeStamp,
-      'nonceStr': prePayMap.nonceStr,
-      'package': prePayMap.package,
-      'signType': 'MD5',
-      'paySign': prePayMap.sign,
-      'success': function (res) {
-        that.setData({
-          isModalShow: true,
+        wx.redirectTo({
+            url: `/pages/index/index`
         })
-      },
-      'fail': function (res) {
-        console.log('支付失败', res)
-        
-      }
-    })
-  },
-  modalConfirmHandler() {
-    this.setData({
-      isModalShow: false
-    })
-    wx.redirectTo({
-      url: `/pages/index/index`
-    })
-  },
+    },
 })

File diff suppressed because it is too large
+ 660 - 660
utils/APIClient.js


+ 2 - 2
utils/const.js

@@ -5,6 +5,6 @@ module.exports = {
   productApi:  'https://reader-test.efunbox.cn/readerProduct/',
   // baseApi: 'https://reader.lingjiao.cn/readerBase/'
   // baseApi: 'https://readertest.lingjiao.cn:442/readerBase/'
-  baseApi: 'https://reader-api.ai160.com//'
-  // baseApi: 'https://reader-api.ai160.com//'
+  baseApi: 'https://reader-api.efunbox.cn/'
+  // baseApi: 'https://reader-api.efunbox.cn/'
 }

+ 1 - 1
utils/request.js

@@ -1,4 +1,4 @@
-let baseUrl = 'https://reader-api.ai160.com//wx'
+let baseUrl = 'https://reader-api.efunbox.cn/wx'
 
 
 function request(url, method, data, abort = false) {