成员登录
This commit is contained in:
parent
5876801bd4
commit
087d7c354b
@ -39,6 +39,7 @@ import com.foxinmy.weixin4j.qy.model.ChatInfo;
|
||||
import com.foxinmy.weixin4j.qy.model.ChatMute;
|
||||
import com.foxinmy.weixin4j.qy.model.Contacts;
|
||||
import com.foxinmy.weixin4j.qy.model.IdParameter;
|
||||
import com.foxinmy.weixin4j.qy.model.OUserInfo;
|
||||
import com.foxinmy.weixin4j.qy.model.Party;
|
||||
import com.foxinmy.weixin4j.qy.model.Tag;
|
||||
import com.foxinmy.weixin4j.qy.model.User;
|
||||
@ -188,7 +189,8 @@ public class WeixinProxy {
|
||||
private WeixinProxy(WeixinAccount weixinAccount, TokenCreator tokenCreator,
|
||||
CacheStorager<Token> cacheStorager) {
|
||||
if (weixinAccount == null) {
|
||||
throw new IllegalArgumentException("weixinAccount must not be empty");
|
||||
throw new IllegalArgumentException(
|
||||
"weixinAccount must not be empty");
|
||||
}
|
||||
if (tokenCreator == null) {
|
||||
throw new IllegalArgumentException("tokenCreator must not be empty");
|
||||
@ -795,6 +797,22 @@ public class WeixinProxy {
|
||||
return userApi.getUserByCode(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取企业号管理员登录信息
|
||||
*
|
||||
* @param authCode
|
||||
* oauth2.0授权企业号管理员登录产生的code
|
||||
* @return 登陆信息
|
||||
* @see <a href=
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E4%BC%81%E4%B8%9A%E7%AE%A1%E7%90%86%E5%91%98%E7%99%BB%E5%BD%95%E4%BF%A1%E6%81%AF">
|
||||
* 授权获取企业号管理员登录信息</a>
|
||||
* @see com.foxinmy.weixin4j.qy.model.OUserInfo
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public OUserInfo getOUserInfoByCode(String authCode) throws WeixinException {
|
||||
return userApi.getOUserInfoByCode(authCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取成员ID信息
|
||||
*
|
||||
|
||||
@ -87,36 +87,43 @@ public class OauthApi extends QyApi {
|
||||
* redirectUri默认填写weixin4j.properties#third.oauth.redirect.uri <li>
|
||||
* state默认填写state
|
||||
*
|
||||
* @see {@link #getThirdAuthorizationURL(String,String)}
|
||||
* @see {@link #getUserThirdAuthorizationURL(String,String)}
|
||||
*
|
||||
* @return 请求授权的URL
|
||||
*/
|
||||
public String getThirdAuthorizationURL() {
|
||||
String redirectUri = Weixin4jConfigUtil
|
||||
.getValue("third.oauth.redirect.uri");
|
||||
return getThirdAuthorizationURL(redirectUri, "state");
|
||||
return getUserThirdAuthorizationURL(redirectUri, "state", "all");
|
||||
}
|
||||
|
||||
/**
|
||||
* 企业号第三方提供商登陆授权
|
||||
* 企业号成员登陆授权
|
||||
*
|
||||
* @param corpId
|
||||
* 企业号(提供商)的corpid
|
||||
* 服务商的CorpID或者企业的CorpID
|
||||
* @param redirectUri
|
||||
* 重定向地址
|
||||
* @param state
|
||||
* 用于保持请求和回调的状态,授权请求后原样带回给第三方
|
||||
* @param userType
|
||||
* redirect_uri支持登录的类型,有member(成员登录)、admin(管理员登录)、all(成员或管理员皆可登录)
|
||||
* ,默认值为admin
|
||||
* @return 请求授权的URL
|
||||
* @see ProviderApi#getOUserInfoByCode(String)
|
||||
* 授权登录服务商的网站时,使用应用提供商的provider_access_token;
|
||||
* @see UserApi#getOUserInfoByCode(String) 授权登录企业的网站时,使用企业管理组的access_token
|
||||
* @see <a href=
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E6%88%90%E5%91%98%E7%99%BB%E5%BD%95%E6%8E%88%E6%9D%83">
|
||||
* 企业号第三方提供商授权</a>
|
||||
*/
|
||||
public String getThirdAuthorizationURL(String redirectUri, String state) {
|
||||
String oauth_uri = getRequestUri("provider_oauth_uri");
|
||||
public String getUserThirdAuthorizationURL(String redirectUri,
|
||||
String state, String userType) {
|
||||
String oauth_uri = getRequestUri("user_thirdoauth_uri");
|
||||
try {
|
||||
return String.format(oauth_uri, account.getId(),
|
||||
URLEncoder.encode(redirectUri, Consts.UTF_8.name()), state);
|
||||
URLEncoder.encode(redirectUri, Consts.UTF_8.name()), state,
|
||||
userType);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
;
|
||||
}
|
||||
|
||||
@ -44,9 +44,9 @@ public class ProviderApi extends QyApi {
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public OUserInfo getOUserInfoByCode(String authCode) throws WeixinException {
|
||||
String oauth_logininfo_uri = getRequestUri("oauth_logininfo_uri");
|
||||
String oauth_thirdinfo_uri = getRequestUri("oauth_logininfo_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(oauth_logininfo_uri,
|
||||
String.format(oauth_thirdinfo_uri,
|
||||
providerTokenManager.getAccessToken()),
|
||||
String.format("{\"auth_code\":\"%s\"}", authCode));
|
||||
JSONObject obj = response.getAsJson();
|
||||
|
||||
@ -222,8 +222,6 @@ public class UserApi extends QyApi {
|
||||
/**
|
||||
* 获取企业号管理员登录信息
|
||||
*
|
||||
* @param providerToken
|
||||
* 提供商的token
|
||||
* @param authCode
|
||||
* oauth2.0授权企业号管理员登录产生的code
|
||||
* @return 登陆信息
|
||||
@ -233,11 +231,11 @@ public class UserApi extends QyApi {
|
||||
* @see com.foxinmy.weixin4j.qy.model.OUserInfo
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public OUserInfo getOUserInfoByCode(String providerToken, String authCode)
|
||||
throws WeixinException {
|
||||
public OUserInfo getOUserInfoByCode(String authCode) throws WeixinException {
|
||||
Token token = tokenManager.getCache();
|
||||
String oauth_logininfo_uri = getRequestUri("oauth_logininfo_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(oauth_logininfo_uri, providerToken),
|
||||
String.format(oauth_logininfo_uri, token.getAccessToken()),
|
||||
String.format("{\"auth_code\":\"%s\"}", authCode));
|
||||
return JSON.parseObject(response.getAsString(), OUserInfo.class);
|
||||
}
|
||||
|
||||
@ -88,12 +88,12 @@ batch_getresult_uri={api_base_url}/batch/getresult?access_token=%s&jobid=%s
|
||||
|
||||
# \u7528\u6237\u8eab\u4efdoauth\u6388\u6743
|
||||
user_oauth_uri=https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s#wechat_redirect
|
||||
# \u7b2c\u4e09\u65b9\u63d0\u4f9b\u5546oauth\u6388\u6743
|
||||
provider_oauth_uri=https://qy.weixin.qq.com/cgi-bin/loginpage?corp_id=%s&redirect_uri=%s&state=%s
|
||||
# \u4f01\u4e1a\u53f7\u7ba1\u7406\u5458\u767b\u5f55\u4fe1\u606f
|
||||
oauth_logininfo_uri={api_base_url}/service/get_login_info?provider_access_token=%s
|
||||
# \u6210\u5458\u767b\u5f55\u7b2c\u4e09\u65b9oauth\u6388\u6743
|
||||
user_thirdoauth_uri=https://qy.weixin.qq.com/cgi-bin/loginpage?corp_id=%s&redirect_uri=%s&state=%s&usertype=%s
|
||||
# \u4f01\u4e1a\u53f7\u6210\u5458\u767b\u5f55\u7b2c\u4e09\u65b9\u4fe1\u606f
|
||||
oauth_logininfo_uri={api_base_url}/service/get_login_info?access_token=%s
|
||||
# \u767b\u5f55\u4f01\u4e1a\u53f7\u5b98\u7f51\u7684url
|
||||
oauth_loginurl_uri={api_base_url}/service/get_login_url?provider_access_token=%s
|
||||
oauth_loginurl_uri={api_base_url}/service/get_login_url?access_token=%s
|
||||
# \u5e94\u7528\u5957\u4ef6\u8bbe\u7f6e\u6388\u6743\u914d\u7f6e
|
||||
suite_set_session_uri={api_base_url}/service/set_session_info?suite_access_token=%s
|
||||
# \u83b7\u53d6\u4f01\u4e1a\u53f7\u7684\u6c38\u4e45\u6388\u6743\u7801
|
||||
|
||||
@ -6,6 +6,7 @@ import java.util.List;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.qy.type.AgentAuthType;
|
||||
import com.foxinmy.weixin4j.qy.type.LoginUserType;
|
||||
|
||||
/**
|
||||
* 企业号oauth授权登陆信息&第三方应用授权信息
|
||||
@ -19,6 +20,11 @@ import com.foxinmy.weixin4j.qy.type.AgentAuthType;
|
||||
public class OUserInfo implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -567063562050171293L;
|
||||
/**
|
||||
* 登录用户的类型:1.企业号创建者 2.企业号内部系统管理员 3.企业号外部系统管理员 4.企业号分级管理员 5. 企业号成员
|
||||
*/
|
||||
@JSONField(name = "usertype")
|
||||
private int userType;
|
||||
/**
|
||||
* 是否系统管理员
|
||||
*/
|
||||
@ -85,6 +91,19 @@ public class OUserInfo implements Serializable {
|
||||
|
||||
// ---------- setter 应该全部去掉
|
||||
|
||||
public int getUserType() {
|
||||
return userType;
|
||||
}
|
||||
|
||||
@JSONField(serialize = false)
|
||||
public LoginUserType getFormatUserType() {
|
||||
return LoginUserType.values()[userType - 1];
|
||||
}
|
||||
|
||||
public void setUserType(int userType) {
|
||||
this.userType = userType;
|
||||
}
|
||||
|
||||
public void setSysAdmin(boolean isSysAdmin) {
|
||||
this.isSysAdmin = isSysAdmin;
|
||||
}
|
||||
@ -115,9 +134,11 @@ public class OUserInfo implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "OUserInfo [isSysAdmin=" + isSysAdmin + ", isInnerAdmin=" + isInnerAdmin + ", adminInfo=" + adminInfo
|
||||
+ ", corpInfo=" + corpInfo + ", agentInfo=" + agentInfo + ", authInfo=" + authInfo
|
||||
+ ", redirectLoginInfo=" + redirectLoginInfo + "]";
|
||||
return "OUserInfo [userType=" + userType + ", isSysAdmin=" + isSysAdmin
|
||||
+ ", isInnerAdmin=" + isInnerAdmin + ", adminInfo=" + adminInfo
|
||||
+ ", corpInfo=" + corpInfo + ", agentInfo=" + agentInfo
|
||||
+ ", authInfo=" + authInfo + ", redirectLoginInfo="
|
||||
+ redirectLoginInfo + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,8 +197,8 @@ public class OUserInfo implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AuthInfo [isNewAuth=" + isNewAuth + ", agentItems=" + agentItems + ", departItems=" + departItems
|
||||
+ "]";
|
||||
return "AuthInfo [isNewAuth=" + isNewAuth + ", agentItems="
|
||||
+ agentItems + ", departItems=" + departItems + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,8 +225,8 @@ public class OUserInfo implements Serializable {
|
||||
@JSONField(name = "appid")
|
||||
private int appId;
|
||||
/**
|
||||
* 授权方应用敏感权限组,目前仅有get_location,表示是否有权限设置应用获取地理位置的开关,
|
||||
* <font color="red">新的权限体系将废弃</font>
|
||||
* 授权方应用敏感权限组,目前仅有get_location,表示是否有权限设置应用获取地理位置的开关, <font
|
||||
* color="red">新的权限体系将废弃</font>
|
||||
*/
|
||||
@JSONField(name = "api_group")
|
||||
private List<String> apiGroup;
|
||||
@ -261,8 +282,9 @@ public class OUserInfo implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AgentItem [authType=" + authType + ", appId=" + appId + ", apiGroup=" + apiGroup + ", privilege="
|
||||
+ privilege + ", " + super.toString() + "]";
|
||||
return "AgentItem [authType=" + authType + ", appId=" + appId
|
||||
+ ", apiGroup=" + apiGroup + ", privilege=" + privilege
|
||||
+ ", " + super.toString() + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,7 +317,8 @@ public class OUserInfo implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DepartItem [writable=" + writable + ", " + super.toString() + "]";
|
||||
return "DepartItem [writable=" + writable + ", " + super.toString()
|
||||
+ "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
package com.foxinmy.weixin4j.qy.type;
|
||||
|
||||
/**
|
||||
* 成员登录类型
|
||||
*
|
||||
* @className LoginUserType
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2016年11月4日
|
||||
* @since JDK 1.6
|
||||
*/
|
||||
public enum LoginUserType {
|
||||
/**
|
||||
* 企业号创建者
|
||||
*/
|
||||
CREATOR,
|
||||
/**
|
||||
* 企业号内部系统管理员
|
||||
*/
|
||||
INNERADMIN,
|
||||
/**
|
||||
* 企业号外部系统管理员
|
||||
*/
|
||||
OUTTERADMIN,
|
||||
/**
|
||||
* 企业号分级管理员
|
||||
*/
|
||||
LEVELADMIN,
|
||||
/**
|
||||
* 企业号成员
|
||||
*/
|
||||
MEMBER;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user