vue调起微信JSDK 扫一扫,相册等需要注意的事项

在VUE里面需要注意的第一个问题就是路由得设置成

 

 2:第二个就是 跳转路由的时候

不要用this.$router.push 或者this.$router.replace  前者在ios 和安卓端都调不起来的

后者只能在安卓端有效 在ios端无效

this.$router.push的效果图

 

 

 

测试工具上是可以调起,然后在安卓手机上和ios上这个是调不起的

2:

 

 

 

 这个在测试上椰是可以的,然后在安卓端上可以,在ios上会出现无效的token 40029

3:

 

  config:function(res){   //配置JSSDK和调取扫一扫功能
          //  location.reload();
          this.isDisable = true;
          this.model = 'block'; 
          setTimeout(() => {
          this.isDisable = false;
           var that = this,
            USER = JSON.parse(sessionStorage.getItem('USER')),
            iscode = JSON.parse(sessionStorage.getItem('key')),
            dizhi = encodeURIComponent(location.href.split('#')[0]);
            console.log(dizhi);
          var data  = {
            dizhi:dizhi,
            i:USER.uniacid,
            token:USER.token
          }
           this.$fetch('app/index.php/?c=entry&a=wxapp&do=Write&m=mzhk_sun&calltest=?&',data)
          .then((res)=>{
            console.log(res)
              that.model = 'none';
              
            wx.config({
                debug : false, // true为开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
                appId : res.appId, // 必填,公众号的唯一标识
                timestamp : res.timestamp, // 必填,生成签名的时间戳
                nonceStr : res.nonceStr, // 必填,生成签名的随机串
                signature : res.signature,// 必填,签名
                jsApiList : ['checkJsApi', 'startRecord', 'stopRecord','translateVoice','scanQRCode', 'openCard'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2

            });
             // 初始化
              wx.ready(function(){
                  wx.scanQRCode({
                      needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果
                      scanType: ["qrCode","barCode"],
                      success:((option)=>{
                          var o = JSON.parse(option.resultStr);
                          var id = o.id;
                          var ordertype = o.ordertype;
                          var user_id = o.user_id
                          that.id = id;
                          that.ordertype = ordertype;
                          that.user_id = o.user_id;
                         
                          let parm = {
                            i:USER.uniacid,
                            id:id,
                            ordertype:ordertype,
                            user_id:user_id,
                            bid:USER.bid,
                            token:USER.token,
                          }
                          that.$fetch('app/index.php/?c=entry&a=wxapp&do=Couinfo&m=mzhk_sun&calltest=?',parm)
                          .then((res)=>{
                            console.log('扫码核销的接口',res)
                            if(res.code == 1){
                              alert(res.msg)
                            }else{
                              if(ordertype == 10){
                                that.bname = res.data.bname;
                                that.couname = res.data.couname;
                                that.limittime = res.data.limittime;
                                that.type = 1;
                                that.uid = res.data.uid
                                if(res.data.isUsed == "0"){
                                  that.isUsed = "未使用";
                                }else if(res.data.isUsed == "1"){
                                  that.isUsed = "已使用";
                                }
                              }else if(ordertype == 11){
                                that.bname = res.data.bname;
                                that.couname = res.data.fname;
                                that.limittime = res.data.wtime;
                                that.uid = res.data.openid;
                                that.type = 1;
                                if(res.data.isUsed == "0"){
                                  that.isUsed = "未核销";
                                }else if(res.data.isUsed == "1"){
                                  that.isUsed = "已核销";
                                }

                              }
                            }

                          })
                      })
                  })
              })
          })
        

          }, 300);
         
         
          
        }

 

 

 所以用了这个,用了这个的话,在安卓端和ios端都可以掉的起来。

posted @ 2020-08-17 11:44  落魄的程序员  阅读(501)  评论(0)    收藏  举报