├── .gitignore ├── LICENSE ├── README.md ├── donation.jpg └── get-weixin-code.html /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Bean Deng 邓斌 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GetWeixinCode 2 | 3 | 解决微信OAuth2.0网页授权只能设置一个回调域名的问题 4 | 5 | ## UPDATE 6 | 7 | **最近发现微信公众号的网页授权域名已经支持配置多个,目前该项目的存在意义没有之前强烈了。目前唯一的用处就是多个域名可以统一在一个地方处理。** 8 | 9 | ## 使用方法 10 | 11 | 1. 部署`get-weixin-code.html`至你的微信授权回调域名的目录下 12 | 13 | 2. 使用方式类似于直接通过微信回调的方式,只是将回调地址改成了`get-weixin-code.html`所在的地址,另外省去了`response_type`参数(因为它只能为`code`)以及`#wechat_redirect`(它是固定的),它们会在`get-weixin-code.html`里面自己加上 14 | 15 | 3. `get-weixin-code.html`页面从微信那里拿到code之后会重新跳转回`redirect_uri`里面填写的url,并且在url后面带上`code`和`state` 16 | 17 | ## 详细示例 18 | 19 | 1. 前往微信公众平台->接口权限->网页授权获取用户基本信息->修改,填写授权回调页面域名,例如`www.abc.com` 20 | 21 | 2. 在`www.abc.com`域名下部署`get-weixin-code.html`,不一定是根目录,例如:`http://www.abc.com/xxx/get-weixin-code.html` 22 | 23 | 3. 假设你的`http://www.xyz.com/hello-world.html`这个页面需要获取微信授权,那么你应该使用以下地址来获取授权:`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` 24 | 25 | 4. 这样最终就会跳转到这样一个地址:`http://www.xyz.com/hello-world.html?code=XXXXXXXXXXXXXXXXX&state=hello-world`,从而你就拿到了授权`code`以及自定义的`state`参数了 26 | 27 | ## Star走势图 28 | 29 | ![Stargazers over time](https://starcharts.herokuapp.com/HADB/GetWeixinCode.svg) 30 | 31 | ## 特别感谢 32 | 33 | 感谢以下朋友为本项目提供的贡献(排名不分先后) 34 | 35 | - [star769706697](https://github.com/star769706697) 36 | 37 | - [davidqhr](https://github.com/davidqhr) 38 | 39 | - [tianhe1986](https://github.com/tianhe1986) 40 | 41 | - [AnthonyHuang001](https://github.com/AnthonyHuang001) 42 | 43 | - [sanzhumu](https://github.com/sanzhumu) 44 | 45 | - [q250305917](https://github.com/q250305917) 46 | 47 | - [kisChang](https://github.com/kisChang) 48 | 49 | - [EasonShen1989](https://github.com/EasonShen1989) 50 | 51 | ## 其他说明 52 | 53 | - 通过多一次的跳转,解决了微信限制回调域名只能设置一个的问题 54 | 55 | - 牺牲了一点用户体验,换来了项目部署的美感,不需要将各种项目都部署到一个域名下 56 | 57 | - 如果你有这样的需求,可以使用本项目 58 | 59 | - 欢迎提交pull request 60 | 61 | - **建议先弄懂微信授权回调的流程再使用本项目** 62 | 63 | - **很多朋友问我怎么支持第三方微信平台,这个需要对不同的第三方平台的授权方式有所了解,熟悉他们的授权方式,请求参数等。如果他们是通过在网站入口处的URL上进行授权的,那么可以使用本项目,将入口的URL改成上述的方式,如果他们是在流程中的某些页面去获取授权,那么是没法改变他们的获取地址的,所以本项目就不适用了** 64 | 65 | ## 支持作者 66 | 67 | ![Donation](donation.jpg) 68 | -------------------------------------------------------------------------------- /donation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HADB/GetWeixinCode/817d91aeb8f68f6f1388e7e65fd3d81e202d1dca/donation.jpg -------------------------------------------------------------------------------- /get-weixin-code.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 微信登录 7 | 8 | 9 | 10 | 90 | 91 | 92 | 93 | --------------------------------------------------------------------------------