来源于:http://www.jylt.cc/#/detail?id=7144852fb3a50f8f7ff03de89643cb82
问题复现
在使用企业微信网页授权链接时,redirect_url中无法加入自定义的参数。
比如:
https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=https://www.baidu.com?need_trim=need_trim&agentId=1&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect
这样的授权链接,在重定向到redirect_url的时候,是不会携带need_trim和agentId参数的。
解决方案
将redirect_url进行encodeUrlComponent
,推荐一个在线转换的网址:encodeUrlComponent。转换之后授权链接就成了这种形式:
https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=https%3A%2F%2Fwww.baidu.com%3Fneed_trim%3Dneed_trim%26agentId%3D1&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect
这个时候,重定向redirect_url之后,会携带need_trim和agentId两个自定义的参数。