From 0891b02adb0ae89391c6fff8f4e8937bdd750c16 Mon Sep 17 00:00:00 2001
From: kongdeqiang <123456>
Date: 星期五, 15 九月 2023 15:32:37 +0800
Subject: [PATCH] 修改前端页面

---
 src/components/page/IndexTest.vue |  187 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 148 insertions(+), 39 deletions(-)

diff --git a/src/components/page/IndexTest.vue b/src/components/page/IndexTest.vue
index 79b94c5..9102021 100644
--- a/src/components/page/IndexTest.vue
+++ b/src/components/page/IndexTest.vue
@@ -34,7 +34,7 @@
                             <!--<el-input v-model="statisticData.code" readonly></el-input>-->
                         </el-form-item>
                         <el-form-item class="weizhang-footer-box" style="display: flex;justify-content: center;margin-top: 4.498vh" label-width="0" v-show="showFlag">
-                            <el-button class="jiaofei-btn" type="primary" @click="getCode()" :loading="payFlag">鍘荤即璐�</el-button>
+                            <el-button class="jiaofei-btn" type="primary" @click="pay()" :loading="payFlag">鍘荤即璐�</el-button>
                         </el-form-item>
                     </el-form>
 <!--                    <el-form label-width="100px" label-position="left">-->
@@ -55,12 +55,14 @@
 </template>
 
 <script>
-    export default {
+import wx from 'weixin-js-sdk'
+export default {
         name: 'dashboard',
         data() {
             return {
                 payFlag:false,
                 outParkId:"",
+                type:null,
                 statisticData:{
 
                 },
@@ -68,11 +70,35 @@
                 showFlag2:true,
                 status3:0,
                 carNo:"",
-                code2:""
+                code2:"",
+                code:""
             }
         },
         created(){
+          let ua = window.navigator.userAgent.toLowerCase();
+          //鍒ゆ柇鏄笉鏄井淇�
+          if (ua.match(/MicroMessenger/i) == "micromessenger") {
+            // 寰俊
+            this.type = 0
+          }
+          //鍒ゆ柇鏄笉鏄敮浠樺疂
+          if (ua.match(/AlipayClient/i) == "alipayclient") {
+            //鏀粯瀹�
+            this.type = 1
+          }
+          if(this.type == null){
+            this.$message.error("璇风敤寰俊鎴栨敮浠樺疂鎵弿浜岀淮鐮�")
+            return;
+          }
+
+
             var url = window.location.href;
+            var count = url.split('?').length-1;
+            if(count >1){
+              this.code = this.getCodeFromUrl(url)
+              this.code2 = this.getCode2FromUrl(url)
+              window.location.href = "http://hesuancj.cn/#/indexTest?code="+this.code+"&state=STATE&code2="+this.code2
+            }
             var cs = url.split('?')[1];
             var cs_arr = cs.split('&');
             var cs={};
@@ -80,20 +106,22 @@
                 cs[cs_arr[i].split('=')[0]] = cs_arr[i].split('=')[1]
             }
             //this.outParkId = cs.code;
-            this.code2 = cs.code;
-            this.$byutil.postData(this, this.$systemconfig.basePath + '/outPark/findByBarrierCode', {code:cs.code}, res => {
-                this.statisticData = res.data;
-                this.outParkId = this.statisticData.id;
-                this.status3 = this.statisticData.status3;
-                this.payFlag = false
-                if(this.status3==1){
-                    this.$message({
-                        message: '鎮ㄦ湁杩濈珷鏈鐞嗭紝璇峰厛澶勭悊鎴栬仈绯诲仠杞﹀満绠$悊浜哄憳',
-                        type: 'error',
-                        duration:5000,
-                    });
-                }
-            })
+          this.code2 = cs.code2;
+          this.code = cs.code;
+          this.$byutil.postData(this, this.$systemconfig.basePath + '/ffzf/outpark/findByBarrierCode', {code2:cs.code2}, res => {
+            this.statisticData = res.data;
+            this.outParkId = this.statisticData.id;
+            this.status3 = this.statisticData.status3;
+            this.oldCarNo = this.statisticData.carNo;
+            this.payFlag = false
+            if(this.status3==1){
+              this.$message({
+                message: '鎮ㄦ湁杩濈珷鏈鐞嗭紝璇峰厛澶勭悊鎴栬仈绯诲仠杞﹀満绠$悊浜哄憳',
+                type: 'error',
+                duration:5000,
+              });
+            }
+          })
         },
         methods: {
             pay(){
@@ -106,9 +134,9 @@
                     });
                     return;
                 }
-                this.$byutil.postData(this, this.$systemconfig.basePath + '/ffzf/api/park', {id:this.outParkId}, res => {
+                this.$byutil.postData(this, this.$systemconfig.basePath + '/ffzf/api/parkXT', {id:this.outParkId}, res => {
                   if(res.code === 0){
-                    window.location.href = res.msg
+                    this.getCode()
                     this.showFlag = false
                   }
                 })
@@ -141,31 +169,112 @@
               var r = window.location.search.substr(1).match(reg);
               if (r != null) return unescape(r[2]); return null;
             },
+            /**
+             * 瑙f瀽寰俊redirect_uri鍦板潃涓殑code
+             */
+            getCodeFromUrl (cur_url) {
+              let index = cur_url.split('?')[1]
+              let paramStr =index.split('&')[0];
+              let code =paramStr.split('=')[1];
+              return code
+            },
+            /**
+             * 瑙f瀽寰俊redirect_uri鍦板潃涓殑code2
+             */
+            getCode2FromUrl (cur_url) {
+              let index = cur_url.split('?')[2]
+              let code2 =index.split('=')[1];
+              return code2
+            },
+
             getCode(){
-              var code = this.GetQueryString('code');
-              var code2 = this.GetQueryString('code2');
-              alert(code,'code=====')
-              if(code==null||code==""){
-                var url = encodeURIComponent("hesuancj.cn");
-                window.location.href ="https://open.weixin.qq.com/connect/oauth2/authorize?" +
-                    "appid=wxcb0e4256748b327c&redirect_uri="+url+"&response_type=code" +
-                   // "&scope=snsapi_userinfo&state=STATE#wechat_redirect";
-                    "&scope=SCOPE&state=STATE#wechat_redirect";
-              }else{
-                $.ajax({
-                  type : "POST", //鎻愪氦鏂瑰紡
-                  url : this.$systemconfig.basePath + '/ffzf/test/getCode',//璺緞
-                  data : {
-                    "code" : code
-                  },
-                  success : function(result) {//杩斿洖鏁版嵁鏍规嵁缁撴灉杩涜鐩稿簲鐨勫鐞�
+              if(this.type == 0 ){
+                //寰俊锛岃幏鍙朿ode
+                if(this.code==null||this.code==""){
+                  var url = encodeURIComponent("http://hesuancj.cn/#/indexTest?code2="+this.code2);
+                  window.location.href ="https://open.weixin.qq.com/connect/oauth2/authorize?" +
+                      "appid=wx46e756aed958f895&redirect_uri="+url+"&response_type=code" +
+                       "&scope=snsapi_userinfo&state=STATE#wechat_redirect";
+                      //"&scope=SCOPE&state=STATE#wechat_redirect";
+                }else{
+                  this.$byutil.postData(this, this.$systemconfig.basePath + '/ffzf/api/getOpenId', {id:this.outParkId,code:this.code}, res => {
+                    if(res.code === 0){
+                      var param = res.data;
+                      alert(param)
+                      // 鐐瑰嚮鏀粯鏃跺�欒皟鐢�
+                      if (typeof WeixinJSBridge === 'undefined') {
+                        if (document.addEventListener) {
+                          document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady(param), false)
+                        } else if (document.attachEvent) {
+                          document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady(param))
+                          document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady(param))
+                        }
+                      } else {
+                        this.onBridgeReady(param)
+                      }
 
+                      this.showFlag = false
+                    }else {
+                      alert('寰俊鏀粯璋冭捣澶辫触锛�')
+                    }
+                  })
+                }
+              }else if(this.type == 1){
+                //鏀粯瀹濓紝涓嶈幏鍙朿ode
+                this.$byutil.postData(this, this.$systemconfig.basePath + '/ffzf/api/payByAli', {id:this.outParkId}, res => {
+                  if(res.code != 0){
+                    alert(res.data)
+                    this.showFlag = false
+                  }else {
+                    this.$message({
+                      message: '2绉掑悗鑷姩璺宠浆鍒版敮浠橀〉闈紝闃叉鍐呭缃戞暟鎹悓姝ュ欢杩燂紝璇风◢绛�',
+                      type: 'success',
+                      duration:2000,
+                    });
+                    setTimeout(function(){window.location.href = res.msg;},2000);
+                    this.showFlag = false;
                   }
-                });
-             }
-            }
+                })
 
+              }
+            },
+          onBridgeReady (params) {
+            const that = this
+            WeixinJSBridge.invoke(
+                'getBrandWCPayRequest',
+                {
+                  appId: params.appId, // 鍏紬鍙峰悕绉帮紝鐢卞晢鎴蜂紶鍏�
+                  timeStamp: params.timeStamp, // 鏀粯绛惧悕鏃堕棿鎴筹紝娉ㄦ剰寰俊jssdk涓殑鎵�鏈変娇鐢╰imestamp瀛楁鍧囦负灏忓啓銆備絾鏈�鏂扮増鐨勬敮浠樺悗鍙扮敓鎴愮鍚嶄娇鐢ㄧ殑timeStamp瀛楁鍚嶉渶澶у啓鍏朵腑鐨凷瀛楃
+                  nonceStr: params.nonceStr, // 鏀粯绛惧悕闅忔満涓诧紝涓嶉暱浜� 32 浣�
+                  package: params.prepay_id, // 缁熶竴鏀粯鎺ュ彛杩斿洖鐨刾repay_id鍙傛暟鍊硷紝鎻愪氦鏍煎紡濡傦細prepay_id=\*\*\*锛�
+                  signType: params.signType, // 绛惧悕鏂瑰紡锛岄粯璁や负'SHA1'锛屼娇鐢ㄦ柊鐗堟敮浠橀渶浼犲叆'MD5'
+                  paySign: params.paySign // 鏀粯绛惧悕
+                },
+                (res) => {
+                  if (res.err_msg === 'get_brand_wcpay_request:ok') {
+                    that.queryOrder() // 杩欓噷鏄煡璇㈣鍗曟槸鍚︽敮浠樺畬鎴愶紝鐒跺悗鎵ц鎴愬姛鍜屽け璐ョ殑涓氬姟閫昏緫
+                  } else if (res.err_msg === 'get_brand_wcpay_request:fail') {
+                    alert('鏀粯澶辫触锛�')
+                  } else if (res.err_msg === 'get_brand_wcpay_request:cancel') {
+                    alert('鏀粯鍙栨秷锛�')
+                  }
+                }
+            )
+          },
+          queryOrder() {
+            this.$byutil.postData(this, this.$systemconfig.basePath + '/ffzf/outpark/getById', {id: this.outParkId}, res => {
+              if (res.code == 0) {
+                let outpark = res.data
+                if(outPark.status == 1){
+                  window.location.href = "http://hesuancj.cn/#/indexOk?code2="+this.code2
+                }else {
+                  window.location.href = "http://hesuancj.cn/#/indexFail?code2="+this.code2
+                }
+              }
+            })
+          }
       }
+
     }
 
 </script>

--
Gitblit v1.9.1