Zhengxiaowei vor 5 Jahren
Ursprung
Commit
6510fbdac7
5 geänderte Dateien mit 113 neuen und 105 gelöschten Zeilen
  1. 4 0
      src/api/index.js
  2. 11 8
      src/assets/less/pay.less
  3. 60 1
      src/helper/index.js
  4. 17 9
      src/manifest.json
  5. 21 87
      src/views/Pay/index.ux

+ 4 - 0
src/api/index.js

@@ -61,3 +61,7 @@ export const getUserShelfBooks = () => {
   return fly.get(`/userShelfBooks`);
 };
 
+// 充值
+export const getPayQuery = (params) => {
+  return fly.get("/goToPay", params);
+}

+ 11 - 8
src/assets/less/pay.less

@@ -7,14 +7,17 @@
   }
 
   .wrap-fixed {
-    height: 120px;
-    flex-shrink: 0;
-    background-color: #fff;
-    border-top: 2px solid #f7f7f7;
-    background-color: #fff;
-    justify-content: space-between;
-    align-items: center;
-    padding: 28px 24px;
+    flex-direction: column;
+    
+    .total-wrap {
+      height: 120px;
+      flex-shrink: 0;
+      background-color: #fff;
+      background-color: #fff;
+      justify-content: space-between;
+      align-items: center;
+      padding: 28px 24px;
+    }
 
     .total-cost {
       flex: 1;

+ 60 - 1
src/helper/index.js

@@ -1,4 +1,7 @@
 
+import wxpay from '@service.wxpay';
+import { getPayQuery } from "../api";
+
 export const pageLoad = (meta, fn, params) => {
   return new Promise(async (resolve, reject) => {
     if (meta.current_page) {
@@ -12,4 +15,60 @@ export const pageLoad = (meta, fn, params) => {
       resolve(ret);
     }
   })
-}
+}
+
+// 支付配置
+export const configWxPay = async (params) => {
+  let config = await getPayQuery(params);
+  console.log("pay config", config);
+  let prepayid = config.prepay_id;
+  // app中的配置信息
+  let extraAppConfig = {
+    app_id: config.appId,
+    partner_id: "",
+    package_value: "",
+    nonce_str: config.nonce_str,
+    time_stamp: "",
+    order_sign: config.sign
+  }
+  // web端的配置信息
+  let extraWebConfig = {
+    mweb_url: "http://www.baidu.com"
+  }
+  let payType = wxpay.getType();
+  let ret = null;
+  console.log(payType);
+  // return;
+  switch (payType) {
+    case "APP": ret = await useWxPay(prepayid, extraAppConfig); break;
+    case "MWEB": ret = await useWxPay(prepayid, extraWebConfig); break;
+    default: ret = "app not install or wx pay is not avaliable";
+  }
+
+  console.log(ret);
+}
+
+let useWxPay = (prepayid, extra) => {
+  return new Promise((resolve, reject) => {
+    console.log(prepayid);
+    console.log(extra);
+    wxpay.pay({
+      prepayid: prepayid,
+      extra: extra,
+      success: (data) => {
+        console.log("success", data);
+        // app中返回prepayid web中返回final_url
+        resolve(data);
+      },
+      fail: (data, code) => {
+        console.log("error");
+        console.log(data, code);
+        reject({ data, code });
+      },
+      cancel: () => {
+        console.log("user cancel");
+        reject({ message: "user cancel" });
+      }
+    })
+  })
+}

+ 17 - 9
src/manifest.json

@@ -1,5 +1,5 @@
 {
-  "package": "com.application.demo",
+  "package": "com.application.zhuishuyun",
   "name": "追书云小说",
   "versionName": "1.0.0",
   "versionCode": "1",
@@ -9,14 +9,14 @@
     {
       "name": "system.app"
     },
-    { 
-      "name": "system.clipboard" 
+    {
+      "name": "system.clipboard"
     },
-    { 
-      "name": "system.media" 
+    {
+      "name": "system.media"
     },
-    { 
-      "name": "system.request" 
+    {
+      "name": "system.request"
     },
     {
       "name": "system.prompt"
@@ -35,6 +35,14 @@
     },
     {
       "name": "system.storage"
+    },
+    {
+      "name": "service.wxpay",
+      "params": {
+        "package": "com.application.zhuishuyun",
+        "sign": "",
+        "url": ""
+      }
     }
   ],
   "permissions": [
@@ -46,7 +54,7 @@
     "logLevel": "debug"
   },
   "router": {
-    "entry": "views/Index",
+    "entry": "views/Pay",
     "pages": {
       "views/Index": {
         "component": "index"
@@ -151,4 +159,4 @@
       }
     }
   }
-}
+}

+ 21 - 87
src/views/Pay/index.ux

@@ -34,7 +34,7 @@
                   <div class="recharge-item {{curSelect === $idx ? 'recharge-item__select' : ''}}">
                     <text class="price {{curSelect === $idx ? 'price__select' : ''}}">{{charge.price}}</text>
                     <text class="send {{curSelect === $idx ? 'send__select' : ''}}">{{charge.text}}</text>
-                    <div class="discount {{curSelect === $idx ? 'discount__select' : ''}}">
+                    <div class="discount {{curSelect === $idx ? 'discount__select' : ''}}" if="charge.save_text">
                       <block if="!charge.is_year_order">
                         <text>省</text>
                       </block>
@@ -53,16 +53,22 @@
       </tab-content>
     </tabs>
     <div class="wrap-fixed">
-      <div class="total-cost">
-        <text>合计:{{total}}</text>
-        <text class="notice">选择充值金额(1元=100书币)</text>
+      <image src="../../assets/imgs/shadow.png" class="shadow"></image>
+      <div class="total-wrap">
+        <div class="total-cost">
+          <text>合计:{{total}}</text>
+          <text class="notice">选择充值金额(1元=100书币)</text>
+        </div>
+        <text class="go-to-pay" @click="toPay">立即充值</text>
       </div>
-      <text class="go-to-pay">立即充值</text>
     </div>
   </div>
 </template>
 
 <script>
+import { getChargeList } from "../../api";
+import { configWxPay } from "../../helper";
+
 export default {
   private: {
     curPayType: 1,
@@ -80,86 +86,7 @@ export default {
         value: 2
       }
     ],
-    rechargeList: [
-      {
-
-        price: "5元",
-        is_year_order: 0,
-        is_month_order: 0,
-        text: "500+300书币",
-        first_charge: false,
-        today_special: false,
-        save_text: "3元",
-        product_id: 5448,
-        show_free_ads: 0
-      },
-      {
-        price: "9.9元",
-        is_year_order: 0,
-        is_month_order: 0,
-        text: "990+450书币",
-        first_charge: false,
-        today_special: false,
-        save_text: "4.5元",
-        product_id: 5057,
-        show_free_ads: 0
-      },
-      {
-        price: "18元",
-        is_year_order: 0,
-        is_month_order: 0,
-        text: "1800+900书币",
-        first_charge: false,
-        today_special: false,
-        save_text: "9元",
-        product_id: 5059,
-        show_free_ads: 0
-      },
-      {
-        price: "30元",
-        is_year_order: 0,
-        is_month_order: 0,
-        text: "3000+1500书币",
-        first_charge: false,
-        today_special: false,
-        save_text: "15元",
-        product_id: 5061,
-        show_free_ads: 0
-      },
-      {
-        price: "50元",
-        is_year_order: 0,
-        is_month_order: 0,
-        text: "5000+3000书币",
-        first_charge: false,
-        today_special: true,
-        save_text: "30元",
-        product_id: 5062,
-        show_free_ads: 0
-      },
-      {
-        price: "100元",
-        is_year_order: 0,
-        is_month_order: 0,
-        text: "10000+9000书币",
-        first_charge: false,
-        today_special: false,
-        save_text: "90元",
-        product_id: 5063,
-        show_free_ads: 0
-      },
-      {
-        price: "365元",
-        is_year_order: 1,
-        is_month_order: 0,
-        text: "每天1元,全年免费看",
-        first_charge: false,
-        today_special: false,
-        save_text: "年费vip会员",
-        product_id: 5064,
-        show_free_ads: 0
-      }
-    ]
+    rechargeList: []
   },
   changePayType(type) {
     this.curPayType = type.value;
@@ -168,14 +95,21 @@ export default {
     this.curSelect = key;
     this.total = this.rechargeList[key].price;
   },
-  onInit() {
-    // 选择默认
+  async initChargeList() {
+    this.rechargeList = await getChargeList();
     this.rechargeList.forEach((p, k) => {
       if (p.today_special) {
         this.curSelect = k;
       }
     })
   },
+  toPay() {
+    let product_id = this.rechargeList[this.curSelect].product_id;
+    configWxPay({ product_id: product_id })
+  },
+  onInit() {
+    this.initChargeList();
+  },
   onHide() {
     this.$app.$def.createShortcut(true);
   }