Просмотр исходного кода

【功能完善】商城:支付宝 wap 的接入

Xiao_123 9 месяцев назад
Родитель
Сommit
13161bd675

+ 0 - 1
pages/commission/withdraw.vue

@@ -224,7 +224,6 @@
   // 提交提现
   const onConfirm = async () => {
     // 参数校验
-    debugger;
     if (
       !state.accountInfo.price ||
       state.accountInfo.price > state.brokerageInfo.price ||

+ 196 - 0
sheep/components/countDown/index.vue

@@ -0,0 +1,196 @@
+<!-- TODO 霖:是不是怎么复用 s-count-down 组件 -->
+<template>
+  <view class="time" :style="justifyLeft">
+    <text class="" v-if="tipText">{{ tipText }}</text>
+    <text
+      class="styleAll p6"
+      v-if="isDay === true"
+      :style="{ background: bgColor.bgColor, color: bgColor.Color }"
+      >{{ day }}{{ bgColor.isDay ? '天' : '' }}</text
+    >
+    <text
+      class="timeTxt"
+      v-if="dayText"
+      :style="{ width: bgColor.timeTxtwidth, color: bgColor.bgColor }"
+      >{{ dayText }}</text
+    >
+    <text
+      class="styleAll"
+      :class="isCol ? 'timeCol' : ''"
+      :style="{ background: bgColor.bgColor, color: bgColor.Color, width: bgColor.width }"
+      >{{ hour }}</text
+    >
+    <text
+      class="timeTxt"
+      v-if="hourText"
+      :class="isCol ? 'whit' : ''"
+      :style="{ width: bgColor.timeTxtwidth, color: bgColor.bgColor }"
+      >{{ hourText }}</text
+    >
+    <text
+      class="styleAll"
+      :class="isCol ? 'timeCol' : ''"
+      :style="{ background: bgColor.bgColor, color: bgColor.Color, width: bgColor.width }"
+      >{{ minute }}</text
+    >
+    <text
+      class="timeTxt"
+      v-if="minuteText"
+      :class="isCol ? 'whit' : ''"
+      :style="{ width: bgColor.timeTxtwidth, color: bgColor.bgColor }"
+      >{{ minuteText }}</text
+    >
+    <text
+      class="styleAll"
+      :class="isCol ? 'timeCol' : ''"
+      :style="{ background: bgColor.bgColor, color: bgColor.Color, width: bgColor.width }"
+      >{{ second }}</text
+    >
+    <text class="timeTxt" v-if="secondText">{{ secondText }}</text>
+  </view>
+</template>
+
+<script>
+  export default {
+    name: 'countDown',
+    props: {
+      justifyLeft: {
+        type: String,
+        default: '',
+      },
+      //距离开始提示文字
+      tipText: {
+        type: String,
+        default: '倒计时',
+      },
+      dayText: {
+        type: String,
+        default: '天',
+      },
+      hourText: {
+        type: String,
+        default: '时',
+      },
+      minuteText: {
+        type: String,
+        default: '分',
+      },
+      secondText: {
+        type: String,
+        default: '秒',
+      },
+      datatime: {
+        type: Number,
+        default: 0,
+      },
+      isDay: {
+        type: Boolean,
+        default: true,
+      },
+      isCol: {
+        type: Boolean,
+        default: false,
+      },
+      bgColor: {
+        type: Object,
+        default: null,
+      },
+    },
+    data: function () {
+      return {
+        day: '00',
+        hour: '00',
+        minute: '00',
+        second: '00',
+      };
+    },
+    created: function () {
+      this.show_time();
+    },
+    mounted: function () {},
+    methods: {
+      show_time: function () {
+        let that = this;
+
+        function runTime() {
+          //时间函数
+          let intDiff = that.datatime - Date.parse(new Date()) / 1000; //获取数据中的时间戳的时间差;
+          let day = 0,
+            hour = 0,
+            minute = 0,
+            second = 0;
+          if (intDiff > 0) {
+            //转换时间
+            if (that.isDay === true) {
+              day = Math.floor(intDiff / (60 * 60 * 24));
+            } else {
+              day = 0;
+            }
+            hour = Math.floor(intDiff / (60 * 60)) - day * 24;
+            minute = Math.floor(intDiff / 60) - day * 24 * 60 - hour * 60;
+            second = Math.floor(intDiff) - day * 24 * 60 * 60 - hour * 60 * 60 - minute * 60;
+            if (hour <= 9) hour = '0' + hour;
+            if (minute <= 9) minute = '0' + minute;
+            if (second <= 9) second = '0' + second;
+            that.day = day;
+            that.hour = hour;
+            that.minute = minute;
+            that.second = second;
+          } else {
+            that.day = '00';
+            that.hour = '00';
+            that.minute = '00';
+            that.second = '00';
+          }
+        }
+        runTime();
+        setInterval(runTime, 1000);
+      },
+    },
+  };
+</script>
+
+<style scoped>
+  .p6 {
+    padding: 0 8rpx;
+  }
+  .styleAll {
+    /* color: #fff; */
+    font-size: 24rpx;
+    height: 36rpx;
+    line-height: 36rpx;
+    border-radius: 6rpx;
+    text-align: center;
+    /* padding: 0 6rpx; */
+  }
+  .timeTxt {
+    text-align: center;
+    /* width: 16rpx; */
+    height: 36rpx;
+    line-height: 36rpx;
+    display: inline-block;
+  }
+  .whit {
+    color: #fff !important;
+  }
+  .time {
+    display: flex;
+    justify-content: center;
+  }
+
+  .red {
+    color: #fc4141;
+    margin: 0 4rpx;
+  }
+
+  .timeCol {
+    /* width: 40rpx;
+    height: 40rpx;
+    line-height: 40rpx;
+    text-align:center;
+    border-radius: 6px;
+    background: #fff;
+    font-size: 24rpx; */
+    color: #e93323;
+  }
+</style>

+ 64 - 52
sheep/platform/pay.js

@@ -35,7 +35,7 @@ export default class SheepPay {
         },
         mock: () => {
           this.mockPay();
-        }
+        },
       },
       WechatMiniProgram: {
         wechat: () => {
@@ -49,7 +49,7 @@ export default class SheepPay {
         },
         mock: () => {
           this.mockPay();
-        }
+        },
       },
       App: {
         wechat: () => {
@@ -63,7 +63,7 @@ export default class SheepPay {
         },
         mock: () => {
           this.mockPay();
-        }
+        },
       },
       H5: {
         wechat: () => {
@@ -77,7 +77,7 @@ export default class SheepPay {
         },
         mock: () => {
           this.mockPay();
-        }
+        },
       },
     };
     return payAction[sheep.$platform.name][this.payment]();
@@ -89,7 +89,7 @@ export default class SheepPay {
       let data = {
         id: this.id,
         channelCode: channel,
-        channelExtras: {}
+        channelExtras: {},
       };
       // 特殊逻辑:微信公众号、小程序支付时,必须传入 openid
       if (['wx_pub', 'wx_lite'].includes(channel)) {
@@ -108,8 +108,11 @@ export default class SheepPay {
         // 失败时
         if (res.code !== 0 && res.msg.indexOf('无效的openid') >= 0) {
           // 特殊逻辑:微信公众号、小程序支付时,必须传入 openid 不正确的情况
-          if (res.msg.indexOf('无效的openid') >= 0 // 获取的 openid 不正确时,或者随便输入了个 openid
-            || res.msg.indexOf('下单账号与支付账号不一致') >= 0) { // https://developers.weixin.qq.com/community/develop/doc/00008c53c347804beec82aed051c00
+          if (
+            res.msg.indexOf('无效的openid') >= 0 || // 获取的 openid 不正确时,或者随便输入了个 openid
+            res.msg.indexOf('下单账号与支付账号不一致') >= 0
+          ) {
+            // https://developers.weixin.qq.com/community/develop/doc/00008c53c347804beec82aed051c00
             this.bindWeixin();
           }
         }
@@ -133,30 +136,34 @@ export default class SheepPay {
       },
       fail: (error) => {
         if (error.errMsg.indexOf('chooseWXPay:没有此SDK或暂不支持此SDK模拟') >= 0) {
-          sheep.$helper.toast('发起微信支付失败,原因:可能是微信开发者工具不支持,建议使用微信打开网页后支付');
-          return
+          sheep.$helper.toast(
+            '发起微信支付失败,原因:可能是微信开发者工具不支持,建议使用微信打开网页后支付',
+          );
+          return;
         }
         this.payResult('fail');
       },
     });
   }
 
-  // 浏览器微信 H5 支付 TODO 芋艿:待接入
+  // 浏览器微信 H5 支付 TODO 芋艿:待接入(注意:H5 支付是给普通浏览器,不是微信公众号的支付,绝大多数人用不到,可以忽略)
   async wechatWapPay() {
     const { error, data } = await this.prepay();
     if (error === 0) {
-      const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${this.payment}&orderType=${this.orderType}`;
+      const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${
+        this.payment
+      }&orderType=${this.orderType}`;
       location.href = `${data.pay_data.h5_url}&redirect_url=${encodeURIComponent(redirect_url)}`;
     }
   }
 
-  // 支付链接  TODO 芋艿:待接入
+  // 支付链接(支付宝 wap 支付)
   async redirectPay() {
-    let { error, data } = await this.prepay();
-    if (error === 0) {
-      const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${this.payment}&orderType=${this.orderType}`;
-      location.href = data.pay_data + encodeURIComponent(redirect_url);
+    let { code, data } = await this.prepay('alipay_wap');
+    if (code !== 0) {
+      return;
     }
+    location.href = data.displayContent;
   }
 
   // #endif
@@ -202,26 +209,26 @@ export default class SheepPay {
     code === 0 && this.payResult('success');
   }
 
-  // 支付宝复制链接支付  TODO 芋艿:待接入
+  // 支付宝复制链接支付(通过支付宝 wap 支付实现)
   async copyPayLink() {
-    let that = this;
-    let { error, data } = await this.prepay();
-    if (error === 0) {
-      // 引入showModal 点击确认 复制链接;
-      uni.showModal({
-        title: '支付宝支付',
-        content: '复制链接到外部浏览器',
-        confirmText: '复制链接',
-        success: (res) => {
-          if (res.confirm) {
-            sheep.$helper.copyText(data.pay_data);
-          }
-        },
-      });
+    let { code, data } = await this.prepay('alipay_wap');
+    if (code !== 0) {
+      return;
     }
+    // 引入 showModal 点击确认:复制链接;
+    uni.showModal({
+      title: '支付宝支付',
+      content: '复制链接到外部浏览器',
+      confirmText: '复制链接',
+      success: (res) => {
+        if (res.confirm) {
+          sheep.$helper.copyText(data.displayContent);
+        }
+      },
+    });
   }
 
-  // 支付宝支付  TODO 芋艿:待接入
+  // 支付宝支付(App) TODO 芋艿:待接入【暂时没打包 app,所以没接入,一般人用不到】
   async alipay() {
     let that = this;
     const { error, data } = await this.prepay();
@@ -243,7 +250,7 @@ export default class SheepPay {
     }
   }
 
-  // 微信支付  TODO 芋艿:待接入
+  // 微信支付(App)  TODO 芋艿:待接入:待接入【暂时没打包 app,所以没接入,一般人用不到】
   async wechatAppPay() {
     let that = this;
     let { error, data } = await this.prepay();
@@ -263,11 +270,7 @@ export default class SheepPay {
 
   // 支付结果跳转,success:成功,fail:失败
   payResult(resultType) {
-    sheep.$router.redirect('/pages/pay/result', {
-      id: this.id,
-      orderType: this.orderType,
-      payState: resultType
-    });
+    goPayResult(this.id, this.orderType, resultType);
   }
 
   // 引导绑定微信
@@ -282,7 +285,6 @@ export default class SheepPay {
       },
     });
   }
-
 }
 
 export function getPayMethods(channels) {
@@ -292,14 +294,12 @@ export function getPayMethods(channels) {
       title: '微信支付',
       value: 'wechat',
       disabled: true,
-      hide: true,
     },
     {
       icon: '/static/img/shop/pay/alipay.png',
       title: '支付宝支付',
       value: 'alipay',
       disabled: true,
-      hide: true,
     },
     {
       icon: '/static/img/shop/pay/wallet.png',
@@ -312,31 +312,34 @@ export function getPayMethods(channels) {
       title: 'Apple Pay',
       value: 'apple',
       disabled: true,
-      hide: true,
     },
     {
       icon: '/static/img/shop/pay/wallet.png',
       title: '模拟支付',
       value: 'mock',
       disabled: true,
-    }
+    },
   ];
-  const platform = sheep.$platform.name
+  const platform = sheep.$platform.name;
 
   // 1. 处理【微信支付】
   const wechatMethod = payMethods[0];
-  if ((platform === 'WechatOfficialAccount' && channels.includes('wx_pub'))
-    || (platform === 'WechatMiniProgram' && channels.includes('wx_lite'))
-    || (platform === 'App' && channels.includes('wx_app'))) {
+  if (
+    (platform === 'WechatOfficialAccount' && channels.includes('wx_pub')) ||
+    (platform === 'WechatMiniProgram' && channels.includes('wx_lite')) ||
+    (platform === 'App' && channels.includes('wx_app'))
+  ) {
     wechatMethod.disabled = false;
   }
-  wechatMethod.disabled = false; // TODO 芋艿:临时测试
 
   // 2. 处理【支付宝支付】
   const alipayMethod = payMethods[1];
-  if ((platform === 'WechatOfficialAccount' && channels.includes('alipay_wap'))
-    || platform === 'WechatMiniProgram' && channels.includes('alipay_wap')
-    || platform === 'App' && channels.includes('alipay_app')) {
+  if (
+    (platform === 'H5' && channels.includes('alipay_wap')) ||
+    (platform === 'WechatOfficialAccount' && channels.includes('alipay_wap')) ||
+    (platform === 'WechatMiniProgram' && channels.includes('alipay_wap')) ||
+    (platform === 'App' && channels.includes('alipay_app'))
+  ) {
     alipayMethod.disabled = false;
   }
   // 3. 处理【余额支付】
@@ -351,4 +354,13 @@ export function getPayMethods(channels) {
     mockMethod.disabled = false;
   }
   return payMethods;
-}
+}
+
+// 支付结果跳转,success:成功,fail:失败
+export function goPayResult(id, orderType, resultType) {
+  sheep.$router.redirect('/pages/pay/result', {
+    id,
+    orderType,
+    payState: resultType,
+  });
+}

+ 0 - 1
sheep/platform/provider/wechat/openPlatform.js

@@ -15,7 +15,6 @@ const login = () => {
       provider: 'weixin',
       onlyAuthorize: true,
     });
-    debugger
     if (loginRes.errMsg == 'login:ok') {
       // TODO third.wechat.login 函数未实现
       const res = await third.wechat.login({