解決微信js-jdk invalid signature 簽名非法的問題

timg?image&quality=80&size=b9999_10000&sec=1517401690303&di=c281fc3ce24a7b1c21953f8f3e2177cc&imgtype=jpg&src=http%3A%2F%2Fimg1.imgtn.bdimg.com%2Fit%2Fu%3D1724495011%2C1941983274%26fm%3D214%26gp%3D0.jpg
內容如題:解決微信jdk invalid signature 簽名非法的問題balabala~~~php

今日做者在解決一個微信公衆號網頁上傳圖片的問題
百般調試後仍是調用不了微信上傳文件的 wx.chooseImage({})方法。

偶然在度娘看到decodeURIComponent()這個方法,恍悟是否是本身的域名連接傳遞時被編碼了 
因而乎直接簡單粗暴alert出來。
果不其然,url中特殊符號均被encode編碼

解決方法很簡單:前端

decodeURIComponent(document.URL.split(‘#’)[0])

附上vue代碼:vue

// 獲取微信配置
    this.$http.post('/jsConfig/getConfig', Qs.stringify({url: url})).then(response => {
      wx.config({
        debug: false, // 開啓調試模式,調用的全部api的返回值會在客戶端alert出來,若要查看傳入的參數,能夠在pc端打開,參數信息會經過log打出,僅在pc端時纔會打印。
        appId: response.data.data.appId, // 必填,企業號的惟一標識,此處填寫企業號corpid
        timestamp: response.data.data.timestamp, // 必填,生成簽名的時間戳
        nonceStr: response.data.data.nonceStr, // 必填,生成簽名的隨機串
        signature: response.data.data.signature, // 必填,簽名,見附錄1
        jsApiList: response.data.data.jsApiList // 必填,須要使用的JS接口列表,全部JS接口列表見附錄2
      })
      wx.ready(function () {
      })
      wx.error(function (res) {
      })
    })

最後解決調用微信jssdk報錯的問題jquery

wx.chooseImage({
        count: 1, // 默認9
        sizeType: ['original', 'compressed'], // 能夠指定是原圖仍是壓縮圖,默認兩者都有
        sourceType: ['album', 'camera'], // 能夠指定來源是相冊仍是相機,默認兩者都有
        success: function (res) {
          self.$vux.loading.show({
            text: '圖片上傳中'
          })
       })

前端技術錦集:我的博客 (vue,jquery,建站教程) ,才疏學淺,不到之處還請指正。api

【更新】
回答了一下別人的問題,還有人遇到invalid signature 時是由於access token 過時的問題,補充息知。微信

相關文章
相關標籤/搜索