解决微信免登录重定向地址只能带一个参数问题
一、常用方法?
const url = encodeURI(“http://192.168.0.56:91/official/login”);
export function toAuthorize(recCode,isNetWork) {
const APPID = "wx2222222222222";
const url = encodeURI("http://192.168.0.56:91/official/login");location.href =
"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
APPID +
"&redirect_uri=" +
url +
"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
}
二、解决办法
将encodeURI 改成 encodeURIComponent
export function toAuthorize(recCode,isNetWork) {
const APPID = "wx2222222222222";
const url = encodeURIComponent("https://***.***.***.com/official/login?recCode="+recCode+"&isNetWork="+isNetWork);
location.href =
"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
APPID +
"&redirect_uri=" +
url +
"&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
}
本文探讨了在微信OAuth2授权过程中遇到的重定向URL只能携带一个参数的问题,并提供了解决方案。通过将`encodeURI`替换为`encodeURIComponent`,可以正确编码包含多个参数的URL,确保微信能够正确解析并跳转。
901

被折叠的 条评论
为什么被折叠?



