优化企业号第三方套件接口
This commit is contained in:
parent
845c4d111b
commit
5b31f1c8f0
@ -1,9 +1,12 @@
|
|||||||
package com.foxinmy.weixin4j.qy;
|
package com.foxinmy.weixin4j.qy;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
|
import com.foxinmy.weixin4j.model.Consts;
|
||||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||||
import com.foxinmy.weixin4j.qy.api.ProviderApi;
|
import com.foxinmy.weixin4j.qy.api.ProviderApi;
|
||||||
import com.foxinmy.weixin4j.qy.api.SuiteApi;
|
import com.foxinmy.weixin4j.qy.api.SuiteApi;
|
||||||
@ -13,8 +16,10 @@ import com.foxinmy.weixin4j.qy.suite.SuiteTicketHolder;
|
|||||||
import com.foxinmy.weixin4j.qy.suite.Weixin4jSuiteSettings;
|
import com.foxinmy.weixin4j.qy.suite.Weixin4jSuiteSettings;
|
||||||
import com.foxinmy.weixin4j.qy.token.WeixinProviderTokenCreator;
|
import com.foxinmy.weixin4j.qy.token.WeixinProviderTokenCreator;
|
||||||
import com.foxinmy.weixin4j.qy.type.LoginTargetType;
|
import com.foxinmy.weixin4j.qy.type.LoginTargetType;
|
||||||
|
import com.foxinmy.weixin4j.qy.type.URLConsts;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
import com.foxinmy.weixin4j.util.StringUtil;
|
import com.foxinmy.weixin4j.util.StringUtil;
|
||||||
|
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信第三方应用接口实现
|
* 微信第三方应用接口实现
|
||||||
@ -24,8 +29,9 @@ import com.foxinmy.weixin4j.util.StringUtil;
|
|||||||
* @date 2015年6月22日
|
* @date 2015年6月22日
|
||||||
* @since JDK 1.6
|
* @since JDK 1.6
|
||||||
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
||||||
* @see <a
|
* @see <a href=
|
||||||
* 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>
|
* "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 WeixinSuiteProxy {
|
public class WeixinSuiteProxy {
|
||||||
|
|
||||||
@ -55,25 +61,20 @@ public class WeixinSuiteProxy {
|
|||||||
this.suiteSettings = suiteSettings;
|
this.suiteSettings = suiteSettings;
|
||||||
if (suiteSettings.getWeixinAccount().getSuiteAccounts() != null) {
|
if (suiteSettings.getWeixinAccount().getSuiteAccounts() != null) {
|
||||||
this.suiteMap = new HashMap<String, SuiteApi>();
|
this.suiteMap = new HashMap<String, SuiteApi>();
|
||||||
for (WeixinAccount suite : suiteSettings.getWeixinAccount()
|
for (WeixinAccount suite : suiteSettings.getWeixinAccount().getSuiteAccounts()) {
|
||||||
.getSuiteAccounts()) {
|
|
||||||
this.suiteMap.put(suite.getId(), new SuiteApi(
|
this.suiteMap.put(suite.getId(), new SuiteApi(
|
||||||
new SuiteTicketHolder(suite.getId(), suite.getSecret(),
|
new SuiteTicketHolder(suite.getId(), suite.getSecret(), suiteSettings.getTokenStorager0())));
|
||||||
suiteSettings.getTokenStorager0())));
|
this.suiteMap.put(null,
|
||||||
this.suiteMap.put(
|
suiteMap.get(suiteSettings.getWeixinAccount().getSuiteAccounts().get(0).getId()));
|
||||||
null,
|
|
||||||
suiteMap.get(suiteSettings.getWeixinAccount()
|
|
||||||
.getSuiteAccounts().get(0).getId()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (StringUtil.isNotBlank(suiteSettings.getWeixinAccount().getId())
|
if (StringUtil.isNotBlank(suiteSettings.getWeixinAccount().getId())
|
||||||
&& StringUtil.isNotBlank(suiteSettings.getWeixinAccount()
|
&& StringUtil.isNotBlank(suiteSettings.getWeixinAccount().getProviderSecret())) {
|
||||||
.getProviderSecret())) {
|
this.providerApi = new ProviderApi(
|
||||||
this.providerApi = new ProviderApi(new TokenHolder(
|
new TokenHolder(
|
||||||
new WeixinProviderTokenCreator(suiteSettings
|
new WeixinProviderTokenCreator(suiteSettings.getWeixinAccount().getId(),
|
||||||
.getWeixinAccount().getId(), suiteSettings
|
suiteSettings.getWeixinAccount().getProviderSecret()),
|
||||||
.getWeixinAccount().getProviderSecret()),
|
suiteSettings.getTokenStorager0()),
|
||||||
suiteSettings.getTokenStorager0()),
|
|
||||||
suiteSettings.getTokenStorager0());
|
suiteSettings.getTokenStorager0());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,27 +89,84 @@ public class WeixinSuiteProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 只关注第一个套件获取API(如果只有一个套件
|
* 获取套件接口对象(只关注第一个套件
|
||||||
*
|
*
|
||||||
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
||||||
* @return API实例
|
* @return API实例
|
||||||
*/
|
*/
|
||||||
public SuiteApi api() {
|
public SuiteApi suite() {
|
||||||
return this.suiteMap.get(null);
|
return this.suiteMap.get(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 多个套件获取API
|
* 获取套件接口对象(多个套件
|
||||||
*
|
*
|
||||||
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
||||||
* @param suiteId
|
* @param suiteId
|
||||||
* 套件ID
|
* 套件ID
|
||||||
* @return API实例
|
* @return API实例
|
||||||
*/
|
*/
|
||||||
public SuiteApi api(String suiteId) {
|
public SuiteApi suite(String suiteId) {
|
||||||
return this.suiteMap.get(suiteId);
|
return this.suiteMap.get(suiteId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 缓存套件ticket(多个套件
|
||||||
|
*
|
||||||
|
* @param suiteId
|
||||||
|
* 套件ID
|
||||||
|
* @param suiteTicket
|
||||||
|
* 套件ticket内容
|
||||||
|
* @see <a href=
|
||||||
|
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%9B%9E%E8%B0%83%E5%8D%8F%E8%AE%AE#.E6.8E.A8.E9.80.81suite_ticket.E5.8D.8F.E8.AE.AE">
|
||||||
|
* 推送suite_ticket协议</a>
|
||||||
|
* @throws WeixinException
|
||||||
|
*/
|
||||||
|
public void cacheTicket(String suiteId, String suiteTicket) throws WeixinException {
|
||||||
|
suite(suiteId).getTicketHolder().cachingTicket(suiteTicket);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用套件授权 <font color="red">需先缓存ticket</font>
|
||||||
|
*
|
||||||
|
* @see {@link #getSuiteAuthorizeURL(String, String,String)}
|
||||||
|
* @param suiteId
|
||||||
|
* 套件ID
|
||||||
|
* @see {@link #cacheTicket(String, String)}
|
||||||
|
* @return 请求授权的URL
|
||||||
|
* @throws WeixinException
|
||||||
|
*/
|
||||||
|
public String getSuiteAuthorizeURL(String suiteId) throws WeixinException {
|
||||||
|
String redirectUri = Weixin4jConfigUtil.getValue("suite.oauth.redirect.uri");
|
||||||
|
return getSuiteAuthorizeURL(suiteId, redirectUri, "state");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用套件授权 <font color="red">需先缓存ticket</font>
|
||||||
|
*
|
||||||
|
* @param suiteId
|
||||||
|
* 套件ID
|
||||||
|
* @param redirectUri
|
||||||
|
* 授权后重定向url
|
||||||
|
* @param state
|
||||||
|
* 回调后原样返回
|
||||||
|
* @see <a 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%
|
||||||
|
* 8E%88%E6%9D%83%E5%BA%94%E7%94%A8">企业号第三方应用套件授权</a>
|
||||||
|
* @see {@link SuiteApi#getPreCodeHolder}
|
||||||
|
* @return 请求授权的URL
|
||||||
|
* @throws WeixinException
|
||||||
|
*/
|
||||||
|
public String getSuiteAuthorizeURL(String suiteId, String redirectUri, String state) throws WeixinException {
|
||||||
|
try {
|
||||||
|
return String.format(URLConsts.SUITE_OAUTH_URL, suiteId, suite(suiteId).getTicketHolder().getTicket(),
|
||||||
|
URLEncoder.encode(redirectUri, Consts.UTF_8.name()), state);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
;
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 第三方套件获取企业号管理员登录信息
|
* 第三方套件获取企业号管理员登录信息
|
||||||
*
|
*
|
||||||
@ -116,8 +174,9 @@ public class WeixinSuiteProxy {
|
|||||||
* oauth2.0授权企业号管理员登录产生的code
|
* oauth2.0授权企业号管理员登录产生的code
|
||||||
* @return 登陆信息
|
* @return 登陆信息
|
||||||
* @see com.foxinmy.weixin4j.qy.api.ProviderApi
|
* @see com.foxinmy.weixin4j.qy.api.ProviderApi
|
||||||
* @see <a
|
* @see <a href=
|
||||||
* 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>
|
* "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
|
* @see com.foxinmy.weixin4j.qy.model.OUserInfo
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
@ -136,12 +195,12 @@ public class WeixinSuiteProxy {
|
|||||||
* 授权方应用id 小余1时则不传递
|
* 授权方应用id 小余1时则不传递
|
||||||
* @return 登陆URL
|
* @return 登陆URL
|
||||||
* @see com.foxinmy.weixin4j.qy.api.ProviderApi
|
* @see com.foxinmy.weixin4j.qy.api.ProviderApi
|
||||||
* @see <a
|
* @see <a href=
|
||||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%99%BB%E5%BD%95%E4%BC%81%E4%B8%9A%E5%8F%B7%E5%AE%98%E7%BD%91%E7%9A%84url">获取登录企业号官网的url</a>
|
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%99%BB%E5%BD%95%E4%BC%81%E4%B8%9A%E5%8F%B7%E5%AE%98%E7%BD%91%E7%9A%84url">
|
||||||
|
* 获取登录企业号官网的url</a>
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public String getLoginUrl(String corpId, LoginTargetType targetType,
|
public String getLoginUrl(String corpId, LoginTargetType targetType, int agentId) throws WeixinException {
|
||||||
int agentId) throws WeixinException {
|
|
||||||
return providerApi.getLoginUrl(corpId, targetType, agentId);
|
return providerApi.getLoginUrl(corpId, targetType, agentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,8 +215,7 @@ public class WeixinSuiteProxy {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public WeixinProxy getWeixinProxy(String suiteId, String authCorpId) {
|
public WeixinProxy getWeixinProxy(String suiteId, String authCorpId) {
|
||||||
return new WeixinProxy(api(suiteId).getPerCodeHolder(authCorpId), api(
|
return new WeixinProxy(suite(suiteId).getPerCodeHolder(authCorpId), suite(suiteId).getSuiteTokenHolder());
|
||||||
suiteId).getSuiteTokenHolder());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final static String VERSION = "1.6.7";
|
public final static String VERSION = "1.6.7";
|
||||||
|
|||||||
@ -1,158 +1,113 @@
|
|||||||
package com.foxinmy.weixin4j.qy.api;
|
package com.foxinmy.weixin4j.qy.api;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
import com.foxinmy.weixin4j.model.Consts;
|
import com.foxinmy.weixin4j.model.Consts;
|
||||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 企业号oauth授权
|
* 企业号oauth授权
|
||||||
*
|
*
|
||||||
* @className OauthApi
|
* @className OauthApi
|
||||||
* @author jy
|
* @author jy
|
||||||
* @date 2015年6月11日
|
* @date 2015年6月11日
|
||||||
* @since JDK 1.6
|
* @since JDK 1.6
|
||||||
* @see <a
|
* @see <a href=
|
||||||
* href="http://qydev.weixin.qq.com/wiki/index.php?title=OAuth%E9%AA%8C%E8%AF%81%E6%8E%A5%E5%8F%A3">企业号用户身份授权说明</a>
|
* "http://qydev.weixin.qq.com/wiki/index.php?title=OAuth%E9%AA%8C%E8%AF%81%E6%8E%A5%E5%8F%A3">
|
||||||
* @see <a
|
* 企业号用户身份授权说明</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=
|
||||||
* @see <a
|
* "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">
|
||||||
* 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>
|
* 企业号第三方提供商授权说明</a>
|
||||||
*/
|
* @see <a href=
|
||||||
public class OauthApi extends QyApi {
|
* "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">
|
||||||
private final WeixinAccount account;
|
* 企业号第三方套件应用授权说明</a>
|
||||||
|
*/
|
||||||
public OauthApi() {
|
public class OauthApi extends QyApi {
|
||||||
this(Weixin4jConfigUtil.getWeixinAccount());
|
private final WeixinAccount account;
|
||||||
}
|
|
||||||
|
public OauthApi() {
|
||||||
public OauthApi(WeixinAccount account) {
|
this(Weixin4jConfigUtil.getWeixinAccount());
|
||||||
this.account = account;
|
}
|
||||||
}
|
|
||||||
|
public OauthApi(WeixinAccount account) {
|
||||||
/**
|
this.account = account;
|
||||||
* 企业号用户身份授权
|
}
|
||||||
*
|
|
||||||
* @see {@link #getUserAuthorizeURL(String, String,String)}
|
/**
|
||||||
*
|
* 企业号用户身份授权
|
||||||
* @return 请求授权的URL
|
*
|
||||||
*/
|
* @see {@link #getUserAuthorizeURL(String, String,String)}
|
||||||
public String getUserAuthorizeURL() {
|
*
|
||||||
String corpId = account.getId();
|
* @return 请求授权的URL
|
||||||
String redirectUri = Weixin4jConfigUtil
|
*/
|
||||||
.getValue("user.oauth.redirect.uri");
|
public String getUserAuthorizeURL() {
|
||||||
return getUserAuthorizeURL(corpId, redirectUri, "state");
|
String corpId = account.getId();
|
||||||
}
|
String redirectUri = Weixin4jConfigUtil.getValue("user.oauth.redirect.uri");
|
||||||
|
return getUserAuthorizeURL(corpId, redirectUri, "state");
|
||||||
/**
|
}
|
||||||
* 企业号用户身份授权
|
|
||||||
*
|
/**
|
||||||
* @param corpId
|
* 企业号用户身份授权
|
||||||
* 企业号的corpid
|
*
|
||||||
* @param redirectUri
|
* @param corpId
|
||||||
* 重定向地址
|
* 企业号的corpid
|
||||||
* @param state
|
* @param redirectUri
|
||||||
* 用于保持请求和回调的状态
|
* 重定向地址
|
||||||
* @return 请求授权的URL
|
* @param state
|
||||||
* @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>
|
* @return 请求授权的URL
|
||||||
*/
|
* @see <a href=
|
||||||
public String getUserAuthorizeURL(String corpId, String redirectUri,
|
* "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">
|
||||||
String state) {
|
* 企业号用户身份授权</a>
|
||||||
String oauth_uri = getRequestUri("user_oauth_uri");
|
*/
|
||||||
try {
|
public String getUserAuthorizeURL(String corpId, String redirectUri, String state) {
|
||||||
return String.format(oauth_uri, corpId,
|
String oauth_uri = getRequestUri("user_oauth_uri");
|
||||||
URLEncoder.encode(redirectUri, Consts.UTF_8.name()), state);
|
try {
|
||||||
} catch (UnsupportedEncodingException e) {
|
return String.format(oauth_uri, corpId, URLEncoder.encode(redirectUri, Consts.UTF_8.name()), state);
|
||||||
;
|
} catch (UnsupportedEncodingException e) {
|
||||||
}
|
;
|
||||||
return "";
|
}
|
||||||
}
|
return "";
|
||||||
|
}
|
||||||
/**
|
|
||||||
* 企业号第三方提供商授权
|
/**
|
||||||
*
|
* 企业号第三方提供商授权
|
||||||
* @see {@link #getThirdAuthorizeURL(String, String,String)}
|
*
|
||||||
*
|
* @see {@link #getThirdAuthorizeURL(String, String,String)}
|
||||||
* @return 请求授权的URL
|
*
|
||||||
*/
|
* @return 请求授权的URL
|
||||||
public String getThirdAuthorizeURL() {
|
*/
|
||||||
String corpId = account.getId();
|
public String getThirdAuthorizeURL() {
|
||||||
String redirectUri = Weixin4jConfigUtil
|
String corpId = account.getId();
|
||||||
.getValue("third.oauth.redirect.uri");
|
String redirectUri = Weixin4jConfigUtil.getValue("third.oauth.redirect.uri");
|
||||||
return getThirdAuthorizeURL(corpId, redirectUri, "state");
|
return getThirdAuthorizeURL(corpId, redirectUri, "state");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 企业号登陆授权
|
* 企业号登陆授权
|
||||||
*
|
*
|
||||||
* @param corpId
|
* @param corpId
|
||||||
* 企业号(提供商)的corpid
|
* 企业号(提供商)的corpid
|
||||||
* @param redirectUri
|
* @param redirectUri
|
||||||
* 重定向地址
|
* 重定向地址
|
||||||
* @param state
|
* @param state
|
||||||
* 用于保持请求和回调的状态,授权请求后原样带回给第三方
|
* 用于保持请求和回调的状态,授权请求后原样带回给第三方
|
||||||
* @return 请求授权的URL
|
* @return 请求授权的URL
|
||||||
* @see ProviderApi
|
* @see ProviderApi
|
||||||
* @see {@link com.foxinmy.weixin4j.qy.WeixinSuiteProxy#getOUserInfoByCode(String)}
|
* @see {@link com.foxinmy.weixin4j.qy.WeixinSuiteProxy#getOUserInfoByCode(String)}
|
||||||
* @see <a
|
* @see <a href=
|
||||||
* 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>
|
* "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 getThirdAuthorizeURL(String corpId, String redirectUri,
|
*/
|
||||||
String state) {
|
public String getThirdAuthorizeURL(String corpId, String redirectUri, String state) {
|
||||||
String oauth_uri = getRequestUri("provider_oauth_uri");
|
String oauth_uri = getRequestUri("provider_oauth_uri");
|
||||||
try {
|
try {
|
||||||
return String.format(oauth_uri, corpId,
|
return String.format(oauth_uri, corpId, URLEncoder.encode(redirectUri, Consts.UTF_8.name()), state);
|
||||||
URLEncoder.encode(redirectUri, Consts.UTF_8.name()), state);
|
} catch (UnsupportedEncodingException e) {
|
||||||
} catch (UnsupportedEncodingException e) {
|
;
|
||||||
;
|
}
|
||||||
}
|
return "";
|
||||||
return "";
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 应用套件授权
|
|
||||||
*
|
|
||||||
* @see {@link #getSuiteAuthorizeURL(String,String, String,String)}
|
|
||||||
* @param suiteId
|
|
||||||
* 套件ID
|
|
||||||
* @param preAuthCode
|
|
||||||
* 预授权码
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public String getSuiteAuthorizeURL(String suiteId, String preAuthCode) {
|
|
||||||
String redirectUri = Weixin4jConfigUtil
|
|
||||||
.getValue("suite.oauth.redirect.uri");
|
|
||||||
return getSuiteAuthorizeURL(suiteId, preAuthCode, redirectUri, "state");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 应用套件授权
|
|
||||||
*
|
|
||||||
* @param suiteId
|
|
||||||
* 套件ID
|
|
||||||
* @param preAuthCode
|
|
||||||
* 预授权码
|
|
||||||
* @param redirectUri
|
|
||||||
* 授权后重定向url
|
|
||||||
* @param state
|
|
||||||
* 回调后原样返回
|
|
||||||
* @see <a 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%
|
|
||||||
* 8E%88%E6%9D%83%E5%BA%94%E7%94%A8">企业号第三方应用套件授权</a>
|
|
||||||
* @return 请求授权的URL
|
|
||||||
*/
|
|
||||||
public String getSuiteAuthorizeURL(String suiteId, String preAuthCode,
|
|
||||||
String redirectUri, String state) {
|
|
||||||
String suite_oauth_uri = getRequestUri("suite_oauth_uri");
|
|
||||||
try {
|
|
||||||
return String.format(suite_oauth_uri, suiteId, preAuthCode,
|
|
||||||
URLEncoder.encode(redirectUri, Consts.UTF_8.name()), state);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -94,8 +94,6 @@ provider_oauth_uri=https://qy.weixin.qq.com/cgi-bin/loginpage?corp_id=%s&redirec
|
|||||||
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
|
||||||
# \u767b\u5f55\u4f01\u4e1a\u53f7\u5b98\u7f51\u7684url
|
# \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?provider_access_token=%s
|
||||||
# \u5e94\u7528\u5957\u4ef6oauth\u6388\u6743
|
|
||||||
suite_oauth_uri=https://qy.weixin.qq.com/cgi-bin/loginpage?suite_id=%s&pre_auth_code=%s&redirect_uri=%s&state=%s
|
|
||||||
# \u5e94\u7528\u5957\u4ef6\u8bbe\u7f6e\u6388\u6743\u914d\u7f6e
|
# \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
|
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
|
# \u83b7\u53d6\u4f01\u4e1a\u53f7\u7684\u6c38\u4e45\u6388\u6743\u7801
|
||||||
|
|||||||
@ -54,7 +54,7 @@ public class WeixinTicketCreator implements TokenCreator {
|
|||||||
response = weixinExecutor
|
response = weixinExecutor
|
||||||
.get(String.format(URLConsts.JS_TICKET_URL, weixinTokenHolder.getToken().getAccessToken()));
|
.get(String.format(URLConsts.JS_TICKET_URL, weixinTokenHolder.getToken().getAccessToken()));
|
||||||
} else {
|
} else {
|
||||||
response = weixinExecutor.get(String.format(URLConsts.TICKET_URL,
|
response = weixinExecutor.get(String.format(URLConsts.SUITE_TICKET_URL,
|
||||||
weixinTokenHolder.getToken().getAccessToken(), ticketType.name()));
|
weixinTokenHolder.getToken().getAccessToken(), ticketType.name()));
|
||||||
}
|
}
|
||||||
JSONObject result = response.getAsJson();
|
JSONObject result = response.getAsJson();
|
||||||
|
|||||||
@ -1,54 +1,51 @@
|
|||||||
package com.foxinmy.weixin4j.qy.type;
|
package com.foxinmy.weixin4j.qy.type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL常量类
|
* URL常量类
|
||||||
*
|
*
|
||||||
* @className URLConsts
|
* @className URLConsts
|
||||||
* @author jy
|
* @author jy
|
||||||
* @date 2014年12月3日
|
* @date 2014年12月3日
|
||||||
* @since JDK 1.6
|
* @since JDK 1.6
|
||||||
* @see
|
* @see
|
||||||
*/
|
*/
|
||||||
public final class URLConsts {
|
public final class URLConsts {
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static final String BASE_URL = "https://qyapi.weixin.qq.com/cgi-bin";
|
public static final String BASE_URL = "https://qyapi.weixin.qq.com/cgi-bin";
|
||||||
/**
|
/**
|
||||||
* 企业号获取token的url
|
* 企业号获取token的url
|
||||||
*/
|
*/
|
||||||
public static final String ASSESS_TOKEN_URL = BASE_URL
|
public static final String ASSESS_TOKEN_URL = BASE_URL + "/gettoken?corpid=%s&corpsecret=%s";
|
||||||
+ "/gettoken?corpid=%s&corpsecret=%s";
|
/**
|
||||||
/**
|
* 企业号提供商获取token的url
|
||||||
* 企业号提供商获取token的url
|
*/
|
||||||
*/
|
public static final String PROVIDER_TOKEN_URL = BASE_URL + "/service/get_provider_token";
|
||||||
public static final String PROVIDER_TOKEN_URL = BASE_URL
|
/**
|
||||||
+ "/service/get_provider_token";
|
* 企业号jssdk获取token的url
|
||||||
/**
|
*/
|
||||||
* 企业号jssdk获取token的url
|
public static final String JS_TICKET_URL = BASE_URL + "/get_jsapi_ticket?access_token=%s";
|
||||||
*/
|
/**
|
||||||
public static final String JS_TICKET_URL = BASE_URL
|
* 应用套件oauth授权
|
||||||
+ "/get_jsapi_ticket?access_token=%s";
|
*/
|
||||||
/**
|
public static final String SUITE_OAUTH_URL = "https://qy.weixin.qq.com/cgi-bin/loginpage?suite_id=%s&pre_auth_code=%s&redirect_uri=%s&state=%s";
|
||||||
* 企业号获取ticket的url
|
/**
|
||||||
*/
|
* 企业号获取ticket的url
|
||||||
public static final String TICKET_URL = BASE_URL
|
*/
|
||||||
+ "/ticket/get?access_token=%s&type=%s";
|
public static final String SUITE_TICKET_URL = BASE_URL + "/ticket/get?access_token=%s&type=%s";
|
||||||
/**
|
/**
|
||||||
* 企业号第三方应用套件获取token的url
|
* 企业号第三方应用套件获取token的url
|
||||||
*/
|
*/
|
||||||
public static final String SUITE_TOKEN_URL = BASE_URL
|
public static final String SUITE_TOKEN_URL = BASE_URL + "/service/get_suite_token";
|
||||||
+ "/service/get_suite_token";
|
|
||||||
|
/**
|
||||||
/**
|
* 企业号第三方应用套件获取预授权码的url
|
||||||
* 企业号第三方应用套件获取预授权码的url
|
*/
|
||||||
*/
|
public static final String SUITE_PRE_CODE_URL = BASE_URL + "/service/get_pre_auth_code?suite_access_token=%s";
|
||||||
public static final String SUITE_PRE_CODE_URL = BASE_URL
|
|
||||||
+ "/service/get_pre_auth_code?suite_access_token=%s";
|
/**
|
||||||
|
* 企业号第三方应用套件获取企业号access_token的url
|
||||||
/**
|
*/
|
||||||
* 企业号第三方应用套件获取企业号access_token的url
|
public static final String TOKEN_SUITE_URL = BASE_URL + "/service/get_corp_token?suite_access_token=%s";
|
||||||
*/
|
}
|
||||||
public static final String TOKEN_SUITE_URL = BASE_URL
|
|
||||||
+ "/service/get_corp_token?suite_access_token=%s";
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user