系统配置类抽象化
This commit is contained in:
parent
f6c12e07f3
commit
18303642f2
@ -700,3 +700,5 @@
|
||||
+ weixin4j-base:删除AbstractTokenCreator,引入CacheCreator<T>类
|
||||
|
||||
+ weixin4j-base:修改Memcached-Java-Client的依赖
|
||||
|
||||
+ weixin4j-base:系统配置类抽象化
|
||||
@ -41,7 +41,7 @@ public class WeixinException extends Exception {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getErrorMsg() {
|
||||
public String getErrorDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
@ -51,8 +51,8 @@ public class WeixinException extends Exception {
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if (StringUtil.isNotBlank(code)) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append(code).append(" >> ").append(desc);
|
||||
String text = getErrorText();
|
||||
if (StringUtil.isNotBlank(text)) {
|
||||
|
||||
@ -36,11 +36,11 @@ import com.foxinmy.weixin4j.payment.mch.RedpacketSendResult;
|
||||
import com.foxinmy.weixin4j.payment.mch.RefundRecord;
|
||||
import com.foxinmy.weixin4j.payment.mch.RefundResult;
|
||||
import com.foxinmy.weixin4j.payment.mch.SettlementRecord;
|
||||
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.type.BillType;
|
||||
import com.foxinmy.weixin4j.type.CurrencyType;
|
||||
import com.foxinmy.weixin4j.type.CustomsCity;
|
||||
import com.foxinmy.weixin4j.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jSettings;
|
||||
|
||||
/**
|
||||
* 微信支付接口实现
|
||||
@ -85,14 +85,14 @@ public class WeixinPayProxy {
|
||||
*
|
||||
* @param settings
|
||||
* 支付相关配置信息
|
||||
* @see com.foxinmy.weixin4j.util.Weixin4jSettings
|
||||
* @see com.foxinmy.weixin4j.setting.Weixin4jSettings
|
||||
*/
|
||||
public WeixinPayProxy(Weixin4jSettings settings) {
|
||||
this.settings = settings;
|
||||
this.payApi = new PayApi(settings.getWeixinPayAccount());
|
||||
this.couponApi = new CouponApi(settings.getWeixinPayAccount());
|
||||
this.cashApi = new CashApi(settings.getWeixinPayAccount());
|
||||
this.customsApi = new CustomsApi(settings.getWeixinPayAccount());
|
||||
this.payApi = new PayApi(settings.getPayAccount());
|
||||
this.couponApi = new CouponApi(settings.getPayAccount());
|
||||
this.cashApi = new CashApi(settings.getPayAccount());
|
||||
this.customsApi = new CustomsApi(settings.getPayAccount());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -100,8 +100,8 @@ public class WeixinPayProxy {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public WeixinPayAccount getPayAccount() {
|
||||
return this.settings.getWeixinPayAccount();
|
||||
public WeixinPayAccount getWeixinPayAccount() {
|
||||
return this.settings.getPayAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,90 @@
|
||||
package com.foxinmy.weixin4j.setting;
|
||||
|
||||
import com.foxinmy.weixin4j.http.HttpParams;
|
||||
import com.foxinmy.weixin4j.token.FileTokenStorager;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
|
||||
/**
|
||||
* 系统配置相关
|
||||
*
|
||||
* @className SystemSettings
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2016年1月28日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public abstract class SystemSettings<T> {
|
||||
/**
|
||||
* 账号信息
|
||||
*/
|
||||
private T account;
|
||||
/**
|
||||
* Http参数
|
||||
*/
|
||||
private HttpParams httpParams;
|
||||
/**
|
||||
* token存储方式 默认为FileTokenStorager
|
||||
*/
|
||||
private TokenStorager tokenStorager;
|
||||
/**
|
||||
* 系统临时目录
|
||||
*/
|
||||
private String tmpdir;
|
||||
|
||||
/**
|
||||
* @param account
|
||||
*/
|
||||
public SystemSettings(T account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public T getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public HttpParams getHttpParams() {
|
||||
return httpParams;
|
||||
}
|
||||
|
||||
public HttpParams getHttpParams0() {
|
||||
if (httpParams == null) {
|
||||
return new HttpParams();
|
||||
}
|
||||
return httpParams;
|
||||
}
|
||||
|
||||
public String getTmpdir() {
|
||||
return tmpdir;
|
||||
}
|
||||
|
||||
public abstract String getTmpdir0();
|
||||
|
||||
public TokenStorager getTokenStorager() {
|
||||
return tokenStorager;
|
||||
}
|
||||
|
||||
public TokenStorager getTokenStorager0() {
|
||||
if (tokenStorager == null) {
|
||||
return new FileTokenStorager(getTmpdir0());
|
||||
}
|
||||
return tokenStorager;
|
||||
}
|
||||
|
||||
public void setHttpParams(HttpParams httpParams) {
|
||||
this.httpParams = httpParams;
|
||||
}
|
||||
|
||||
public void setTmpdir(String tmpdir) {
|
||||
this.tmpdir = tmpdir;
|
||||
}
|
||||
|
||||
public void setTokenStorager(TokenStorager tokenStorager) {
|
||||
this.tokenStorager = tokenStorager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "account=" + account + ", httpParams=" + httpParams
|
||||
+ ",tokenStorager=" + tokenStorager + ", tmpdir=" + tmpdir;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,106 @@
|
||||
package com.foxinmy.weixin4j.setting;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
|
||||
/**
|
||||
* 微信配置相关
|
||||
*
|
||||
* @className Weixin4jSettings
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2016年1月28日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class Weixin4jSettings extends SystemSettings<WeixinAccount> {
|
||||
/**
|
||||
* 微信支付账号信息
|
||||
*/
|
||||
private WeixinPayAccount weixinPayAccount;
|
||||
/**
|
||||
* 支付接口需要的证书文件(*.p12)
|
||||
*/
|
||||
private String certificateFile;
|
||||
|
||||
/**
|
||||
* 默认使用weixin4j.properties配置的信息
|
||||
*/
|
||||
public Weixin4jSettings() {
|
||||
this(JSON.parseObject(Weixin4jConfigUtil.getValue("account"),
|
||||
WeixinPayAccount.class), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付代理接口
|
||||
*
|
||||
* @param weixinPayAccount
|
||||
* 商户信息
|
||||
* @param certificateFile
|
||||
* 支付接口需要的证书文件(*.p12),比如退款接口
|
||||
*/
|
||||
public Weixin4jSettings(WeixinPayAccount weixinPayAccount,
|
||||
String certificateFile) {
|
||||
this(weixinPayAccount);
|
||||
this.certificateFile = certificateFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付代理接口
|
||||
*
|
||||
* @param weixinPayAccount
|
||||
* 商户信息
|
||||
*/
|
||||
public Weixin4jSettings(WeixinPayAccount weixinPayAccount) {
|
||||
this(new WeixinAccount(weixinPayAccount.getId(),
|
||||
weixinPayAccount.getSecret()));
|
||||
this.weixinPayAccount = weixinPayAccount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 账号信息
|
||||
*
|
||||
* @param account
|
||||
*/
|
||||
public Weixin4jSettings(WeixinAccount account) {
|
||||
super(account);
|
||||
}
|
||||
|
||||
public WeixinPayAccount getPayAccount() {
|
||||
return weixinPayAccount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTmpdir0() {
|
||||
if (StringUtil.isBlank(getTmpdir())) {
|
||||
return Weixin4jConfigUtil.getClassPathValue("weixin4j.tmpdir",
|
||||
System.getProperty("java.io.tmpdir"));
|
||||
}
|
||||
return getTmpdir();
|
||||
}
|
||||
|
||||
public String getCertificateFile() {
|
||||
return certificateFile;
|
||||
}
|
||||
|
||||
public String getCertificateFile0() {
|
||||
if (StringUtil.isBlank(certificateFile)) {
|
||||
return Weixin4jConfigUtil.getClassPathValue(
|
||||
"weixin4j.certificate.file", "classpath:ca.p12");
|
||||
}
|
||||
return certificateFile;
|
||||
}
|
||||
|
||||
public void setCertificateFile(String certificateFile) {
|
||||
this.certificateFile = certificateFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Weixin4jSettings [weixinPayAccount=" + weixinPayAccount
|
||||
+ ", certificateFile=" + certificateFile + ", "
|
||||
+ super.toString() + "]";
|
||||
}
|
||||
}
|
||||
@ -22,7 +22,8 @@ public interface CacheCreator<T> {
|
||||
/**
|
||||
* 创建Cache
|
||||
*
|
||||
* @return
|
||||
* @throws WeixinException
|
||||
* @return 缓存对象
|
||||
*/
|
||||
public T create() throws WeixinException;
|
||||
}
|
||||
|
||||
@ -1,7 +1,5 @@
|
||||
package com.foxinmy.weixin4j.token;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
|
||||
/**
|
||||
* Cache的存储
|
||||
*
|
||||
@ -18,9 +16,8 @@ public interface CacheStorager<T> {
|
||||
* @param key
|
||||
* 缓存key
|
||||
* @return 缓存对象
|
||||
* @throws WeixinException
|
||||
*/
|
||||
T lookup(String key) throws WeixinException;
|
||||
T lookup(String key);
|
||||
|
||||
/**
|
||||
* 缓存新的对象
|
||||
@ -30,9 +27,8 @@ public interface CacheStorager<T> {
|
||||
*
|
||||
* @param cache
|
||||
* 将要缓存的对象
|
||||
* @throws WeixinException
|
||||
*/
|
||||
void caching(String key, T cache) throws WeixinException;
|
||||
void caching(String key, T cache);
|
||||
|
||||
/**
|
||||
* 移除缓存对象
|
||||
@ -41,10 +37,10 @@ public interface CacheStorager<T> {
|
||||
* 缓存key
|
||||
* @return 移除的对象
|
||||
*/
|
||||
T evict(String key) throws WeixinException;
|
||||
T evict(String key);
|
||||
|
||||
/**
|
||||
* 清除所有缓存对象(<font color="red">请慎重</font>)
|
||||
*/
|
||||
void clear() throws WeixinException;
|
||||
void clear();
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.foxinmy.weixin4j.util.FileUtil;
|
||||
import com.foxinmy.weixin4j.xml.XmlStream;
|
||||
@ -28,7 +27,7 @@ public class FileTokenStorager implements TokenStorager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token lookup(String cacheKey) throws WeixinException {
|
||||
public Token lookup(String cacheKey) {
|
||||
File token_file = new File(String.format("%s/%s.xml", cachePath,
|
||||
cacheKey));
|
||||
try {
|
||||
@ -45,24 +44,24 @@ public class FileTokenStorager implements TokenStorager {
|
||||
}
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
throw new WeixinException(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void caching(String cacheKey, Token token) throws WeixinException {
|
||||
public void caching(String cacheKey, Token token) {
|
||||
try {
|
||||
XmlStream.toXML(
|
||||
token,
|
||||
new FileOutputStream(new File(String.format("%s/%s.xml",
|
||||
cachePath, cacheKey))));
|
||||
} catch (IOException e) {
|
||||
throw new WeixinException(e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token evict(String cacheKey) throws WeixinException {
|
||||
public Token evict(String cacheKey) {
|
||||
Token token = null;
|
||||
File token_file = new File(String.format("%s/%s.xml", cachePath,
|
||||
cacheKey));
|
||||
@ -79,7 +78,7 @@ public class FileTokenStorager implements TokenStorager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() throws WeixinException {
|
||||
public void clear() {
|
||||
File[] files = new File(cachePath).listFiles(new FileFilter() {
|
||||
@Override
|
||||
public boolean accept(File file) {
|
||||
|
||||
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
import com.whalin.MemCached.MemCachedClient;
|
||||
import com.whalin.MemCached.SockIOPool;
|
||||
@ -28,12 +27,12 @@ public class MemcacheTokenStorager implements TokenStorager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token lookup(String cacheKey) throws WeixinException {
|
||||
public Token lookup(String cacheKey) {
|
||||
return (Token) mc.get(cacheKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void caching(String cacheKey, Token token) throws WeixinException {
|
||||
public void caching(String cacheKey, Token token) {
|
||||
if (token.getExpiresIn() > 0) {
|
||||
mc.set(cacheKey, token,
|
||||
new Date(token.getCreateTime() + token.getExpiresIn()
|
||||
@ -44,14 +43,14 @@ public class MemcacheTokenStorager implements TokenStorager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token evict(String cacheKey) throws WeixinException {
|
||||
public Token evict(String cacheKey) {
|
||||
Token token = lookup(cacheKey);
|
||||
mc.delete(cacheKey);
|
||||
return token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() throws WeixinException {
|
||||
public void clear() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@ package com.foxinmy.weixin4j.token;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
|
||||
/**
|
||||
@ -24,7 +23,7 @@ public class MemoryTokenStorager implements TokenStorager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token lookup(String cacheKey) throws WeixinException {
|
||||
public Token lookup(String cacheKey) {
|
||||
Token token = this.CONMAP.get(cacheKey);
|
||||
if (token != null) {
|
||||
if ((token.getCreateTime() + (token.getExpiresIn() * 1000l) - CUTMS) > System
|
||||
@ -36,17 +35,17 @@ public class MemoryTokenStorager implements TokenStorager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void caching(String cacheKey, Token token) throws WeixinException {
|
||||
public void caching(String cacheKey, Token token) {
|
||||
this.CONMAP.put(cacheKey, token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token evict(String cacheKey) throws WeixinException {
|
||||
public Token evict(String cacheKey) {
|
||||
return this.CONMAP.remove(cacheKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() throws WeixinException {
|
||||
public void clear() {
|
||||
this.CONMAP.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,7 +9,6 @@ import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.Pipeline;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.model.Token;
|
||||
|
||||
/**
|
||||
@ -56,7 +55,7 @@ public class RedisTokenStorager implements TokenStorager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token lookup(String cacheKey) throws WeixinException {
|
||||
public Token lookup(String cacheKey) {
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
jedis = jedisPool.getResource();
|
||||
@ -73,7 +72,7 @@ public class RedisTokenStorager implements TokenStorager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void caching(String cacheKey, Token token) throws WeixinException {
|
||||
public void caching(String cacheKey, Token token) {
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
jedis = jedisPool.getResource();
|
||||
@ -112,7 +111,7 @@ public class RedisTokenStorager implements TokenStorager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token evict(String cacheKey) throws WeixinException {
|
||||
public Token evict(String cacheKey) {
|
||||
Token token = lookup(cacheKey);
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
@ -127,7 +126,7 @@ public class RedisTokenStorager implements TokenStorager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() throws WeixinException {
|
||||
public void clear() {
|
||||
Jedis jedis = null;
|
||||
try {
|
||||
jedis = jedisPool.getResource();
|
||||
|
||||
@ -1,158 +0,0 @@
|
||||
package com.foxinmy.weixin4j.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.http.HttpParams;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.model.WeixinPayAccount;
|
||||
import com.foxinmy.weixin4j.token.FileTokenStorager;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
|
||||
/**
|
||||
* 微信配置相关
|
||||
*
|
||||
* @className Weixin4jSettings
|
||||
* @author jinyu(foxinmy@gmail.com)
|
||||
* @date 2016年1月28日
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class Weixin4jSettings {
|
||||
/**
|
||||
* 微信支付账号信息
|
||||
*/
|
||||
private WeixinPayAccount weixinPayAccount;
|
||||
/**
|
||||
* 微信账号信息
|
||||
*/
|
||||
private WeixinAccount weixinAccount;
|
||||
/**
|
||||
* Http参数
|
||||
*/
|
||||
private HttpParams httpParams;
|
||||
/**
|
||||
* token存储方式 默认为FileTokenStorager
|
||||
*/
|
||||
private TokenStorager tokenStorager;
|
||||
/**
|
||||
* 系统临时目录
|
||||
*/
|
||||
private String tmpdir;
|
||||
/**
|
||||
* 支付接口需要的证书文件(*.p12)
|
||||
*/
|
||||
private String certificateFile;
|
||||
|
||||
/**
|
||||
* 默认使用weixin4j.properties配置的信息
|
||||
*/
|
||||
public Weixin4jSettings() {
|
||||
this(JSON.parseObject(Weixin4jConfigUtil.getValue("account"), WeixinPayAccount.class), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付代理接口
|
||||
*
|
||||
* @param weixinPayAccount
|
||||
* 商户信息
|
||||
* @param certificateFile
|
||||
* 支付接口需要的证书文件(*.p12),比如退款接口
|
||||
*/
|
||||
public Weixin4jSettings(WeixinPayAccount weixinPayAccount, String certificateFile) {
|
||||
this(weixinPayAccount);
|
||||
this.certificateFile = certificateFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付代理接口
|
||||
*
|
||||
* @param weixinPayAccount
|
||||
* 商户信息
|
||||
*/
|
||||
public Weixin4jSettings(WeixinPayAccount weixinPayAccount) {
|
||||
this.weixinPayAccount = weixinPayAccount;
|
||||
this.weixinAccount = new WeixinAccount(weixinPayAccount.getId(), weixinPayAccount.getSecret());
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通代理接口
|
||||
*
|
||||
* @param weixinAccount
|
||||
*/
|
||||
public Weixin4jSettings(WeixinAccount weixinAccount) {
|
||||
this.weixinAccount = weixinAccount;
|
||||
}
|
||||
|
||||
public WeixinPayAccount getWeixinPayAccount() {
|
||||
return weixinPayAccount;
|
||||
}
|
||||
|
||||
public WeixinAccount getWeixinAccount() {
|
||||
return weixinAccount;
|
||||
}
|
||||
|
||||
public HttpParams getHttpParams() {
|
||||
return httpParams;
|
||||
}
|
||||
|
||||
public HttpParams getHttpParams0() {
|
||||
if (httpParams == null) {
|
||||
return new HttpParams();
|
||||
}
|
||||
return httpParams;
|
||||
}
|
||||
|
||||
public String getTmpdir() {
|
||||
return tmpdir;
|
||||
}
|
||||
|
||||
public String getTmpdir0() {
|
||||
if (StringUtil.isBlank(tmpdir)) {
|
||||
return Weixin4jConfigUtil.getClassPathValue("weixin4j.tmpdir", System.getProperty("java.io.tmpdir"));
|
||||
}
|
||||
return tmpdir;
|
||||
}
|
||||
|
||||
public TokenStorager getTokenStorager() {
|
||||
return tokenStorager;
|
||||
}
|
||||
|
||||
public TokenStorager getTokenStorager0() {
|
||||
if (tokenStorager == null) {
|
||||
return new FileTokenStorager(getTmpdir0());
|
||||
}
|
||||
return tokenStorager;
|
||||
}
|
||||
|
||||
public String getCertificateFile() {
|
||||
return certificateFile;
|
||||
}
|
||||
|
||||
public String getCertificateFile0() {
|
||||
if (StringUtil.isBlank(certificateFile)) {
|
||||
return Weixin4jConfigUtil.getClassPathValue("weixin4j.certificate.file", "classpath:ca.p12");
|
||||
}
|
||||
return certificateFile;
|
||||
}
|
||||
|
||||
public void setHttpParams(HttpParams httpParams) {
|
||||
this.httpParams = httpParams;
|
||||
}
|
||||
|
||||
public void setTmpdir(String tmpdir) {
|
||||
this.tmpdir = tmpdir;
|
||||
}
|
||||
|
||||
public void setTokenStorager(TokenStorager tokenStorager) {
|
||||
this.tokenStorager = tokenStorager;
|
||||
}
|
||||
|
||||
public void setCertificateFile(String certificateFile) {
|
||||
this.certificateFile = certificateFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Weixin4jSettings [weixinAccount=" + weixinAccount + ", httpParams=" + httpParams + ",tokenStorager="
|
||||
+ tokenStorager + ", tmpdir=" + tmpdir + ", certificateFile= " + certificateFile + "]";
|
||||
}
|
||||
}
|
||||
@ -21,12 +21,12 @@ import com.foxinmy.weixin4j.payment.mch.Order;
|
||||
import com.foxinmy.weixin4j.payment.mch.PrePay;
|
||||
import com.foxinmy.weixin4j.payment.mch.RefundRecord;
|
||||
import com.foxinmy.weixin4j.payment.mch.RefundResult;
|
||||
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.sign.WeixinPaymentSignature;
|
||||
import com.foxinmy.weixin4j.sign.WeixinSignature;
|
||||
import com.foxinmy.weixin4j.type.IdQuery;
|
||||
import com.foxinmy.weixin4j.type.IdType;
|
||||
import com.foxinmy.weixin4j.type.TradeType;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jSettings;
|
||||
|
||||
/**
|
||||
* 支付测试(商户平台)
|
||||
|
||||
@ -50,6 +50,7 @@ import com.foxinmy.weixin4j.mp.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.mp.type.DatacubeType;
|
||||
import com.foxinmy.weixin4j.mp.type.IndustryType;
|
||||
import com.foxinmy.weixin4j.mp.type.Lang;
|
||||
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.tuple.MassTuple;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
@ -57,7 +58,6 @@ import com.foxinmy.weixin4j.tuple.MpVideo;
|
||||
import com.foxinmy.weixin4j.tuple.Tuple;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.foxinmy.weixin4j.type.TicketType;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jSettings;
|
||||
|
||||
/**
|
||||
* 微信公众平台接口实现
|
||||
@ -138,11 +138,11 @@ public class WeixinProxy {
|
||||
*
|
||||
* @param settings
|
||||
* 微信配置信息
|
||||
* @see com.foxinmy.weixin4j.util.Weixin4jSettings
|
||||
* @see com.foxinmy.weixin4j.setting.Weixin4jSettings
|
||||
*/
|
||||
public WeixinProxy(Weixin4jSettings settings) {
|
||||
this(new TokenHolder(new WeixinTokenCreator(settings.getWeixinAccount()
|
||||
.getId(), settings.getWeixinAccount().getSecret()),
|
||||
this(new TokenHolder(new WeixinTokenCreator(settings.getAccount()
|
||||
.getId(), settings.getAccount().getSecret()),
|
||||
settings.getTokenStorager0()));
|
||||
this.settings = settings;
|
||||
}
|
||||
@ -175,7 +175,7 @@ public class WeixinProxy {
|
||||
* @return
|
||||
*/
|
||||
public WeixinAccount getWeixinAccount() {
|
||||
return this.settings.getWeixinAccount();
|
||||
return this.settings.getAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,8 +6,8 @@ import org.junit.Test;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.mp.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jSettings;
|
||||
|
||||
/**
|
||||
* token测试
|
||||
@ -26,7 +26,7 @@ public class TokenTest {
|
||||
public void setUp() {
|
||||
this.settings = new Weixin4jSettings();
|
||||
tokenHolder = new TokenHolder(new WeixinTokenCreator(settings
|
||||
.getWeixinAccount().getId(), settings.getWeixinAccount()
|
||||
.getAccount().getId(), settings.getAccount()
|
||||
.getSecret()), settings.getTokenStorager0());
|
||||
}
|
||||
|
||||
|
||||
@ -46,11 +46,11 @@ import com.foxinmy.weixin4j.qy.type.ChatType;
|
||||
import com.foxinmy.weixin4j.qy.type.InviteType;
|
||||
import com.foxinmy.weixin4j.qy.type.KfType;
|
||||
import com.foxinmy.weixin4j.qy.type.UserStatus;
|
||||
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.tuple.MpArticle;
|
||||
import com.foxinmy.weixin4j.type.MediaType;
|
||||
import com.foxinmy.weixin4j.type.TicketType;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jSettings;
|
||||
|
||||
/**
|
||||
* 微信企业号接口实现
|
||||
@ -123,11 +123,11 @@ public class WeixinProxy {
|
||||
*
|
||||
* @param settings
|
||||
* 微信配置信息
|
||||
* @see com.foxinmy.weixin4j.util.Weixin4jSettings
|
||||
* @see com.foxinmy.weixin4j.setting.Weixin4jSettings
|
||||
*/
|
||||
public WeixinProxy(Weixin4jSettings settings) {
|
||||
this(new TokenHolder(
|
||||
new WeixinTokenCreator(settings.getWeixinAccount().getId(), settings.getWeixinAccount().getSecret()),
|
||||
this(new TokenHolder(new WeixinTokenCreator(settings.getAccount()
|
||||
.getId(), settings.getAccount().getSecret()),
|
||||
settings.getTokenStorager0()));
|
||||
this.settings = settings;
|
||||
}
|
||||
@ -144,15 +144,17 @@ public class WeixinProxy {
|
||||
* @see com.foxinmy.weixin4j.qy.api.SuiteApi
|
||||
* @see WeixinSuiteProxy#getWeixinProxy(String, String)
|
||||
*/
|
||||
public WeixinProxy(SuitePerCodeHolder perCodeHolder, TokenHolder suiteTokenHolder) {
|
||||
this(new TokenHolder(new WeixinTokenSuiteCreator(perCodeHolder, suiteTokenHolder),
|
||||
perCodeHolder.getTokenStorager()));
|
||||
this.settings = new Weixin4jSettings(new WeixinAccount(perCodeHolder.getAuthCorpId(), null));
|
||||
public WeixinProxy(SuitePerCodeHolder perCodeHolder,
|
||||
TokenHolder suiteTokenHolder) {
|
||||
this(new TokenHolder(new WeixinTokenSuiteCreator(perCodeHolder,
|
||||
suiteTokenHolder), perCodeHolder.getTokenStorager()));
|
||||
this.settings = new Weixin4jSettings(new WeixinAccount(
|
||||
perCodeHolder.getAuthCorpId(), null));
|
||||
}
|
||||
|
||||
/**
|
||||
* 注意:TokenCreator 需为
|
||||
* <font color="red">WeixinTokenCreator或WeixinTokenSuiteCreator</font>
|
||||
* 注意:TokenCreator 需为 <font
|
||||
* color="red">WeixinTokenCreator或WeixinTokenSuiteCreator</font>
|
||||
*
|
||||
* @see com.foxinmy.weixin4j.qy.token.WeixinTokenCreator
|
||||
* @param tokenHolder
|
||||
@ -186,7 +188,7 @@ public class WeixinProxy {
|
||||
* @return
|
||||
*/
|
||||
public WeixinAccount getWeixinAccount() {
|
||||
return this.settings.getWeixinAccount();
|
||||
return this.settings.getAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -197,7 +199,8 @@ public class WeixinProxy {
|
||||
* @return
|
||||
*/
|
||||
public TokenHolder getTicketHolder(TicketType ticketType) {
|
||||
return new TokenHolder(new WeixinTicketCreator(getWeixinAccount().getId(), ticketType, this.tokenHolder),
|
||||
return new TokenHolder(new WeixinTicketCreator(getWeixinAccount()
|
||||
.getId(), ticketType, this.tokenHolder),
|
||||
this.settings.getTokenStorager0());
|
||||
}
|
||||
|
||||
@ -212,8 +215,7 @@ public class WeixinProxy {
|
||||
* @param message
|
||||
* 客服消息对象
|
||||
* @return 如果对应用或收件人、部门、标签任何一个无权限,则本次发送失败;如果收件人、部门或标签不存在,发送仍然执行,但返回无效的部分
|
||||
* </br>
|
||||
* { "errcode": 0, "errmsg": "ok", "invaliduser": "UserID1",
|
||||
* </br> { "errcode": 0, "errmsg": "ok", "invaliduser": "UserID1",
|
||||
* "invalidparty":"PartyID1", "invalidtag":"TagID1" }
|
||||
* @throws WeixinException
|
||||
* @see com.foxinmy.weixin4j.qy.api.NotifyApi
|
||||
@ -232,7 +234,8 @@ public class WeixinProxy {
|
||||
* @see com.foxinmy.weixin4j.tuple.MpNews
|
||||
* @see com.foxinmy.weixin4j.qy.model.IdParameter
|
||||
*/
|
||||
public IdParameter sendNotifyMessage(NotifyMessage message) throws WeixinException {
|
||||
public IdParameter sendNotifyMessage(NotifyMessage message)
|
||||
throws WeixinException {
|
||||
return notifyApi.sendNotifyMessage(message);
|
||||
}
|
||||
|
||||
@ -254,7 +257,8 @@ public class WeixinProxy {
|
||||
* @see com.foxinmy.weixin4j.qy.message.CustomeMessage
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult sendCustomeMessage(CustomeMessage message) throws WeixinException {
|
||||
public JsonResult sendCustomeMessage(CustomeMessage message)
|
||||
throws WeixinException {
|
||||
return notifyApi.sendCustomeMessage(message);
|
||||
}
|
||||
|
||||
@ -290,7 +294,8 @@ public class WeixinProxy {
|
||||
* 创建自定义菜单</a>
|
||||
* @see com.foxinmy.weixin4j.model.Button
|
||||
*/
|
||||
public JsonResult createMenu(int agentid, List<Button> buttons) throws WeixinException {
|
||||
public JsonResult createMenu(int agentid, List<Button> buttons)
|
||||
throws WeixinException {
|
||||
return menuApi.createMenu(agentid, buttons);
|
||||
}
|
||||
|
||||
@ -342,7 +347,8 @@ public class WeixinProxy {
|
||||
* @see com.foxinmy.weixin4j.qy.api.MediaApi
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String uploadImage(InputStream is, String fileName) throws WeixinException {
|
||||
public String uploadImage(InputStream is, String fileName)
|
||||
throws WeixinException {
|
||||
return mediaApi.uploadImage(is, fileName);
|
||||
}
|
||||
|
||||
@ -370,7 +376,8 @@ public class WeixinProxy {
|
||||
* 上传永久素材文件说明</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public MediaUploadResult uploadMedia(int agentid, InputStream is, String fileName) throws WeixinException {
|
||||
public MediaUploadResult uploadMedia(int agentid, InputStream is,
|
||||
String fileName) throws WeixinException {
|
||||
return mediaApi.uploadMedia(agentid, is, fileName);
|
||||
}
|
||||
|
||||
@ -392,7 +399,8 @@ public class WeixinProxy {
|
||||
* 获取永久媒体说明</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public MediaDownloadResult downloadMedia(int agentid, String mediaId) throws WeixinException {
|
||||
public MediaDownloadResult downloadMedia(int agentid, String mediaId)
|
||||
throws WeixinException {
|
||||
return mediaApi.downloadMedia(agentid, mediaId);
|
||||
}
|
||||
|
||||
@ -415,7 +423,8 @@ public class WeixinProxy {
|
||||
* 上传永久媒体素材</a>
|
||||
* @see com.foxinmy.weixin4j.tuple.MpArticle
|
||||
*/
|
||||
public String uploadMaterialArticle(int agentid, List<MpArticle> articles) throws WeixinException {
|
||||
public String uploadMaterialArticle(int agentid, List<MpArticle> articles)
|
||||
throws WeixinException {
|
||||
return mediaApi.uploadMaterialArticle(agentid, articles);
|
||||
}
|
||||
|
||||
@ -433,7 +442,8 @@ public class WeixinProxy {
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E5%88%A0%E9%99%A4%E6%B0%B8%E4%B9%85%E7%B4%A0%E6%9D%90">
|
||||
* 删除永久媒体素材</a>
|
||||
*/
|
||||
public JsonResult deleteMaterialMedia(int agentid, String mediaId) throws WeixinException {
|
||||
public JsonResult deleteMaterialMedia(int agentid, String mediaId)
|
||||
throws WeixinException {
|
||||
return mediaApi.deleteMaterialMedia(agentid, mediaId);
|
||||
}
|
||||
|
||||
@ -450,7 +460,8 @@ public class WeixinProxy {
|
||||
* @see com.foxinmy.weixin4j.qy.api.MediaApi
|
||||
* @see com.foxinmy.weixin4j.tuple.MpArticle
|
||||
*/
|
||||
public List<MpArticle> downloadArticle(int agentid, String mediaId) throws WeixinException {
|
||||
public List<MpArticle> downloadArticle(int agentid, String mediaId)
|
||||
throws WeixinException {
|
||||
return mediaApi.downloadArticle(agentid, mediaId);
|
||||
}
|
||||
|
||||
@ -471,7 +482,8 @@ public class WeixinProxy {
|
||||
* 修改永久媒体素材</a>
|
||||
* @see com.foxinmy.weixin4j.tuple.MpArticle
|
||||
*/
|
||||
public String updateMaterialArticle(int agentid, String mediaId, List<MpArticle> articles) throws WeixinException {
|
||||
public String updateMaterialArticle(int agentid, String mediaId,
|
||||
List<MpArticle> articles) throws WeixinException {
|
||||
return mediaApi.updateMaterialArticle(agentid, mediaId, articles);
|
||||
}
|
||||
|
||||
@ -513,7 +525,8 @@ public class WeixinProxy {
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E8%8E%B7%E5%8F%96%E7%B4%A0%E6%9D%90%E5%88%97%E8%A1%A8">
|
||||
* 获取素材列表</a>
|
||||
*/
|
||||
public MediaRecord listMaterialMedia(int agentid, MediaType mediaType, Pageable pageable) throws WeixinException {
|
||||
public MediaRecord listMaterialMedia(int agentid, MediaType mediaType,
|
||||
Pageable pageable) throws WeixinException {
|
||||
return mediaApi.listMaterialMedia(agentid, mediaType, pageable);
|
||||
}
|
||||
|
||||
@ -529,7 +542,8 @@ public class WeixinProxy {
|
||||
* @see {@link #listMaterialMedia(int,MediaType, Pageable)}
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public List<MediaItem> listAllMaterialMedia(int agentid, MediaType mediaType) throws WeixinException {
|
||||
public List<MediaItem> listAllMaterialMedia(int agentid, MediaType mediaType)
|
||||
throws WeixinException {
|
||||
return mediaApi.listAllMaterialMedia(agentid, mediaType);
|
||||
}
|
||||
|
||||
@ -614,7 +628,8 @@ public class WeixinProxy {
|
||||
* @return 上传后的mediaId
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String batchUploadParties(List<Party> parties) throws WeixinException {
|
||||
public String batchUploadParties(List<Party> parties)
|
||||
throws WeixinException {
|
||||
return mediaApi.batchUploadParties(parties);
|
||||
}
|
||||
|
||||
@ -650,7 +665,8 @@ public class WeixinProxy {
|
||||
* @return 处理结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult createUser(User user, InputStream avatar) throws WeixinException {
|
||||
public JsonResult createUser(User user, InputStream avatar)
|
||||
throws WeixinException {
|
||||
return userApi.createUser(user, avatar);
|
||||
}
|
||||
|
||||
@ -686,7 +702,8 @@ public class WeixinProxy {
|
||||
* @return 处理结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult updateUser(User user, InputStream avatar) throws WeixinException {
|
||||
public JsonResult updateUser(User user, InputStream avatar)
|
||||
throws WeixinException {
|
||||
return userApi.updateUser(user, avatar);
|
||||
}
|
||||
|
||||
@ -765,8 +782,8 @@ public class WeixinProxy {
|
||||
* @return 成员列表
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public List<User> listUser(int partyId, boolean fetchChild, UserStatus userStatus, boolean findDetail)
|
||||
throws WeixinException {
|
||||
public List<User> listUser(int partyId, boolean fetchChild,
|
||||
UserStatus userStatus, boolean findDetail) throws WeixinException {
|
||||
return userApi.listUser(partyId, fetchChild, userStatus, findDetail);
|
||||
}
|
||||
|
||||
@ -812,7 +829,8 @@ public class WeixinProxy {
|
||||
* @return 处理结果
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult batchDeleteUser(List<String> userIds) throws WeixinException {
|
||||
public JsonResult batchDeleteUser(List<String> userIds)
|
||||
throws WeixinException {
|
||||
return userApi.batchDeleteUser(userIds);
|
||||
}
|
||||
|
||||
@ -830,7 +848,8 @@ public class WeixinProxy {
|
||||
* 邀请成员关注说明</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public InviteType inviteUser(String userId, String tips) throws WeixinException {
|
||||
public InviteType inviteUser(String userId, String tips)
|
||||
throws WeixinException {
|
||||
return userApi.inviteUser(userId, tips);
|
||||
}
|
||||
|
||||
@ -838,9 +857,8 @@ public class WeixinProxy {
|
||||
* 创建标签(创建的标签属于管理组;默认为未加锁状态)
|
||||
*
|
||||
* @param tag
|
||||
* 标签对象;</br>
|
||||
* 标签名称,长度为1~64个字节,标签名不可与其他标签重名;</br>
|
||||
* 标签id,整型, 指定此参数时新增的标签会生成对应的标签id,不指定时则以目前最大的id自增。
|
||||
* 标签对象;</br> 标签名称,长度为1~64个字节,标签名不可与其他标签重名;</br> 标签id,整型,
|
||||
* 指定此参数时新增的标签会生成对应的标签id,不指定时则以目前最大的id自增。
|
||||
* @see <a href=
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%A0%87%E7%AD%BE#.E5.88.9B.E5.BB.BA.E6.A0.87.E7.AD.BE">
|
||||
* 创建标签说明</a>
|
||||
@ -910,8 +928,8 @@ public class WeixinProxy {
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%A0%87%E7%AD%BE#.E8.8E.B7.E5.8F.96.E6.A0.87.E7.AD.BE.E6.88.90.E5.91.98">
|
||||
* 获取标签成员说明</a>
|
||||
* @see com.foxinmy.weixin4j.qy.api.TagApi
|
||||
* @return 成员列表<font color="red">Contacts#getUsers</font>和部门列表
|
||||
* <font color="red">Contacts#getPartyIds</font>
|
||||
* @return 成员列表<font color="red">Contacts#getUsers</font>和部门列表 <font
|
||||
* color="red">Contacts#getPartyIds</font>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public Contacts getTagUsers(int tagId) throws WeixinException {
|
||||
@ -935,7 +953,8 @@ public class WeixinProxy {
|
||||
* @return 非法的userIds和partyIds
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public IdParameter addTagUsers(int tagId, List<String> userIds, List<Integer> partyIds) throws WeixinException {
|
||||
public IdParameter addTagUsers(int tagId, List<String> userIds,
|
||||
List<Integer> partyIds) throws WeixinException {
|
||||
return tagApi.addTagUsers(tagId, userIds, partyIds);
|
||||
}
|
||||
|
||||
@ -956,7 +975,8 @@ public class WeixinProxy {
|
||||
* @return 非法的userIds和partyIds
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public IdParameter deleteTagUsers(int tagId, List<String> userIds, List<Integer> partyIds) throws WeixinException {
|
||||
public IdParameter deleteTagUsers(int tagId, List<String> userIds,
|
||||
List<Integer> partyIds) throws WeixinException {
|
||||
return tagApi.deleteTagUsers(tagId, userIds, partyIds);
|
||||
}
|
||||
|
||||
@ -1041,7 +1061,8 @@ public class WeixinProxy {
|
||||
* 邀请成员关注</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String batchInviteUser(IdParameter parameter, Callback callback, String tips) throws WeixinException {
|
||||
public String batchInviteUser(IdParameter parameter, Callback callback,
|
||||
String tips) throws WeixinException {
|
||||
return batchApi.inviteUser(parameter, callback, tips);
|
||||
}
|
||||
|
||||
@ -1049,8 +1070,7 @@ public class WeixinProxy {
|
||||
* 批量更新成员,本接口以userid为主键,增量更新企业号通讯录成员。
|
||||
* <p>
|
||||
* 1.模板中的部门需填写部门ID,多个部门用分号分隔,部门ID必须为数字</br>
|
||||
* 2.文件中存在、通讯录中也存在的成员,更新成员在文件中指定的字段值 </br>
|
||||
* 3.文件中存在、通讯录中不存在的成员,执行添加操作</br>
|
||||
* 2.文件中存在、通讯录中也存在的成员,更新成员在文件中指定的字段值 </br> 3.文件中存在、通讯录中不存在的成员,执行添加操作</br>
|
||||
* 4.通讯录中存在、文件中不存在的成员,保持不变</br>
|
||||
* </p>
|
||||
*
|
||||
@ -1066,15 +1086,15 @@ public class WeixinProxy {
|
||||
* 批量更新成员</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String batchSyncUser(String mediaId, Callback callback) throws WeixinException {
|
||||
public String batchSyncUser(String mediaId, Callback callback)
|
||||
throws WeixinException {
|
||||
return batchApi.syncUser(mediaId, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量覆盖成员,本接口以userid为主键,全量覆盖企业号通讯录成员,任务完成后企业号通讯录成员与提交的文件完全保持一致。
|
||||
* <p>
|
||||
* 1.模板中的部门需填写部门ID,多个部门用分号分隔,部门ID必须为数字</br>
|
||||
* 2.文件中存在、通讯录中也存在的成员,完全以文件为准</br>
|
||||
* 1.模板中的部门需填写部门ID,多个部门用分号分隔,部门ID必须为数字</br> 2.文件中存在、通讯录中也存在的成员,完全以文件为准</br>
|
||||
* 3.文件中存在、通讯录中不存在的成员,执行添加操作</br>
|
||||
* 4.通讯录中存在、文件中不存在的成员,执行删除操作。出于安全考虑,如果需要删除的成员多于50人,
|
||||
* 且多于现有人数的20%以上,系统将中止导入并返回相应的错误码
|
||||
@ -1092,7 +1112,8 @@ public class WeixinProxy {
|
||||
* 批量覆盖成员</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String batchReplaceUser(String mediaId, Callback callback) throws WeixinException {
|
||||
public String batchReplaceUser(String mediaId, Callback callback)
|
||||
throws WeixinException {
|
||||
return batchApi.replaceUser(mediaId, callback);
|
||||
}
|
||||
|
||||
@ -1118,8 +1139,7 @@ public class WeixinProxy {
|
||||
/**
|
||||
* 批量覆盖部门,本接口以partyid为键,全量覆盖企业号通讯录组织架构,任务完成后企业号通讯录组织架构与提交的文件完全保持一致。
|
||||
* <p>
|
||||
* 1.文件中存在、通讯录中也存在的部门,执行修改操作</br>
|
||||
* 2.文件中存在、通讯录中不存在的部门,执行添加操作</br>
|
||||
* 1.文件中存在、通讯录中也存在的部门,执行修改操作</br> 2.文件中存在、通讯录中不存在的部门,执行添加操作</br>
|
||||
* 3.文件中不存在、通讯录中存在的部门,当部门为空时,执行删除操作</br>
|
||||
* 4.CSV文件中,部门名称、部门ID、父部门ID为必填字段,部门ID必须为数字;排序为可选字段,置空或填0不修改排序
|
||||
* </p>
|
||||
@ -1136,7 +1156,8 @@ public class WeixinProxy {
|
||||
* 批量覆盖部门</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public String batchReplaceParty(String mediaId, Callback callback) throws WeixinException {
|
||||
public String batchReplaceParty(String mediaId, Callback callback)
|
||||
throws WeixinException {
|
||||
return batchApi.replaceParty(mediaId, callback);
|
||||
}
|
||||
|
||||
@ -1172,7 +1193,8 @@ public class WeixinProxy {
|
||||
* "http://qydev.weixin.qq.com/wiki/index.php?title=Userid%E4%B8%8Eopenid%E4%BA%92%E6%8D%A2%E6%8E%A5%E5%8F%A3">
|
||||
* userid转换成openid</a>
|
||||
*/
|
||||
public String[] userid2openid(String userid, int agentid) throws WeixinException {
|
||||
public String[] userid2openid(String userid, int agentid)
|
||||
throws WeixinException {
|
||||
return userApi.userid2openid(userid, agentid);
|
||||
}
|
||||
|
||||
@ -1246,7 +1268,8 @@ public class WeixinProxy {
|
||||
* 修改会话信息</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult updateChat(ChatInfo chatInfo, String operator, List<String> addUsers, List<String> deleteUsers)
|
||||
public JsonResult updateChat(ChatInfo chatInfo, String operator,
|
||||
List<String> addUsers, List<String> deleteUsers)
|
||||
throws WeixinException {
|
||||
return chatApi.updateChat(chatInfo, operator, addUsers, deleteUsers);
|
||||
}
|
||||
@ -1265,7 +1288,8 @@ public class WeixinProxy {
|
||||
* 退出会话</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult quitChat(String chatId, String operator) throws WeixinException {
|
||||
public JsonResult quitChat(String chatId, String operator)
|
||||
throws WeixinException {
|
||||
return chatApi.quitChat(chatId, operator);
|
||||
}
|
||||
|
||||
@ -1285,7 +1309,8 @@ public class WeixinProxy {
|
||||
* 清除会话未读状态</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult clearChatNotify(String targetId, String owner, ChatType chatType) throws WeixinException {
|
||||
public JsonResult clearChatNotify(String targetId, String owner,
|
||||
ChatType chatType) throws WeixinException {
|
||||
return chatApi.clearChatNotify(targetId, owner, chatType);
|
||||
}
|
||||
|
||||
@ -1303,7 +1328,8 @@ public class WeixinProxy {
|
||||
* @return 列表中不存在的成员,剩余合法成员会继续执行。
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public List<String> setChatMute(List<ChatMute> chatMutes) throws WeixinException {
|
||||
public List<String> setChatMute(List<ChatMute> chatMutes)
|
||||
throws WeixinException {
|
||||
return chatApi.setChatMute(chatMutes);
|
||||
}
|
||||
|
||||
@ -1320,7 +1346,8 @@ public class WeixinProxy {
|
||||
* 发送消息</a>
|
||||
* @throws WeixinException
|
||||
*/
|
||||
public JsonResult sendChatMessage(ChatMessage message) throws WeixinException {
|
||||
public JsonResult sendChatMessage(ChatMessage message)
|
||||
throws WeixinException {
|
||||
return chatApi.sendChatMessage(message);
|
||||
}
|
||||
|
||||
|
||||
@ -59,26 +59,26 @@ public class WeixinSuiteProxy {
|
||||
*/
|
||||
public WeixinSuiteProxy(Weixin4jSuiteSettings suiteSettings) {
|
||||
this.suiteSettings = suiteSettings;
|
||||
if (suiteSettings.getWeixinAccount().getSuiteAccounts() != null) {
|
||||
if (suiteSettings.getAccount().getSuiteAccounts() != null) {
|
||||
this.suiteMap = new HashMap<String, SuiteApi>();
|
||||
for (WeixinAccount suite : suiteSettings.getWeixinAccount()
|
||||
for (WeixinAccount suite : suiteSettings.getAccount()
|
||||
.getSuiteAccounts()) {
|
||||
this.suiteMap.put(suite.getId(), new SuiteApi(
|
||||
new SuiteTicketHolder(suite.getId(), suite.getSecret(),
|
||||
suiteSettings.getTokenStorager0())));
|
||||
this.suiteMap.put(
|
||||
null,
|
||||
suiteMap.get(suiteSettings.getWeixinAccount()
|
||||
suiteMap.get(suiteSettings.getAccount()
|
||||
.getSuiteAccounts().get(0).getId()));
|
||||
}
|
||||
}
|
||||
if (StringUtil.isNotBlank(suiteSettings.getWeixinAccount().getId())
|
||||
&& StringUtil.isNotBlank(suiteSettings.getWeixinAccount()
|
||||
if (StringUtil.isNotBlank(suiteSettings.getAccount().getId())
|
||||
&& StringUtil.isNotBlank(suiteSettings.getAccount()
|
||||
.getProviderSecret())) {
|
||||
this.providerApi = new ProviderApi(new TokenHolder(
|
||||
new WeixinProviderTokenCreator(suiteSettings
|
||||
.getWeixinAccount().getId(), suiteSettings
|
||||
.getWeixinAccount().getProviderSecret()),
|
||||
.getAccount().getId(), suiteSettings
|
||||
.getAccount().getProviderSecret()),
|
||||
suiteSettings.getTokenStorager0()),
|
||||
suiteSettings.getTokenStorager0());
|
||||
}
|
||||
@ -90,7 +90,7 @@ public class WeixinSuiteProxy {
|
||||
* @return
|
||||
*/
|
||||
public WeixinQyAccount getWeixinAccount() {
|
||||
return this.suiteSettings.getWeixinAccount();
|
||||
return this.suiteSettings.getAccount();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -3,11 +3,9 @@ package com.foxinmy.weixin4j.qy.suite;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.foxinmy.weixin4j.http.HttpParams;
|
||||
import com.foxinmy.weixin4j.model.WeixinAccount;
|
||||
import com.foxinmy.weixin4j.qy.model.WeixinQyAccount;
|
||||
import com.foxinmy.weixin4j.token.FileTokenStorager;
|
||||
import com.foxinmy.weixin4j.token.TokenStorager;
|
||||
import com.foxinmy.weixin4j.setting.SystemSettings;
|
||||
import com.foxinmy.weixin4j.util.StringUtil;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
|
||||
@ -20,23 +18,7 @@ import com.foxinmy.weixin4j.util.Weixin4jConfigUtil;
|
||||
* @since JDK 1.6
|
||||
* @see
|
||||
*/
|
||||
public class Weixin4jSuiteSettings {
|
||||
/**
|
||||
* 微信企业号信息
|
||||
*/
|
||||
private final WeixinQyAccount weixinAccount;
|
||||
/**
|
||||
* Http参数
|
||||
*/
|
||||
private HttpParams httpParams;
|
||||
/**
|
||||
* token存储方式 默认为FileTokenStorager
|
||||
*/
|
||||
private TokenStorager tokenStorager;
|
||||
/**
|
||||
* 系统临时目录
|
||||
*/
|
||||
private String tmpdir;
|
||||
public class Weixin4jSuiteSettings extends SystemSettings<WeixinQyAccount> {
|
||||
|
||||
/**
|
||||
* 默认使用weixin4j.properties配置的信息
|
||||
@ -57,68 +39,30 @@ public class Weixin4jSuiteSettings {
|
||||
*/
|
||||
public Weixin4jSuiteSettings(String providerCorpId, String providerSecret,
|
||||
WeixinAccount... suites) {
|
||||
this.weixinAccount = new WeixinQyAccount(providerCorpId, null,
|
||||
Arrays.asList(suites), providerSecret, null);
|
||||
this(new WeixinQyAccount(providerCorpId, null, Arrays.asList(suites),
|
||||
providerSecret, null));
|
||||
}
|
||||
|
||||
private Weixin4jSuiteSettings(WeixinQyAccount weixinAccount) {
|
||||
this.weixinAccount = weixinAccount;
|
||||
}
|
||||
|
||||
public WeixinQyAccount getWeixinAccount() {
|
||||
return weixinAccount;
|
||||
}
|
||||
|
||||
public HttpParams getHttpParams() {
|
||||
return httpParams;
|
||||
}
|
||||
|
||||
public HttpParams getHttpParams0() {
|
||||
if (httpParams == null) {
|
||||
return new HttpParams();
|
||||
}
|
||||
return httpParams;
|
||||
}
|
||||
|
||||
public String getTmpdir() {
|
||||
return tmpdir;
|
||||
/**
|
||||
* 账号信息
|
||||
*
|
||||
* @param account
|
||||
*/
|
||||
private Weixin4jSuiteSettings(WeixinQyAccount account) {
|
||||
super(account);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTmpdir0() {
|
||||
if (StringUtil.isBlank(tmpdir)) {
|
||||
if (StringUtil.isBlank(getTmpdir())) {
|
||||
return Weixin4jConfigUtil.getClassPathValue("weixin4j.tmpdir",
|
||||
System.getProperty("java.io.tmpdir"));
|
||||
}
|
||||
return tmpdir;
|
||||
}
|
||||
|
||||
public TokenStorager getTokenStorager() {
|
||||
return tokenStorager;
|
||||
}
|
||||
|
||||
public TokenStorager getTokenStorager0() {
|
||||
if (tokenStorager == null) {
|
||||
return new FileTokenStorager(getTmpdir0());
|
||||
}
|
||||
return tokenStorager;
|
||||
}
|
||||
|
||||
public void setHttpParams(HttpParams httpParams) {
|
||||
this.httpParams = httpParams;
|
||||
}
|
||||
|
||||
public void setTmpdir(String tmpdir) {
|
||||
this.tmpdir = tmpdir;
|
||||
}
|
||||
|
||||
public void setTokenStorager(TokenStorager tokenStorager) {
|
||||
this.tokenStorager = tokenStorager;
|
||||
return getTmpdir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Weixin4jSuiteSettings [weixinAccount=" + weixinAccount
|
||||
+ ", httpParams=" + httpParams + ",tokenStorager="
|
||||
+ tokenStorager + ", tmpdir=" + tmpdir + "]";
|
||||
return "Weixin4jSuiteSettings [" + super.toString() + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,8 +6,8 @@ import org.junit.Test;
|
||||
|
||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||
import com.foxinmy.weixin4j.qy.token.WeixinTokenCreator;
|
||||
import com.foxinmy.weixin4j.setting.Weixin4jSettings;
|
||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||
import com.foxinmy.weixin4j.util.Weixin4jSettings;
|
||||
|
||||
/**
|
||||
* token测试
|
||||
@ -26,7 +26,7 @@ public class TokenTest {
|
||||
public void setUp() {
|
||||
this.settings = new Weixin4jSettings();
|
||||
tokenHolder = new TokenHolder(new WeixinTokenCreator(settings
|
||||
.getWeixinAccount().getId(), settings.getWeixinAccount()
|
||||
.getAccount().getId(), settings.getAccount()
|
||||
.getSecret()), settings.getTokenStorager0());
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user