-
Notifications
You must be signed in to change notification settings - Fork 489
开放平台开发设置
borball edited this page Dec 29, 2016
·
3 revisions
-
默认配置方式
可以直接在 classpath 下面增加 wx-open-settings.xml,内容如下:
<AppSetting> <appId>your appId</appId> <secret>your secret</secret> </AppSetting>
使用:
//生成授权链接,默认scope: snsapi_base OpenOAuth2s.defaultOpenOAuth2s().authenticationUrl("url"); //生成授权链接,指定scope: snsapi_base or snsapi_userinfo OpenOAuth2s.defaultOpenOAuth2s().authenticationUrl("url", "scope"); //生成授权链接,指定scope,指定state OpenOAuth2s.defaultOpenOAuth2s().authenticationUrl("url", "scope", "state"); //获取AccessToken AccessToken accessToken = OpenOAuth2s.defaultOpenOAuth2s().getAccessToken("code"); //获取用户信息 OpenUser user = OpenOAuth2s.defaultOpenOAuth2s().userInfo(accessToken, "openId");
-
使用编程的方式:
AppSetting appSetting = new AppSetting("appId", "secret"); //生成授权链接,默认scope: snsapi_base OpenOAuth2s.with(appSetting).authenticationUrl("url"); //生成授权链接,指定scope: snsapi_base or snsapi_userinfo OpenOAuth2s.with(appSetting).authenticationUrl("url", "scope"); //生成授权链接,指定scope,指定state OpenOAuth2s.with(appSetting).authenticationUrl("url", "scope", "state"); //获取AccessToken AccessToken accessToken = OpenOAuth2s.with(appSetting).getAccessToken("code"); //获取用户信息 OpenUser user = OpenOAuth2s.with(appSetting).userInfo(accessToken, "openId");