search

Home  >  Q&A  >  body text

javascript - In which life cycle does vue introduce WeChat jssdk configuration to call the interface configuration?

Invalid signature error will be reported in ios, but it will be fine in Android, and it will be fine in WeChat developer tools
I tried to do wx.ready in create beforecreate mounted but always reported invalid signature. After closing this alert, the WeChat interface can be used. If encodeURIcomponent directly reports an error when calling the background interface, the background interface log parameters will also be in the style after encoding when the front end is not encoded. Please tell me what causes this.

为情所困为情所困2779 days ago1108

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-06-28 09:26:43

    Regarding WeChat signature errors, please refer to the official documentation, analyze the specific problems in detail, and check carefully according to the steps.
    Then regarding initializing WeChat, if a single component is used, it is declared in mounted, or it can be declared globally in main.js .
    Paste the general code I extracted:

    export default {
      init() {
          let that = this;
          Service.wxConfig({//调用服务端获取签名配置
            url: location.href.split('#')[0]
          }, result => {
            if (result.success) {
              that.weixinConfig(result.data);
            }
          });
        },
    
        weixinConfig(data) {
          wx.config({
            debug: false,
            appId: data.appId,
            timestamp: data.timestamp,
            nonceStr: data.nonceStr,
            signature: data.signature,
            jsApiList: [
              'onMenuShareTimeline',
              'onMenuShareAppMessage',
              'showOptionMenu',
              'hideOptionMenu',
              'showMenuItems',
              'hideMenuItems',
              'chooseImage',
              'previewImage',
              'uploadImage',
              'chooseWXPay'
            ]
          });
        }
    }

    reply
    0
  • Cancelreply