微信公众平台网页授权两次重定向跳转问题

在做微信公众平台网页授权时,发现每次请求授权链接

https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxx&redirect_uri=xxx&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect

时都会重定向链接redirect_uri都会自动请求两次,由于并发导致了一些问题,

{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest, hints: [ req_id: PSp.LA0036s182 ]"}

那么,为什么会请求两次呢?,调试时发现会访问两次,一次是301,页面重定向了,第二次跟第一次就差这个参数。加上后,不再报错。code 可以了。

后来发现只要加个属性就不会有这个问题了。

https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxx&redirect_uri=xxx&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect

&connect_redirect=1 这个参数

主要是微信开发者文档里没提到这个参数:1 第一步:用户同意授权,获取code

原文地址:https://www.cnblogs.com/liea/p/12000031.html