- 调试工具
微信开发者工具
- 服务器
Nginx
- 前端框架
umi.js
微信公众号的授权,需要配置一个可访问的域名,本地开发中的搭建的服务器,不具备这个基础,所以考虑在本地搭建Nginx反向代理服务器,来指向微信公众号配置的域名。
1. 在nginx的配置文件nginx.conf中添加配置脚本,如下:
server {
listen 80;
server_name test.com;
location / {
proxy_pass http://localhost:8000;
}
}
上述的配置文件:test.com是你在微信公众平台配置的后台域名;http://localhost:8000你本地的服务。
2. 在微信开发者工具打开 http://test.com
3.在首页重定向至微信授权的页面
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${encodeURIComponent('http://test.com')}&response_type=code&scope=snsapi_userinfo&state=123&connect_redirect=1#wechat_redirect`;
网友评论