微信公众号返回scanQrcode permissinodenied?
发布于 6 年前 作者 fang56 2791 次浏览 来自 问答

微信公众号返回扫一扫 scanQrcode permissinodenied

<template>
  <div class="hello">
    <van-button type="primary" @click="saoyisao()">默认按钮</van-button>
  </div>
</template>

<script>
 import wx from 'weixin-js-sdk';
export default {

  name: 'HelloWorld',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App'
    }
  },
  mounted:function(){
     this.getInfo();
  },
  methods: {
      getInfo:function(){

          this.$axios.post('/api/wechat/getJssign')
           .then(function (result) {
             console.log(result.data);
             wx.config({
                 debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
                 appId: "XXXXXXX", // 必填,公众号的唯一标识
                 timestamp: result.data.timestamp, // 必填,生成签名的时间戳
                 nonceStr: result.data.nonceStr, // 必填,生成签名的随机串
                 signature: result.data.signature, // 必填,签名,见附录1
                 jsApiList: ['checkJsApi', 'chooseImage', 'uploadImage', 'scanQRCode']
                 // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
             });
           })
           .catch(function (error) {
             console.log(error);
           });

      },
      saoyisao:function(){
        wx.scanQRCode({
            needResult: 1,
            success: function (res) { //res.resultStr二维码中的数据
              alert("ok")
            },
            fail: function (res) {
                alert("扫码失败");
                return false;
            }
        })
      }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>

1 回复

permission denied该公众号没有权限使用这个JSAPI,或者是调用的JSAPI没有传入config的jsApiList参数中(部分接口需要认证之后才能使用)。请参考:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#%E9%99%84%E5%BD%951-JS-SDK%E4%BD%BF%E7%94%A8%E6%9D%83%E9%99%90%E7%AD%BE%E5%90%8D%E7%AE%97%E6%B3%95

回到顶部