Solve the problem that only one callback domain name can be set for WeChat OAuth2.0 web authorization
Recently, it was discovered that the WeChat public account’s web page authorization domain name can now support the configuration of multiple domains. Currently, the significance of the existence of this project is not as strong as before. The only use currently is that multiple domain names can be processed in one place.
Deploy get-weixin-code.html
to the directory of your WeChat authorized callback domain name
The usage method is similar to the method of calling back directly through WeChat, except that the callback address is changed to the address where get-weixin-code.html
is located, and response_type
parameter is omitted (because it can only be code
) and #wechat_redirect
(it is fixed ), they will be added by themselves in get-weixin-code.html
After the get-weixin-code.html
page gets the code from WeChat, it will jump back to the url filled in redirect_uri
, and put code
and state
after the url.
Go to the WeChat public platform->Interface permissions->Web page authorization to obtain basic user information->Modify, fill in the domain name of the authorization callback page, for example www.abc.com
Deploy get-weixin-code.html
under the domain name www.abc.com
, not necessarily the root directory, for example: http://www.abc.com/xxx/get-weixin-code.html
Assuming that your page http://www.xyz.com/hello-world.html
needs to obtain WeChat authorization, then you should use the following address to obtain authorization: http://www.abc.com/xxx/get-weixin-code.html?appid=XXXX&scope=snsapi_base&state=hello-world&redirect_uri=http%3A%2F%2Fwww.xyz.com%2Fhello-world.html
This will eventually jump to such an address: http://www.xyz.com/hello-world.html?code=XXXXXXXXXXXXXXXXX&state=hello-world
, and you will get the authorization code
and customized state
parameters.
Thanks to the following friends for their contributions to this project (listed in no particular order)
star769706697
davidqr
tianhe1986
AnthonyHuang001
sanzhumu
q250305917
kisChang
EasonShen1989
Through one more jump, the problem of WeChat restricting the setting of only one callback domain name is solved.
A bit of user experience is sacrificed in exchange for the beauty of project deployment. There is no need to deploy various projects under one domain name.
If you have such needs, you can use this project
Welcome to submit pull requests
It is recommended to first understand the WeChat authorization callback process before using this project.
Many friends ask me how to support third-party WeChat platforms. This requires understanding the authorization methods of different third-party platforms, and being familiar with their authorization methods, request parameters, etc. If they are authorized through the URL at the website entrance, then you can use this project to change the entrance URL to the above method. If they obtain authorization on certain pages in the process, then it cannot be changed. They obtain the address, so this project is not applicable.