本地微信授權(quán)登錄-redirect_uri參數(shù)錯誤

背景

使用微信公眾平臺的測試號進行本地聯(lián)調(diào),可以使用內(nèi)網(wǎng)的IP地址,筆者項目是Vue的

開發(fā)流程

1、啟動vue的項目

yarn serve

2、找到cmd上的 Network:ip+port


image.png

3、復(fù)制ip+端口 例如:192.168.0.105:8088
4、把第3步去微信公眾平臺測試號上配置好:看圖片名字描述


1.png

點擊后就用微信登錄就可以.png
掃一下關(guān)注上

將上邊的ip+端口寫上去

image.png

5、綜上就算微信端配置完畢了
6、接下來就是在Vue代碼上進行開發(fā)了

const appId = 'wx2323232323';
const state = 1;
//轉(zhuǎn)碼url
const redirectUri = encodeURIComponent(window.location.href);
window.location. + appId
                                            + '&redirect_uri=' + redirectUri + '&response_type=code&scope=snsapi_userinfo&state='
                                            + state + '#wechat_redirect';

7、重新在進入此頁面,后續(xù)拿到code-使用這個獲取

getCode () {
            let url = location.search;
            let theRequest = new Object()
            if (url.indexOf("?") != -1) {
                let str = url.substr(1)
                let strs = str.split("&")
                for(let i = 0; i < strs.length; i ++) {
                    theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1])
                }
            }
            return theRequest;
},

8、然后通過code調(diào)用后端接口拉

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容