update md & added WeixinSuiteProxy class.
This commit is contained in:
parent
e2a63b1b79
commit
37503acac6
@ -338,3 +338,7 @@
|
|||||||
+ 新增了默认常量对象在BaseApi.java类
|
+ 新增了默认常量对象在BaseApi.java类
|
||||||
|
|
||||||
+ **weixin4j-qy**: 新增企业号[第三方应用API](weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/suite)。
|
+ **weixin4j-qy**: 新增企业号[第三方应用API](weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/suite)。
|
||||||
|
|
||||||
|
* 2015-06-22
|
||||||
|
|
||||||
|
+ **weixin4j-qy**: 新增企业号[第三方应用代理](weixin4j-qy/src/main/java/com/foxinmy/weixin4j/qy/WeixinSuiteProxy.java)。
|
||||||
@ -39,6 +39,8 @@ weixin4j-mp
|
|||||||
|
|
||||||
* CashApi `现金API`
|
* CashApi `现金API`
|
||||||
|
|
||||||
|
* PayUtil [微信支付工具类](./src/main/java/com/foxinmy/weixin4j/mp/payment/PayUtil.java)
|
||||||
|
|
||||||
如何使用
|
如何使用
|
||||||
--------
|
--------
|
||||||
0.maven依赖(1.5.0,2015-06-10 released)
|
0.maven依赖(1.5.0,2015-06-10 released)
|
||||||
@ -84,18 +86,22 @@ weixin4j.properties说明
|
|||||||
#公众号登陆授权的重定向路径(使用OauthApi时需要填写)
|
#公众号登陆授权的重定向路径(使用OauthApi时需要填写)
|
||||||
redirect_uri=http://xxx
|
redirect_uri=http://xxx
|
||||||
|
|
||||||
2.实例化一个`WeixinProxy`对象,调用API,需要强调的是如果只传入appid,appsecret两个参数将无法调用支付相关接口
|
2.实例化微信企业号接口实现对象,调用具体的API方法
|
||||||
|
|
||||||
|
// 微信公众号API
|
||||||
WeixinProxy weixinProxy = new WeixinProxy();
|
WeixinProxy weixinProxy = new WeixinProxy();
|
||||||
// weixinProxy = new WeixinProxy(appid,appsecret);
|
// weixinProxy = new WeixinProxy(appid,appsecret);
|
||||||
// weixinProxy = new WeixinProxy(weixinAccount);
|
|
||||||
weixinProxy.getUser(openId);
|
weixinProxy.getUser(openId);
|
||||||
|
// 微信支付API
|
||||||
|
WeixinPayProxy weixinPayProxy = new WeixinPayProxy();
|
||||||
|
// weixinPayProxy = new WeixinPayProxy(weixinAccount);
|
||||||
|
weixinPayProxy.orderQueryV3(idQuery);
|
||||||
|
|
||||||
> 针对`token`存储有两种方案,`File存储`/`Redis存储`,当然也可自己实现`TokenStorager`,默认使用文件(xml)的方式保存token,如果环境中支持`redis`,建议使用[RedisTokenStorager](https://github.com/foxinmy/weixin4j/wiki/%E7%94%A8redis%E4%BF%9D%E5%AD%98token).
|
> 针对`token`存储有两种方案,`File存储`/`Redis存储`,当然也可自己实现`TokenStorager`,默认使用文件(xml)的方式保存token,如果环境中支持`redis`,建议使用[RedisTokenStorager](https://github.com/foxinmy/weixin4j/wiki/%E7%94%A8redis%E4%BF%9D%E5%AD%98token).
|
||||||
>
|
>
|
||||||
> WeixinProxy weixinProxy = new WeixinProxy(new RedisTokenStorager());
|
> WeixinProxy weixinProxy = new WeixinProxy(new RedisTokenStorager());
|
||||||
|
|
||||||
> // weixinProxy = new WeixinProxy(new RedisTokenStorager(weixinAccount));
|
> // weixinProxy = new WeixinProxy(new RedisTokenStorager(appid,appsecret));
|
||||||
|
|
||||||
[更新LOG](./CHANGE.md)
|
[更新LOG](./CHANGE.md)
|
||||||
----------------------
|
----------------------
|
||||||
@ -68,9 +68,19 @@ public class WeixinPayProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 使用文件保存token
|
||||||
*
|
*
|
||||||
* @param weixinAccount
|
* @param weixinAccount
|
||||||
* 公众号账号信息
|
* 支付相关的公众号账号信息
|
||||||
|
*/
|
||||||
|
public WeixinPayProxy(WeixinMpAccount weixinAccount) {
|
||||||
|
this(weixinAccount, MpApi.DEFAULT_TOKEN_STORAGER);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param weixinAccount
|
||||||
|
* 支付相关的公众号账号信息
|
||||||
*
|
*
|
||||||
* @param tokenStorager
|
* @param tokenStorager
|
||||||
* token的存储策略
|
* token的存储策略
|
||||||
|
|||||||
@ -56,4 +56,8 @@
|
|||||||
|
|
||||||
* 2015-06-21
|
* 2015-06-21
|
||||||
|
|
||||||
+ **weixin4j-qy**:新增企业号[第三方应用API](src/main/java/com/foxinmy/weixin4j/qy/suite)。
|
+ 新增企业号[第三方应用API](src/main/java/com/foxinmy/weixin4j/qy/suite)。
|
||||||
|
|
||||||
|
* 2015-06-22
|
||||||
|
|
||||||
|
+ 新增企业号[第三方应用代理](src/main/java/com/foxinmy/weixin4j/qy/WeixinSuiteProxy.java)。
|
||||||
@ -64,18 +64,22 @@ weixin4j.properties说明
|
|||||||
#企业号第三方应用套件授权后重定向的url(使用OauthApi时需要填写)
|
#企业号第三方应用套件授权后重定向的url(使用OauthApi时需要填写)
|
||||||
suite_redirect_uri=http://xxx
|
suite_redirect_uri=http://xxx
|
||||||
|
|
||||||
2.实例化一个`WeixinProxy`对象,调用API
|
2.实例化微信企业号接口实现对象,调用具体的API方法
|
||||||
|
|
||||||
|
// 微信企业号API
|
||||||
WeixinProxy weixinProxy = new WeixinProxy();
|
WeixinProxy weixinProxy = new WeixinProxy();
|
||||||
// weixinProxy = new WeixinProxy(corpid,corpsecret);
|
// weixinProxy = new WeixinProxy(corpid,corpsecret);
|
||||||
// weixinProxy = new WeixinProxy(weixinAccount);
|
|
||||||
weixinProxy.getUser(userid);
|
weixinProxy.getUser(userid);
|
||||||
|
// 微信第三方应用API
|
||||||
|
WeixinSuiteProxy weixinSuiteProxy = new WeixinSuiteProxy();
|
||||||
|
//weixinSuiteProxy = new WeixinSuiteProxy(suiteId,suiteSecret);
|
||||||
|
weixinSuiteProxy.getOAuthInfo(authCorpid);
|
||||||
|
|
||||||
> 针对`token`存储有两种方案,`File存储`/`Redis存储`,当然也可自己实现`TokenStorager`,默认使用文件(xml)的方式保存token,如果环境中支持`redis`,建议使用[RedisTokenStorager](https://github.com/foxinmy/weixin4j/wiki/%E7%94%A8redis%E4%BF%9D%E5%AD%98token).
|
> 针对`token`存储有两种方案,`File存储`/`Redis存储`,当然也可自己实现`TokenStorager`,默认使用文件(xml)的方式保存token,如果环境中支持`redis`,建议使用[RedisTokenStorager](https://github.com/foxinmy/weixin4j/wiki/%E7%94%A8redis%E4%BF%9D%E5%AD%98token).
|
||||||
|
|
||||||
> WeixinProxy weixinProxy = new WeixinProxy(new RedisTokenStorager());
|
> WeixinProxy weixinProxy = new WeixinProxy(new RedisTokenStorager());
|
||||||
|
|
||||||
> // weixinProxy = new WeixinProxy(new RedisTokenStorager(weixinAccount));
|
> // weixinProxy = new WeixinProxy(new RedisTokenStorager(corpid,corpsecret));
|
||||||
|
|
||||||
[更新LOG](./CHANGE.md)
|
[更新LOG](./CHANGE.md)
|
||||||
----------------------
|
----------------------
|
||||||
@ -0,0 +1,188 @@
|
|||||||
|
package com.foxinmy.weixin4j.qy;
|
||||||
|
|
||||||
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
|
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||||
|
import com.foxinmy.weixin4j.qy.api.QyApi;
|
||||||
|
import com.foxinmy.weixin4j.qy.api.SuiteApi;
|
||||||
|
import com.foxinmy.weixin4j.qy.model.AgentInfo;
|
||||||
|
import com.foxinmy.weixin4j.qy.model.AgentSetter;
|
||||||
|
import com.foxinmy.weixin4j.qy.model.OUserInfo;
|
||||||
|
import com.foxinmy.weixin4j.qy.suite.SuitePerCodeHolder;
|
||||||
|
import com.foxinmy.weixin4j.qy.suite.SuiteTicketHolder;
|
||||||
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
|
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信第三方应用接口实现
|
||||||
|
*
|
||||||
|
* @className WeixinSuiteProxy
|
||||||
|
* @author jy
|
||||||
|
* @date 2015年6月22日
|
||||||
|
* @since JDK 1.7
|
||||||
|
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
||||||
|
* @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 WeixinSuiteProxy {
|
||||||
|
/**
|
||||||
|
* 第三方应用API
|
||||||
|
*/
|
||||||
|
private final SuiteApi suiteApi;
|
||||||
|
|
||||||
|
public WeixinSuiteProxy() throws WeixinException {
|
||||||
|
this(QyApi.DEFAULT_WEIXIN_ACCOUNT.getSuiteId(),
|
||||||
|
QyApi.DEFAULT_WEIXIN_ACCOUNT.getSuiteSecret());
|
||||||
|
}
|
||||||
|
|
||||||
|
public WeixinSuiteProxy(String suiteId, String suiteSecret)
|
||||||
|
throws WeixinException {
|
||||||
|
this(suiteId, suiteSecret, QyApi.DEFAULT_TOKEN_STORAGER);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param suiteId
|
||||||
|
* 应用ID
|
||||||
|
* @param suiteSecret
|
||||||
|
* 应用secret
|
||||||
|
* @param ticketStorager
|
||||||
|
* 应用ticket存储器(用于读取)
|
||||||
|
* @param tokenStorager
|
||||||
|
* 应用token存储器
|
||||||
|
* @throws WeixinException
|
||||||
|
*/
|
||||||
|
public WeixinSuiteProxy(String suiteId, String suiteSecret,
|
||||||
|
TokenStorager tokenStorager) throws WeixinException {
|
||||||
|
this.suiteApi = new SuiteApi(suiteId, suiteSecret, tokenStorager);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用套件token
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public TokenHolder getTokenHolder() {
|
||||||
|
return suiteApi.getTokenHolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用套件ticket
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public SuiteTicketHolder getTicketHolder() {
|
||||||
|
return suiteApi.getTicketHolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用套件永久授权码
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public SuitePerCodeHolder getPerCodeHolder() {
|
||||||
|
return suiteApi.getPerCodeHolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用套件预授权码
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public TokenHolder getPreCodeHolder() {
|
||||||
|
return suiteApi.getPreCodeHolder();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取企业号access_token(永久授权码)
|
||||||
|
*
|
||||||
|
* @param authCorpid
|
||||||
|
* 授权方corpid
|
||||||
|
* @return 企业号token
|
||||||
|
*/
|
||||||
|
public TokenHolder crateTokenHolder(String authCorpid) {
|
||||||
|
return suiteApi.crateTokenHolder(authCorpid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置套件授权配置:如果需要对某次授权进行配置,则调用本接口,目前仅可以设置哪些应用可以授权,不调用则默认允许所有应用进行授权。
|
||||||
|
*
|
||||||
|
* @param appids
|
||||||
|
* 允许进行授权的应用id,如1、2、3
|
||||||
|
* @return 处理结果
|
||||||
|
* @throws WeixinException
|
||||||
|
* @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%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.AE.BE.E7.BD.AE.E6.8E.88.E6.9D.83.E9.85.8D.E7.BD.AE"
|
||||||
|
* >设置套件授权配置</a>
|
||||||
|
*/
|
||||||
|
public JsonResult setSuiteSession(int... appids) throws WeixinException {
|
||||||
|
return suiteApi.setSuiteSession(appids);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取企业号的永久授权码
|
||||||
|
*
|
||||||
|
* @param authCode
|
||||||
|
* 临时授权码会在授权成功时附加在redirect_uri中跳转回应用提供商网站。
|
||||||
|
* @return 授权得到的信息
|
||||||
|
* @throws WeixinException
|
||||||
|
* @see com.foxinmy.weixin4j.qy.model.OUserInfo
|
||||||
|
* @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%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E4.BC.81.E4.B8.9A.E5.8F.B7.E7.9A.84.E6.B0.B8.E4.B9.85.E6.8E.88.E6.9D.83.E7.A0.81"
|
||||||
|
* >获取企业号的永久授权码</a>
|
||||||
|
*/
|
||||||
|
public OUserInfo exchangePermanentCode(String authCode)
|
||||||
|
throws WeixinException {
|
||||||
|
return suiteApi.exchangePermanentCode(authCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取企业号的授权信息
|
||||||
|
*
|
||||||
|
* @param authCorpid
|
||||||
|
* 授权方corpid
|
||||||
|
* @return 授权方信息
|
||||||
|
* @throws WeixinException
|
||||||
|
* @see com.foxinmy.weixin4j.qy.model.OUserInfo
|
||||||
|
* @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%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E4.BC.81.E4.B8.9A.E5.8F.B7.E7.9A.84.E6.8E.88.E6.9D.83.E4.BF.A1.E6.81.AF">获取企业号的授权信息</a>
|
||||||
|
*/
|
||||||
|
public OUserInfo getOAuthInfo(String authCorpid) throws WeixinException {
|
||||||
|
return suiteApi.getOAuthInfo(authCorpid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取企业号应用
|
||||||
|
*
|
||||||
|
* @param authCorpid
|
||||||
|
* 授权方corpid
|
||||||
|
* @param agentid
|
||||||
|
* 授权方应用id
|
||||||
|
* @return 应用信息
|
||||||
|
* @see com.foxinmy.weixin4j.qy.model.AgentInfo
|
||||||
|
* @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%A5%E5%8F%A3%E8%AF%B4%E6%98%8E#.E8.8E.B7.E5.8F.96.E4.BC.81.E4.B8.9A.E5.8F.B7.E5.BA.94.E7.94.A8">获取企业号应用</a>
|
||||||
|
* @throws WeixinException
|
||||||
|
*/
|
||||||
|
public AgentInfo getAgent(String authCorpid, int agentid)
|
||||||
|
throws WeixinException {
|
||||||
|
return suiteApi.getAgent(authCorpid, agentid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置企业应用的选项设置信息,如:地理位置上报等
|
||||||
|
*
|
||||||
|
* @param authCorpid
|
||||||
|
* 授权方corpid
|
||||||
|
* @param agentSet
|
||||||
|
* 设置信息
|
||||||
|
* @see com.foxinmy.weixin4j.qy.model.AgentSetter
|
||||||
|
* @see <a
|
||||||
|
* href="http://qydev.weixin.qq.com/wiki/index.php?title=%E8%AE%BE%E7%BD%AE%E4%BC%81%E4%B8%9A%E5%8F%B7%E5%BA%94%E7%94%A8">设置企业号信息</a>
|
||||||
|
* @return 处理结果
|
||||||
|
* @throws WeixinException
|
||||||
|
*/
|
||||||
|
public JsonResult setAgent(String authCorpid, AgentSetter agentSet)
|
||||||
|
throws WeixinException {
|
||||||
|
return suiteApi.setAgent(authCorpid, agentSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,11 +3,7 @@ package com.foxinmy.weixin4j.qy.api;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
|
||||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
|
||||||
import com.foxinmy.weixin4j.model.Consts;
|
import com.foxinmy.weixin4j.model.Consts;
|
||||||
import com.foxinmy.weixin4j.qy.model.OUserInfo;
|
|
||||||
import com.foxinmy.weixin4j.util.ConfigUtil;
|
import com.foxinmy.weixin4j.util.ConfigUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,28 +58,6 @@ public class OauthApi extends QyApi {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取企业号管理员登录信息
|
|
||||||
*
|
|
||||||
* @param providerToken
|
|
||||||
* 提供商的token
|
|
||||||
* @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 getOUserInfo(String providerToken, String authCode)
|
|
||||||
throws WeixinException {
|
|
||||||
String oauth_logininfo_uri = getRequestUri("oauth_logininfo_uri");
|
|
||||||
WeixinResponse response = weixinClient.post(
|
|
||||||
String.format(oauth_logininfo_uri, providerToken),
|
|
||||||
String.format("{\"auth_code\":\"%s\"}", authCode));
|
|
||||||
return JSON.parseObject(response.getAsString(), OUserInfo.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see {@link com.foxinmy.weixin4j.qy.api.OauthApi#getSuiteAuthorizeURL(String,String, String,String)}
|
* @see {@link com.foxinmy.weixin4j.qy.api.OauthApi#getSuiteAuthorizeURL(String,String, String,String)}
|
||||||
* @param preAuthCode
|
* @param preAuthCode
|
||||||
|
|||||||
@ -16,7 +16,6 @@ import com.foxinmy.weixin4j.qy.suite.SuiteTicketHolder;
|
|||||||
import com.foxinmy.weixin4j.qy.suite.WeixinSuitePreCodeCreator;
|
import com.foxinmy.weixin4j.qy.suite.WeixinSuitePreCodeCreator;
|
||||||
import com.foxinmy.weixin4j.qy.suite.WeixinSuiteTokenCreator;
|
import com.foxinmy.weixin4j.qy.suite.WeixinSuiteTokenCreator;
|
||||||
import com.foxinmy.weixin4j.qy.suite.WeixinTokenSuiteCreator;
|
import com.foxinmy.weixin4j.qy.suite.WeixinTokenSuiteCreator;
|
||||||
import com.foxinmy.weixin4j.qy.token.WeixinTokenCreator;
|
|
||||||
import com.foxinmy.weixin4j.token.TokenCreator;
|
import com.foxinmy.weixin4j.token.TokenCreator;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||||
@ -48,10 +47,6 @@ public class SuiteApi extends QyApi {
|
|||||||
* 应用套件pre_code
|
* 应用套件pre_code
|
||||||
*/
|
*/
|
||||||
private final TokenHolder suitePreCodeHolder;
|
private final TokenHolder suitePreCodeHolder;
|
||||||
/**
|
|
||||||
* 应用套件的存储策略
|
|
||||||
*/
|
|
||||||
private final TokenStorager tokenStorager;
|
|
||||||
/**
|
/**
|
||||||
* 应用套件ID
|
* 应用套件ID
|
||||||
*/
|
*/
|
||||||
@ -87,7 +82,6 @@ public class SuiteApi extends QyApi {
|
|||||||
new WeixinSuitePreCodeCreator(suiteTokenHolder, suiteId),
|
new WeixinSuitePreCodeCreator(suiteTokenHolder, suiteId),
|
||||||
tokenStorager);
|
tokenStorager);
|
||||||
this.suitePerCodeHolder = new SuitePerCodeHolder(tokenStorager);
|
this.suitePerCodeHolder = new SuitePerCodeHolder(tokenStorager);
|
||||||
this.tokenStorager = tokenStorager;
|
|
||||||
this.suiteId = suiteId;
|
this.suiteId = suiteId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,6 +103,15 @@ public class SuiteApi extends QyApi {
|
|||||||
return this.suiteTicketHolder;
|
return this.suiteTicketHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用套件预授权码
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public TokenHolder getPreCodeHolder() {
|
||||||
|
return this.suitePreCodeHolder;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 应用套件永久授权码
|
* 应用套件永久授权码
|
||||||
*
|
*
|
||||||
@ -118,15 +121,6 @@ public class SuiteApi extends QyApi {
|
|||||||
return this.suitePerCodeHolder;
|
return this.suitePerCodeHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 应用套件pre_code
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public TokenHolder getPreCodeHolder() {
|
|
||||||
return this.suitePreCodeHolder;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取企业号access_token(永久授权码)
|
* 获取企业号access_token(永久授权码)
|
||||||
*
|
*
|
||||||
@ -136,7 +130,7 @@ public class SuiteApi extends QyApi {
|
|||||||
*/
|
*/
|
||||||
public TokenHolder crateTokenHolder(String authCorpid) {
|
public TokenHolder crateTokenHolder(String authCorpid) {
|
||||||
return new TokenHolder(new WeixinTokenSuiteCreator(suiteId, authCorpid,
|
return new TokenHolder(new WeixinTokenSuiteCreator(suiteId, authCorpid,
|
||||||
suitePerCodeHolder), tokenStorager);
|
suitePerCodeHolder), suiteTicketHolder.getTokenStorager());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -153,7 +147,7 @@ public class SuiteApi extends QyApi {
|
|||||||
public JsonResult setSuiteSession(int... appids) throws WeixinException {
|
public JsonResult setSuiteSession(int... appids) throws WeixinException {
|
||||||
String suite_set_session_uri = getRequestUri("suite_set_session_uri");
|
String suite_set_session_uri = getRequestUri("suite_set_session_uri");
|
||||||
JSONObject para = new JSONObject();
|
JSONObject para = new JSONObject();
|
||||||
para.put("pre_auth_code", suiteTicketHolder.lookup(suiteId));
|
para.put("pre_auth_code", suiteTicketHolder.getTicket(suiteId));
|
||||||
para.put("session_info", appids);
|
para.put("session_info", appids);
|
||||||
WeixinResponse response = weixinClient
|
WeixinResponse response = weixinClient
|
||||||
.post(String.format(suite_set_session_uri,
|
.post(String.format(suite_set_session_uri,
|
||||||
@ -187,14 +181,16 @@ public class SuiteApi extends QyApi {
|
|||||||
obj.put("user_info", obj.remove("auth_user_info"));
|
obj.put("user_info", obj.remove("auth_user_info"));
|
||||||
OUserInfo oInfo = JSON.toJavaObject(obj, OUserInfo.class);
|
OUserInfo oInfo = JSON.toJavaObject(obj, OUserInfo.class);
|
||||||
// 缓存微信企业号access_token
|
// 缓存微信企业号access_token
|
||||||
TokenCreator tokenCreator = new WeixinTokenCreator(oInfo.getCorpinfo()
|
TokenCreator tokenCreator = new WeixinTokenSuiteCreator(suiteId, null,
|
||||||
.getCorpid(), null);
|
suitePerCodeHolder);
|
||||||
Token token = new Token(obj.getString("access_token"));
|
Token token = new Token(obj.getString("access_token"));
|
||||||
token.setExpiresIn(obj.getIntValue("expires_in"));
|
token.setExpiresIn(obj.getIntValue("expires_in"));
|
||||||
token.setTime(System.currentTimeMillis());
|
token.setTime(System.currentTimeMillis());
|
||||||
tokenStorager.caching(tokenCreator.getCacheKey(), token);
|
suiteTicketHolder.getTokenStorager().caching(
|
||||||
|
tokenCreator.getCacheKey(), token);
|
||||||
// 缓存微信企业号永久授权码
|
// 缓存微信企业号永久授权码
|
||||||
suitePerCodeHolder.caching(suiteId, obj.getString("permanent_code"));
|
suitePerCodeHolder.cachingPermanentCode(suiteId,
|
||||||
|
obj.getString("permanent_code"));
|
||||||
return oInfo;
|
return oInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,7 +210,7 @@ public class SuiteApi extends QyApi {
|
|||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("suite_id", suiteId);
|
obj.put("suite_id", suiteId);
|
||||||
obj.put("auth_corpid", authCorpid);
|
obj.put("auth_corpid", authCorpid);
|
||||||
obj.put("permanent_code", suitePerCodeHolder.lookup(suiteId));
|
obj.put("permanent_code", suitePerCodeHolder.getPermanentCode(suiteId));
|
||||||
WeixinResponse response = weixinClient.post(
|
WeixinResponse response = weixinClient.post(
|
||||||
String.format(suite_get_authinfo_uri,
|
String.format(suite_get_authinfo_uri,
|
||||||
suiteTokenHolder.getAccessToken()), obj.toJSONString());
|
suiteTokenHolder.getAccessToken()), obj.toJSONString());
|
||||||
@ -241,7 +237,7 @@ public class SuiteApi extends QyApi {
|
|||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("suite_id", suiteId);
|
obj.put("suite_id", suiteId);
|
||||||
obj.put("auth_corpid", authCorpid);
|
obj.put("auth_corpid", authCorpid);
|
||||||
obj.put("permanent_code", suitePerCodeHolder.lookup(suiteId));
|
obj.put("permanent_code", suitePerCodeHolder.getPermanentCode(suiteId));
|
||||||
obj.put("agentid", agentid);
|
obj.put("agentid", agentid);
|
||||||
WeixinResponse response = weixinClient.post(String.format(
|
WeixinResponse response = weixinClient.post(String.format(
|
||||||
suite_get_agent_uri, suiteTokenHolder.getAccessToken(),
|
suite_get_agent_uri, suiteTokenHolder.getAccessToken(),
|
||||||
@ -278,7 +274,7 @@ public class SuiteApi extends QyApi {
|
|||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("suite_id", suiteId);
|
obj.put("suite_id", suiteId);
|
||||||
obj.put("auth_corpid", authCorpid);
|
obj.put("auth_corpid", authCorpid);
|
||||||
obj.put("permanent_code", suitePerCodeHolder.lookup(suiteId));
|
obj.put("permanent_code", suitePerCodeHolder.getPermanentCode(suiteId));
|
||||||
obj.put("agent", agentSet);
|
obj.put("agent", agentSet);
|
||||||
WeixinResponse response = weixinClient.post(
|
WeixinResponse response = weixinClient.post(
|
||||||
String.format(suite_set_agent_uri,
|
String.format(suite_set_agent_uri,
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import com.foxinmy.weixin4j.exception.WeixinException;
|
|||||||
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||||
import com.foxinmy.weixin4j.model.Token;
|
import com.foxinmy.weixin4j.model.Token;
|
||||||
|
import com.foxinmy.weixin4j.qy.model.OUserInfo;
|
||||||
import com.foxinmy.weixin4j.qy.model.User;
|
import com.foxinmy.weixin4j.qy.model.User;
|
||||||
import com.foxinmy.weixin4j.qy.type.InviteType;
|
import com.foxinmy.weixin4j.qy.type.InviteType;
|
||||||
import com.foxinmy.weixin4j.qy.type.UserStatus;
|
import com.foxinmy.weixin4j.qy.type.UserStatus;
|
||||||
@ -126,6 +127,28 @@ public class UserApi extends QyApi {
|
|||||||
return getUser(getUserIdByCode(code, agentid).getString("UserId"));
|
return getUser(getUserIdByCode(code, agentid).getString("UserId"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取企业号管理员登录信息
|
||||||
|
*
|
||||||
|
* @param providerToken
|
||||||
|
* 提供商的token
|
||||||
|
* @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 providerToken, String authCode)
|
||||||
|
throws WeixinException {
|
||||||
|
String oauth_logininfo_uri = getRequestUri("oauth_logininfo_uri");
|
||||||
|
WeixinResponse response = weixinClient.post(
|
||||||
|
String.format(oauth_logininfo_uri, providerToken),
|
||||||
|
String.format("{\"auth_code\":\"%s\"}", authCode));
|
||||||
|
return JSON.parseObject(response.getAsString(), OUserInfo.class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据code获取成员信息
|
* 根据code获取成员信息
|
||||||
*
|
*
|
||||||
@ -144,8 +167,8 @@ public class UserApi extends QyApi {
|
|||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
String user_getid_uri = getRequestUri("user_getid_uri");
|
String user_getid_uri = getRequestUri("user_getid_uri");
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
WeixinResponse response = weixinClient.post(String.format(user_getid_uri,
|
WeixinResponse response = weixinClient.post(String.format(
|
||||||
token.getAccessToken(), code, agentid));
|
user_getid_uri, token.getAccessToken(), code, agentid));
|
||||||
return response.getAsJson();
|
return response.getAsJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,9 +194,9 @@ public class UserApi extends QyApi {
|
|||||||
String user_list_uri = findDetail ? getRequestUri("user_list_uri")
|
String user_list_uri = findDetail ? getRequestUri("user_list_uri")
|
||||||
: getRequestUri("user_slist_uri");
|
: getRequestUri("user_slist_uri");
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
WeixinResponse response = weixinClient.post(String.format(user_list_uri,
|
WeixinResponse response = weixinClient.post(String.format(
|
||||||
token.getAccessToken(), departId, fetchChild ? 1 : 0,
|
user_list_uri, token.getAccessToken(), departId, fetchChild ? 1
|
||||||
userStatus.getVal()));
|
: 0, userStatus.getVal()));
|
||||||
List<User> list = null;
|
List<User> list = null;
|
||||||
if (findDetail) {
|
if (findDetail) {
|
||||||
JSONArray arrays = response.getAsJson().getJSONArray("userlist");
|
JSONArray arrays = response.getAsJson().getJSONArray("userlist");
|
||||||
@ -220,8 +243,8 @@ public class UserApi extends QyApi {
|
|||||||
public JsonResult deleteUser(String userid) throws WeixinException {
|
public JsonResult deleteUser(String userid) throws WeixinException {
|
||||||
String user_delete_uri = getRequestUri("user_delete_uri");
|
String user_delete_uri = getRequestUri("user_delete_uri");
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
WeixinResponse response = weixinClient.post(String.format(user_delete_uri,
|
WeixinResponse response = weixinClient.post(String.format(
|
||||||
token.getAccessToken(), userid));
|
user_delete_uri, token.getAccessToken(), userid));
|
||||||
return response.getAsJsonResult();
|
return response.getAsJsonResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,8 +265,8 @@ public class UserApi extends QyApi {
|
|||||||
obj.put("useridlist", userIds);
|
obj.put("useridlist", userIds);
|
||||||
String user_delete_uri = getRequestUri("user_batchdelete_uri");
|
String user_delete_uri = getRequestUri("user_batchdelete_uri");
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
WeixinResponse response = weixinClient.post(String.format(user_delete_uri,
|
WeixinResponse response = weixinClient.post(String.format(
|
||||||
token.getAccessToken(), obj.toJSONString()));
|
user_delete_uri, token.getAccessToken(), obj.toJSONString()));
|
||||||
return response.getAsJsonResult();
|
return response.getAsJsonResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,8 +283,8 @@ public class UserApi extends QyApi {
|
|||||||
public JsonResult authsucc(String userId) throws WeixinException {
|
public JsonResult authsucc(String userId) throws WeixinException {
|
||||||
String user_authsucc_uri = getRequestUri("user_authsucc_uri");
|
String user_authsucc_uri = getRequestUri("user_authsucc_uri");
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
WeixinResponse response = weixinClient.post(String.format(user_authsucc_uri,
|
WeixinResponse response = weixinClient.post(String.format(
|
||||||
token.getAccessToken(), userId));
|
user_authsucc_uri, token.getAccessToken(), userId));
|
||||||
return response.getAsJsonResult();
|
return response.getAsJsonResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,7 @@ public class SuitePerCodeHolder {
|
|||||||
* @param permanentCode
|
* @param permanentCode
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public void caching(String suiteId, String permanentCode)
|
public void cachingPermanentCode(String suiteId, String permanentCode)
|
||||||
throws WeixinException {
|
throws WeixinException {
|
||||||
Token token = new Token(permanentCode);
|
Token token = new Token(permanentCode);
|
||||||
token.setExpiresIn(-1);
|
token.setExpiresIn(-1);
|
||||||
@ -52,7 +52,7 @@ public class SuitePerCodeHolder {
|
|||||||
* @return
|
* @return
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public String lookup(String suiteId) throws WeixinException {
|
public String getPermanentCode(String suiteId) throws WeixinException {
|
||||||
return tokenStorager.lookup(getCacheKey(suiteId)).getAccessToken();
|
return tokenStorager.lookup(getCacheKey(suiteId)).getAccessToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,7 +15,7 @@ import com.foxinmy.weixin4j.token.TokenStorager;
|
|||||||
*/
|
*/
|
||||||
public class SuiteTicketHolder {
|
public class SuiteTicketHolder {
|
||||||
|
|
||||||
public final TokenStorager tokenStorager;
|
private final TokenStorager tokenStorager;
|
||||||
|
|
||||||
public SuiteTicketHolder(TokenStorager tokenStorager) {
|
public SuiteTicketHolder(TokenStorager tokenStorager) {
|
||||||
this.tokenStorager = tokenStorager;
|
this.tokenStorager = tokenStorager;
|
||||||
@ -28,7 +28,7 @@ public class SuiteTicketHolder {
|
|||||||
* @return
|
* @return
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public String lookup(String suiteId) throws WeixinException {
|
public String getTicket(String suiteId) throws WeixinException {
|
||||||
return tokenStorager.lookup(getCacheKey(suiteId)).getAccessToken();
|
return tokenStorager.lookup(getCacheKey(suiteId)).getAccessToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,9 +48,14 @@ public class SuiteTicketHolder {
|
|||||||
* @param suiteTicket
|
* @param suiteTicket
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
*/
|
*/
|
||||||
public void caching(SuiteTicketMessage suiteTicket) throws WeixinException {
|
public void cachingTicket(SuiteTicketMessage suiteTicket)
|
||||||
|
throws WeixinException {
|
||||||
Token token = new Token(suiteTicket.getSuiteTicket());
|
Token token = new Token(suiteTicket.getSuiteTicket());
|
||||||
token.setExpiresIn(-1);
|
token.setExpiresIn(-1);
|
||||||
tokenStorager.caching(getCacheKey(suiteTicket.getSuiteId()), token);
|
tokenStorager.caching(getCacheKey(suiteTicket.getSuiteId()), token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TokenStorager getTokenStorager() {
|
||||||
|
return this.tokenStorager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,7 +53,7 @@ public class WeixinSuiteTokenCreator implements TokenCreator {
|
|||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("suite_id", suiteId);
|
obj.put("suite_id", suiteId);
|
||||||
obj.put("suite_secret", suiteSecret);
|
obj.put("suite_secret", suiteSecret);
|
||||||
obj.put("suite_ticket", ticketHolder.lookup(suiteId));
|
obj.put("suite_ticket", ticketHolder.getTicket(suiteId));
|
||||||
WeixinResponse response = httpClient.post(URLConsts.SUITE_TOKEN_URL,
|
WeixinResponse response = httpClient.post(URLConsts.SUITE_TOKEN_URL,
|
||||||
obj.toJSONString());
|
obj.toJSONString());
|
||||||
obj = response.getAsJson();
|
obj = response.getAsJson();
|
||||||
|
|||||||
@ -53,7 +53,7 @@ public class WeixinTokenSuiteCreator implements TokenCreator {
|
|||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("suite_id", suiteId);
|
obj.put("suite_id", suiteId);
|
||||||
obj.put("auth_corpid", authCorpid);
|
obj.put("auth_corpid", authCorpid);
|
||||||
obj.put("permanent_code", perCodeHolder.lookup(suiteId));
|
obj.put("permanent_code", perCodeHolder.getPermanentCode(suiteId));
|
||||||
WeixinResponse response = httpClient.post(URLConsts.TOKEN_SUITE_URL,
|
WeixinResponse response = httpClient.post(URLConsts.TOKEN_SUITE_URL,
|
||||||
obj.toJSONString());
|
obj.toJSONString());
|
||||||
obj = response.getAsJson();
|
obj = response.getAsJson();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user