Selaa lähdekoodia

条件编译支付

bayi 1 vuosi sitten
vanhempi
commit
b3b2e90c9e
4 muutettua tiedostoa jossa 75 lisäystä ja 38 poistoa
  1. 1 0
      app.js
  2. 39 0
      pages/commodity/index.js
  3. 3 13
      pages/commodity/index.wxml
  4. 32 25
      pages/my/index.js

+ 1 - 0
app.js

@@ -98,6 +98,7 @@ App({
                 }
             })
             // #elif ANDROID
+            console.log('eqw');
             wx.getMiniProgramCode({
                 success(res) {
                     if (res.code) {

+ 39 - 0
pages/commodity/index.js

@@ -10,6 +10,7 @@ import {
 } from '~/api/global'
 import {
     buyVip,
+    androidbuyVip,
 } from '~/api/user'
 import event from '~/mixins/event'
 
@@ -58,6 +59,8 @@ Page({
             title: '提交中',
             mask: true
         })
+        // #if MP
+
         let res = await buyVip({
             productId: this.data.active
         }).finally(() => {
@@ -98,6 +101,42 @@ Page({
                 })
             }
         })
+        // #elif ANDROID
+        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.setData({
+                        mask: true
+                    })
+                }, 1500)
+                userEvent({
+                    action: 'ANDROID_PAY_SUCCESS',
+                })
+            },
+            fail(res) {
+                wx.showToast({
+                    title: "支付失败",
+                    icon: "none",
+                    duration: 3000
+                })
+            },
+            complete: (res) => {
+                console.error('wx.miniapp.requestPayment complete:', res)
+            }
+        })
+        // #endif
     },
     // 设置用户信息及vip状态
     async setUserInfo() {

+ 3 - 13
pages/commodity/index.wxml

@@ -1,19 +1,9 @@
 <view id="container">
     <view class="commoditys" wx:if="{{products.length>0}}">
-        <view class="['commodity c-1', {{active==products[0].id?'aborder':''}}]" bindtap="selected"
-            data-product="{{products[0]}}">
+        <view wx:for="{{products}}" wx:key="id" class="['commodity,{{item.payType=='LIFELONG'?'c-1':item.payType=='YEAR'?'c-2':'c-3'}} {{active==item.id?'aborder':''}}]"
+            bindtap="selected" data-product="{{item}}">
             <image src="http://reader-wx.ai160.com/images/reader/v3/active.png" class="active"
-                wx:if="{{active==products[0].id}}" />
-        </view>
-        <view class="['commodity c-2', {{active==products[2].id?'aborder':''}}]" bindtap="selected"
-            data-product="{{products[2]}}">
-            <image src="http://reader-wx.ai160.com/images/reader/v3/active.png" class="active"
-                wx:if="{{active==products[2].id}}" />
-        </view>
-        <view class="['commodity c-3', {{active==products[1].id?'aborder':''}}]" bindtap="selected"
-            data-product="{{products[1]}}">
-            <image src="http://reader-wx.ai160.com/images/reader/v3/active.png" class="active"
-                wx:if="{{active==products[1].id}}" />
+                wx:if="{{active==item.id}}" />
         </view>
     </view>
     <view class="payBox" wx:if="{{active!=''}}">

+ 32 - 25
pages/my/index.js

@@ -143,18 +143,28 @@ Page({
             title: '提交中',
             mask: true
         })
-        let res = await androidbuyVip({
+        // #if MP
+        userEvent({
+            action: 'ANDROID_PAY_ACTIVITY',
+        })
+        let res = await buyVip({
             productId: currentTarget.dataset.id
         }).finally(() => {
             wx.hideLoading()
         })
-        wx.miniapp.requestPayment({
-            timeStamp: res.timestamp,
-            mchId: res.partnerid,
-            prepayId: res.prepayid,
+        let {
+            timeStamp,
+            nonceStr,
+            signType,
+            paySign
+        } = res
+        // package保留字
+        wx.requestPayment({
+            timeStamp,
+            nonceStr,
             package: res.package,
-            nonceStr: res.noncestr,
-            sign: res.sign,
+            signType,
+            paySign,
             success: async (res) => {
                 setTimeout(() => {
                     this.setUserInfo()
@@ -170,28 +180,21 @@ Page({
                     icon: "none",
                     duration: 3000
                 })
-            },
-            complete: (res) => {
-                console.error('wx.miniapp.requestPayment complete:', res)
             }
         })
-        return
-        userEvent({
-            action: 'ANDROID_PAY_ACTIVITY',
+        // #elif ANDROID
+        let res = await androidbuyVip({
+            productId: currentTarget.dataset.id
+        }).finally(() => {
+            wx.hideLoading()
         })
-        let {
-            timeStamp,
-            nonceStr,
-            signType,
-            paySign
-        } = res
-        // package保留字
-        wx.requestPayment({
-            timeStamp,
-            nonceStr,
+        wx.miniapp.requestPayment({
+            timeStamp: res.timestamp,
+            mchId: res.partnerid,
+            prepayId: res.prepayid,
             package: res.package,
-            signType,
-            paySign,
+            nonceStr: res.noncestr,
+            sign: res.sign,
             success: async (res) => {
                 setTimeout(() => {
                     this.setUserInfo()
@@ -207,8 +210,12 @@ Page({
                     icon: "none",
                     duration: 3000
                 })
+            },
+            complete: (res) => {
+                console.error('wx.miniapp.requestPayment complete:', res)
             }
         })
+        // #endif
     },
     jump({
         currentTarget