Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加PC端扫码操作 #26

Merged
merged 1 commit into from
Aug 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion get-weixin-code.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@
var appId = GWC.urlParams['appid'];
var scope = GWC.urlParams['scope'] || 'snsapi_base';
var state = GWC.urlParams['state'];
var isMp = GWC.urlParams['isMp']; //isMp为true时使用开放平台作授权登录,false为网页扫码登录
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里会有一个问题,对于其他用户来说,不传isMp时会自动网页扫码登录,向下兼容有问题。并且我们这个主要是作为手机端使用,建议使用一个相反的条件来针对网页扫码登录做单独判断

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里传与不传的话默认不会去到网页扫码登录,需要同时传进snsapi_login才会去到扫码登录,这里是我的注释解释的有问题。。= =。。isMp只是利用开放平台在公众平台上作授权而已。。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

了解,刚刚查了下,公众平台没有snsapi_login这个选项,那这里是不是可以直接通过snsapi_login这一个值来判断就可以了,还需要isMp这个参数吗?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,公众平台是没有snsapi_login这个选项的,snsapi_login这个选项是开放平台中的扫码登录的选项,isMp这个选项是必须的,因为针对开放平台的话 扫码与授权 所请求的url不一致。isMp仅仅是针对于使用开放平台在公众号内做授权(个人订阅号或未认证订阅号没有接口权限),如果本身的的公众号有接口权限的话就不需要了。

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,LGTM!

var baseUrl;
var redirectUri;

if (!code) {
baseUrl = "https://open.weixin.qq.com/connect/oauth2/authorize#wechat_redirect";
if(scope == 'snsapi_login' && !isMp){
baseUrl = "https://open.weixin.qq.com/connect/qrconnect";
}
//第一步,没有拿到code,跳转至微信授权页面获取code
redirectUri = GWC.appendParams('https://open.weixin.qq.com/connect/oauth2/authorize#wechat_redirect', {
redirectUri = GWC.appendParams(baseUrl, {
'appid': appId,
'redirect_uri': encodeURIComponent(location.href),
'response_type': 'code',
Expand Down