[微信开发]微信登录之任意域名的授权登录

应用场景:

test.com可通过微信登录。此时,另一个网站dev.test.com也想通过微信登录,但是dev.test.com微信没有登录权

1、在主站引入

https://github.com/HADB/GetWeixinCode项目资源将本文件放置在适当的位置

2、 配置授权URL

authorize_url=http://test.com/static/html/get-weixin-code.html

不直接通过微信授权,而是通过微信授权URL进行授权

3、配置回调地址

redirect_uri=/oauth/authc/weixin

自定义回调URL

4、需要授权时访问的URL

1)开放平台(扫码登录)

url = authorize_url "?" "appid=" appid "&redirect_uri="

       URLEncoder.encode(request.getScheme() "://" request.getServerName() redirect_uri,"UTF-8") "&response_type=" response_type "&scope=" scope

       "&state=" state;

2)公共平台(默默登录微信客户端)

url = authorize_url "?" "appid=" weixinAppid "&redirect_uri="

       URLEncoder.encode(request.getScheme() "://" request.getServerName() redirect_uri.replace("weixin","weixin_mp"),"UTF-8") "&response_type=" response_type "&scope=snsapi_userinfo"

       "&state=" state "#wechat_redirect";

备注:weixinAppid!=appid,appid属于开发平台,weixinAppid属于公共平台。

加我们 免费用

源码出售 支持二开

立即获取免费试用

Copyright © All Rights Reserved 皖ICP备2021007790号-4

立即咨询