背景
使用微信公眾平臺的測試號進行本地聯(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)用后端接口拉