up
This commit is contained in:
parent
4ef35151de
commit
89bbc8ecb6
@ -59,9 +59,11 @@ public class WeixinPayProxy {
|
||||
* 现金API
|
||||
*/
|
||||
private final CashApi cashApi;
|
||||
|
||||
/**
|
||||
* 配置相关
|
||||
*/
|
||||
private final Weixin4jSettings settings;
|
||||
|
||||
|
||||
/**
|
||||
* 使用weixin4j.properties配置的支付账号信息
|
||||
*/
|
||||
|
||||
@ -112,8 +112,13 @@ public class WeixinProxy {
|
||||
* 数据统计API
|
||||
*/
|
||||
private final DataApi dataApi;
|
||||
|
||||
/**
|
||||
* token实现
|
||||
*/
|
||||
private final TokenHolder tokenHolder;
|
||||
/**
|
||||
* 配置相关
|
||||
*/
|
||||
private Weixin4jSettings settings;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,179 +1,179 @@
|
||||
package com.foxinmy.weixin4j.mp.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.NameFilter;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.message.TemplateMessage;
|
||||
import com.foxinmy.weixin4j.mp.model.TemplateMessageInfo;
|
||||
import com.foxinmy.weixin4j.mp.type.IndustryType;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.util.NameValue;
|
||||
|
||||
/**
|
||||
* 模板消息相关API
|
||||
*
|
||||
* @className TemplApi
|
||||
* @author jy
|
||||
* @date 2014年9月30日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class TmplApi extends MpApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
|
||||
public TmplApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置所属行业(每月可修改行业1次,账号仅可使用所属行业中相关的模板)
|
||||
*
|
||||
* @param industryTypes
|
||||
* 所处行业 目前不超过两个
|
||||
* @return 操作结果
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.type.IndustryType
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.AE.BE.E7.BD.AE.E6.89.80.E5.B1.9E.E8.A1.8C.E4.B8.9A">设置所处行业</a>
|
||||
*/
|
||||
public JsonResult setTmplIndustry(IndustryType... industryTypes)
|
||||
throws WeixinException {
|
||||
JSONObject obj = new JSONObject();
|
||||
for (int i = 0; i < industryTypes.length; i++) {
|
||||
obj.put(String.format("industry_id%d", i + 1),
|
||||
Integer.toString(industryTypes[i].getTypeId()));
|
||||
}
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_set_industry_uri = getRequestUri("template_set_industry_uri");
|
||||
WeixinResponse response = weixinExecutor.post(String.format(
|
||||
template_set_industry_uri, token.getAccessToken()), obj
|
||||
.toJSONString());
|
||||
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置的行业信息
|
||||
*
|
||||
* @return 行业信息数组 第一个元素为帐号设置的主营行业 第二个元素为帐号设置的副营行业
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.type.IndustryType
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.8E.B7.E5.8F.96.E8.AE.BE.E7.BD.AE.E7.9A.84.E8.A1.8C.E4.B8.9A.E4.BF.A1.E6.81.AF">获取设置的行业信息</a>
|
||||
*/
|
||||
public IndustryType[] getTmplIndustry() throws WeixinException {
|
||||
String template_get_industry_uri = getRequestUri("template_get_industry_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
template_get_industry_uri, tokenHolder.getAccessToken()));
|
||||
JSONObject primary = response.getAsJson().getJSONObject(
|
||||
"primary_industry");
|
||||
JSONObject secondary = response.getAsJson().getJSONObject(
|
||||
"secondary_industry");
|
||||
return new IndustryType[] {
|
||||
primary != null ? IndustryType.getIndustry(
|
||||
primary.getString("first_class"),
|
||||
primary.getString("second_class")) : null,
|
||||
secondary != null ? IndustryType.getIndustry(
|
||||
secondary.getString("first_class"),
|
||||
secondary.getString("second_class")) : null };
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板ID
|
||||
*
|
||||
* @param shortId
|
||||
* 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式
|
||||
* @return 模板ID
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.8E.B7.E5.BE.97.E6.A8.A1.E6.9D.BFID">获得模板ID</a>
|
||||
*/
|
||||
public String getTemplateId(String shortId) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_getid_uri = getRequestUri("template_getid_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(template_getid_uri, token.getAccessToken()),
|
||||
String.format("{\"template_id_short\":\"%s\"}", shortId));
|
||||
|
||||
return response.getAsJson().getString("template_id");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板列表
|
||||
*
|
||||
* @return 模板列表
|
||||
* @see com.foxinmy.weixin4j.mp.model.TemplateMessageInfo
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.8E.B7.E5.8F.96.E6.A8.A1.E6.9D.BF.E5.88.97.E8.A1.A8">获取模板列表</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public List<TemplateMessageInfo> getAllTemplates() throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_getall_uri = getRequestUri("template_getall_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
template_getall_uri, token.getAccessToken()));
|
||||
return JSON.parseArray(response.getAsJson().getString("template_list"),
|
||||
TemplateMessageInfo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除模板
|
||||
*
|
||||
* @param templateId
|
||||
* 公众帐号下模板消息ID
|
||||
* @return 处理结果
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E5.88.A0.E9.99.A4.E6.A8.A1.E6.9D.BF">删除模板</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult deleteTemplate(String templateId) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_del_uri = getRequestUri("template_del_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(template_del_uri, token.getAccessToken()),
|
||||
String.format("{\"template_id\"=\"%s\"}", templateId));
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送模板消息
|
||||
*
|
||||
* @param tplMessage
|
||||
* 消息对象
|
||||
* @return 发送结果
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/17/304c1885ea66dbedf7dc170d84999a9d.html#.E5.8F.91.E9.80.81.E6.A8.A1.E6.9D.BF.E6.B6.88.E6.81.AF">模板消息</a>
|
||||
* @see <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/2/def71e3ecb5706c132229ae505815966.html"
|
||||
* >运营规范</a>
|
||||
* @see com.foxinmy.weixin4j.mp.message.TemplateMessage
|
||||
* @seee com.foxinmy.weixin4j.msg.event.TemplatesendjobfinishMessage
|
||||
*/
|
||||
public JsonResult sendTmplMessage(TemplateMessage tplMessage)
|
||||
throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_send_uri = getRequestUri("template_send_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(template_send_uri, token.getAccessToken()),
|
||||
JSON.toJSONString(tplMessage, new NameFilter() {
|
||||
@Override
|
||||
public String process(Object object, String name,
|
||||
Object value) {
|
||||
if (object instanceof NameValue && name.equals("name")) {
|
||||
return "color";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}));
|
||||
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
}
|
||||
package com.foxinmy.weixin4j.mp.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.NameFilter;
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.mp.message.TemplateMessage;
|
||||
import com.foxinmy.weixin4j.mp.model.TemplateMessageInfo;
|
||||
import com.foxinmy.weixin4j.mp.type.IndustryType;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.util.NameValue;
|
||||
|
||||
/**
|
||||
* 模板消息相关API
|
||||
*
|
||||
* @className TemplApi
|
||||
* @author jy
|
||||
* @date 2014年9月30日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class TmplApi extends MpApi {
|
||||
|
||||
private final TokenHolder tokenHolder;
|
||||
|
||||
public TmplApi(TokenHolder tokenHolder) {
|
||||
this.tokenHolder = tokenHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置所属行业(每月可修改行业1次,账号仅可使用所属行业中相关的模板)
|
||||
*
|
||||
* @param industryTypes
|
||||
* 所处行业 目前不超过两个
|
||||
* @return 操作结果
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.type.IndustryType
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.AE.BE.E7.BD.AE.E6.89.80.E5.B1.9E.E8.A1.8C.E4.B8.9A">设置所处行业</a>
|
||||
*/
|
||||
public JsonResult setTmplIndustry(IndustryType... industryTypes)
|
||||
throws WeixinException {
|
||||
JSONObject obj = new JSONObject();
|
||||
for (int i = 0; i < industryTypes.length; i++) {
|
||||
obj.put(String.format("industry_id%d", i + 1),
|
||||
Integer.toString(industryTypes[i].getTypeId()));
|
||||
}
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_set_industry_uri = getRequestUri("template_set_industry_uri");
|
||||
WeixinResponse response = weixinExecutor.post(String.format(
|
||||
template_set_industry_uri, token.getAccessToken()), obj
|
||||
.toJSONString());
|
||||
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设置的行业信息
|
||||
*
|
||||
* @return 行业信息数组 第一个元素为帐号设置的主营行业 第二个元素为帐号设置的副营行业
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.mp.type.IndustryType
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.8E.B7.E5.8F.96.E8.AE.BE.E7.BD.AE.E7.9A.84.E8.A1.8C.E4.B8.9A.E4.BF.A1.E6.81.AF">获取设置的行业信息</a>
|
||||
*/
|
||||
public IndustryType[] getTmplIndustry() throws WeixinException {
|
||||
String template_get_industry_uri = getRequestUri("template_get_industry_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
template_get_industry_uri, tokenHolder.getAccessToken()));
|
||||
JSONObject primary = response.getAsJson().getJSONObject(
|
||||
"primary_industry");
|
||||
JSONObject secondary = response.getAsJson().getJSONObject(
|
||||
"secondary_industry");
|
||||
return new IndustryType[] {
|
||||
primary != null ? IndustryType.getIndustry(
|
||||
primary.getString("first_class"),
|
||||
primary.getString("second_class")) : null,
|
||||
secondary != null ? IndustryType.getIndustry(
|
||||
secondary.getString("first_class"),
|
||||
secondary.getString("second_class")) : null };
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板ID
|
||||
*
|
||||
* @param shortId
|
||||
* 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式
|
||||
* @return 模板ID
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.8E.B7.E5.BE.97.E6.A8.A1.E6.9D.BFID">获得模板ID</a>
|
||||
*/
|
||||
public String getTemplateId(String shortId) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_getid_uri = getRequestUri("template_getid_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(template_getid_uri, token.getAccessToken()),
|
||||
String.format("{\"template_id_short\":\"%s\"}", shortId));
|
||||
|
||||
return response.getAsJson().getString("template_id");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板列表
|
||||
*
|
||||
* @return 模板列表
|
||||
* @see com.foxinmy.weixin4j.mp.model.TemplateMessageInfo
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E8.8E.B7.E5.8F.96.E6.A8.A1.E6.9D.BF.E5.88.97.E8.A1.A8">获取模板列表</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public List<TemplateMessageInfo> getAllTemplates() throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_getall_uri = getRequestUri("template_getall_uri");
|
||||
WeixinResponse response = weixinExecutor.get(String.format(
|
||||
template_getall_uri, token.getAccessToken()));
|
||||
return JSON.parseArray(response.getAsJson().getString("template_list"),
|
||||
TemplateMessageInfo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除模板
|
||||
*
|
||||
* @param templateId
|
||||
* 公众帐号下模板消息ID
|
||||
* @return 处理结果
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/5/6dde9eaa909f83354e0094dc3ad99e05.html#.E5.88.A0.E9.99.A4.E6.A8.A1.E6.9D.BF">删除模板</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult deleteTemplate(String templateId) throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_del_uri = getRequestUri("template_del_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(template_del_uri, token.getAccessToken()),
|
||||
String.format("{\"template_id\"=\"%s\"}", templateId));
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送模板消息
|
||||
*
|
||||
* @param tplMessage
|
||||
* 消息对象
|
||||
* @return 发送结果
|
||||
* @throws WeixinException
|
||||
* @see <a
|
||||
* href="http://mp.weixin.qq.com/wiki/17/304c1885ea66dbedf7dc170d84999a9d.html#.E5.8F.91.E9.80.81.E6.A8.A1.E6.9D.BF.E6.B6.88.E6.81.AF">模板消息</a>
|
||||
* @see <a href=
|
||||
* "http://mp.weixin.qq.com/wiki/2/def71e3ecb5706c132229ae505815966.html"
|
||||
* >运营规范</a>
|
||||
* @see com.foxinmy.weixin4j.mp.message.TemplateMessage
|
||||
* @see com.foxinmy.weixin4j.msg.event.TemplatesendjobfinishMessage
|
||||
*/
|
||||
public JsonResult sendTmplMessage(TemplateMessage tplMessage)
|
||||
throws WeixinException {
|
||||
Token token = tokenHolder.getToken();
|
||||
String template_send_uri = getRequestUri("template_send_uri");
|
||||
WeixinResponse response = weixinExecutor.post(
|
||||
String.format(template_send_uri, token.getAccessToken()),
|
||||
JSON.toJSONString(tplMessage, new NameFilter() {
|
||||
@Override
|
||||
public String process(Object object, String name,
|
||||
Object value) {
|
||||
if (object instanceof NameValue && name.equals("name")) {
|
||||
return "color";
|
||||
}
|
||||
return name;
|
||||
}
|
||||
}));
|
||||
|
||||
return response.getAsJsonResult();
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,9 +103,13 @@ public class WeixinProxy {
|
||||
* 聊天服务API
|
||||
*/
|
||||
private final ChatApi chatApi;
|
||||
|
||||
/**
|
||||
* token实现
|
||||
*/
|
||||
private final TokenHolder tokenHolder;
|
||||
|
||||
/**
|
||||
* 配置相关
|
||||
*/
|
||||
private Weixin4jSettings settings;
|
||||
|
||||
/**
|
||||
|
||||
@ -1,162 +1,164 @@
|
||||
package com.foxinmy.weixin4j.qy;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.qy.api.ProviderApi;
|
||||
import com.foxinmy.weixin4j.qy.api.SuiteApi;
|
||||
import com.foxinmy.weixin4j.qy.model.OUserInfo;
|
||||
import com.foxinmy.weixin4j.qy.model.WeixinQyAccount;
|
||||
import com.foxinmy.weixin4j.qy.suite.SuiteTicketHolder;
|
||||
import com.foxinmy.weixin4j.qy.suite.Weixin4jSuiteSettings;
|
||||
import com.foxinmy.weixin4j.qy.token.WeixinProviderTokenCreator;
|
||||
import com.foxinmy.weixin4j.qy.type.LoginTargetType;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
/**
|
||||
* 微信第三方应用接口实现
|
||||
*
|
||||
* @className WeixinSuiteProxy
|
||||
* @author jy
|
||||
* @date 2015年6月22日
|
||||
* @since JDK 1.6
|
||||
* @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 {
|
||||
|
||||
/**
|
||||
* 每个套件授权不一样 suiteId - suiteApi
|
||||
*/
|
||||
private Map<String, SuiteApi> suiteMap;
|
||||
/**
|
||||
* 供应商API:如登陆URL
|
||||
*/
|
||||
private ProviderApi providerApi;
|
||||
|
||||
private final Weixin4jSuiteSettings suiteSettings;
|
||||
|
||||
public WeixinSuiteProxy() {
|
||||
this(new Weixin4jSuiteSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param suiteSettings
|
||||
* 套件信息配置
|
||||
*/
|
||||
public WeixinSuiteProxy(Weixin4jSuiteSettings suiteSettings) {
|
||||
this.suiteSettings = suiteSettings;
|
||||
if (suiteSettings.getWeixinAccount().getSuiteAccounts() != null) {
|
||||
this.suiteMap = new HashMap<String, SuiteApi>();
|
||||
for (WeixinAccount suite : suiteSettings.getWeixinAccount()
|
||||
.getSuiteAccounts()) {
|
||||
this.suiteMap.put(suite.getId(), new SuiteApi(
|
||||
new SuiteTicketHolder(suite.getId(), suite.getSecret(),
|
||||
suiteSettings.getTokenStorager0())));
|
||||
this.suiteMap.put(
|
||||
null,
|
||||
suiteMap.get(suiteSettings.getWeixinAccount()
|
||||
.getSuiteAccounts().get(0).getId()));
|
||||
}
|
||||
}
|
||||
if (StringUtil.isNotBlank(suiteSettings.getWeixinAccount().getId())
|
||||
&& StringUtil.isNotBlank(suiteSettings.getWeixinAccount()
|
||||
.getProviderSecret())) {
|
||||
this.providerApi = new ProviderApi(new TokenHolder(
|
||||
new WeixinProviderTokenCreator(suiteSettings
|
||||
.getWeixinAccount().getId(), suiteSettings
|
||||
.getWeixinAccount().getProviderSecret()),
|
||||
suiteSettings.getTokenStorager0()),
|
||||
suiteSettings.getTokenStorager0());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 企业号信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public WeixinQyAccount getWeixinAccount() {
|
||||
return this.suiteSettings.getWeixinAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
* 只关注第一个套件获取API(如果只有一个套件
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
||||
* @return API实例
|
||||
*/
|
||||
public SuiteApi api() {
|
||||
return this.suiteMap.get(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多个套件获取API
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
||||
* @param suiteId
|
||||
* 套件ID
|
||||
* @return API实例
|
||||
*/
|
||||
public SuiteApi api(String suiteId) {
|
||||
return this.suiteMap.get(suiteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方套件获取企业号管理员登录信息
|
||||
*
|
||||
* @param authCode
|
||||
* oauth2.0授权企业号管理员登录产生的code
|
||||
* @return 登陆信息
|
||||
* @see com.foxinmy.weixin4j.qy.api.ProviderApi
|
||||
* @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 providerApi.getOUserInfoByCode(authCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录企业号官网的url
|
||||
*
|
||||
* @param corpId
|
||||
* <font color="red">oauth授权的corpid</font>
|
||||
* @param targetType
|
||||
* 登录跳转到企业号后台的目标页面
|
||||
* @param agentId
|
||||
* 授权方应用id 小余1时则不传递
|
||||
* @return 登陆URL
|
||||
* @see com.foxinmy.weixin4j.qy.api.ProviderApi
|
||||
* @see <a
|
||||
* 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>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String getLoginUrl(String corpId, LoginTargetType targetType,
|
||||
int agentId) throws WeixinException {
|
||||
return providerApi.getLoginUrl(corpId, targetType, agentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建WeixinProxy对象
|
||||
*
|
||||
* @param suiteId
|
||||
* 套件ID
|
||||
* @param authCorpId
|
||||
* 已授权的corpid
|
||||
* @see com.foxinmy.weixin4j.qy.WeixinProxy
|
||||
* @return
|
||||
*/
|
||||
public WeixinProxy getWeixinProxy(String suiteId, String authCorpId) {
|
||||
return new WeixinProxy(api(suiteId).getPerCodeHolder(authCorpId), api(
|
||||
suiteId).getSuiteTokenHolder());
|
||||
}
|
||||
|
||||
public final static String VERSION = "1.6.7";
|
||||
}
|
||||
package com.foxinmy.weixin4j.qy;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.qy.api.ProviderApi;
|
||||
import com.foxinmy.weixin4j.qy.api.SuiteApi;
|
||||
import com.foxinmy.weixin4j.qy.model.OUserInfo;
|
||||
import com.foxinmy.weixin4j.qy.model.WeixinQyAccount;
|
||||
import com.foxinmy.weixin4j.qy.suite.SuiteTicketHolder;
|
||||
import com.foxinmy.weixin4j.qy.suite.Weixin4jSuiteSettings;
|
||||
import com.foxinmy.weixin4j.qy.token.WeixinProviderTokenCreator;
|
||||
import com.foxinmy.weixin4j.qy.type.LoginTargetType;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
|
||||
/**
|
||||
* 微信第三方应用接口实现
|
||||
*
|
||||
* @className WeixinSuiteProxy
|
||||
* @author jy
|
||||
* @date 2015年6月22日
|
||||
* @since JDK 1.6
|
||||
* @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 {
|
||||
|
||||
/**
|
||||
* 每个套件授权不一样 suiteId - suiteApi
|
||||
*/
|
||||
private Map<String, SuiteApi> suiteMap;
|
||||
/**
|
||||
* 供应商API:如登陆URL
|
||||
*/
|
||||
private ProviderApi providerApi;
|
||||
/**
|
||||
* 配置相关
|
||||
*/
|
||||
private final Weixin4jSuiteSettings suiteSettings;
|
||||
|
||||
public WeixinSuiteProxy() {
|
||||
this(new Weixin4jSuiteSettings());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param suiteSettings
|
||||
* 套件信息配置
|
||||
*/
|
||||
public WeixinSuiteProxy(Weixin4jSuiteSettings suiteSettings) {
|
||||
this.suiteSettings = suiteSettings;
|
||||
if (suiteSettings.getWeixinAccount().getSuiteAccounts() != null) {
|
||||
this.suiteMap = new HashMap<String, SuiteApi>();
|
||||
for (WeixinAccount suite : suiteSettings.getWeixinAccount()
|
||||
.getSuiteAccounts()) {
|
||||
this.suiteMap.put(suite.getId(), new SuiteApi(
|
||||
new SuiteTicketHolder(suite.getId(), suite.getSecret(),
|
||||
suiteSettings.getTokenStorager0())));
|
||||
this.suiteMap.put(
|
||||
null,
|
||||
suiteMap.get(suiteSettings.getWeixinAccount()
|
||||
.getSuiteAccounts().get(0).getId()));
|
||||
}
|
||||
}
|
||||
if (StringUtil.isNotBlank(suiteSettings.getWeixinAccount().getId())
|
||||
&& StringUtil.isNotBlank(suiteSettings.getWeixinAccount()
|
||||
.getProviderSecret())) {
|
||||
this.providerApi = new ProviderApi(new TokenHolder(
|
||||
new WeixinProviderTokenCreator(suiteSettings
|
||||
.getWeixinAccount().getId(), suiteSettings
|
||||
.getWeixinAccount().getProviderSecret()),
|
||||
suiteSettings.getTokenStorager0()),
|
||||
suiteSettings.getTokenStorager0());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 企业号信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public WeixinQyAccount getWeixinAccount() {
|
||||
return this.suiteSettings.getWeixinAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
* 只关注第一个套件获取API(如果只有一个套件
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
||||
* @return API实例
|
||||
*/
|
||||
public SuiteApi api() {
|
||||
return this.suiteMap.get(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 多个套件获取API
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
||||
* @param suiteId
|
||||
* 套件ID
|
||||
* @return API实例
|
||||
*/
|
||||
public SuiteApi api(String suiteId) {
|
||||
return this.suiteMap.get(suiteId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 第三方套件获取企业号管理员登录信息
|
||||
*
|
||||
* @param authCode
|
||||
* oauth2.0授权企业号管理员登录产生的code
|
||||
* @return 登陆信息
|
||||
* @see com.foxinmy.weixin4j.qy.api.ProviderApi
|
||||
* @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 providerApi.getOUserInfoByCode(authCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录企业号官网的url
|
||||
*
|
||||
* @param corpId
|
||||
* <font color="red">oauth授权的corpid</font>
|
||||
* @param targetType
|
||||
* 登录跳转到企业号后台的目标页面
|
||||
* @param agentId
|
||||
* 授权方应用id 小余1时则不传递
|
||||
* @return 登陆URL
|
||||
* @see com.foxinmy.weixin4j.qy.api.ProviderApi
|
||||
* @see <a
|
||||
* 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>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String getLoginUrl(String corpId, LoginTargetType targetType,
|
||||
int agentId) throws WeixinException {
|
||||
return providerApi.getLoginUrl(corpId, targetType, agentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建WeixinProxy对象
|
||||
*
|
||||
* @param suiteId
|
||||
* 套件ID
|
||||
* @param authCorpId
|
||||
* 已授权的corpid
|
||||
* @see com.foxinmy.weixin4j.qy.WeixinProxy
|
||||
* @return
|
||||
*/
|
||||
public WeixinProxy getWeixinProxy(String suiteId, String authCorpId) {
|
||||
return new WeixinProxy(api(suiteId).getPerCodeHolder(authCorpId), api(
|
||||
suiteId).getSuiteTokenHolder());
|
||||
}
|
||||
|
||||
public final static String VERSION = "1.6.7";
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user