oauthapi 修改 新增用户身份授权
This commit is contained in:
parent
ea539fdedd
commit
ba5d2da3a1
@ -101,8 +101,7 @@ public class ConfigUtil {
|
|||||||
public static WeixinAccount getWeixinAccount() {
|
public static WeixinAccount getWeixinAccount() {
|
||||||
WeixinAccount account = null;
|
WeixinAccount account = null;
|
||||||
try {
|
try {
|
||||||
String text = getValue("account");
|
account = JSON.parseObject(getValue("account"), WeixinAccount.class);
|
||||||
account = JSON.parseObject(text, WeixinAccount.class);
|
|
||||||
} catch (MissingResourceException e) {
|
} catch (MissingResourceException e) {
|
||||||
System.err
|
System.err
|
||||||
.println("'account' key not found in weixin4j.properties file.");
|
.println("'account' key not found in weixin4j.properties file.");
|
||||||
|
|||||||
@ -51,8 +51,9 @@ weixin4j.properties说明
|
|||||||
| account | 微信企业号信息 `json格式` |
|
| account | 微信企业号信息 `json格式` |
|
||||||
| token_path | 使用FileTokenStorager时token保存的物理路径 |
|
| token_path | 使用FileTokenStorager时token保存的物理路径 |
|
||||||
| media_path | 调用媒体接口时保存媒体文件的物理路径 |
|
| media_path | 调用媒体接口时保存媒体文件的物理路径 |
|
||||||
| redirect_uri | 企业号登陆授权后重定向的url(OauthApi接口) |
|
| user_oauth_redirect_uri | 企业号用户身份授权后重定向的url(OauthApi接口) |
|
||||||
| suite_redirect_uri | 企业号第三方应用套件授权后重定向的url(OauthApi接口) |
|
| third_oauth_redirect_uri | 企业号第三方提供商授权后重定向的url(OauthApi接口) |
|
||||||
|
| suite_oauth_redirect_uri | 企业号第三方应用套件授权后重定向的url(OauthApi接口) |
|
||||||
|
|
||||||
示例(properties中换行用右斜杆\\)
|
示例(properties中换行用右斜杆\\)
|
||||||
|
|
||||||
@ -64,8 +65,11 @@ weixin4j.properties说明
|
|||||||
token_path=/tmp/weixin4j/token
|
token_path=/tmp/weixin4j/token
|
||||||
media_path=/tmp/weixin4j/media
|
media_path=/tmp/weixin4j/media
|
||||||
|
|
||||||
#企业号登陆授权的重定向路径(使用OauthApi时需要填写)
|
#企业号用户身份授权后重定向的url(使用OauthApi时需要填写)
|
||||||
redirect_uri=http://xxx
|
user_oauth_redirect_uri=http://xxx
|
||||||
|
|
||||||
|
#企业号第三方管理员授权后重定向的url(使用OauthApi时需要填写)
|
||||||
|
third_oauth_redirect_uri=http://xxx
|
||||||
|
|
||||||
#企业号第三方应用套件授权后重定向的url(使用OauthApi时需要填写)
|
#企业号第三方应用套件授权后重定向的url(使用OauthApi时需要填写)
|
||||||
suite_redirect_uri=http://xxx
|
suite_redirect_uri=http://xxx
|
||||||
|
|||||||
@ -18,23 +18,63 @@ import com.foxinmy.weixin4j.util.ConfigUtil;
|
|||||||
* @date 2015年6月11日
|
* @date 2015年6月11日
|
||||||
* @since JDK 1.7
|
* @since JDK 1.7
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%8F%B7%E7%99%BB%E5%BD%95%E6%8E%88%E6%9D%83">企业号登录授权说明</a>
|
* href="http://qydev.weixin.qq.com/wiki/index.php?title=OAuth%E9%AA%8C%E8%AF%81%E6%8E%A5%E5%8F%A3">企业号用户身份授权说明</a>
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%88%E6%9D%83">第三方应用授权说明</a>
|
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%8F%B7%E7%99%BB%E5%BD%95%E6%8E%88%E6%9D%83">企业号第三方提供商授权说明</a>
|
||||||
|
* @see <a
|
||||||
|
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E6%8E%88%E6%9D%83">企业号第三方套件应用授权说明</a>
|
||||||
*/
|
*/
|
||||||
public class OauthApi extends QyApi {
|
public class OauthApi extends QyApi {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 企业号登陆授权
|
* 企业号用户身份授权
|
||||||
*
|
*
|
||||||
* @see {@link com.foxinmy.weixin4j.qy.api.OauthApi#getAuthorizeURL(String, String,String)}
|
* @see {@link com.foxinmy.weixin4j.qy.api.OauthApi#getUserAuthorizeURL(String, String,String)}
|
||||||
*
|
*
|
||||||
* @return 请求授权的URL
|
* @return 请求授权的URL
|
||||||
*/
|
*/
|
||||||
public String getAuthorizeURL() {
|
public String getUserAuthorizeURL() {
|
||||||
String corpId = DEFAULT_WEIXIN_ACCOUNT.getId();
|
String corpId = DEFAULT_WEIXIN_ACCOUNT.getId();
|
||||||
String redirectUri = ConfigUtil.getValue("redirect_uri");
|
String redirectUri = ConfigUtil.getValue("user_oauth_redirect_uri");
|
||||||
return getAuthorizeURL(corpId, redirectUri, "state");
|
return getUserAuthorizeURL(corpId, redirectUri, "state");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业号用户身份授权
|
||||||
|
*
|
||||||
|
* @param corpId
|
||||||
|
* 企业号的corpid
|
||||||
|
* @param redirectUri
|
||||||
|
* 重定向地址
|
||||||
|
* @param state
|
||||||
|
* 用于保持请求和回调的状态
|
||||||
|
* @return 请求授权的URL
|
||||||
|
* @see <a
|
||||||
|
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%8F%B7%E7%99%BB%E5%BD%95%E6%8E%88%E6%9D%83">企业号用户身份授权</a>
|
||||||
|
*/
|
||||||
|
public String getUserAuthorizeURL(String corpId, String redirectUri,
|
||||||
|
String state) {
|
||||||
|
String oauth_uri = getRequestUri("user_oauth_uri");
|
||||||
|
try {
|
||||||
|
return String.format(oauth_uri, corpId,
|
||||||
|
URLEncoder.encode(redirectUri, Consts.UTF_8.name()), state);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业号第三方提供商授权
|
||||||
|
*
|
||||||
|
* @see {@link com.foxinmy.weixin4j.qy.api.OauthApi#getThirdAuthorizeURL(String, String,String)}
|
||||||
|
*
|
||||||
|
* @return 请求授权的URL
|
||||||
|
*/
|
||||||
|
public String getThirdAuthorizeURL() {
|
||||||
|
String corpId = DEFAULT_WEIXIN_ACCOUNT.getId();
|
||||||
|
String redirectUri = ConfigUtil.getValue("third_oauth_redirect_uri");
|
||||||
|
return getThirdAuthorizeURL(corpId, redirectUri, "state");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,9 +88,9 @@ public class OauthApi extends QyApi {
|
|||||||
* 用于保持请求和回调的状态,授权请求后原样带回给第三方
|
* 用于保持请求和回调的状态,授权请求后原样带回给第三方
|
||||||
* @return 请求授权的URL
|
* @return 请求授权的URL
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%8F%B7%E7%99%BB%E5%BD%95%E6%8E%88%E6%9D%83">企业号登陆授权</a>
|
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E4%BC%81%E4%B8%9A%E5%8F%B7%E7%99%BB%E5%BD%95%E6%8E%88%E6%9D%83">企业号第三方提供商授权</a>
|
||||||
*/
|
*/
|
||||||
public String getAuthorizeURL(String corpId, String redirectUri,
|
public String getThirdAuthorizeURL(String corpId, String redirectUri,
|
||||||
String state) {
|
String state) {
|
||||||
String oauth_uri = getRequestUri("provider_oauth_uri");
|
String oauth_uri = getRequestUri("provider_oauth_uri");
|
||||||
try {
|
try {
|
||||||
@ -63,7 +103,7 @@ public class OauthApi extends QyApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取企业号管理员登录信息
|
* 第三方套件获取企业号管理员登录信息
|
||||||
*
|
*
|
||||||
* @param providerToken
|
* @param providerToken
|
||||||
* 提供商的token
|
* 提供商的token
|
||||||
@ -92,7 +132,7 @@ public class OauthApi extends QyApi {
|
|||||||
*/
|
*/
|
||||||
public String getSuiteAuthorizeURL(String preAuthCode) {
|
public String getSuiteAuthorizeURL(String preAuthCode) {
|
||||||
String suiteId = DEFAULT_WEIXIN_ACCOUNT.getSuiteId();
|
String suiteId = DEFAULT_WEIXIN_ACCOUNT.getSuiteId();
|
||||||
String redirectUri = ConfigUtil.getValue("suite_redirect_uri");
|
String redirectUri = ConfigUtil.getValue("suite_oauth_redirect_uri");
|
||||||
return getSuiteAuthorizeURL(suiteId, preAuthCode, redirectUri, "state");
|
return getSuiteAuthorizeURL(suiteId, preAuthCode, redirectUri, "state");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,10 +147,10 @@ public class OauthApi extends QyApi {
|
|||||||
* 授权后重定向url
|
* 授权后重定向url
|
||||||
* @param state
|
* @param state
|
||||||
* 回调后原样返回
|
* 回调后原样返回
|
||||||
* @return 请求授权的URL <a
|
* @see <a href="http://qydev.weixin.qq.com/wiki/index.php?title
|
||||||
* href=""http://qydev.weixin.qq.com/wiki/index.php?title
|
* =%E4%BC%81%E4%B8%9A%E5%8F%B7%E7%AE%A1%E7%90%86%E5%91%98%E6%
|
||||||
* =%E4%BC%81%E4%B8%9A%E5%8F%B7%E7%AE%A1%E7%90%86%E5%91%98%E6%
|
* 8E%88%E6%9D%83%E5%BA%94%E7%94%A8">企业号第三方应用套件授权</a>
|
||||||
* 8E%88%E6%9D%83%E5%BA%94%E7%94%A8>应用套件授权</a>
|
* @return 请求授权的URL
|
||||||
*/
|
*/
|
||||||
public String getSuiteAuthorizeURL(String suiteId, String preAuthCode,
|
public String getSuiteAuthorizeURL(String suiteId, String preAuthCode,
|
||||||
String redirectUri, String state) {
|
String redirectUri, String state) {
|
||||||
|
|||||||
@ -40,10 +40,10 @@ public class PartyApi extends QyApi {
|
|||||||
* @return 部门ID
|
* @return 部门ID
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public int createParty(Party depart) throws WeixinException {
|
public int createParty(Party party) throws WeixinException {
|
||||||
String department_create_uri = getRequestUri("department_create_uri");
|
String department_create_uri = getRequestUri("department_create_uri");
|
||||||
JSONObject obj = (JSONObject) JSON.toJSON(depart);
|
JSONObject obj = (JSONObject) JSON.toJSON(party);
|
||||||
if (depart.getId() < 1) {
|
if (party.getId() < 1) {
|
||||||
obj.remove("id");
|
obj.remove("id");
|
||||||
}
|
}
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
|
|||||||
@ -80,7 +80,9 @@ batch_replaceparty.cvs={"header":"\u90e8\u95e8\u540d\u79f0,\u90e8\u95e8ID,\u7236
|
|||||||
# \u83b7\u53d6\u5f02\u6b65\u4efb\u52a1\u6267\u884c\u7ed3\u679c
|
# \u83b7\u53d6\u5f02\u6b65\u4efb\u52a1\u6267\u884c\u7ed3\u679c
|
||||||
batch_getresult_uri={api_base_url}/batch/getresult?access_token=%s&jobid=%s
|
batch_getresult_uri={api_base_url}/batch/getresult?access_token=%s&jobid=%s
|
||||||
|
|
||||||
# \u63d0\u4f9b\u5546oauth\u6388\u6743
|
# \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
|
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
|
# \u4f01\u4e1a\u53f7\u7ba1\u7406\u5458\u767b\u5f55\u4fe1\u606f
|
||||||
oauth_logininfo_uri={api_base_url}/service/get_login_info?provider_access_token=%s
|
oauth_logininfo_uri={api_base_url}/service/get_login_info?provider_access_token=%s
|
||||||
|
|||||||
@ -13,8 +13,11 @@ token_path=/tmp/weixin4j/token
|
|||||||
# \u5a92\u4f53\u6587\u4ef6\u4fdd\u5b58\u8def\u5f84
|
# \u5a92\u4f53\u6587\u4ef6\u4fdd\u5b58\u8def\u5f84
|
||||||
media_path=/tmp/weixin4j/media
|
media_path=/tmp/weixin4j/media
|
||||||
|
|
||||||
# \u4f01\u4e1a\u53f7\u767b\u9646\u6388\u6743\u540e\u91cd\u5b9a\u5411\u7684url
|
# \u4f01\u4e1a\u53f7\u7528\u6237\u8eab\u4efd\u6388\u6743\u540e\u91cd\u5b9a\u5411\u7684url
|
||||||
redirect_uri=
|
user_oauth_redirect_uri=
|
||||||
|
|
||||||
|
# \u4f01\u4e1a\u53f7\u7b2c\u4e09\u65b9\u63d0\u4f9b\u5546\u6388\u6743\u540e\u91cd\u5b9a\u5411\u7684url
|
||||||
|
third_oauth_redirect_uri=
|
||||||
|
|
||||||
# \u4f01\u4e1a\u53f7\u7b2c\u4e09\u65b9\u5e94\u7528\u5957\u4ef6\u6388\u6743\u540e\u91cd\u5b9a\u5411\u7684url
|
# \u4f01\u4e1a\u53f7\u7b2c\u4e09\u65b9\u5e94\u7528\u5957\u4ef6\u6388\u6743\u540e\u91cd\u5b9a\u5411\u7684url
|
||||||
suite_redirect_uri=
|
suite_oauth_redirect_uri=
|
||||||
Loading…
x
Reference in New Issue
Block a user